scitex 2.1.2__py3-none-any.whl → 2.4.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- scitex/__init__.py +90 -10
- scitex/__main__.py +0 -110
- scitex/__version__.py +1 -1
- scitex/_optional_deps.py +0 -0
- scitex/ai/_gen_ai/_BaseGenAI.py +1 -1
- scitex/ai/classification/examples/timeseries_cv_demo.py +0 -0
- scitex/ai/classification/reporters/_ClassificationReporter.py +1 -1
- scitex/ai/classification/reporters/__init__.py +0 -0
- scitex/ai/classification/reporters/reporter_utils/_Plotter.py +1 -1
- scitex/ai/classification/reporters/reporter_utils/__init__.py +0 -0
- scitex/ai/classification/reporters/reporter_utils/aggregation.py +0 -0
- scitex/ai/classification/reporters/reporter_utils/data_models.py +0 -0
- scitex/ai/classification/reporters/reporter_utils/reporting.py +0 -0
- scitex/ai/classification/reporters/reporter_utils/validation.py +0 -0
- scitex/ai/classification/timeseries/_TimeSeriesBlockingSplit.py +2 -2
- scitex/ai/classification/timeseries/_TimeSeriesCalendarSplit.py +2 -2
- scitex/ai/classification/timeseries/_TimeSeriesSlidingWindowSplit.py +6 -6
- scitex/ai/classification/timeseries/_TimeSeriesSlidingWindowSplit_v01-not-using-n_splits.py +6 -6
- scitex/ai/classification/timeseries/_TimeSeriesStratifiedSplit.py +2 -2
- scitex/ai/classification/timeseries/_normalize_timestamp.py +1 -1
- scitex/ai/feature_extraction/vit.py +1 -1
- scitex/ai/feature_selection/__init__.py +0 -0
- scitex/ai/feature_selection/feature_selection.py +0 -0
- scitex/ai/loss/multi_task_loss.py +1 -1
- scitex/ai/metrics/_calc_bacc.py +0 -0
- scitex/ai/metrics/_calc_bacc_from_conf_mat.py +0 -0
- scitex/ai/metrics/_calc_clf_report.py +0 -0
- scitex/ai/metrics/_calc_conf_mat.py +0 -0
- scitex/ai/metrics/_calc_feature_importance.py +0 -0
- scitex/ai/metrics/_calc_mcc.py +0 -0
- scitex/ai/metrics/_calc_pre_rec_auc.py +0 -0
- scitex/ai/metrics/_calc_roc_auc.py +0 -0
- scitex/ai/metrics/_calc_seizure_prediction_metrics.py +1 -1
- scitex/ai/metrics/_normalize_labels.py +0 -0
- scitex/ai/plt/__init__.py +2 -2
- scitex/ai/plt/_plot_feature_importance.py +1 -1
- scitex/ai/plt/_plot_learning_curve.py +1 -1
- scitex/ai/plt/_plot_optuna_study.py +1 -1
- scitex/ai/plt/_plot_pre_rec_curve.py +1 -1
- scitex/ai/plt/_plot_roc_curve.py +1 -1
- scitex/ai/plt/{_plot_conf_mat.py → _stx_conf_mat.py} +4 -4
- scitex/ai/sampling/undersample.py +1 -1
- scitex/ai/training/_LearningCurveLogger.py +1 -1
- scitex/benchmark/__init__.py +3 -3
- scitex/benchmark/benchmark.py +0 -0
- scitex/benchmark/monitor.py +0 -0
- scitex/benchmark/profiler.py +0 -0
- scitex/browser/__init__.py +0 -0
- scitex/browser/auth/__init__.py +35 -0
- scitex/browser/auth/google.py +381 -0
- scitex/browser/automation/CookieHandler.py +1 -1
- scitex/browser/automation/__init__.py +0 -0
- scitex/browser/collaboration/__init__.py +5 -0
- scitex/browser/collaboration/auth_helpers.py +0 -0
- scitex/browser/collaboration/collaborative_agent.py +0 -0
- scitex/browser/collaboration/credential_manager.py +0 -0
- scitex/browser/collaboration/interactive_panel.py +0 -0
- scitex/browser/collaboration/persistent_browser.py +0 -0
- scitex/browser/collaboration/shared_session.py +0 -0
- scitex/browser/collaboration/standard_interactions.py +0 -0
- scitex/browser/collaboration/visual_feedback.py +0 -0
- scitex/browser/core/BrowserMixin.py +1 -1
- scitex/browser/core/ChromeProfileManager.py +1 -1
- scitex/browser/core/__init__.py +0 -0
- scitex/browser/debugging/_browser_logger.py +1 -1
- scitex/browser/debugging/_highlight_element.py +1 -1
- scitex/browser/debugging/_show_grid.py +1 -1
- scitex/browser/interaction/click_center.py +1 -1
- scitex/browser/interaction/click_with_fallbacks.py +1 -1
- scitex/browser/interaction/close_popups.py +1 -1
- scitex/browser/interaction/fill_with_fallbacks.py +1 -1
- scitex/browser/pdf/__init__.py +0 -0
- scitex/browser/pdf/click_download_for_chrome_pdf_viewer.py +1 -1
- scitex/browser/pdf/detect_chrome_pdf_viewer.py +1 -1
- scitex/browser/remote/CaptchaHandler.py +0 -0
- scitex/browser/remote/ZenRowsAPIClient.py +0 -0
- scitex/browser/remote/__init__.py +0 -0
- scitex/browser/stealth/HumanBehavior.py +1 -1
- scitex/browser/stealth/StealthManager.py +1 -1
- scitex/browser/stealth/__init__.py +0 -0
- scitex/cli/__init__.py +0 -0
- scitex/cli/cloud.py +200 -9
- scitex/cli/main.py +139 -10
- scitex/cli/scholar.py +0 -0
- scitex/cli/security.py +109 -0
- scitex/cli/web.py +409 -0
- scitex/cli/writer.py +270 -0
- scitex/cloud/__init__.py +131 -0
- scitex/cloud/_matplotlib_hook.py +146 -0
- scitex/config/PriorityConfig.py +195 -0
- scitex/config/__init__.py +24 -0
- scitex/db/_delete_duplicates.py +1 -1
- scitex/db/_inspect_optimized.py +0 -0
- scitex/db/_postgresql/_PostgreSQL.py +1 -1
- scitex/db/_sqlite3/_SQLite3.py +1 -1
- scitex/decorators/__init__.py +9 -0
- scitex/dict/_DotDict.py +65 -138
- scitex/dict/__init__.py +1 -0
- scitex/dict/_flatten.py +2 -10
- scitex/dict/_listed_dict.py +2 -3
- scitex/dict/_pop_keys.py +2 -3
- scitex/dict/_replace.py +1 -3
- scitex/dict/_safe_merge.py +6 -16
- scitex/dict/_to_str.py +6 -3
- scitex/dsp/_demo_sig.py +1 -1
- scitex/dsp/_detect_ripples.py +1 -1
- scitex/dsp/_ensure_3d.py +1 -1
- scitex/dsp/_hilbert.py +2 -2
- scitex/dsp/_misc.py +1 -1
- scitex/dsp/_modulation_index.py +2 -2
- scitex/dsp/_pac.py +3 -3
- scitex/dsp/_psd.py +2 -2
- scitex/dsp/_resample.py +1 -1
- scitex/dsp/_transform.py +1 -1
- scitex/dsp/_wavelet.py +2 -2
- scitex/dsp/add_noise.py +1 -1
- scitex/dsp/filt.py +6 -6
- scitex/dsp/norm.py +1 -1
- scitex/dsp/reference.py +1 -1
- scitex/dsp/utils/_differential_bandpass_filters.py +3 -3
- scitex/dsp/utils/_ensure_3d.py +1 -1
- scitex/dsp/utils/_zero_pad.py +1 -1
- scitex/dsp/utils/filter.py +2 -2
- scitex/dt/_normalize_timestamp.py +1 -1
- scitex/gen/_check_host.py +1 -1
- scitex/gen/_deprecated_close.py +3 -3
- scitex/gen/_deprecated_start.py +1 -1
- scitex/gen/_norm.py +2 -2
- scitex/gen/_norm_cache.py +1 -1
- scitex/gen/_symlink.py +1 -1
- scitex/gen/_to_rank.py +1 -1
- scitex/gen/_transpose.py +1 -1
- scitex/git/__init__.py +0 -0
- scitex/git/_branch.py +5 -3
- scitex/git/_clone.py +35 -6
- scitex/git/_commit.py +3 -2
- scitex/git/_constants.py +0 -0
- scitex/git/_init.py +0 -0
- scitex/git/_remote.py +1 -1
- scitex/git/_result.py +0 -0
- scitex/git/_retry.py +0 -0
- scitex/git/_session.py +1 -1
- scitex/git/_types.py +0 -0
- scitex/git/_utils.py +0 -0
- scitex/git/_validation.py +0 -0
- scitex/git/_workflow.py +1 -1
- scitex/io/README.md +65 -1
- scitex/io/__init__.py +12 -0
- scitex/io/_glob.py +1 -1
- scitex/io/_load.py +59 -9
- scitex/io/_load_cache.py +0 -0
- scitex/io/_load_configs.py +9 -4
- scitex/io/_load_modules/_image.py +48 -4
- scitex/io/_load_modules/_pdf.py +95 -32
- scitex/io/_load_modules/_sqlite3.py +1 -1
- scitex/io/_metadata.py +298 -0
- scitex/io/_path.py +2 -2
- scitex/io/_qr_utils.py +75 -0
- scitex/io/_save.py +324 -45
- scitex/io/_save_modules/_image.py +92 -23
- scitex/io/_save_modules/_tex.py +1 -1
- scitex/io/memo.md +2827 -0
- scitex/io/utils/h5_to_zarr.py +1 -1
- scitex/linalg/_distance.py +2 -2
- scitex/linalg/_geometric_median.py +1 -1
- scitex/logging/README.md +1 -1
- scitex/logging/_Tee.py +2 -2
- scitex/logging/_context.py +0 -0
- scitex/logging/_formatters.py +9 -2
- scitex/logging/_handlers.py +0 -0
- scitex/logging/_levels.py +0 -0
- scitex/logging/_logger.py +59 -20
- scitex/logging/_print_capture.py +0 -0
- scitex/ml/__init__.py +1 -1
- scitex/nn/_Filters.py +6 -6
- scitex/nn/_Spectrogram.py +1 -1
- scitex/nn/_Wavelet.py +2 -2
- scitex/pd/_force_df.py +1 -1
- scitex/plt/README.md +26 -1
- scitex/plt/__init__.py +559 -8
- scitex/plt/_subplots/_AxesWrapper.py +2 -1
- scitex/plt/_subplots/_AxisWrapper.py +98 -50
- scitex/plt/_subplots/_AxisWrapperMixins/_AdjustmentMixin.py +93 -4
- scitex/plt/_subplots/_AxisWrapperMixins/_MatplotlibPlotMixin.py +572 -127
- scitex/plt/_subplots/_AxisWrapperMixins/_SeabornMixin.py +49 -8
- scitex/plt/_subplots/_AxisWrapperMixins/_UnitAwareMixin.py +2 -2
- scitex/plt/_subplots/_FigWrapper.py +104 -10
- scitex/plt/_subplots/_SubplotsWrapper.py +471 -26
- scitex/plt/_subplots/_export_as_csv.py +193 -57
- scitex/plt/_subplots/_export_as_csv_formatters/__init__.py +26 -16
- scitex/plt/_subplots/_export_as_csv_formatters/_format_annotate.py +0 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_contourf.py +54 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_hexbin.py +41 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_hist2d.py +41 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_imshow.py +59 -47
- scitex/plt/_subplots/_export_as_csv_formatters/_format_matshow.py +42 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_pie.py +42 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_plot.py +72 -35
- scitex/plt/_subplots/_export_as_csv_formatters/_format_plot_box.py +1 -1
- scitex/plt/_subplots/_export_as_csv_formatters/_format_plot_imshow.py +40 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_plot_kde.py +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/_format_plot_scatter.py +0 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_quiver.py +53 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_stem.py +42 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_step.py +42 -0
- scitex/plt/_subplots/_export_as_csv_formatters/_format_streamplot.py +48 -0
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_conf_mat.py → _format_stx_conf_mat.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_ecdf.py → _format_stx_ecdf.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_fillv.py → _format_stx_fillv.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_heatmap.py → _format_stx_heatmap.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_image.py → _format_stx_image.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_joyplot.py → _format_stx_joyplot.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_line.py → _format_stx_line.py} +3 -3
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_mean_ci.py → _format_stx_mean_ci.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_mean_std.py → _format_stx_mean_std.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_median_iqr.py → _format_stx_median_iqr.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_raster.py → _format_stx_raster.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_rectangle.py → _format_stx_rectangle.py} +1 -1
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_scatter_hist.py → _format_stx_scatter_hist.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_shaded_line.py → _format_stx_shaded_line.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/{_format_plot_violin.py → _format_stx_violin.py} +2 -2
- scitex/plt/_subplots/_export_as_csv_formatters/verify_formatters.py +23 -23
- scitex/plt/ax/__init__.py +25 -16
- scitex/plt/ax/_plot/__init__.py +32 -30
- scitex/plt/ax/_plot/_add_fitted_line.py +151 -0
- scitex/plt/ax/_plot/_plot_statistical_shaded_line.py +104 -76
- scitex/plt/ax/_plot/{_plot_conf_mat.py → _stx_conf_mat.py} +12 -12
- scitex/plt/ax/_plot/_stx_ecdf.py +109 -0
- scitex/plt/ax/_plot/{_plot_fillv.py → _stx_fillv.py} +7 -7
- scitex/plt/ax/_plot/_stx_heatmap.py +366 -0
- scitex/plt/ax/_plot/{_plot_image.py → _stx_image.py} +1 -1
- scitex/plt/ax/_plot/_stx_joyplot.py +113 -0
- scitex/plt/ax/_plot/{_plot_raster.py → _stx_raster.py} +37 -25
- scitex/plt/ax/_plot/{_plot_rectangle.py → _stx_rectangle.py} +10 -9
- scitex/plt/ax/_plot/{_plot_scatter_hist.py → _stx_scatter_hist.py} +1 -1
- scitex/plt/ax/_plot/_stx_shaded_line.py +215 -0
- scitex/plt/ax/_plot/{_plot_violin.py → _stx_violin.py} +13 -6
- scitex/plt/ax/_style/__init__.py +4 -0
- scitex/plt/ax/_style/_auto_scale_axis.py +195 -0
- scitex/plt/ax/_style/_format_units.py +103 -0
- scitex/plt/ax/_style/_set_ticks.py +2 -2
- scitex/plt/ax/_style/_style_barplot.py +69 -0
- scitex/plt/ax/_style/_style_boxplot.py +144 -0
- scitex/plt/ax/_style/_style_errorbar.py +82 -0
- scitex/plt/ax/_style/_style_scatter.py +82 -0
- scitex/plt/ax/_style/_style_suptitles.py +76 -0
- scitex/plt/ax/_style/_style_violinplot.py +109 -0
- scitex/plt/color/_PARAMS.py +2 -2
- scitex/plt/color/_colors.py +1 -1
- scitex/plt/color/_vizualize_colors.py +3 -3
- scitex/plt/styles/SCITEX_STYLE.yaml +104 -0
- scitex/plt/styles/__init__.py +57 -0
- scitex/plt/styles/_plot_defaults.py +209 -0
- scitex/plt/styles/_plot_postprocess.py +518 -0
- scitex/plt/styles/_style_loader.py +268 -0
- scitex/plt/styles/presets.py +208 -0
- scitex/plt/utils/__init__.py +21 -0
- scitex/plt/utils/_calc_bacc_from_conf_mat.py +1 -1
- scitex/plt/utils/_collect_figure_metadata.py +620 -0
- scitex/plt/utils/_colorbar.py +72 -10
- scitex/plt/utils/_configure_mpl.py +194 -68
- scitex/plt/utils/_crop.py +246 -0
- scitex/plt/utils/_dimension_viewer.py +437 -0
- scitex/plt/utils/_figure_from_axes_mm.py +353 -0
- scitex/plt/utils/_figure_mm.py +356 -0
- scitex/plt/utils/_get_actual_font.py +56 -0
- scitex/plt/utils/_units.py +123 -0
- scitex/{rng/README.md → repro/README_RandomStateManager.md} +2 -2
- scitex/{rng → repro}/_RandomStateManager.py +99 -10
- scitex/repro/__init__.py +32 -50
- scitex/repro/_gen_ID.py +84 -0
- scitex/repro/_gen_timestamp.py +78 -0
- scitex/repro/_hash_array.py +143 -0
- scitex/reproduce/__init__.py +2 -2
- scitex/resource/_get_specs.py +1 -1
- scitex/resource/_log_processor_usages.py +4 -4
- scitex/rng/__init__.py +20 -27
- scitex/scholar/auth/core/__init__.py +0 -0
- scitex/scholar/auth/gateway/__init__.py +0 -0
- scitex/scholar/auth/providers/OpenAthensAuthenticator.py +3 -3
- scitex/scholar/auth/providers/__init__.py +0 -0
- scitex/scholar/auth/session/__init__.py +0 -0
- scitex/scholar/auth/sso/BaseSSOAutomator.py +1 -1
- scitex/scholar/auth/sso/__init__.py +0 -0
- scitex/scholar/browser/utils/__init__.py +0 -0
- scitex/scholar/citation_graph/README.md +117 -0
- scitex/scholar/citation_graph/__init__.py +29 -0
- scitex/scholar/citation_graph/builder.py +214 -0
- scitex/scholar/citation_graph/database.py +239 -0
- scitex/scholar/citation_graph/example.py +96 -0
- scitex/scholar/citation_graph/models.py +80 -0
- scitex/scholar/cli/_CentralArgumentParser.py +0 -0
- scitex/scholar/cli/_argument_groups.py +0 -0
- scitex/scholar/cli/_doi_operations.py +0 -0
- scitex/scholar/cli/_url_utils.py +0 -0
- scitex/scholar/cli/handlers/__init__.py +0 -0
- scitex/scholar/cli/handlers/bibtex_handler.py +0 -0
- scitex/scholar/cli/handlers/doi_handler.py +0 -0
- scitex/scholar/cli/handlers/project_handler.py +0 -0
- scitex/scholar/cli/open_browser.py +0 -0
- scitex/scholar/cli/open_browser_auto.py +0 -0
- scitex/scholar/cli/open_browser_monitored.py +0 -0
- scitex/scholar/config/PublisherRules.py +0 -0
- scitex/scholar/config/core/_PathManager.py +42 -0
- scitex/scholar/config/default.yaml +1 -0
- scitex/scholar/core/__init__.py +0 -0
- scitex/scholar/docs/template.py +1 -1
- scitex/scholar/docs/to_claude/guidelines/python/env.md +1 -1
- scitex/scholar/docs/to_claude/guidelines/python/general.md +1 -1
- scitex/scholar/examples/07_storage_integration.py +1 -1
- scitex/scholar/examples/zotero_integration.py +0 -0
- scitex/scholar/impact_factor/estimation/ImpactFactorEstimationEngine.py +0 -0
- scitex/scholar/impact_factor/estimation/__init__.py +0 -0
- scitex/scholar/impact_factor/estimation/build_database.py +0 -0
- scitex/scholar/impact_factor/estimation/core/__init__.py +0 -0
- scitex/scholar/impact_factor/estimation/core/cache_manager.py +0 -0
- scitex/scholar/impact_factor/estimation/core/calculator.py +0 -0
- scitex/scholar/impact_factor/estimation/core/journal_matcher.py +0 -0
- scitex/scholar/impact_factor/jcr/ImpactFactorJCREngine.py +1 -1
- scitex/scholar/impact_factor/jcr/build_database.py +1 -1
- scitex/scholar/integration/__init__.py +0 -0
- scitex/scholar/integration/base.py +0 -0
- scitex/scholar/integration/mendeley/__init__.py +0 -0
- scitex/scholar/integration/mendeley/exporter.py +0 -0
- scitex/scholar/integration/mendeley/importer.py +0 -0
- scitex/scholar/integration/mendeley/linker.py +0 -0
- scitex/scholar/integration/mendeley/mapper.py +0 -0
- scitex/scholar/integration/zotero/__init__.py +0 -0
- scitex/scholar/integration/zotero/__main__.py +0 -0
- scitex/scholar/integration/zotero/exporter.py +0 -0
- scitex/scholar/integration/zotero/importer.py +0 -0
- scitex/scholar/integration/zotero/linker.py +0 -0
- scitex/scholar/integration/zotero/mapper.py +0 -0
- scitex/scholar/metadata_engines/ScholarEngine.py +9 -1
- scitex/scholar/metadata_engines/individual/ArXivEngine.py +4 -1
- scitex/scholar/metadata_engines/individual/CrossRefEngine.py +20 -3
- scitex/scholar/metadata_engines/individual/CrossRefLocalEngine.py +82 -21
- scitex/scholar/metadata_engines/individual/__init__.py +0 -0
- scitex/scholar/metadata_engines/utils/_URLDOIExtractor.py +19 -1
- scitex/scholar/pdf_download/ScholarPDFDownloader.py +1 -1
- scitex/scholar/pdf_download/__init__.py +0 -0
- scitex/scholar/pipelines/ScholarPipelineBibTeX.py +1 -1
- scitex/scholar/pipelines/ScholarPipelineMetadataParallel.py +0 -0
- scitex/scholar/pipelines/ScholarPipelineMetadataSingle.py +102 -7
- scitex/scholar/pipelines/ScholarPipelineParallel.py +1 -1
- scitex/scholar/pipelines/ScholarPipelineSearchParallel.py +9 -6
- scitex/scholar/pipelines/ScholarPipelineSearchSingle.py +9 -6
- scitex/scholar/pipelines/ScholarPipelineSingle.py +1 -1
- scitex/scholar/pipelines/SearchQueryParser.py +0 -0
- scitex/scholar/pipelines/__init__.py +0 -0
- scitex/scholar/search_engines/ScholarSearchEngine.py +6 -1
- scitex/scholar/search_engines/_BaseSearchEngine.py +0 -0
- scitex/scholar/search_engines/__init__.py +0 -0
- scitex/scholar/search_engines/individual/ArXivSearchEngine.py +0 -0
- scitex/scholar/search_engines/individual/CrossRefSearchEngine.py +0 -0
- scitex/scholar/search_engines/individual/OpenAlexSearchEngine.py +0 -0
- scitex/scholar/search_engines/individual/PubMedSearchEngine.py +0 -0
- scitex/scholar/search_engines/individual/SemanticScholarSearchEngine.py +0 -0
- scitex/scholar/search_engines/individual/__init__.py +0 -0
- scitex/scholar/storage/BibTeXHandler.py +35 -5
- scitex/scholar/storage/PaperIO.py +1 -1
- scitex/scholar/storage/_DeduplicationManager.py +0 -0
- scitex/scholar/storage/_LibraryManager.py +0 -0
- scitex/scholar/storage/__init__.py +0 -0
- scitex/scholar/url_finder/strategies/find_pdf_urls_by_direct_links.py +0 -0
- scitex/scholar/url_finder/strategies/find_pdf_urls_by_dropdown.py +0 -0
- scitex/scholar/url_finder/strategies/find_pdf_urls_by_href.py +0 -0
- scitex/scholar/url_finder/translators/__init__.py +0 -0
- scitex/scholar/url_finder/translators/core/__init__.py +0 -0
- scitex/scholar/url_finder/translators/core/base.py +0 -0
- scitex/scholar/url_finder/translators/core/patterns.py +0 -0
- scitex/scholar/url_finder/translators/individual/BOFiP_Impots.py +0 -0
- scitex/scholar/url_finder/translators/individual/Baidu_Scholar.py +0 -0
- scitex/scholar/url_finder/translators/individual/Bangkok_Post.py +0 -0
- scitex/scholar/url_finder/translators/individual/Baruch_Foundation.py +0 -0
- scitex/scholar/url_finder/translators/individual/Beobachter.py +0 -0
- scitex/scholar/url_finder/translators/individual/Bezneng_Gajit.py +0 -0
- scitex/scholar/url_finder/translators/individual/BibLaTeX.py +0 -0
- scitex/scholar/url_finder/translators/individual/BibTeX.py +0 -0
- scitex/scholar/url_finder/translators/individual/Biblio_com.py +0 -0
- scitex/scholar/url_finder/translators/individual/Bibliontology_RDF.py +0 -0
- scitex/scholar/url_finder/translators/individual/CLASE.py +0 -0
- scitex/scholar/url_finder/translators/individual/COBISS.py +0 -0
- scitex/scholar/url_finder/translators/individual/COinS.py +0 -0
- scitex/scholar/url_finder/translators/individual/CQ_Press.py +0 -0
- scitex/scholar/url_finder/translators/individual/CROSBI.py +0 -0
- scitex/scholar/url_finder/translators/individual/CSL_JSON.py +0 -0
- scitex/scholar/url_finder/translators/individual/CSV.py +0 -0
- scitex/scholar/url_finder/translators/individual/CalMatters.py +0 -0
- scitex/scholar/url_finder/translators/individual/Calisphere.py +0 -0
- scitex/scholar/url_finder/translators/individual/Camara_Brasileira_do_Livro_ISBN.py +0 -0
- scitex/scholar/url_finder/translators/individual/CanLII.py +0 -0
- scitex/scholar/url_finder/translators/individual/Canada_com.py +0 -0
- scitex/scholar/url_finder/translators/individual/Canadian_Letters_and_Images.py +0 -0
- scitex/scholar/url_finder/translators/individual/Canadiana_ca.py +0 -0
- scitex/scholar/url_finder/translators/individual/Cascadilla_Proceedings_Project.py +0 -0
- scitex/scholar/url_finder/translators/individual/Central_and_Eastern_European_Online_Library_Journals.py +0 -0
- scitex/scholar/url_finder/translators/individual/Champlain_Society_Collection.py +0 -0
- scitex/scholar/url_finder/translators/individual/Chicago_Journal_of_Theoretical_Computer_Science.py +0 -0
- scitex/scholar/url_finder/translators/individual/Christian_Science_Monitor.py +0 -0
- scitex/scholar/url_finder/translators/individual/Columbia_University_Press.py +0 -0
- scitex/scholar/url_finder/translators/individual/Common_Place.py +0 -0
- scitex/scholar/url_finder/translators/individual/Cornell_LII.py +0 -0
- scitex/scholar/url_finder/translators/individual/Cornell_University_Press.py +0 -0
- scitex/scholar/url_finder/translators/individual/CourtListener.py +0 -0
- scitex/scholar/url_finder/translators/individual/DAI_Zenon.py +0 -0
- scitex/scholar/url_finder/translators/individual/__init__.py +0 -0
- scitex/scholar/url_finder/translators/individual/abc_news_australia.py +0 -0
- scitex/scholar/url_finder/translators/individual/access_engineering.py +0 -0
- scitex/scholar/url_finder/translators/individual/access_medicine.py +0 -0
- scitex/scholar/url_finder/translators/individual/access_science.py +0 -0
- scitex/scholar/url_finder/translators/individual/acls_humanities_ebook.py +0 -0
- scitex/scholar/url_finder/translators/individual/aclweb.py +0 -0
- scitex/scholar/url_finder/translators/individual/acm.py +0 -0
- scitex/scholar/url_finder/translators/individual/acm_digital_library.py +0 -0
- scitex/scholar/url_finder/translators/individual/acs.py +0 -0
- scitex/scholar/url_finder/translators/individual/acs_publications.py +0 -0
- scitex/scholar/url_finder/translators/individual/adam_matthew_digital.py +0 -0
- scitex/scholar/url_finder/translators/individual/ads_bibcode.py +0 -0
- scitex/scholar/url_finder/translators/individual/aea_web.py +0 -0
- scitex/scholar/url_finder/translators/individual/agencia_del_isbn.py +0 -0
- scitex/scholar/url_finder/translators/individual/agris.py +0 -0
- scitex/scholar/url_finder/translators/individual/ahval_news.py +0 -0
- scitex/scholar/url_finder/translators/individual/aip.py +0 -0
- scitex/scholar/url_finder/translators/individual/air_university_journals.py +0 -0
- scitex/scholar/url_finder/translators/individual/airiti.py +0 -0
- scitex/scholar/url_finder/translators/individual/alexander_street_press.py +0 -0
- scitex/scholar/url_finder/translators/individual/all_africa.py +0 -0
- scitex/scholar/url_finder/translators/individual/allafrica.py +0 -0
- scitex/scholar/url_finder/translators/individual/alsharekh.py +0 -0
- scitex/scholar/url_finder/translators/individual/alternet.py +0 -0
- scitex/scholar/url_finder/translators/individual/aluka.py +0 -0
- scitex/scholar/url_finder/translators/individual/amazon.py +0 -0
- scitex/scholar/url_finder/translators/individual/american_archive_public_broadcasting.py +0 -0
- scitex/scholar/url_finder/translators/individual/american_institute_aeronautics_astronautics.py +0 -0
- scitex/scholar/url_finder/translators/individual/american_prospect.py +0 -0
- scitex/scholar/url_finder/translators/individual/ams_journals.py +0 -0
- scitex/scholar/url_finder/translators/individual/ams_mathscinet.py +0 -0
- scitex/scholar/url_finder/translators/individual/ams_mathscinet_legacy.py +0 -0
- scitex/scholar/url_finder/translators/individual/ancestry_com_us_federal_census.py +0 -0
- scitex/scholar/url_finder/translators/individual/ancestry_us_federal_census.py +0 -0
- scitex/scholar/url_finder/translators/individual/annual_reviews.py +0 -0
- scitex/scholar/url_finder/translators/individual/antikvarium_hu.py +0 -0
- scitex/scholar/url_finder/translators/individual/aosic.py +0 -0
- scitex/scholar/url_finder/translators/individual/apa_psycnet.py +0 -0
- scitex/scholar/url_finder/translators/individual/apn_ru.py +0 -0
- scitex/scholar/url_finder/translators/individual/aps.py +0 -0
- scitex/scholar/url_finder/translators/individual/aps_physics.py +0 -0
- scitex/scholar/url_finder/translators/individual/aquadocs.py +0 -0
- scitex/scholar/url_finder/translators/individual/archeion.py +0 -0
- scitex/scholar/url_finder/translators/individual/archiv_fuer_sozialgeschichte.py +0 -0
- scitex/scholar/url_finder/translators/individual/ariana_news.py +0 -0
- scitex/scholar/url_finder/translators/individual/art_institute_of_chicago.py +0 -0
- scitex/scholar/url_finder/translators/individual/artefacts_canada.py +0 -0
- scitex/scholar/url_finder/translators/individual/artfl_encyclopedie.py +0 -0
- scitex/scholar/url_finder/translators/individual/artforum.py +0 -0
- scitex/scholar/url_finder/translators/individual/artnet.py +0 -0
- scitex/scholar/url_finder/translators/individual/artnews.py +0 -0
- scitex/scholar/url_finder/translators/individual/artstor.py +0 -0
- scitex/scholar/url_finder/translators/individual/arxiv.py +0 -0
- scitex/scholar/url_finder/translators/individual/asce.py +0 -0
- scitex/scholar/url_finder/translators/individual/asco_meeting_library.py +0 -0
- scitex/scholar/url_finder/translators/individual/astis.py +0 -0
- scitex/scholar/url_finder/translators/individual/atlanta_journal_constitution.py +0 -0
- scitex/scholar/url_finder/translators/individual/ats_international_journal.py +0 -0
- scitex/scholar/url_finder/translators/individual/atypon.py +0 -0
- scitex/scholar/url_finder/translators/individual/atypon_journals.py +0 -0
- scitex/scholar/url_finder/translators/individual/austlii_and_nzlii.py +0 -0
- scitex/scholar/url_finder/translators/individual/australian_dictionary_of_biography.py +0 -0
- scitex/scholar/url_finder/translators/individual/bailii.py +0 -0
- scitex/scholar/url_finder/translators/individual/bbc.py +0 -0
- scitex/scholar/url_finder/translators/individual/bbc_genome.py +0 -0
- scitex/scholar/url_finder/translators/individual/beck_online.py +0 -0
- scitex/scholar/url_finder/translators/individual/biblioteca_nacional_de_maestros.py +0 -0
- scitex/scholar/url_finder/translators/individual/bibliotheque_archives_nationale_quebec_pistard.py +0 -0
- scitex/scholar/url_finder/translators/individual/bibliotheque_archives_nationales_quebec.py +0 -0
- scitex/scholar/url_finder/translators/individual/bibliotheque_et_archives_nationale_du_quebec__pistard_.py +0 -0
- scitex/scholar/url_finder/translators/individual/bibliotheque_et_archives_nationales_du_quebec.py +0 -0
- scitex/scholar/url_finder/translators/individual/bibliotheque_nationale_de_france.py +0 -0
- scitex/scholar/url_finder/translators/individual/bibliotheque_nationale_france.py +0 -0
- scitex/scholar/url_finder/translators/individual/bibsys.py +0 -0
- scitex/scholar/url_finder/translators/individual/bioconductor.py +0 -0
- scitex/scholar/url_finder/translators/individual/biomed_central.py +0 -0
- scitex/scholar/url_finder/translators/individual/bioone.py +0 -0
- scitex/scholar/url_finder/translators/individual/biorxiv.py +0 -0
- scitex/scholar/url_finder/translators/individual/blaetter.py +0 -0
- scitex/scholar/url_finder/translators/individual/blogger.py +0 -0
- scitex/scholar/url_finder/translators/individual/bloomberg.py +0 -0
- scitex/scholar/url_finder/translators/individual/bloomsbury_food_library.py +0 -0
- scitex/scholar/url_finder/translators/individual/bluesky.py +0 -0
- scitex/scholar/url_finder/translators/individual/bnf_isbn.py +0 -0
- scitex/scholar/url_finder/translators/individual/bocc.py +0 -0
- scitex/scholar/url_finder/translators/individual/boe.py +0 -0
- scitex/scholar/url_finder/translators/individual/bookmarks.py +0 -0
- scitex/scholar/url_finder/translators/individual/bookshop_org.py +0 -0
- scitex/scholar/url_finder/translators/individual/boston_review.py +0 -0
- scitex/scholar/url_finder/translators/individual/bosworth_toller_anglo_saxon_dictionary.py +0 -0
- scitex/scholar/url_finder/translators/individual/bosworth_toller_s_anglo_saxon_dictionary_online.py +0 -0
- scitex/scholar/url_finder/translators/individual/bracero_history_archive.py +0 -0
- scitex/scholar/url_finder/translators/individual/brill.py +0 -0
- scitex/scholar/url_finder/translators/individual/brukerhandboken.py +0 -0
- scitex/scholar/url_finder/translators/individual/bryn_mawr_classical_review.py +0 -0
- scitex/scholar/url_finder/translators/individual/bundesgesetzblatt.py +0 -0
- scitex/scholar/url_finder/translators/individual/business_standard.py +0 -0
- scitex/scholar/url_finder/translators/individual/cabi___cab_abstracts.py +0 -0
- scitex/scholar/url_finder/translators/individual/cabi_cab_abstracts.py +0 -0
- scitex/scholar/url_finder/translators/individual/cairn.py +0 -0
- scitex/scholar/url_finder/translators/individual/cairn_info.py +0 -0
- scitex/scholar/url_finder/translators/individual/cambridge.py +0 -0
- scitex/scholar/url_finder/translators/individual/cambridge_core.py +0 -0
- scitex/scholar/url_finder/translators/individual/cambridge_engage_preprints.py +0 -0
- scitex/scholar/url_finder/translators/individual/caod.py +0 -0
- scitex/scholar/url_finder/translators/individual/cbc.py +0 -0
- scitex/scholar/url_finder/translators/individual/ccfr__bnf_.py +0 -0
- scitex/scholar/url_finder/translators/individual/ccfr_bnf.py +0 -0
- scitex/scholar/url_finder/translators/individual/cell_press.py +0 -0
- scitex/scholar/url_finder/translators/individual/cern_document_server.py +0 -0
- scitex/scholar/url_finder/translators/individual/ceur_workshop_proceedings.py +0 -0
- scitex/scholar/url_finder/translators/individual/cff.py +0 -0
- scitex/scholar/url_finder/translators/individual/cff_references.py +0 -0
- scitex/scholar/url_finder/translators/individual/champlain_society___collection.py +0 -0
- scitex/scholar/url_finder/translators/individual/chronicling_america.py +0 -0
- scitex/scholar/url_finder/translators/individual/cia_world_factbook.py +0 -0
- scitex/scholar/url_finder/translators/individual/cinii_research.py +0 -0
- scitex/scholar/url_finder/translators/individual/citavi_5_xml.py +0 -0
- scitex/scholar/url_finder/translators/individual/citeseer.py +0 -0
- scitex/scholar/url_finder/translators/individual/citizen_lab.py +0 -0
- scitex/scholar/url_finder/translators/individual/civilization_ca.py +0 -0
- scitex/scholar/url_finder/translators/individual/clacso.py +0 -0
- scitex/scholar/url_finder/translators/individual/climate_change_and_human_health_literature_portal.py +0 -0
- scitex/scholar/url_finder/translators/individual/climate_change_human_health.py +0 -0
- scitex/scholar/url_finder/translators/individual/clinical_key.py +0 -0
- scitex/scholar/url_finder/translators/individual/clinicaltrials_gov.py +0 -0
- scitex/scholar/url_finder/translators/individual/cnki.py +0 -0
- scitex/scholar/url_finder/translators/individual/code4lib_journal.py +0 -0
- scitex/scholar/url_finder/translators/individual/colorado_state_legislature.py +0 -0
- scitex/scholar/url_finder/translators/individual/computer_history_museum_archive.py +0 -0
- scitex/scholar/url_finder/translators/individual/copernicus.py +0 -0
- scitex/scholar/url_finder/translators/individual/crossref_rest.py +0 -0
- scitex/scholar/url_finder/translators/individual/crossref_unixref_xml.py +0 -0
- scitex/scholar/url_finder/translators/individual/csiro_publishing.py +0 -0
- scitex/scholar/url_finder/translators/individual/csiro_publishing_dup.py +0 -0
- scitex/scholar/url_finder/translators/individual/current_affairs.py +0 -0
- scitex/scholar/url_finder/translators/individual/dabi.py +0 -0
- scitex/scholar/url_finder/translators/individual/dagens_nyheter.py +0 -0
- scitex/scholar/url_finder/translators/individual/dagstuhl.py +0 -0
- scitex/scholar/url_finder/translators/individual/dagstuhl_research_online_publication_server.py +0 -0
- scitex/scholar/url_finder/translators/individual/dar_almandumah.py +0 -0
- scitex/scholar/url_finder/translators/individual/dart_europe.py +0 -0
- scitex/scholar/url_finder/translators/individual/data_gov.py +0 -0
- scitex/scholar/url_finder/translators/individual/databrary.py +0 -0
- scitex/scholar/url_finder/translators/individual/datacite_json.py +0 -0
- scitex/scholar/url_finder/translators/individual/dataverse.py +0 -0
- scitex/scholar/url_finder/translators/individual/daum_news.py +0 -0
- scitex/scholar/url_finder/translators/individual/dblp.py +0 -0
- scitex/scholar/url_finder/translators/individual/dblp_computer_science_bibliography.py +0 -0
- scitex/scholar/url_finder/translators/individual/dbpia.py +0 -0
- scitex/scholar/url_finder/translators/individual/de_gruyter_brill.py +0 -0
- scitex/scholar/url_finder/translators/individual/defense_technical_information_center.py +0 -0
- scitex/scholar/url_finder/translators/individual/dejure_org.py +0 -0
- scitex/scholar/url_finder/translators/individual/delpher.py +0 -0
- scitex/scholar/url_finder/translators/individual/demographic_research.py +0 -0
- scitex/scholar/url_finder/translators/individual/denik_cz.py +0 -0
- scitex/scholar/url_finder/translators/individual/depatisnet.py +0 -0
- scitex/scholar/url_finder/translators/individual/der_freitag.py +0 -0
- scitex/scholar/url_finder/translators/individual/der_spiegel.py +0 -0
- scitex/scholar/url_finder/translators/individual/desiring_god.py +0 -0
- scitex/scholar/url_finder/translators/individual/deutsche_fotothek.py +0 -0
- scitex/scholar/url_finder/translators/individual/deutsche_nationalbibliothek.py +0 -0
- scitex/scholar/url_finder/translators/individual/dhistory.py +0 -0
- scitex/scholar/url_finder/translators/individual/dialnet.py +0 -0
- scitex/scholar/url_finder/translators/individual/die_zeit.py +0 -0
- scitex/scholar/url_finder/translators/individual/digibib_net.py +0 -0
- scitex/scholar/url_finder/translators/individual/digital_humanities_quarterly.py +0 -0
- scitex/scholar/url_finder/translators/individual/digital_spy.py +0 -0
- scitex/scholar/url_finder/translators/individual/digizeitschriften.py +0 -0
- scitex/scholar/url_finder/translators/individual/dimensions.py +0 -0
- scitex/scholar/url_finder/translators/individual/dlibra.py +0 -0
- scitex/scholar/url_finder/translators/individual/doaj.py +0 -0
- scitex/scholar/url_finder/translators/individual/doi.py +0 -0
- scitex/scholar/url_finder/translators/individual/doi_content_negotiation.py +0 -0
- scitex/scholar/url_finder/translators/individual/douban.py +0 -0
- scitex/scholar/url_finder/translators/individual/dpla.py +0 -0
- scitex/scholar/url_finder/translators/individual/dreier_neuerscheinungsdienst.py +0 -0
- scitex/scholar/url_finder/translators/individual/drugbank_ca.py +0 -0
- scitex/scholar/url_finder/translators/individual/dryad.py +0 -0
- scitex/scholar/url_finder/translators/individual/dryad_digital_repository.py +0 -0
- scitex/scholar/url_finder/translators/individual/dspace.py +0 -0
- scitex/scholar/url_finder/translators/individual/dspace_intermediate_metadata.py +0 -0
- scitex/scholar/url_finder/translators/individual/duke_university_press_books.py +0 -0
- scitex/scholar/url_finder/translators/individual/e_periodica_switzerland.py +0 -0
- scitex/scholar/url_finder/translators/individual/eastview.py +0 -0
- scitex/scholar/url_finder/translators/individual/ebrary.py +0 -0
- scitex/scholar/url_finder/translators/individual/ebsco_discovery_layer.py +0 -0
- scitex/scholar/url_finder/translators/individual/ebscohost.py +0 -0
- scitex/scholar/url_finder/translators/individual/edinburgh_university_press_journals.py +0 -0
- scitex/scholar/url_finder/translators/individual/education_week.py +0 -0
- scitex/scholar/url_finder/translators/individual/eidr.py +0 -0
- scitex/scholar/url_finder/translators/individual/el_comercio__peru_.py +0 -0
- scitex/scholar/url_finder/translators/individual/el_pais.py +0 -0
- scitex/scholar/url_finder/translators/individual/electronic_colloquium_on_computational_complexity.py +0 -0
- scitex/scholar/url_finder/translators/individual/elibrary_ru.py +0 -0
- scitex/scholar/url_finder/translators/individual/elicit.py +0 -0
- scitex/scholar/url_finder/translators/individual/elife.py +0 -0
- scitex/scholar/url_finder/translators/individual/elsevier_health.py +0 -0
- scitex/scholar/url_finder/translators/individual/elsevier_health_journals.py +0 -0
- scitex/scholar/url_finder/translators/individual/elsevier_pure.py +0 -0
- scitex/scholar/url_finder/translators/individual/embedded_metadata.py +0 -0
- scitex/scholar/url_finder/translators/individual/emedicine.py +0 -0
- scitex/scholar/url_finder/translators/individual/emerald.py +0 -0
- scitex/scholar/url_finder/translators/individual/emerald_insight.py +0 -0
- scitex/scholar/url_finder/translators/individual/emja.py +0 -0
- scitex/scholar/url_finder/translators/individual/encyclopedia_of_chicago.py +0 -0
- scitex/scholar/url_finder/translators/individual/encyclopedia_of_korean_culture.py +0 -0
- scitex/scholar/url_finder/translators/individual/endnote_xml.py +0 -0
- scitex/scholar/url_finder/translators/individual/engineering_village.py +0 -0
- scitex/scholar/url_finder/translators/individual/envidat.py +0 -0
- scitex/scholar/url_finder/translators/individual/epa_national_library_catalog.py +0 -0
- scitex/scholar/url_finder/translators/individual/epicurious.py +0 -0
- scitex/scholar/url_finder/translators/individual/eprint_iacr.py +0 -0
- scitex/scholar/url_finder/translators/individual/eric.py +0 -0
- scitex/scholar/url_finder/translators/individual/erudit.py +0 -0
- scitex/scholar/url_finder/translators/individual/espacenet.py +0 -0
- scitex/scholar/url_finder/translators/individual/etatar_ru.py +0 -0
- scitex/scholar/url_finder/translators/individual/euclid.py +0 -0
- scitex/scholar/url_finder/translators/individual/eur_lex.py +0 -0
- scitex/scholar/url_finder/translators/individual/eurasianet.py +0 -0
- scitex/scholar/url_finder/translators/individual/eurogamerusgamer.py +0 -0
- scitex/scholar/url_finder/translators/individual/europe_pmc.py +0 -0
- scitex/scholar/url_finder/translators/individual/evernote.py +0 -0
- scitex/scholar/url_finder/translators/individual/f1000_research.py +0 -0
- scitex/scholar/url_finder/translators/individual/fachportal_padagogik.py +0 -0
- scitex/scholar/url_finder/translators/individual/factiva.py +0 -0
- scitex/scholar/url_finder/translators/individual/failed_architecture.py +0 -0
- scitex/scholar/url_finder/translators/individual/fairfax_australia.py +0 -0
- scitex/scholar/url_finder/translators/individual/fao_publications.py +0 -0
- scitex/scholar/url_finder/translators/individual/fatcat.py +0 -0
- scitex/scholar/url_finder/translators/individual/faz_net.py +0 -0
- scitex/scholar/url_finder/translators/individual/feb_web_ru.py +0 -0
- scitex/scholar/url_finder/translators/individual/figshare.py +0 -0
- scitex/scholar/url_finder/translators/individual/financial_times.py +0 -0
- scitex/scholar/url_finder/translators/individual/finna.py +0 -0
- scitex/scholar/url_finder/translators/individual/fishpond_co_nz.py +0 -0
- scitex/scholar/url_finder/translators/individual/flickr.py +0 -0
- scitex/scholar/url_finder/translators/individual/foreign_affairs.py +0 -0
- scitex/scholar/url_finder/translators/individual/foreign_policy.py +0 -0
- scitex/scholar/url_finder/translators/individual/fr_online_de.py +0 -0
- scitex/scholar/url_finder/translators/individual/freecite.py +0 -0
- scitex/scholar/url_finder/translators/individual/freepatentsonline.py +0 -0
- scitex/scholar/url_finder/translators/individual/frieze.py +0 -0
- scitex/scholar/url_finder/translators/individual/frontiers.py +0 -0
- scitex/scholar/url_finder/translators/individual/gale_databases.py +0 -0
- scitex/scholar/url_finder/translators/individual/galegdc.py +0 -0
- scitex/scholar/url_finder/translators/individual/galegroup.py +0 -0
- scitex/scholar/url_finder/translators/individual/gallica.py +0 -0
- scitex/scholar/url_finder/translators/individual/game_studies.py +0 -0
- scitex/scholar/url_finder/translators/individual/gamespot.py +0 -0
- scitex/scholar/url_finder/translators/individual/gamestar_gamepro.py +0 -0
- scitex/scholar/url_finder/translators/individual/gasyrlar_awazy.py +0 -0
- scitex/scholar/url_finder/translators/individual/gemeinsamer_bibliotheksverbund_isbn.py +0 -0
- scitex/scholar/url_finder/translators/individual/gene_ontology.py +0 -0
- scitex/scholar/url_finder/translators/individual/github.py +0 -0
- scitex/scholar/url_finder/translators/individual/globes.py +0 -0
- scitex/scholar/url_finder/translators/individual/gmail.py +0 -0
- scitex/scholar/url_finder/translators/individual/gms_german_medical_science.py +0 -0
- scitex/scholar/url_finder/translators/individual/goodreads.py +0 -0
- scitex/scholar/url_finder/translators/individual/google_books.py +0 -0
- scitex/scholar/url_finder/translators/individual/google_patents.py +0 -0
- scitex/scholar/url_finder/translators/individual/google_play.py +0 -0
- scitex/scholar/url_finder/translators/individual/google_presentation.py +0 -0
- scitex/scholar/url_finder/translators/individual/google_research.py +0 -0
- scitex/scholar/url_finder/translators/individual/google_scholar.py +0 -0
- scitex/scholar/url_finder/translators/individual/govinfo.py +0 -0
- scitex/scholar/url_finder/translators/individual/gpo_access_e_cfr.py +0 -0
- scitex/scholar/url_finder/translators/individual/gulag_many_days__many_lives.py +0 -0
- scitex/scholar/url_finder/translators/individual/haaretz.py +0 -0
- scitex/scholar/url_finder/translators/individual/habr.py +0 -0
- scitex/scholar/url_finder/translators/individual/hal.py +0 -0
- scitex/scholar/url_finder/translators/individual/hal_archives_ouvertes.py +0 -0
- scitex/scholar/url_finder/translators/individual/handelszeitung.py +0 -0
- scitex/scholar/url_finder/translators/individual/hanrei_watch.py +0 -0
- scitex/scholar/url_finder/translators/individual/harper_s_magazine.py +0 -0
- scitex/scholar/url_finder/translators/individual/harvard_business_review.py +0 -0
- scitex/scholar/url_finder/translators/individual/harvard_caselaw_access_project.py +0 -0
- scitex/scholar/url_finder/translators/individual/harvard_university_press_books.py +0 -0
- scitex/scholar/url_finder/translators/individual/hathitrust.py +0 -0
- scitex/scholar/url_finder/translators/individual/hcsp.py +0 -0
- scitex/scholar/url_finder/translators/individual/heinonline.py +0 -0
- scitex/scholar/url_finder/translators/individual/heise.py +0 -0
- scitex/scholar/url_finder/translators/individual/herder.py +0 -0
- scitex/scholar/url_finder/translators/individual/highbeam.py +0 -0
- scitex/scholar/url_finder/translators/individual/highwire.py +0 -0
- scitex/scholar/url_finder/translators/individual/highwire2.py +0 -0
- scitex/scholar/url_finder/translators/individual/highwire_2_0.py +0 -0
- scitex/scholar/url_finder/translators/individual/hindawi.py +0 -0
- scitex/scholar/url_finder/translators/individual/hindawi_publishers.py +0 -0
- scitex/scholar/url_finder/translators/individual/hispanic_american_periodical_index.py +0 -0
- scitex/scholar/url_finder/translators/individual/homeland_security_digital_library.py +0 -0
- scitex/scholar/url_finder/translators/individual/hudoc.py +0 -0
- scitex/scholar/url_finder/translators/individual/huff_post.py +0 -0
- scitex/scholar/url_finder/translators/individual/human_rights_watch.py +0 -0
- scitex/scholar/url_finder/translators/individual/ibisworld.py +0 -0
- scitex/scholar/url_finder/translators/individual/idea_alm.py +0 -0
- scitex/scholar/url_finder/translators/individual/idref.py +0 -0
- scitex/scholar/url_finder/translators/individual/ieee_computer_society.py +0 -0
- scitex/scholar/url_finder/translators/individual/ieee_xplore.py +0 -0
- scitex/scholar/url_finder/translators/individual/ietf.py +0 -0
- scitex/scholar/url_finder/translators/individual/ign.py +0 -0
- scitex/scholar/url_finder/translators/individual/imdb.py +0 -0
- scitex/scholar/url_finder/translators/individual/imf.py +0 -0
- scitex/scholar/url_finder/translators/individual/in_these_times.py +0 -0
- scitex/scholar/url_finder/translators/individual/informationssystem_medienpaedagogik.py +0 -0
- scitex/scholar/url_finder/translators/individual/informit_database.py +0 -0
- scitex/scholar/url_finder/translators/individual/infotrac.py +0 -0
- scitex/scholar/url_finder/translators/individual/ingenta_connect.py +0 -0
- scitex/scholar/url_finder/translators/individual/ingentaconnect.py +0 -0
- scitex/scholar/url_finder/translators/individual/inside_higher_ed.py +0 -0
- scitex/scholar/url_finder/translators/individual/insignia_opac.py +0 -0
- scitex/scholar/url_finder/translators/individual/inspire.py +0 -0
- scitex/scholar/url_finder/translators/individual/institute_of_contemporary_art.py +0 -0
- scitex/scholar/url_finder/translators/individual/institute_of_physics.py +0 -0
- scitex/scholar/url_finder/translators/individual/integrum.py +0 -0
- scitex/scholar/url_finder/translators/individual/intellixir.py +0 -0
- scitex/scholar/url_finder/translators/individual/inter_research_science_center.py +0 -0
- scitex/scholar/url_finder/translators/individual/international_nuclear_information_system.py +0 -0
- scitex/scholar/url_finder/translators/individual/internet_archive.py +0 -0
- scitex/scholar/url_finder/translators/individual/internet_archive_scholar.py +0 -0
- scitex/scholar/url_finder/translators/individual/internet_archive_wayback.py +0 -0
- scitex/scholar/url_finder/translators/individual/internet_archive_wayback_machine.py +0 -0
- scitex/scholar/url_finder/translators/individual/invenio_rdm.py +0 -0
- scitex/scholar/url_finder/translators/individual/inveniordm.py +0 -0
- scitex/scholar/url_finder/translators/individual/io_port.py +0 -0
- scitex/scholar/url_finder/translators/individual/iop.py +0 -0
- scitex/scholar/url_finder/translators/individual/ipcc.py +0 -0
- scitex/scholar/url_finder/translators/individual/isidore.py +0 -0
- scitex/scholar/url_finder/translators/individual/istc.py +0 -0
- scitex/scholar/url_finder/translators/individual/j_stage.py +0 -0
- scitex/scholar/url_finder/translators/individual/jahrbuch.py +0 -0
- scitex/scholar/url_finder/translators/individual/japan_times_online.py +0 -0
- scitex/scholar/url_finder/translators/individual/jets.py +0 -0
- scitex/scholar/url_finder/translators/individual/jisc_historical_texts.py +0 -0
- scitex/scholar/url_finder/translators/individual/journal_of_electronic_publishing.py +0 -0
- scitex/scholar/url_finder/translators/individual/journal_of_extension.py +0 -0
- scitex/scholar/url_finder/translators/individual/journal_of_machine_learning_research.py +0 -0
- scitex/scholar/url_finder/translators/individual/journal_of_religion_and_society.py +0 -0
- scitex/scholar/url_finder/translators/individual/jrc_publications_repository.py +0 -0
- scitex/scholar/url_finder/translators/individual/jstage.py +0 -0
- scitex/scholar/url_finder/translators/individual/juricaf.py +0 -0
- scitex/scholar/url_finder/translators/individual/jurion.py +0 -0
- scitex/scholar/url_finder/translators/individual/juris.py +0 -0
- scitex/scholar/url_finder/translators/individual/jurpc.py +0 -0
- scitex/scholar/url_finder/translators/individual/k10plus_isbn.py +0 -0
- scitex/scholar/url_finder/translators/individual/kanopy.py +0 -0
- scitex/scholar/url_finder/translators/individual/karger.py +0 -0
- scitex/scholar/url_finder/translators/individual/khaama_press.py +0 -0
- scitex/scholar/url_finder/translators/individual/kitapyurdu_com.py +0 -0
- scitex/scholar/url_finder/translators/individual/kommersant.py +0 -0
- scitex/scholar/url_finder/translators/individual/korean_national_library.py +0 -0
- scitex/scholar/url_finder/translators/individual/kstudy.py +0 -0
- scitex/scholar/url_finder/translators/individual/l_annee_philologique.py +0 -0
- scitex/scholar/url_finder/translators/individual/la_croix.py +0 -0
- scitex/scholar/url_finder/translators/individual/la_nacion__argentina_.py +0 -0
- scitex/scholar/url_finder/translators/individual/la_presse.py +0 -0
- scitex/scholar/url_finder/translators/individual/la_republica__peru_.py +0 -0
- scitex/scholar/url_finder/translators/individual/la_times.py +0 -0
- scitex/scholar/url_finder/translators/individual/lagen_nu.py +0 -0
- scitex/scholar/url_finder/translators/individual/landesbibliographie_baden_wurttemberg.py +0 -0
- scitex/scholar/url_finder/translators/individual/lapham_s_quarterly.py +0 -0
- scitex/scholar/url_finder/translators/individual/le_devoir.py +0 -0
- scitex/scholar/url_finder/translators/individual/le_figaro.py +0 -0
- scitex/scholar/url_finder/translators/individual/le_maitron.py +0 -0
- scitex/scholar/url_finder/translators/individual/le_monde.py +0 -0
- scitex/scholar/url_finder/translators/individual/le_monde_diplomatique.py +0 -0
- scitex/scholar/url_finder/translators/individual/legifrance.py +0 -0
- scitex/scholar/url_finder/translators/individual/legislative_insight.py +0 -0
- scitex/scholar/url_finder/translators/individual/lexis_.py +0 -0
- scitex/scholar/url_finder/translators/individual/lexisnexis.py +0 -0
- scitex/scholar/url_finder/translators/individual/libraries_tasmania.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__aleph_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__amicus_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__aquabrowser_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__bibliocommons_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__blacklight_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__capita_prism_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__dra_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__dynix_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__encore_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__innopac_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__koha_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__mango_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__opals_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__pica2_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__pica_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__pika_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__polaris_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__quolto_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__rero_ils_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__sirsi_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__sirsi_elibrary_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__slims_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__tind_ils_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__tinread_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__tlcyouseemore_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__visual_library_2021_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__voyager_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__voyager_7_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_catalog__vtls_.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_genesis.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_hub_discover.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_of_congress_digital_collections.py +0 -0
- scitex/scholar/url_finder/translators/individual/library_of_congress_isbn.py +0 -0
- scitex/scholar/url_finder/translators/individual/libris_isbn.py +0 -0
- scitex/scholar/url_finder/translators/individual/lingbuzz.py +0 -0
- scitex/scholar/url_finder/translators/individual/lippincott_williams_and_wilkins.py +0 -0
- scitex/scholar/url_finder/translators/individual/literary_hub.py +0 -0
- scitex/scholar/url_finder/translators/individual/litres.py +0 -0
- scitex/scholar/url_finder/translators/individual/livejournal.py +0 -0
- scitex/scholar/url_finder/translators/individual/livivo.py +0 -0
- scitex/scholar/url_finder/translators/individual/london_review_of_books.py +0 -0
- scitex/scholar/url_finder/translators/individual/lookus.py +0 -0
- scitex/scholar/url_finder/translators/individual/lulu.py +0 -0
- scitex/scholar/url_finder/translators/individual/lwn_net.py +0 -0
- scitex/scholar/url_finder/translators/individual/lww.py +0 -0
- scitex/scholar/url_finder/translators/individual/mab2.py +0 -0
- scitex/scholar/url_finder/translators/individual/magazines_russ_ru.py +0 -0
- scitex/scholar/url_finder/translators/individual/mailman.py +0 -0
- scitex/scholar/url_finder/translators/individual/mainichi_daily_news.py +0 -0
- scitex/scholar/url_finder/translators/individual/marc.py +0 -0
- scitex/scholar/url_finder/translators/individual/marcxml.py +0 -0
- scitex/scholar/url_finder/translators/individual/mastodon.py +0 -0
- scitex/scholar/url_finder/translators/individual/matbugat_ru.py +0 -0
- scitex/scholar/url_finder/translators/individual/max_planck_institute_for_the_history_of_science_virtual_laboratory_library.py +0 -0
- scitex/scholar/url_finder/translators/individual/mcv.py +0 -0
- scitex/scholar/url_finder/translators/individual/mdpi.py +0 -0
- scitex/scholar/url_finder/translators/individual/mdpi_journals.py +0 -0
- scitex/scholar/url_finder/translators/individual/medes.py +0 -0
- scitex/scholar/url_finder/translators/individual/medium.py +0 -0
- scitex/scholar/url_finder/translators/individual/medline_nbib.py +0 -0
- scitex/scholar/url_finder/translators/individual/medlinenbib.py +0 -0
- scitex/scholar/url_finder/translators/individual/medra.py +0 -0
- scitex/scholar/url_finder/translators/individual/metalib.py +0 -0
- scitex/scholar/url_finder/translators/individual/mets.py +0 -0
- scitex/scholar/url_finder/translators/individual/microbiology_society_journals.py +0 -0
- scitex/scholar/url_finder/translators/individual/microsoft_academic.py +0 -0
- scitex/scholar/url_finder/translators/individual/midas_journals.py +0 -0
- scitex/scholar/url_finder/translators/individual/mikromarc.py +0 -0
- scitex/scholar/url_finder/translators/individual/milli_kutuphane.py +0 -0
- scitex/scholar/url_finder/translators/individual/mit_press_books.py +0 -0
- scitex/scholar/url_finder/translators/individual/mods.py +0 -0
- scitex/scholar/url_finder/translators/individual/mpg_pure.py +0 -0
- scitex/scholar/url_finder/translators/individual/musee_du_louvre.py +0 -0
- scitex/scholar/url_finder/translators/individual/nagoya_university_opac.py +0 -0
- scitex/scholar/url_finder/translators/individual/nasa_ads.py +0 -0
- scitex/scholar/url_finder/translators/individual/nasa_ntrs.py +0 -0
- scitex/scholar/url_finder/translators/individual/national_academies_press.py +0 -0
- scitex/scholar/url_finder/translators/individual/national_agriculture_library.py +0 -0
- scitex/scholar/url_finder/translators/individual/national_archives_of_australia.py +0 -0
- scitex/scholar/url_finder/translators/individual/national_archives_of_south_africa.py +0 -0
- scitex/scholar/url_finder/translators/individual/national_bureau_of_economic_research.py +0 -0
- scitex/scholar/url_finder/translators/individual/national_diet_library_catalogue.py +0 -0
- scitex/scholar/url_finder/translators/individual/national_gallery_of_art___usa.py +0 -0
- scitex/scholar/url_finder/translators/individual/national_gallery_of_australia.py +0 -0
- scitex/scholar/url_finder/translators/individual/national_library_of_australia__new_catalog_.py +0 -0
- scitex/scholar/url_finder/translators/individual/national_library_of_belarus.py +0 -0
- scitex/scholar/url_finder/translators/individual/national_library_of_norway.py +0 -0
- scitex/scholar/url_finder/translators/individual/national_library_of_poland_isbn.py +0 -0
- scitex/scholar/url_finder/translators/individual/national_post.py +0 -0
- scitex/scholar/url_finder/translators/individual/national_technical_reports_library.py +0 -0
- scitex/scholar/url_finder/translators/individual/national_transportation_library_rosa_p.py +0 -0
- scitex/scholar/url_finder/translators/individual/nature.py +0 -0
- scitex/scholar/url_finder/translators/individual/nber.py +0 -0
- scitex/scholar/url_finder/translators/individual/ncbi_nucleotide.py +0 -0
- scitex/scholar/url_finder/translators/individual/neural_information_processing_systems.py +0 -0
- scitex/scholar/url_finder/translators/individual/new_left_review.py +0 -0
- scitex/scholar/url_finder/translators/individual/new_zealand_herald.py +0 -0
- scitex/scholar/url_finder/translators/individual/newlines_magazine.py +0 -0
- scitex/scholar/url_finder/translators/individual/news_corp_australia.py +0 -0
- scitex/scholar/url_finder/translators/individual/newsbank.py +0 -0
- scitex/scholar/url_finder/translators/individual/newshub_co_nz.py +0 -0
- scitex/scholar/url_finder/translators/individual/newsnettamedia.py +0 -0
- scitex/scholar/url_finder/translators/individual/newspapers_com.py +0 -0
- scitex/scholar/url_finder/translators/individual/noor_digital_library.py +0 -0
- scitex/scholar/url_finder/translators/individual/note_html.py +0 -0
- scitex/scholar/url_finder/translators/individual/note_markdown.py +0 -0
- scitex/scholar/url_finder/translators/individual/notre_dame_philosophical_reviews.py +0 -0
- scitex/scholar/url_finder/translators/individual/npr.py +0 -0
- scitex/scholar/url_finder/translators/individual/nrc_nl.py +0 -0
- scitex/scholar/url_finder/translators/individual/nrc_research_press.py +0 -0
- scitex/scholar/url_finder/translators/individual/ntsb_accident_reports.py +0 -0
- scitex/scholar/url_finder/translators/individual/nypl_menus.py +0 -0
- scitex/scholar/url_finder/translators/individual/nypl_research_catalog.py +0 -0
- scitex/scholar/url_finder/translators/individual/nytimes_com.py +0 -0
- scitex/scholar/url_finder/translators/individual/nzz_ch.py +0 -0
- scitex/scholar/url_finder/translators/individual/oapen.py +0 -0
- scitex/scholar/url_finder/translators/individual/oclc_worldcat_firstsearch.py +0 -0
- scitex/scholar/url_finder/translators/individual/oecd.py +0 -0
- scitex/scholar/url_finder/translators/individual/oecd_ilibrary.py +0 -0
- scitex/scholar/url_finder/translators/individual/ohiolink.py +0 -0
- scitex/scholar/url_finder/translators/individual/open_conf.py +0 -0
- scitex/scholar/url_finder/translators/individual/open_knowledge_repository.py +0 -0
- scitex/scholar/url_finder/translators/individual/open_worldcat.py +0 -0
- scitex/scholar/url_finder/translators/individual/openalex.py +0 -0
- scitex/scholar/url_finder/translators/individual/openalex_json.py +0 -0
- scitex/scholar/url_finder/translators/individual/openedition_books.py +0 -0
- scitex/scholar/url_finder/translators/individual/openedition_journals.py +0 -0
- scitex/scholar/url_finder/translators/individual/openjur.py +0 -0
- scitex/scholar/url_finder/translators/individual/optical_society_of_america.py +0 -0
- scitex/scholar/url_finder/translators/individual/optimization_online.py +0 -0
- scitex/scholar/url_finder/translators/individual/orcid.py +0 -0
- scitex/scholar/url_finder/translators/individual/osa.py +0 -0
- scitex/scholar/url_finder/translators/individual/osf_preprints.py +0 -0
- scitex/scholar/url_finder/translators/individual/osti_energy_citations.py +0 -0
- scitex/scholar/url_finder/translators/individual/ovid.py +0 -0
- scitex/scholar/url_finder/translators/individual/ovid_tagged.py +0 -0
- scitex/scholar/url_finder/translators/individual/oxford.py +0 -0
- scitex/scholar/url_finder/translators/individual/oxford_dictionaries_premium.py +0 -0
- scitex/scholar/url_finder/translators/individual/oxford_english_dictionary.py +0 -0
- scitex/scholar/url_finder/translators/individual/oxford_music_and_art_online.py +0 -0
- scitex/scholar/url_finder/translators/individual/oxford_reference.py +0 -0
- scitex/scholar/url_finder/translators/individual/oxford_university_press.py +0 -0
- scitex/scholar/url_finder/translators/individual/ozon_ru.py +0 -0
- scitex/scholar/url_finder/translators/individual/pajhwok_afghan_news.py +0 -0
- scitex/scholar/url_finder/translators/individual/papers_past.py +0 -0
- scitex/scholar/url_finder/translators/individual/paris_review.py +0 -0
- scitex/scholar/url_finder/translators/individual/pastebin.py +0 -0
- scitex/scholar/url_finder/translators/individual/patents___uspto.py +0 -0
- scitex/scholar/url_finder/translators/individual/pc_gamer.py +0 -0
- scitex/scholar/url_finder/translators/individual/pc_games.py +0 -0
- scitex/scholar/url_finder/translators/individual/peeters.py +0 -0
- scitex/scholar/url_finder/translators/individual/pei_archival_information_network.py +0 -0
- scitex/scholar/url_finder/translators/individual/pep_web.py +0 -0
- scitex/scholar/url_finder/translators/individual/perceiving_systems.py +0 -0
- scitex/scholar/url_finder/translators/individual/perlego.py +0 -0
- scitex/scholar/url_finder/translators/individual/philosopher_s_imprint.py +0 -0
- scitex/scholar/url_finder/translators/individual/philpapers.py +0 -0
- scitex/scholar/url_finder/translators/individual/pkp_catalog_systems.py +0 -0
- scitex/scholar/url_finder/translators/individual/pleade.py +0 -0
- scitex/scholar/url_finder/translators/individual/plos.py +0 -0
- scitex/scholar/url_finder/translators/individual/plos_journals.py +0 -0
- scitex/scholar/url_finder/translators/individual/pnas.py +0 -0
- scitex/scholar/url_finder/translators/individual/polygon.py +0 -0
- scitex/scholar/url_finder/translators/individual/potsdamer_neueste_nachrichten.py +0 -0
- scitex/scholar/url_finder/translators/individual/prc_history_review.py +0 -0
- scitex/scholar/url_finder/translators/individual/preprints_org.py +0 -0
- scitex/scholar/url_finder/translators/individual/primo.py +0 -0
- scitex/scholar/url_finder/translators/individual/primo_2018.py +0 -0
- scitex/scholar/url_finder/translators/individual/primo_normalized_xml.py +0 -0
- scitex/scholar/url_finder/translators/individual/probing_the_past.py +0 -0
- scitex/scholar/url_finder/translators/individual/project_gutenberg.py +0 -0
- scitex/scholar/url_finder/translators/individual/project_muse.py +0 -0
- scitex/scholar/url_finder/translators/individual/promed.py +0 -0
- scitex/scholar/url_finder/translators/individual/proquest.py +0 -0
- scitex/scholar/url_finder/translators/individual/proquest_ebook_central.py +0 -0
- scitex/scholar/url_finder/translators/individual/proquest_policyfile.py +0 -0
- scitex/scholar/url_finder/translators/individual/protein_data_bank.py +0 -0
- scitex/scholar/url_finder/translators/individual/pubfactory_journals.py +0 -0
- scitex/scholar/url_finder/translators/individual/public_record_office_victoria.py +0 -0
- scitex/scholar/url_finder/translators/individual/publications_du_quebec.py +0 -0
- scitex/scholar/url_finder/translators/individual/publications_office_of_the_european_union.py +0 -0
- scitex/scholar/url_finder/translators/individual/pubmed.py +0 -0
- scitex/scholar/url_finder/translators/individual/pubmed_central.py +0 -0
- scitex/scholar/url_finder/translators/individual/pubmed_xml.py +0 -0
- scitex/scholar/url_finder/translators/individual/pubpub.py +0 -0
- scitex/scholar/url_finder/translators/individual/pypi.py +0 -0
- scitex/scholar/url_finder/translators/individual/qatar_digital_library.py +0 -0
- scitex/scholar/url_finder/translators/individual/queensland_state_archives.py +0 -0
- scitex/scholar/url_finder/translators/individual/r_packages.py +0 -0
- scitex/scholar/url_finder/translators/individual/radio_free_europe__radio_liberty.py +0 -0
- scitex/scholar/url_finder/translators/individual/rand.py +0 -0
- scitex/scholar/url_finder/translators/individual/rdf.py +0 -0
- scitex/scholar/url_finder/translators/individual/rechtspraak_nl.py +0 -0
- scitex/scholar/url_finder/translators/individual/redalyc.py +0 -0
- scitex/scholar/url_finder/translators/individual/reddit.py +0 -0
- scitex/scholar/url_finder/translators/individual/referbibix.py +0 -0
- scitex/scholar/url_finder/translators/individual/refworks_tagged.py +0 -0
- scitex/scholar/url_finder/translators/individual/regeringskansliet.py +0 -0
- scitex/scholar/url_finder/translators/individual/repec___econpapers.py +0 -0
- scitex/scholar/url_finder/translators/individual/repec___ideas.py +0 -0
- scitex/scholar/url_finder/translators/individual/repec_ideas.py +0 -0
- scitex/scholar/url_finder/translators/individual/research_square.py +0 -0
- scitex/scholar/url_finder/translators/individual/researchgate.py +0 -0
- scitex/scholar/url_finder/translators/individual/retsinformation.py +0 -0
- scitex/scholar/url_finder/translators/individual/reuters.py +0 -0
- scitex/scholar/url_finder/translators/individual/ris.py +0 -0
- scitex/scholar/url_finder/translators/individual/rock__paper__shotgun.py +0 -0
- scitex/scholar/url_finder/translators/individual/roll_call.py +0 -0
- scitex/scholar/url_finder/translators/individual/rsc.py +0 -0
- scitex/scholar/url_finder/translators/individual/rsc_publishing.py +0 -0
- scitex/scholar/url_finder/translators/individual/russian_state_library.py +0 -0
- scitex/scholar/url_finder/translators/individual/sacramento_bee.py +0 -0
- scitex/scholar/url_finder/translators/individual/sae_papers.py +0 -0
- scitex/scholar/url_finder/translators/individual/safari_books_online.py +0 -0
- scitex/scholar/url_finder/translators/individual/sage.py +0 -0
- scitex/scholar/url_finder/translators/individual/sage_journals.py +0 -0
- scitex/scholar/url_finder/translators/individual/sage_knowledge.py +0 -0
- scitex/scholar/url_finder/translators/individual/saildart.py +0 -0
- scitex/scholar/url_finder/translators/individual/salt_research_archives.py +0 -0
- scitex/scholar/url_finder/translators/individual/sbn_it.py +0 -0
- scitex/scholar/url_finder/translators/individual/scholars_portal_journals.py +0 -0
- scitex/scholar/url_finder/translators/individual/scholia.py +0 -0
- scitex/scholar/url_finder/translators/individual/schweizer_radio_und_fernsehen_srf.py +0 -0
- scitex/scholar/url_finder/translators/individual/scielo.py +0 -0
- scitex/scholar/url_finder/translators/individual/sciencedirect.py +0 -0
- scitex/scholar/url_finder/translators/individual/scinapse.py +0 -0
- scitex/scholar/url_finder/translators/individual/scopus.py +0 -0
- scitex/scholar/url_finder/translators/individual/semantic_scholar.py +0 -0
- scitex/scholar/url_finder/translators/individual/semantics_visual_library.py +0 -0
- scitex/scholar/url_finder/translators/individual/sfu_ipinch.py +0 -0
- scitex/scholar/url_finder/translators/individual/silverchair.py +0 -0
- scitex/scholar/url_finder/translators/individual/sipri.py +0 -0
- scitex/scholar/url_finder/translators/individual/sirs_knowledge_source.py +0 -0
- scitex/scholar/url_finder/translators/individual/slate.py +0 -0
- scitex/scholar/url_finder/translators/individual/slideshare.py +0 -0
- scitex/scholar/url_finder/translators/individual/slub_dresden.py +0 -0
- scitex/scholar/url_finder/translators/individual/sora.py +0 -0
- scitex/scholar/url_finder/translators/individual/springer.py +0 -0
- scitex/scholar/url_finder/translators/individual/springer_link.py +0 -0
- scitex/scholar/url_finder/translators/individual/ssoar.py +0 -0
- scitex/scholar/url_finder/translators/individual/stack_exchange.py +0 -0
- scitex/scholar/url_finder/translators/individual/standard_ebooks.py +0 -0
- scitex/scholar/url_finder/translators/individual/stanford_encyclopedia_of_philosophy.py +0 -0
- scitex/scholar/url_finder/translators/individual/stanford_university_press.py +0 -0
- scitex/scholar/url_finder/translators/individual/state_records_office_of_western_australia.py +0 -0
- scitex/scholar/url_finder/translators/individual/state_records_office_wa.py +0 -0
- scitex/scholar/url_finder/translators/individual/stitcher.py +0 -0
- scitex/scholar/url_finder/translators/individual/store_norske_leksikon.py +0 -0
- scitex/scholar/url_finder/translators/individual/stuff_co_nz.py +0 -0
- scitex/scholar/url_finder/translators/individual/substack.py +0 -0
- scitex/scholar/url_finder/translators/individual/sud_ouest.py +0 -0
- scitex/scholar/url_finder/translators/individual/sueddeutsche_de.py +0 -0
- scitex/scholar/url_finder/translators/individual/summon_2.py +0 -0
- scitex/scholar/url_finder/translators/individual/superlib.py +0 -0
- scitex/scholar/url_finder/translators/individual/svenska_dagbladet.py +0 -0
- scitex/scholar/url_finder/translators/individual/sveriges_radio.py +0 -0
- scitex/scholar/url_finder/translators/individual/svt_nyheter.py +0 -0
- scitex/scholar/url_finder/translators/individual/tagesspiegel.py +0 -0
- scitex/scholar/url_finder/translators/individual/talis_aspire.py +0 -0
- scitex/scholar/url_finder/translators/individual/talisprism.py +0 -0
- scitex/scholar/url_finder/translators/individual/tatknigafund.py +0 -0
- scitex/scholar/url_finder/translators/individual/tatpressa_ru.py +0 -0
- scitex/scholar/url_finder/translators/individual/taylor___francis_ebooks.py +0 -0
- scitex/scholar/url_finder/translators/individual/taylor_and_francis_nejm.py +0 -0
- scitex/scholar/url_finder/translators/individual/taylor_francis.py +0 -0
- scitex/scholar/url_finder/translators/individual/taylor_francis_nejm.py +0 -0
- scitex/scholar/url_finder/translators/individual/taz_de.py +0 -0
- scitex/scholar/url_finder/translators/individual/tei.py +0 -0
- scitex/scholar/url_finder/translators/individual/tesis_doctorals_en_xarxa.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_art_newspaper.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_atlantic.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_boston_globe.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_chronicle_of_higher_education.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_daily_beast.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_economic_times___the_times_of_india.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_economist.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_free_dictionary.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_globe_and_mail.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_guardian.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_hamilton_spectator.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_hindu.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_independent.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_intercept.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_met.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_microfinance_gateway.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_nation.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_national_archives__uk_.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_new_republic.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_new_york_review_of_books.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_new_yorker.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_open_library.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_straits_times.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_telegraph.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_times_and_sunday_times.py +0 -0
- scitex/scholar/url_finder/translators/individual/the_times_of_israel.py +0 -0
- scitex/scholar/url_finder/translators/individual/themarker.py +0 -0
- scitex/scholar/url_finder/translators/individual/theory_of_computing.py +0 -0
- scitex/scholar/url_finder/translators/individual/thesesfr.py +0 -0
- scitex/scholar/url_finder/translators/individual/thieme.py +0 -0
- scitex/scholar/url_finder/translators/individual/time_com.py +0 -0
- scitex/scholar/url_finder/translators/individual/timesmachine.py +0 -0
- scitex/scholar/url_finder/translators/individual/tony_blair_institute.py +0 -0
- scitex/scholar/url_finder/translators/individual/tony_blair_institute_for_global_change.py +0 -0
- scitex/scholar/url_finder/translators/individual/toronto_star.py +0 -0
- scitex/scholar/url_finder/translators/individual/transportation_research_board.py +0 -0
- scitex/scholar/url_finder/translators/individual/treesearch.py +0 -0
- scitex/scholar/url_finder/translators/individual/trove.py +0 -0
- scitex/scholar/url_finder/translators/individual/tumblr.py +0 -0
- scitex/scholar/url_finder/translators/individual/tv_by_the_numbers.py +0 -0
- scitex/scholar/url_finder/translators/individual/tvnz.py +0 -0
- scitex/scholar/url_finder/translators/individual/twitter.py +0 -0
- scitex/scholar/url_finder/translators/individual/ubiquity_journals.py +0 -0
- scitex/scholar/url_finder/translators/individual/uchicago_vufind.py +0 -0
- scitex/scholar/url_finder/translators/individual/unapi.py +0 -0
- scitex/scholar/url_finder/translators/individual/unesco.py +0 -0
- scitex/scholar/url_finder/translators/individual/university_of_california_press_books.py +0 -0
- scitex/scholar/url_finder/translators/individual/university_of_chicago_press_books.py +0 -0
- scitex/scholar/url_finder/translators/individual/university_of_wisconsin_madison_libraries_catalog.py +0 -0
- scitex/scholar/url_finder/translators/individual/university_press_scholarship.py +0 -0
- scitex/scholar/url_finder/translators/individual/unqualified_dublin_core_rdf.py +0 -0
- scitex/scholar/url_finder/translators/individual/unz_print_archive.py +0 -0
- scitex/scholar/url_finder/translators/individual/upcommons.py +0 -0
- scitex/scholar/url_finder/translators/individual/uptodate_references.py +0 -0
- scitex/scholar/url_finder/translators/individual/us_national_archives_research_catalog.py +0 -0
- scitex/scholar/url_finder/translators/individual/usenix.py +0 -0
- scitex/scholar/url_finder/translators/individual/vanity_fair.py +0 -0
- scitex/scholar/url_finder/translators/individual/verniana.py +0 -0
- scitex/scholar/url_finder/translators/individual/verniana_jules_verne_studies.py +0 -0
- scitex/scholar/url_finder/translators/individual/verso_books.py +0 -0
- scitex/scholar/url_finder/translators/individual/vice.py +0 -0
- scitex/scholar/url_finder/translators/individual/victoria___albert_museum.py +0 -0
- scitex/scholar/url_finder/translators/individual/vimeo.py +0 -0
- scitex/scholar/url_finder/translators/individual/vlex.py +0 -0
- scitex/scholar/url_finder/translators/individual/voxeu.py +0 -0
- scitex/scholar/url_finder/translators/individual/wall_street_journal.py +0 -0
- scitex/scholar/url_finder/translators/individual/wanfang_data.py +0 -0
- scitex/scholar/url_finder/translators/individual/washington_monthly.py +0 -0
- scitex/scholar/url_finder/translators/individual/washington_post.py +0 -0
- scitex/scholar/url_finder/translators/individual/web_of_science.py +0 -0
- scitex/scholar/url_finder/translators/individual/web_of_science_nextgen.py +0 -0
- scitex/scholar/url_finder/translators/individual/web_of_science_tagged.py +0 -0
- scitex/scholar/url_finder/translators/individual/welt_online.py +0 -0
- scitex/scholar/url_finder/translators/individual/westlaw_uk.py +0 -0
- scitex/scholar/url_finder/translators/individual/who.py +0 -0
- scitex/scholar/url_finder/translators/individual/wikidata.py +0 -0
- scitex/scholar/url_finder/translators/individual/wikidata_quickstatements.py +0 -0
- scitex/scholar/url_finder/translators/individual/wikileaks_plusd.py +0 -0
- scitex/scholar/url_finder/translators/individual/wikimedia_commons.py +0 -0
- scitex/scholar/url_finder/translators/individual/wikipedia.py +0 -0
- scitex/scholar/url_finder/translators/individual/wikipedia_citation_templates.py +0 -0
- scitex/scholar/url_finder/translators/individual/wikisource.py +0 -0
- scitex/scholar/url_finder/translators/individual/wikiwand.py +0 -0
- scitex/scholar/url_finder/translators/individual/wiktionary.py +0 -0
- scitex/scholar/url_finder/translators/individual/wildlife_biology_in_practice.py +0 -0
- scitex/scholar/url_finder/translators/individual/wiley.py +0 -0
- scitex/scholar/url_finder/translators/individual/wiley_online_library.py +0 -0
- scitex/scholar/url_finder/translators/individual/wilson_center_digital_archive.py +0 -0
- scitex/scholar/url_finder/translators/individual/winnipeg_free_press.py +0 -0
- scitex/scholar/url_finder/translators/individual/wipo.py +0 -0
- scitex/scholar/url_finder/translators/individual/wired.py +0 -0
- scitex/scholar/url_finder/translators/individual/wiso.py +0 -0
- scitex/scholar/url_finder/translators/individual/womennews.py +0 -0
- scitex/scholar/url_finder/translators/individual/world_bank.py +0 -0
- scitex/scholar/url_finder/translators/individual/world_digital_library.py +0 -0
- scitex/scholar/url_finder/translators/individual/world_history_connected.py +0 -0
- scitex/scholar/url_finder/translators/individual/world_shakespeare_bibliography_online.py +0 -0
- scitex/scholar/url_finder/translators/individual/worldcat_discovery_service.py +0 -0
- scitex/scholar/url_finder/translators/individual/xml_contextobject.py +0 -0
- scitex/scholar/url_finder/translators/individual/yandex_books.py +0 -0
- scitex/scholar/url_finder/translators/individual/ynet.py +0 -0
- scitex/scholar/url_finder/translators/individual/youtube.py +0 -0
- scitex/scholar/url_finder/translators/individual/ypfs.py +0 -0
- scitex/scholar/url_finder/translators/individual/ypsf.py +0 -0
- scitex/scholar/url_finder/translators/individual/zbmath.py +0 -0
- scitex/scholar/url_finder/translators/individual/zenodo.py +0 -0
- scitex/scholar/url_finder/translators/individual/ziponline.py +0 -0
- scitex/scholar/url_finder/translators/individual/zobodat.py +0 -0
- scitex/scholar/url_finder/translators/individual/zotero_org.py +0 -0
- scitex/scholar/url_finder/translators/individual/zotero_rdf.py +0 -0
- scitex/scholar/url_finder/translators/individual/zoterobib.py +0 -0
- scitex/scholar/utils/__init__.py +3 -0
- scitex/scholar/utils/bibtex/__init__.py +0 -0
- scitex/scholar/utils/cleanup/__init__.py +0 -0
- scitex/scholar/utils/text/_TextNormalizer.py +0 -0
- scitex/scholar/utils/text/__init__.py +0 -0
- scitex/scholar/utils/validation/DOIValidator.py +289 -0
- scitex/scholar/utils/validation/README.md +169 -0
- scitex/scholar/utils/validation/__init__.py +13 -0
- scitex/scholar/utils/validation/validate_library_dois.py +221 -0
- scitex/scholar/zotero/__init__.py +0 -0
- scitex/security/README.md +255 -0
- scitex/security/__init__.py +35 -0
- scitex/security/cli.py +140 -0
- scitex/security/github.py +358 -0
- scitex/session/README.md +95 -30
- scitex/session/__init__.py +8 -3
- scitex/session/_decorator.py +610 -0
- scitex/session/_lifecycle.py +155 -62
- scitex/session/_manager.py +0 -0
- scitex/session/template.py +16 -110
- scitex/sh/README.md +1 -1
- scitex/sh/__init__.py +0 -0
- scitex/stats/__init__.py +17 -3
- scitex/stats/_schema.py +578 -0
- scitex/stats/correct/_correct_bonferroni.py +3 -3
- scitex/stats/correct/_correct_fdr.py +62 -62
- scitex/stats/correct/_correct_fdr_.py +634 -0
- scitex/stats/correct/_correct_holm.py +2 -2
- scitex/stats/correct/_correct_sidak.py +2 -2
- scitex/stats/descriptive/_circular.py +2 -2
- scitex/stats/descriptive/_describe.py +2 -2
- scitex/stats/descriptive/_nan.py +2 -2
- scitex/stats/descriptive/_real.py +2 -2
- scitex/stats/effect_sizes/_cliffs_delta.py +1 -1
- scitex/stats/effect_sizes/_cohens_d.py +1 -1
- scitex/stats/effect_sizes/_epsilon_squared.py +1 -1
- scitex/stats/effect_sizes/_eta_squared.py +1 -1
- scitex/stats/effect_sizes/_prob_superiority.py +1 -1
- scitex/stats/posthoc/_dunnett.py +3 -3
- scitex/stats/posthoc/_games_howell.py +3 -3
- scitex/stats/posthoc/_tukey_hsd.py +3 -3
- scitex/stats/power/_power.py +1 -1
- scitex/stats/tests/__init__.py +13 -0
- scitex/stats/tests/correlation/__init__.py +3 -22
- scitex/stats/tests/correlation/_test_pearson.py +180 -506
- scitex/stats/utils/_effect_size.py +1 -1
- scitex/stats/utils/_formatters.py +1 -1
- scitex/stats/utils/_normalizers.py +8 -5
- scitex/stats/utils/_power.py +1 -1
- scitex/str/_parse.py +1 -1
- scitex/str/_replace.py +1 -1
- scitex/template/_clone_project.py +58 -41
- scitex/template/_copy.py +22 -15
- scitex/template/_customize.py +9 -4
- scitex/template/_git_strategy.py +32 -32
- scitex/template/_logging_helpers.py +122 -0
- scitex/template/clone_pip_project.py +24 -17
- scitex/template/clone_research.py +26 -21
- scitex/template/clone_singularity.py +25 -22
- scitex/template/clone_writer_directory.py +24 -17
- scitex/tex/_preview.py +2 -2
- scitex/tex/_to_vec.py +1 -1
- scitex/utils/_email.py +1 -1
- scitex/utils/_verify_scitex_format.py +2 -2
- scitex/utils/template.py +1 -1
- scitex/vis/DJANGO_INTEGRATION.md +677 -0
- scitex/vis/README.md +755 -0
- scitex/vis/__init__.py +117 -0
- scitex/vis/backend/__init__.py +56 -0
- scitex/vis/backend/export.py +166 -0
- scitex/vis/backend/parser.py +190 -0
- scitex/vis/backend/render.py +385 -0
- scitex/vis/editor/__init__.py +23 -0
- scitex/vis/editor/_defaults.py +205 -0
- scitex/vis/editor/_edit.py +342 -0
- scitex/vis/editor/_mpl_editor.py +231 -0
- scitex/vis/editor/_tkinter_editor.py +466 -0
- scitex/vis/editor/_web_editor.py +1440 -0
- scitex/vis/io/__init__.py +36 -0
- scitex/vis/io/load.py +168 -0
- scitex/vis/io/save.py +131 -0
- scitex/vis/model/__init__.py +118 -0
- scitex/vis/model/annotations.py +118 -0
- scitex/vis/model/axes.py +153 -0
- scitex/vis/model/figure.py +139 -0
- scitex/vis/model/guides.py +105 -0
- scitex/vis/model/plot.py +126 -0
- scitex/vis/model/plot_types.py +682 -0
- scitex/vis/model/styles.py +246 -0
- scitex/vis/tmp.txt +239 -0
- scitex/vis/utils/__init__.py +75 -0
- scitex/vis/utils/defaults.py +335 -0
- scitex/vis/utils/validate.py +204 -0
- scitex/web/__init__.py +4 -0
- scitex/web/_scraping.py +373 -0
- scitex/writer/README.md +11 -2
- scitex/writer/Writer.py +75 -15
- scitex/writer/_clone_writer_project.py +41 -28
- scitex/writer/_compile/__init__.py +9 -67
- scitex/writer/_compile/_parser.py +0 -0
- scitex/writer/_compile/_runner.py +249 -28
- scitex/writer/_compile/_validator.py +0 -0
- scitex/writer/_compile/manuscript.py +109 -0
- scitex/writer/_compile/revision.py +81 -0
- scitex/writer/_compile/supplementary.py +99 -0
- scitex/writer/_project/__init__.py +0 -0
- scitex/writer/_project/_create.py +10 -12
- scitex/writer/_project/_trees.py +0 -0
- scitex/writer/_project/_validate.py +1 -1
- scitex/writer/_validate_tree_structures.py +4 -4
- scitex/writer/dataclasses/__init__.py +0 -0
- scitex/writer/dataclasses/config/_WriterConfig.py +3 -3
- scitex/writer/dataclasses/config/__init__.py +0 -0
- scitex/writer/dataclasses/contents/_ManuscriptContents.py +4 -3
- scitex/writer/dataclasses/contents/_RevisionContents.py +9 -5
- scitex/writer/dataclasses/contents/_SupplementaryContents.py +7 -4
- scitex/writer/dataclasses/contents/__init__.py +0 -0
- scitex/writer/dataclasses/core/_Document.py +1 -1
- scitex/writer/dataclasses/core/_DocumentSection.py +1 -1
- scitex/writer/dataclasses/core/__init__.py +0 -0
- scitex/writer/dataclasses/results/_CompilationResult.py +1 -1
- scitex/writer/dataclasses/results/_LaTeXIssue.py +1 -1
- scitex/writer/dataclasses/results/_SaveSectionsResponse.py +107 -0
- scitex/writer/dataclasses/results/_SectionReadResponse.py +117 -0
- scitex/writer/dataclasses/results/__init__.py +4 -0
- scitex/writer/dataclasses/tree/_ConfigTree.py +3 -2
- scitex/writer/dataclasses/tree/_ManuscriptTree.py +5 -3
- scitex/writer/dataclasses/tree/_RevisionTree.py +7 -4
- scitex/writer/dataclasses/tree/_ScriptsTree.py +5 -3
- scitex/writer/dataclasses/tree/_SharedTree.py +5 -4
- scitex/writer/dataclasses/tree/_SupplementaryTree.py +7 -4
- scitex/writer/dataclasses/tree/__init__.py +0 -0
- scitex/writer/tests/__init__.py +0 -0
- scitex/writer/utils/.legacy_git_retry.py +1 -1
- scitex/writer/utils/__init__.py +0 -0
- scitex/writer/utils/_parse_latex_logs.py +1 -1
- scitex/writer/utils/_parse_script_args.py +0 -0
- scitex/writer/utils/_watch.py +0 -0
- {scitex-2.1.2.dist-info → scitex-2.4.2.dist-info}/METADATA +373 -363
- {scitex-2.1.2.dist-info → scitex-2.4.2.dist-info}/RECORD +375 -370
- {scitex-2.1.2.dist-info → scitex-2.4.2.dist-info}/WHEEL +1 -1
- scitex-2.4.2.dist-info/licenses/LICENSE +661 -0
- scitex/.claude/mcp-config.json +0 -42
- scitex/_sh.py +0 -18
- scitex/ai/training/legacy/early_stopping.py +0 -150
- scitex/ai/training/legacy/learning_curve_logger.py +0 -557
- scitex/ai/viewed-ai.md +0 -4984
- scitex/browser/ARCHITECTURE_PROPOSAL.md +0 -795
- scitex/browser/INTERACTIVE_COLLABORATION.md +0 -782
- scitex/browser/SAFE_IMPLEMENTATION_PLAN.md +0 -363
- scitex/browser/SHARED_BROWSER_SESSION.md +0 -652
- scitex/browser/TODO.md +0 -11
- scitex/browser/collaboration/CLIENTSERVER_ARCHITECTURE.md +0 -165
- scitex/browser/collaboration/INTERACTION_STRATEGY.md +0 -547
- scitex/browser/collaboration/NON_INTERFERING_LOGIC.md +0 -730
- scitex/browser/template.py +0 -122
- scitex/db/legacy/_inspect_v02.py +0 -171
- scitex/db/legacy/_inspect_v03-not-optimized.py +0 -179
- scitex/db/legacy/_inspect_v04-working-but-printing-both-scheme-and-first-row.py +0 -337
- scitex/db/legacy/_inspect_v05-working-but-no-clear-separation-between-dtype-and-actual-values.py +0 -358
- scitex/dict/_DotDict_v01-not-handling-recursive-instantiations.py +0 -442
- scitex/dict/_DotDict_v02-not-serializing-Path-object.py +0 -446
- scitex/plt/KNOWN_ISSUES.md +0 -68
- scitex/plt/TODO.md +0 -7
- scitex/plt/ax/_plot/_plot_ecdf.py +0 -84
- scitex/plt/ax/_plot/_plot_heatmap.py +0 -266
- scitex/plt/ax/_plot/_plot_joyplot.py +0 -77
- scitex/plt/ax/_plot/_plot_shaded_line.py +0 -142
- scitex/project/DESIGN.md +0 -423
- scitex/project/DJANGO_INTEGRATION.md +0 -546
- scitex/project/NAMING.md +0 -251
- scitex/project/README.md +0 -441
- scitex/project/__init__.py +0 -80
- scitex/project/core.py +0 -466
- scitex/project/metadata.py +0 -345
- scitex/project/storage.py +0 -321
- scitex/project/validators.py +0 -296
- scitex/reproduce/_hash_array.py +0 -22
- scitex/rng/_RandomStateManager_v01-no-verbose-options.py +0 -414
- scitex/scholar/.claude/agents/ArchitectAgent.md +0 -50
- scitex/scholar/.claude/agents/BulletinBoardOrganizerAgent.md +0 -24
- scitex/scholar/.claude/agents/DebuggerAgent.md +0 -38
- scitex/scholar/.claude/agents/ExamplesDeveloperAgent.md +0 -49
- scitex/scholar/.claude/agents/ExperimentationAgent.md +0 -13
- scitex/scholar/.claude/agents/GitHandlerAgent.md +0 -38
- scitex/scholar/.claude/agents/ResearcherAgent.md +0 -35
- scitex/scholar/.claude/agents/ReviewerAgent.md +0 -70
- scitex/scholar/.claude/agents/SciTeXTranslatorAgent.md +0 -55
- scitex/scholar/.claude/agents/SourceDeveloperAgent.md +0 -48
- scitex/scholar/.claude/agents/TestDeveloperAgent.md +0 -48
- scitex/scholar/.claude/agents/TestResultsReportAgent.md +0 -52
- scitex/scholar/.claude/agents/TestRunnerAgent.md +0 -48
- scitex/scholar/.claude/mcp-config.json +0 -42
- scitex/scholar/.legacy/metadata/doi/utils/legacy/_ConfigurationResolver.py +0 -387
- scitex/scholar/.legacy/metadata/urls/.tmp/open_url/legacy/_MultiInstitutionalResolver.py +0 -397
- scitex/scholar/.legacy/metadata/urls/.tmp/open_url/legacy/_OpenURLResolverWithZenRows.py +0 -718
- scitex/scholar/.legacy/metadata/urls/.tmp/open_url/legacy/_ResumableOpenURLResolver.py +0 -298
- scitex/scholar/.legacy/metadata/urls/.tmp/open_url/legacy/_UnimelbLibraryGoButtonSelector.py +0 -466
- scitex/scholar/.legacy/metadata/urls/.tmp/open_url/legacy/_ZenRowsOpenURLResolver.py +0 -372
- scitex/scholar/docs/to_claude/guidelines/.claude/mcp-config.json +0 -0
- scitex/scholar/docs/to_claude/guidelines/.claude/settings.json +0 -231
- scitex/scholar/url_finder/.tmp/open_url/legacy/_MultiInstitutionalResolver.py +0 -397
- scitex/scholar/url_finder/.tmp/open_url/legacy/_OpenURLResolverWithZenRows.py +0 -718
- scitex/scholar/url_finder/.tmp/open_url/legacy/_ResumableOpenURLResolver.py +0 -298
- scitex/scholar/url_finder/.tmp/open_url/legacy/_UnimelbLibraryGoButtonSelector.py +0 -466
- scitex/scholar/url_finder/.tmp/open_url/legacy/_ZenRowsOpenURLResolver.py +0 -372
- scitex/stats/QUICKSTART.md +0 -260
- scitex/stats/TODO.md +0 -19
- scitex/stats/docs/API.md +0 -165
- scitex/stats/docs/ARCHITECTURE.md +0 -732
- scitex/stats/docs/MIGRATION_GUIDE.md +0 -253
- scitex/stats/docs/PROGRESS.md +0 -635
- scitex/stats/docs/SUMMARY.md +0 -241
- scitex/stats/docs/TODO.md +0 -181
- scitex/stats/docs/ax_parameter_migration.md +0 -125
- scitex/stats/template.py +0 -119
- scitex/stats/tests/categorical/__init__.py +0 -20
- scitex/stats/tests/categorical/_test_chi2.py +0 -708
- scitex/stats/tests/categorical/_test_cochran_q.py +0 -609
- scitex/stats/tests/categorical/_test_fisher.py +0 -585
- scitex/stats/tests/categorical/_test_mcnemar.py +0 -567
- scitex/stats/tests/correlation/_test_kendall.py +0 -508
- scitex/stats/tests/correlation/_test_spearman.py +0 -485
- scitex/stats/tests/correlation/_test_theilsen.py +0 -193
- scitex/stats/tests/nonparametric/__init__.py +0 -23
- scitex/stats/tests/nonparametric/_test_brunner_munzel.py +0 -559
- scitex/stats/tests/nonparametric/_test_friedman.py +0 -595
- scitex/stats/tests/nonparametric/_test_kruskal.py +0 -557
- scitex/stats/tests/nonparametric/_test_mannwhitneyu.py +0 -518
- scitex/stats/tests/nonparametric/_test_wilcoxon.py +0 -505
- scitex/stats/tests/normality/__init__.py +0 -17
- scitex/stats/tests/normality/_test_ks.py +0 -702
- scitex/stats/tests/normality/_test_shapiro.py +0 -498
- scitex/stats/tests/parametric/__init__.py +0 -27
- scitex/stats/tests/parametric/_test_anova.py +0 -625
- scitex/stats/tests/parametric/_test_anova_2way.py +0 -665
- scitex/stats/tests/parametric/_test_anova_rm.py +0 -717
- scitex/stats/tests/parametric/_test_ttest.py +0 -835
- scitex/template/ANALYSIS.md +0 -202
- scitex-2.1.2.dist-info/licenses/LICENSE +0 -21
- {scitex-2.1.2.dist-info → scitex-2.4.2.dist-info}/entry_points.txt +0 -0
scitex/ai/viewed-ai.md
DELETED
|
@@ -1,4984 +0,0 @@
|
|
|
1
|
-
4,982 lines & 13,608 words
|
|
2
|
-
|
|
3
|
-
# Repository View
|
|
4
|
-
#### Repository: `/data/gpfs/projects/punim2354/ywatanabe/SciTeX-Code/src/scitex/ai`
|
|
5
|
-
#### Output: `/data/gpfs/projects/punim2354/ywatanabe/SciTeX-Code/src/scitex/ai/viewed-ai.md`
|
|
6
|
-
|
|
7
|
-
## Configurations
|
|
8
|
-
##### Tree:
|
|
9
|
-
- Maximum depth: 3
|
|
10
|
-
- .gitignore respected
|
|
11
|
-
- Blacklist expresssions:
|
|
12
|
-
```plaintext
|
|
13
|
-
node_modules,.*,*.py[cod],__pycache__,*.elc,env,env-[0-9]*.[0-9]*,[1-2][0-9][0-9
|
|
14
|
-
][0-9]Y-*,htmlcov,*.sif,*.img,*.image,*.sandbox,*.log,logs,build,dist,*_back,*_b
|
|
15
|
-
ackup,*old*,.old,RUNNING,FINISHED
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
#### File content:
|
|
19
|
-
- Number of head: 50
|
|
20
|
-
- Whitelist extensions:
|
|
21
|
-
```plaintext
|
|
22
|
-
.txt,.md,.org,.el,.sh,.py,.yaml,.yml,.json,.def
|
|
23
|
-
```
|
|
24
|
-
- Blacklist expressions:
|
|
25
|
-
```plaintext
|
|
26
|
-
*.mat,*.npy,*.npz,*.csv,*.pkl,*.jpg,*.jpeg,*.mp4,*.pth,*.db*,*.out,*.err,*.cbm,*
|
|
27
|
-
.pt,*.egg-info,*.aux,*.pdf,*.png,*.tiff,*.wav
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
## Tree contents
|
|
32
|
-
.
|
|
33
|
-
├── activation
|
|
34
|
-
│ ├── _define.py
|
|
35
|
-
│ └── __init__.py
|
|
36
|
-
├── classification
|
|
37
|
-
│ ├── Classifier.py
|
|
38
|
-
│ ├── CrossValidationExperiment.py
|
|
39
|
-
│ ├── examples
|
|
40
|
-
│ │ └── timeseries_cv_demo.py
|
|
41
|
-
│ ├── __init__.py
|
|
42
|
-
│ ├── README.md
|
|
43
|
-
│ ├── reporters
|
|
44
|
-
│ │ ├── _BaseClassificationReporter.py
|
|
45
|
-
│ │ ├── _ClassificationReporter.py
|
|
46
|
-
│ │ ├── __init__.py
|
|
47
|
-
│ │ ├── _MultiClassificationReporter.py
|
|
48
|
-
│ │ └── _SingleClassificationReporter.py
|
|
49
|
-
│ └── timeseries
|
|
50
|
-
│ ├── __init__.py
|
|
51
|
-
│ ├── _normalize_timestamp.py
|
|
52
|
-
│ ├── README.md
|
|
53
|
-
│ ├── run_all.sh
|
|
54
|
-
│ ├── _TimeSeriesBlockingSplit.py
|
|
55
|
-
│ ├── _TimeSeriesCalendarSplit.py
|
|
56
|
-
│ ├── _TimeSeriesMetadata.py
|
|
57
|
-
│ ├── _TimeSeriesSlidingWindowSplit.py
|
|
58
|
-
│ ├── _TimeSeriesSlidingWindowSplit_v01-not-using-n_splits.py
|
|
59
|
-
│ ├── _TimeSeriesStrategy.py
|
|
60
|
-
│ └── _TimeSeriesStratifiedSplit.py
|
|
61
|
-
├── clustering
|
|
62
|
-
│ ├── __init__.py
|
|
63
|
-
│ ├── _pca.py
|
|
64
|
-
│ └── _umap.py
|
|
65
|
-
├── feature_extraction
|
|
66
|
-
│ ├── __init__.py
|
|
67
|
-
│ └── vit.py
|
|
68
|
-
├── _gen_ai
|
|
69
|
-
│ ├── _Anthropic.py
|
|
70
|
-
│ ├── _BaseGenAI.py
|
|
71
|
-
│ ├── _calc_cost.py
|
|
72
|
-
│ ├── _DeepSeek.py
|
|
73
|
-
│ ├── _format_output_func.py
|
|
74
|
-
│ ├── _genai_factory.py
|
|
75
|
-
│ ├── _Google.py
|
|
76
|
-
│ ├── _Groq.py
|
|
77
|
-
│ ├── __init__.py
|
|
78
|
-
│ ├── _Llama.py
|
|
79
|
-
│ ├── _OpenAI.py
|
|
80
|
-
│ ├── _PARAMS.py
|
|
81
|
-
│ └── _Perplexity.py
|
|
82
|
-
├── __init__.py
|
|
83
|
-
├── loss
|
|
84
|
-
│ ├── __init__.py
|
|
85
|
-
│ ├── _L1L2Losses.py
|
|
86
|
-
│ └── multi_task_loss.py
|
|
87
|
-
├── metrics
|
|
88
|
-
│ ├── _calc_bacc_from_conf_mat.py
|
|
89
|
-
│ ├── _calc_bacc.py
|
|
90
|
-
│ ├── _calc_clf_report.py
|
|
91
|
-
│ ├── _calc_conf_mat.py
|
|
92
|
-
│ ├── _calc_feature_importance.py
|
|
93
|
-
│ ├── _calc_mcc.py
|
|
94
|
-
│ ├── _calc_pre_rec_auc.py
|
|
95
|
-
│ ├── _calc_roc_auc.py
|
|
96
|
-
│ ├── _calc_seizure_prediction_metrics.py
|
|
97
|
-
│ ├── _calc_silhouette_score.py
|
|
98
|
-
│ ├── __init__.py
|
|
99
|
-
│ └── _normalize_labels.py
|
|
100
|
-
├── optim
|
|
101
|
-
│ ├── _get_set.py
|
|
102
|
-
│ ├── __init__.py
|
|
103
|
-
│ ├── MIGRATION.md
|
|
104
|
-
│ ├── _optimizers.py
|
|
105
|
-
│ └── Ranger_Deep_Learning_Optimizer
|
|
106
|
-
│ ├── __init__.py
|
|
107
|
-
│ ├── LICENSE
|
|
108
|
-
│ ├── ranger-init.jpg
|
|
109
|
-
│ ├── ranger-with-gc-options.jpg
|
|
110
|
-
│ ├── README.md
|
|
111
|
-
│ └── setup.py
|
|
112
|
-
├── plt
|
|
113
|
-
│ ├── __init__.py
|
|
114
|
-
│ ├── _plot_conf_mat.py
|
|
115
|
-
│ ├── _plot_feature_importance.py
|
|
116
|
-
│ ├── _plot_learning_curve.py
|
|
117
|
-
│ ├── _plot_optuna_study.py
|
|
118
|
-
│ ├── _plot_pre_rec_curve.py
|
|
119
|
-
│ └── _plot_roc_curve.py
|
|
120
|
-
├── README.md
|
|
121
|
-
├── sampling
|
|
122
|
-
│ └── undersample.py
|
|
123
|
-
├── sk
|
|
124
|
-
│ ├── _clf.py
|
|
125
|
-
│ ├── __init__.py
|
|
126
|
-
│ └── _to_sktime.py
|
|
127
|
-
├── sklearn
|
|
128
|
-
│ ├── clf.py
|
|
129
|
-
│ ├── __init__.py
|
|
130
|
-
│ └── to_sktime.py
|
|
131
|
-
├── training
|
|
132
|
-
│ ├── _EarlyStopping.py
|
|
133
|
-
│ ├── __init__.py
|
|
134
|
-
│ ├── _LearningCurveLogger.py
|
|
135
|
-
│ └── legacy
|
|
136
|
-
│ ├── early_stopping.py
|
|
137
|
-
│ └── learning_curve_logger.py
|
|
138
|
-
├── utils
|
|
139
|
-
│ ├── _check_params.py
|
|
140
|
-
│ ├── _default_dataset.py
|
|
141
|
-
│ ├── _format_samples_for_sktime.py
|
|
142
|
-
│ ├── grid_search.py
|
|
143
|
-
│ ├── __init__.py
|
|
144
|
-
│ ├── _label_encoder.py
|
|
145
|
-
│ ├── _merge_labels.py
|
|
146
|
-
│ ├── _sliding_window_data_augmentation.py
|
|
147
|
-
│ ├── _under_sample.py
|
|
148
|
-
│ └── _verify_n_gpus.py
|
|
149
|
-
└── viewed-ai.md
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
## File contents
|
|
153
|
-
|
|
154
|
-
### `./activation/_define.py`
|
|
155
|
-
|
|
156
|
-
```python
|
|
157
|
-
import torch.nn as nn
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
def define(act_str):
|
|
161
|
-
acts_dict = {
|
|
162
|
-
"relu": nn.ReLU(),
|
|
163
|
-
"swish": nn.SiLU(),
|
|
164
|
-
"mish": nn.Mish(),
|
|
165
|
-
"lrelu": nn.LeakyReLU(0.1),
|
|
166
|
-
}
|
|
167
|
-
return acts_dict[act_str]
|
|
168
|
-
|
|
169
|
-
...
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
### `./activation/__init__.py`
|
|
174
|
-
|
|
175
|
-
```python
|
|
176
|
-
#!/usr/bin/env python3
|
|
177
|
-
"""Scitex act module."""
|
|
178
|
-
|
|
179
|
-
from ._define import define
|
|
180
|
-
|
|
181
|
-
__all__ = [
|
|
182
|
-
"define",
|
|
183
|
-
]
|
|
184
|
-
|
|
185
|
-
...
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
### `./classification/Classifier.py`
|
|
190
|
-
|
|
191
|
-
```python
|
|
192
|
-
#!/usr/bin/env python3
|
|
193
|
-
# -*- coding: utf-8 -*-
|
|
194
|
-
# Time-stamp: "2024-12-12 06:49:15 (ywatanabe)"
|
|
195
|
-
# File: ./scitex_repo/src/scitex/ai/Classifier.py
|
|
196
|
-
|
|
197
|
-
THIS_FILE = (
|
|
198
|
-
"/data/gpfs/projects/punim2354/ywatanabe/scitex_repo/src/scitex/ai/Classifier.py"
|
|
199
|
-
)
|
|
200
|
-
|
|
201
|
-
"""
|
|
202
|
-
Functionality:
|
|
203
|
-
* Provides a unified interface for initializing various scikit-learn classifiers
|
|
204
|
-
* Supports optional preprocessing with StandardScaler
|
|
205
|
-
|
|
206
|
-
Input:
|
|
207
|
-
* Classifier name as string
|
|
208
|
-
* Optional class weights for imbalanced datasets
|
|
209
|
-
* Optional scaler for feature preprocessing
|
|
210
|
-
|
|
211
|
-
Output:
|
|
212
|
-
* Initialized classifier or pipeline with scaler
|
|
213
|
-
|
|
214
|
-
Prerequisites:
|
|
215
|
-
* scikit-learn
|
|
216
|
-
* Optional: CatBoost for CatBoostClassifier
|
|
217
|
-
"""
|
|
218
|
-
|
|
219
|
-
from typing import Dict, List, Optional, Union
|
|
220
|
-
|
|
221
|
-
from sklearn.base import BaseEstimator as _BaseEstimator
|
|
222
|
-
from sklearn.discriminant_analysis import (
|
|
223
|
-
QuadraticDiscriminantAnalysis as _QuadraticDiscriminantAnalysis,
|
|
224
|
-
)
|
|
225
|
-
from sklearn.ensemble import AdaBoostClassifier as _AdaBoostClassifier
|
|
226
|
-
from sklearn.gaussian_process import (
|
|
227
|
-
GaussianProcessClassifier as _GaussianProcessClassifier,
|
|
228
|
-
)
|
|
229
|
-
from sklearn.linear_model import LogisticRegression as _LogisticRegression
|
|
230
|
-
from sklearn.linear_model import (
|
|
231
|
-
PassiveAggressiveClassifier as _PassiveAggressiveClassifier,
|
|
232
|
-
)
|
|
233
|
-
from sklearn.linear_model import Perceptron as _Perceptron
|
|
234
|
-
from sklearn.linear_model import RidgeClassifier as _RidgeClassifier
|
|
235
|
-
from sklearn.linear_model import SGDClassifier as _SGDClassifier
|
|
236
|
-
from sklearn.neighbors import KNeighborsClassifier as _KNeighborsClassifier
|
|
237
|
-
from sklearn.pipeline import Pipeline as _Pipeline
|
|
238
|
-
from sklearn.pipeline import make_pipeline as _make_pipeline
|
|
239
|
-
from sklearn.preprocessing import StandardScaler as _StandardScaler
|
|
240
|
-
from sklearn.svm import SVC as _SVC
|
|
241
|
-
from sklearn.svm import LinearSVC as _LinearSVC
|
|
242
|
-
|
|
243
|
-
...
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
### `./classification/CrossValidationExperiment.py`
|
|
248
|
-
|
|
249
|
-
```python
|
|
250
|
-
#!/usr/bin/env python3
|
|
251
|
-
# -*- coding: utf-8 -*-
|
|
252
|
-
# Timestamp: "2025-09-22 00:54:37 (ywatanabe)"
|
|
253
|
-
# File: /ssh:sp:/home/ywatanabe/proj/scitex_repo/src/scitex/ml/classification/cross_validation.py
|
|
254
|
-
# ----------------------------------------
|
|
255
|
-
from __future__ import annotations
|
|
256
|
-
import os
|
|
257
|
-
__FILE__ = __file__
|
|
258
|
-
__DIR__ = os.path.dirname(__FILE__)
|
|
259
|
-
# ----------------------------------------
|
|
260
|
-
|
|
261
|
-
"""
|
|
262
|
-
Cross-validation helper for streamlined machine learning experiments.
|
|
263
|
-
|
|
264
|
-
Provides a high-level interface for running cross-validation with
|
|
265
|
-
automatic metric tracking, validation, and report generation.
|
|
266
|
-
"""
|
|
267
|
-
|
|
268
|
-
import time
|
|
269
|
-
from datetime import datetime
|
|
270
|
-
from pathlib import Path
|
|
271
|
-
from typing import Any, Callable, Dict, List, Optional, Union
|
|
272
|
-
|
|
273
|
-
import numpy as np
|
|
274
|
-
import pandas as pd
|
|
275
|
-
from sklearn.model_selection import BaseCrossValidator, StratifiedKFold
|
|
276
|
-
|
|
277
|
-
from .reporters import ClassificationReporter
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
class CrossValidationExperiment:
|
|
281
|
-
"""
|
|
282
|
-
Streamlined cross-validation experiment runner.
|
|
283
|
-
|
|
284
|
-
This class handles:
|
|
285
|
-
- Cross-validation splitting
|
|
286
|
-
- Model training and evaluation
|
|
287
|
-
- Automatic metric calculation
|
|
288
|
-
- Hyperparameter tracking
|
|
289
|
-
- Progress monitoring
|
|
290
|
-
- Report generation
|
|
291
|
-
|
|
292
|
-
Parameters
|
|
293
|
-
----------
|
|
294
|
-
name : str
|
|
295
|
-
Experiment name
|
|
296
|
-
model_fn : Callable
|
|
297
|
-
Function that returns a model instance
|
|
298
|
-
cv : BaseCrossValidator, optional
|
|
299
|
-
Cross-validation splitter (default: 5-fold stratified)
|
|
300
|
-
|
|
301
|
-
...
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
### `./classification/examples/timeseries_cv_demo.py`
|
|
306
|
-
|
|
307
|
-
```python
|
|
308
|
-
#!/usr/bin/env python3
|
|
309
|
-
# -*- coding: utf-8 -*-
|
|
310
|
-
# Timestamp: "2025-09-21 20:20:00 (ywatanabe)"
|
|
311
|
-
# File: timeseries_cv_demo.py
|
|
312
|
-
|
|
313
|
-
"""
|
|
314
|
-
Examples demonstrating the time series cross-validation modules.
|
|
315
|
-
|
|
316
|
-
This script shows how to use:
|
|
317
|
-
1. Individual time series CV splitters
|
|
318
|
-
2. The intelligent TimeSeriesCVCoordinator
|
|
319
|
-
3. Integration with classification reporters
|
|
320
|
-
"""
|
|
321
|
-
|
|
322
|
-
import numpy as np
|
|
323
|
-
import pandas as pd
|
|
324
|
-
from sklearn.linear_model import LogisticRegression
|
|
325
|
-
from sklearn.ensemble import RandomForestClassifier
|
|
326
|
-
from sklearn.metrics import balanced_accuracy_score
|
|
327
|
-
import matplotlib.pyplot as plt
|
|
328
|
-
from typing import List, Tuple
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
def generate_synthetic_timeseries(
|
|
332
|
-
n_samples: int = 1000,
|
|
333
|
-
n_features: int = 10,
|
|
334
|
-
n_groups: int = None,
|
|
335
|
-
noise_level: float = 0.1,
|
|
336
|
-
imbalance_ratio: float = 0.5,
|
|
337
|
-
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
|
|
338
|
-
"""
|
|
339
|
-
Generate synthetic time series data for demonstration.
|
|
340
|
-
|
|
341
|
-
Returns
|
|
342
|
-
-------
|
|
343
|
-
X : Features
|
|
344
|
-
y : Labels (binary)
|
|
345
|
-
timestamps : Time points
|
|
346
|
-
groups : Group labels (if n_groups specified)
|
|
347
|
-
"""
|
|
348
|
-
np.random.seed(42)
|
|
349
|
-
|
|
350
|
-
# Generate features with temporal correlation
|
|
351
|
-
X = np.zeros((n_samples, n_features))
|
|
352
|
-
for i in range(n_features):
|
|
353
|
-
# AR(1) process with different parameters
|
|
354
|
-
phi = 0.3 + i * 0.05 # Autocorrelation
|
|
355
|
-
X[:, i] = np.random.randn(n_samples)
|
|
356
|
-
for t in range(1, n_samples):
|
|
357
|
-
X[t, i] = phi * X[t-1, i] + np.sqrt(1 - phi**2) * np.random.randn()
|
|
358
|
-
|
|
359
|
-
...
|
|
360
|
-
```
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
### `./classification/__init__.py`
|
|
364
|
-
|
|
365
|
-
```python
|
|
366
|
-
#!/usr/bin/env python3
|
|
367
|
-
"""Classification utilities with unified API."""
|
|
368
|
-
|
|
369
|
-
# Import reporters
|
|
370
|
-
from .reporters import ClassificationReporter, SingleTaskClassificationReporter
|
|
371
|
-
|
|
372
|
-
# Import other existing modules
|
|
373
|
-
from .Classifier import Classifier
|
|
374
|
-
from .CrossValidationExperiment import CrossValidationExperiment, quick_experiment
|
|
375
|
-
|
|
376
|
-
# Import time series module
|
|
377
|
-
from . import timeseries
|
|
378
|
-
|
|
379
|
-
# Import time series CV utilities from submodule
|
|
380
|
-
from .timeseries import (
|
|
381
|
-
TimeSeriesStratifiedSplit,
|
|
382
|
-
TimeSeriesBlockingSplit,
|
|
383
|
-
TimeSeriesSlidingWindowSplit,
|
|
384
|
-
TimeSeriesCalendarSplit,
|
|
385
|
-
TimeSeriesStrategy,
|
|
386
|
-
TimeSeriesMetadata,
|
|
387
|
-
)
|
|
388
|
-
|
|
389
|
-
# Backward compatibility alias
|
|
390
|
-
CVExperiment = CrossValidationExperiment
|
|
391
|
-
|
|
392
|
-
__all__ = [
|
|
393
|
-
# Reporters
|
|
394
|
-
"ClassificationReporter",
|
|
395
|
-
"SingleTaskClassificationReporter",
|
|
396
|
-
# Classifier management
|
|
397
|
-
"Classifier",
|
|
398
|
-
# Cross-validation
|
|
399
|
-
"CrossValidationExperiment",
|
|
400
|
-
"CVExperiment", # Alias
|
|
401
|
-
"quick_experiment",
|
|
402
|
-
# Time series module
|
|
403
|
-
"timeseries",
|
|
404
|
-
# Time series CV splitters (re-exported from timeseries module)
|
|
405
|
-
"TimeSeriesStratifiedSplit",
|
|
406
|
-
"TimeSeriesBlockingSplit",
|
|
407
|
-
"TimeSeriesSlidingWindowSplit",
|
|
408
|
-
"TimeSeriesCalendarSplit",
|
|
409
|
-
"TimeSeriesStrategy",
|
|
410
|
-
"TimeSeriesMetadata",
|
|
411
|
-
]
|
|
412
|
-
|
|
413
|
-
...
|
|
414
|
-
```
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
### `./classification/README.md`
|
|
418
|
-
|
|
419
|
-
```markdown
|
|
420
|
-
# SciTeX Classification Module
|
|
421
|
-
|
|
422
|
-
A comprehensive classification module for scientific machine learning experiments with standardized reporting, validation, and publication-ready outputs.
|
|
423
|
-
|
|
424
|
-
## Overview
|
|
425
|
-
|
|
426
|
-
The classification module provides:
|
|
427
|
-
- **Modular reporter utilities** for metric calculation and storage
|
|
428
|
-
- **Single and multi-task classification reporters** with automatic file organization
|
|
429
|
-
- **Validation utilities** to ensure completeness and scientific rigor
|
|
430
|
-
- **Publication-ready exports** in multiple formats (CSV, LaTeX, Markdown)
|
|
431
|
-
- **Decoupled architecture** without hard dependencies on scitex.io
|
|
432
|
-
|
|
433
|
-
## Directory Structure
|
|
434
|
-
|
|
435
|
-
```
|
|
436
|
-
src/scitex/ai/classification/
|
|
437
|
-
├── __init__.py
|
|
438
|
-
├── README.md (this file)
|
|
439
|
-
├── _Classifiers.py # Classifier implementations
|
|
440
|
-
├── Classifier.py # Server for classifier services
|
|
441
|
-
├── _ClassificationReporter.py # Base reporter class
|
|
442
|
-
├── _SingleClassificationReporter.py # Single-task reporter
|
|
443
|
-
├── _MultiClassificationReporter.py # Multi-task reporter
|
|
444
|
-
└── reporter_utils/ # Modular utilities
|
|
445
|
-
├── __init__.py
|
|
446
|
-
├── metrics.py # Pure metric calculations
|
|
447
|
-
├── storage.py # Standalone storage (no scitex.io dependency)
|
|
448
|
-
├── data_models.py # Type-safe data models
|
|
449
|
-
├── validation.py # Validation and completeness checks
|
|
450
|
-
├── aggregation.py # Cross-fold aggregation
|
|
451
|
-
└── reporting.py # Report generation utilities
|
|
452
|
-
```
|
|
453
|
-
|
|
454
|
-
## Quick Start
|
|
455
|
-
|
|
456
|
-
### Basic Usage
|
|
457
|
-
|
|
458
|
-
```python
|
|
459
|
-
from scitex.ai.classification.reporter_utils import (
|
|
460
|
-
calc_bacc,
|
|
461
|
-
calc_mcc,
|
|
462
|
-
MetricStorage,
|
|
463
|
-
create_summary_table,
|
|
464
|
-
generate_markdown_report
|
|
465
|
-
)
|
|
466
|
-
|
|
467
|
-
# Calculate metrics
|
|
468
|
-
ba = calc_bacc(y_true, y_pred, fold=0)
|
|
469
|
-
mcc = calc_mcc(y_true, y_pred, fold=0)
|
|
470
|
-
```
|
|
471
|
-
|
|
472
|
-
...
|
|
473
|
-
```
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
### `./classification/reporters/_BaseClassificationReporter.py`
|
|
477
|
-
|
|
478
|
-
```python
|
|
479
|
-
#!/usr/bin/env python3
|
|
480
|
-
# -*- coding: utf-8 -*-
|
|
481
|
-
# Timestamp: "2025-09-22 15:00:10 (ywatanabe)"
|
|
482
|
-
# File: /ssh:sp:/home/ywatanabe/proj/scitex_repo/src/scitex/ml/classification/reporters/_BaseClassificationReporter.py
|
|
483
|
-
# ----------------------------------------
|
|
484
|
-
from __future__ import annotations
|
|
485
|
-
import os
|
|
486
|
-
__FILE__ = __file__
|
|
487
|
-
__DIR__ = os.path.dirname(__FILE__)
|
|
488
|
-
# ----------------------------------------
|
|
489
|
-
|
|
490
|
-
"""
|
|
491
|
-
Base Classification Reporter - Unified API Interface.
|
|
492
|
-
|
|
493
|
-
This module provides the base class and interface for all classification reporters,
|
|
494
|
-
ensuring consistent APIs and behavior across single-task and multi-task scenarios.
|
|
495
|
-
"""
|
|
496
|
-
|
|
497
|
-
from abc import ABC, abstractmethod
|
|
498
|
-
from pathlib import Path
|
|
499
|
-
from typing import Any, Dict, List, Optional, Union
|
|
500
|
-
|
|
501
|
-
import numpy as np
|
|
502
|
-
from scitex import logging
|
|
503
|
-
|
|
504
|
-
logger = logging.getLogger(__name__)
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
class BaseClassificationReporter(ABC):
|
|
508
|
-
"""
|
|
509
|
-
Abstract base class for all classification reporters.
|
|
510
|
-
|
|
511
|
-
This class defines the unified API that all classification reporters must implement,
|
|
512
|
-
ensuring consistent parameter names, method signatures, and behavior.
|
|
513
|
-
|
|
514
|
-
Parameters
|
|
515
|
-
----------
|
|
516
|
-
output_dir : Union[str, Path]
|
|
517
|
-
Base directory for outputs. If None, creates timestamped directory.
|
|
518
|
-
precision : int, default 3
|
|
519
|
-
Number of decimal places for numerical outputs
|
|
520
|
-
"""
|
|
521
|
-
|
|
522
|
-
def __init__(
|
|
523
|
-
self,
|
|
524
|
-
output_dir: Union[str, Path],
|
|
525
|
-
precision: int = 3,
|
|
526
|
-
verbose=True,
|
|
527
|
-
):
|
|
528
|
-
self.precision = precision
|
|
529
|
-
|
|
530
|
-
...
|
|
531
|
-
```
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
### `./classification/reporters/_ClassificationReporter.py`
|
|
535
|
-
|
|
536
|
-
```python
|
|
537
|
-
#!/usr/bin/env python3
|
|
538
|
-
# -*- coding: utf-8 -*-
|
|
539
|
-
# Timestamp: "2025-10-02 06:38:58 (ywatanabe)"
|
|
540
|
-
# File: /ssh:sp:/home/ywatanabe/proj/scitex_repo/src/scitex/ml/classification/reporters/_ClassificationReporter.py
|
|
541
|
-
# ----------------------------------------
|
|
542
|
-
from __future__ import annotations
|
|
543
|
-
import os
|
|
544
|
-
__FILE__ = __file__
|
|
545
|
-
__DIR__ = os.path.dirname(__FILE__)
|
|
546
|
-
# ----------------------------------------
|
|
547
|
-
|
|
548
|
-
"""
|
|
549
|
-
Unified Classification Reporter.
|
|
550
|
-
|
|
551
|
-
A single, unified reporter that handles both single-task and multi-task
|
|
552
|
-
classification scenarios seamlessly.
|
|
553
|
-
"""
|
|
554
|
-
|
|
555
|
-
from pathlib import Path
|
|
556
|
-
from typing import Any, Dict, List, Optional, Union
|
|
557
|
-
|
|
558
|
-
import numpy as np
|
|
559
|
-
|
|
560
|
-
# Import base class and single reporter for internal use
|
|
561
|
-
from ._BaseClassificationReporter import (BaseClassificationReporter,
|
|
562
|
-
ReporterConfig)
|
|
563
|
-
from ._SingleClassificationReporter import SingleTaskClassificationReporter
|
|
564
|
-
from .reporter_utils.storage import MetricStorage
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
class ClassificationReporter(BaseClassificationReporter):
|
|
568
|
-
"""
|
|
569
|
-
Unified classification reporter for single and multi-task scenarios.
|
|
570
|
-
|
|
571
|
-
This reporter automatically adapts to your use case:
|
|
572
|
-
- Single task: Just use it without specifying tasks
|
|
573
|
-
- Multiple tasks: Specify tasks upfront or create them dynamically
|
|
574
|
-
- Seamless switching between single and multi-task workflows
|
|
575
|
-
|
|
576
|
-
Features:
|
|
577
|
-
- Comprehensive metrics calculation (balanced accuracy, MCC, ROC-AUC, PR-AUC, etc.)
|
|
578
|
-
- Automated visualization generation:
|
|
579
|
-
* Confusion matrices
|
|
580
|
-
* ROC and Precision-Recall curves
|
|
581
|
-
* Feature importance plots (via plotter)
|
|
582
|
-
* CV aggregation plots with faded fold lines
|
|
583
|
-
* Comprehensive metrics dashboard
|
|
584
|
-
- Multi-format report generation (Org, Markdown, LaTeX, HTML, DOCX, PDF)
|
|
585
|
-
- Cross-validation support with automatic fold aggregation
|
|
586
|
-
- Multi-task classification tracking
|
|
587
|
-
|
|
588
|
-
...
|
|
589
|
-
```
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
### `./classification/reporters/__init__.py`
|
|
593
|
-
|
|
594
|
-
```python
|
|
595
|
-
#!/usr/bin/env python3
|
|
596
|
-
"""Reporter implementations for classification."""
|
|
597
|
-
|
|
598
|
-
# Export the unified reporter and single-task reporter
|
|
599
|
-
from ._ClassificationReporter import ClassificationReporter
|
|
600
|
-
from ._SingleClassificationReporter import SingleTaskClassificationReporter
|
|
601
|
-
|
|
602
|
-
__all__ = [
|
|
603
|
-
"ClassificationReporter",
|
|
604
|
-
"SingleTaskClassificationReporter",
|
|
605
|
-
]
|
|
606
|
-
...
|
|
607
|
-
```
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
### `./classification/reporters/_MultiClassificationReporter.py`
|
|
611
|
-
|
|
612
|
-
```python
|
|
613
|
-
#!/usr/bin/env python3
|
|
614
|
-
# -*- coding: utf-8 -*-
|
|
615
|
-
# Timestamp: "2025-09-22 15:00:55 (ywatanabe)"
|
|
616
|
-
# File: /ssh:sp:/home/ywatanabe/proj/scitex_repo/src/scitex/ml/classification/reporters/_MultiClassificationReporter.py
|
|
617
|
-
# ----------------------------------------
|
|
618
|
-
from __future__ import annotations
|
|
619
|
-
import os
|
|
620
|
-
__FILE__ = __file__
|
|
621
|
-
__DIR__ = os.path.dirname(__FILE__)
|
|
622
|
-
# ----------------------------------------
|
|
623
|
-
|
|
624
|
-
"""
|
|
625
|
-
Improved Multiple Tasks Classification Reporter with unified API.
|
|
626
|
-
|
|
627
|
-
Enhanced version that addresses all identified issues:
|
|
628
|
-
- Unified API interface matching SingleTaskClassificationReporter
|
|
629
|
-
- Lazy directory creation
|
|
630
|
-
- Numerical precision control
|
|
631
|
-
- Graceful plotting with error handling
|
|
632
|
-
- Consistent parameter names
|
|
633
|
-
"""
|
|
634
|
-
|
|
635
|
-
from pathlib import Path
|
|
636
|
-
from typing import Any, Dict, List, Optional, Union
|
|
637
|
-
|
|
638
|
-
import numpy as np
|
|
639
|
-
|
|
640
|
-
# Import base class and improved single reporter
|
|
641
|
-
from ._BaseClassificationReporter import (BaseClassificationReporter,
|
|
642
|
-
ReporterConfig)
|
|
643
|
-
from ._SingleClassificationReporter import SingleTaskClassificationReporter
|
|
644
|
-
from .reporter_utils.storage import MetricStorage
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
class MultipleTasksClassificationReporter(BaseClassificationReporter):
|
|
648
|
-
"""
|
|
649
|
-
Improved multi-task classification reporter with unified API.
|
|
650
|
-
|
|
651
|
-
This reporter manages multiple SingleTaskClassificationReporter instances,
|
|
652
|
-
one for each target/task, providing a unified interface for multi-task scenarios.
|
|
653
|
-
|
|
654
|
-
Key improvements:
|
|
655
|
-
- Same API as SingleTaskClassificationReporter (calculate_metrics method)
|
|
656
|
-
- Lazy directory creation (no empty folders)
|
|
657
|
-
- Numerical precision control
|
|
658
|
-
- Graceful plotting with proper error handling
|
|
659
|
-
- Consistent parameter names across all methods
|
|
660
|
-
|
|
661
|
-
Parameters
|
|
662
|
-
----------
|
|
663
|
-
|
|
664
|
-
...
|
|
665
|
-
```
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
### `./classification/reporters/_SingleClassificationReporter.py`
|
|
669
|
-
|
|
670
|
-
```python
|
|
671
|
-
#!/usr/bin/env python3
|
|
672
|
-
# -*- coding: utf-8 -*-
|
|
673
|
-
# Timestamp: "2025-10-03 01:21:52 (ywatanabe)"
|
|
674
|
-
# File: /ssh:sp:/home/ywatanabe/proj/scitex_repo/src/scitex/ml/classification/reporters/_SingleClassificationReporter.py
|
|
675
|
-
# ----------------------------------------
|
|
676
|
-
from __future__ import annotations
|
|
677
|
-
import os
|
|
678
|
-
__FILE__ = (
|
|
679
|
-
"./src/scitex/ml/classification/reporters/_SingleClassificationReporter.py"
|
|
680
|
-
)
|
|
681
|
-
__DIR__ = os.path.dirname(__FILE__)
|
|
682
|
-
# ----------------------------------------
|
|
683
|
-
|
|
684
|
-
__FILE__ = __file__
|
|
685
|
-
|
|
686
|
-
from pprint import pprint
|
|
687
|
-
|
|
688
|
-
"""
|
|
689
|
-
Improved Single Classification Reporter with unified API.
|
|
690
|
-
|
|
691
|
-
Enhanced version that addresses all identified issues:
|
|
692
|
-
- Unified API interface
|
|
693
|
-
- Lazy directory creation
|
|
694
|
-
- Numerical precision control
|
|
695
|
-
- Graceful plotting with error handling
|
|
696
|
-
- Consistent parameter names
|
|
697
|
-
"""
|
|
698
|
-
|
|
699
|
-
from pathlib import Path
|
|
700
|
-
from typing import Any, Dict, List, Optional, Union
|
|
701
|
-
|
|
702
|
-
import numpy as np
|
|
703
|
-
import pandas as pd
|
|
704
|
-
from scitex.logging import getLogger
|
|
705
|
-
|
|
706
|
-
# Import base class and utilities
|
|
707
|
-
from ._BaseClassificationReporter import (BaseClassificationReporter,
|
|
708
|
-
ReporterConfig)
|
|
709
|
-
# Import original metric calculation functions (these are good)
|
|
710
|
-
from .reporter_utils import (calc_bacc, calc_clf_report, calc_conf_mat,
|
|
711
|
-
calc_mcc, calc_pre_rec_auc, calc_roc_auc)
|
|
712
|
-
from .reporter_utils._Plotter import Plotter
|
|
713
|
-
from .reporter_utils.reporting import (create_summary_statistics,
|
|
714
|
-
generate_latex_report,
|
|
715
|
-
generate_markdown_report,
|
|
716
|
-
generate_org_report)
|
|
717
|
-
from .reporter_utils.storage import MetricStorage, save_metric
|
|
718
|
-
|
|
719
|
-
logger = getLogger(__name__)
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
...
|
|
723
|
-
```
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
### `./classification/timeseries/__init__.py`
|
|
727
|
-
|
|
728
|
-
```python
|
|
729
|
-
#!/usr/bin/env python3
|
|
730
|
-
# -*- coding: utf-8 -*-
|
|
731
|
-
# Timestamp: "2025-09-21 20:45:00 (ywatanabe)"
|
|
732
|
-
# File: timeseries/__init__.py
|
|
733
|
-
|
|
734
|
-
"""
|
|
735
|
-
Time series cross-validation utilities for classification.
|
|
736
|
-
|
|
737
|
-
This module provides specialized cross-validation strategies for time series data,
|
|
738
|
-
ensuring proper temporal ordering and preventing data leakage.
|
|
739
|
-
"""
|
|
740
|
-
|
|
741
|
-
# Import splitters
|
|
742
|
-
from ._TimeSeriesStratifiedSplit import TimeSeriesStratifiedSplit
|
|
743
|
-
from ._TimeSeriesBlockingSplit import TimeSeriesBlockingSplit
|
|
744
|
-
from ._TimeSeriesSlidingWindowSplit import TimeSeriesSlidingWindowSplit
|
|
745
|
-
from ._TimeSeriesCalendarSplit import TimeSeriesCalendarSplit
|
|
746
|
-
|
|
747
|
-
# Import metadata and strategy
|
|
748
|
-
from ._TimeSeriesStrategy import TimeSeriesStrategy
|
|
749
|
-
from ._TimeSeriesMetadata import TimeSeriesMetadata
|
|
750
|
-
|
|
751
|
-
# Import timestamp normalizer
|
|
752
|
-
from ._normalize_timestamp import normalize_timestamp
|
|
753
|
-
|
|
754
|
-
__all__ = [
|
|
755
|
-
# Main time series CV splitters
|
|
756
|
-
"TimeSeriesStratifiedSplit",
|
|
757
|
-
"TimeSeriesBlockingSplit",
|
|
758
|
-
"TimeSeriesSlidingWindowSplit",
|
|
759
|
-
"TimeSeriesCalendarSplit",
|
|
760
|
-
|
|
761
|
-
# Support classes
|
|
762
|
-
"TimeSeriesStrategy",
|
|
763
|
-
"TimeSeriesMetadata",
|
|
764
|
-
|
|
765
|
-
# Timestamp normalizer
|
|
766
|
-
"normalize_timestamp",
|
|
767
|
-
]
|
|
768
|
-
...
|
|
769
|
-
```
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
### `./classification/timeseries/_normalize_timestamp.py`
|
|
773
|
-
|
|
774
|
-
```python
|
|
775
|
-
#!/usr/bin/env python3
|
|
776
|
-
# -*- coding: utf-8 -*-
|
|
777
|
-
# Timestamp: "2025-09-22 15:21:06 (ywatanabe)"
|
|
778
|
-
# File: /ssh:sp:/home/ywatanabe/proj/scitex_repo/src/scitex/ml/classification/timeseries/_normalize_timestamp.py
|
|
779
|
-
# ----------------------------------------
|
|
780
|
-
from __future__ import annotations
|
|
781
|
-
import os
|
|
782
|
-
__FILE__ = __file__
|
|
783
|
-
__DIR__ = os.path.dirname(__FILE__)
|
|
784
|
-
# ----------------------------------------
|
|
785
|
-
|
|
786
|
-
"""
|
|
787
|
-
Timestamp Standardization Utilities
|
|
788
|
-
|
|
789
|
-
Functionality:
|
|
790
|
-
- Standardizes timestamps to consistent format defined in CONFIG.FORMATS.TIMESTAMP
|
|
791
|
-
- Handles various input formats (datetime objects, strings, timestamps)
|
|
792
|
-
- Provides UTC normalization
|
|
793
|
-
- Ensures consistent timestamp formatting across the codebase
|
|
794
|
-
|
|
795
|
-
Input formats supported:
|
|
796
|
-
- datetime objects (with or without timezone)
|
|
797
|
-
- Unix timestamps (int/float)
|
|
798
|
-
- Various string formats
|
|
799
|
-
|
|
800
|
-
Output:
|
|
801
|
-
- Standardized timestamp strings in format: "%Y-%m-%d %H:%M:%S.%f"
|
|
802
|
-
- UTC normalized timestamps
|
|
803
|
-
- Validation utilities
|
|
804
|
-
|
|
805
|
-
Prerequisites:
|
|
806
|
-
- CONFIG.FORMATS.TIMESTAMP for standard format
|
|
807
|
-
"""
|
|
808
|
-
|
|
809
|
-
"""Imports"""
|
|
810
|
-
import argparse
|
|
811
|
-
from datetime import datetime, timezone
|
|
812
|
-
from typing import Union
|
|
813
|
-
|
|
814
|
-
import scitex as stx
|
|
815
|
-
|
|
816
|
-
"""Parameters"""
|
|
817
|
-
# Default standard format if CONFIG not available
|
|
818
|
-
try:
|
|
819
|
-
CONFIG = stx.io.load_configs()
|
|
820
|
-
STANDARD_FORMAT = CONFIG.FORMATS.TIMESTAMP
|
|
821
|
-
except (AttributeError, ImportError):
|
|
822
|
-
# Fallback to a sensible default
|
|
823
|
-
STANDARD_FORMAT = "%Y-%m-%d %H:%M:%S.%f"
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
...
|
|
827
|
-
```
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
### `./classification/timeseries/README.md`
|
|
831
|
-
|
|
832
|
-
```markdown
|
|
833
|
-
# Time Series Cross-Validation Module
|
|
834
|
-
|
|
835
|
-
Production-ready time series cross-validation utilities with temporal integrity guarantees and enhanced visualizations.
|
|
836
|
-
|
|
837
|
-
## 🎯 Overview
|
|
838
|
-
|
|
839
|
-
This module provides specialized cross-validation strategies for time series data, ensuring:
|
|
840
|
-
- **Temporal order preservation** (no future data leakage)
|
|
841
|
-
- **Visual verification** with scatter plot overlays
|
|
842
|
-
- **SciTeX framework integration** for standalone testing
|
|
843
|
-
- **Support for multiple time series scenarios**
|
|
844
|
-
- **Calendar-aware splitting** with business logic
|
|
845
|
-
- **Robust timestamp handling** across formats
|
|
846
|
-
|
|
847
|
-
## 📊 Visual Comparison of Splitters
|
|
848
|
-
|
|
849
|
-
### TimeSeriesStratifiedSplit
|
|
850
|
-
```
|
|
851
|
-
Maintains class balance while preserving temporal order
|
|
852
|
-
Supports optional validation set between train and test
|
|
853
|
-
|
|
854
|
-
Without validation: With validation (val_ratio=0.15):
|
|
855
|
-
Fold 0: [TTTTTTTTTT] [SSS] Fold 0: [TTTTTTTT] [VV] [SSS]
|
|
856
|
-
Fold 1: [TTTTTTTTTTTT] [SSS] Fold 1: [TTTTTTTTTT][VV] [SSS]
|
|
857
|
-
Fold 2: [TTTTTTTTTTTTTT][SSS] Fold 2: [TTTTTTTTTTTT][VV][SSS]
|
|
858
|
-
└─ Expanding ─┘ Test └─Expanding─┘ Val Test
|
|
859
|
-
|
|
860
|
-
Legend: T=Train, V=Validation, S=teSt
|
|
861
|
-
```
|
|
862
|
-
|
|
863
|
-
### TimeSeriesSlidingWindowSplit
|
|
864
|
-
```
|
|
865
|
-
Fixed-size windows sliding through time
|
|
866
|
-
Optional validation carved from training window
|
|
867
|
-
|
|
868
|
-
Without validation: With validation (val_ratio=0.2):
|
|
869
|
-
Fold 0: [TTTT] [SS] Fold 0: [TTT][V] [SS]
|
|
870
|
-
Fold 1: [TTTT] [SS] Fold 1: [TTT][V] [SS]
|
|
871
|
-
Fold 2: [TTTT] [SS] Fold 2: [TTT][V] [SS]
|
|
872
|
-
└─Win─┘ Gap └Test┘ └Train┘Val Gap└Test┘
|
|
873
|
-
|
|
874
|
-
Legend: T=Train, V=Validation, S=teSt, Gap=temporal separation
|
|
875
|
-
```
|
|
876
|
-
|
|
877
|
-
### TimeSeriesBlockingSplit
|
|
878
|
-
```
|
|
879
|
-
Multiple subjects with temporal separation per subject
|
|
880
|
-
Each subject gets its own train/val/test split
|
|
881
|
-
|
|
882
|
-
Without validation: With validation (val_ratio=0.15):
|
|
883
|
-
```
|
|
884
|
-
|
|
885
|
-
...
|
|
886
|
-
```
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
### `./classification/timeseries/run_all.sh`
|
|
890
|
-
|
|
891
|
-
```bash
|
|
892
|
-
#!/bin/bash
|
|
893
|
-
# -*- coding: utf-8 -*-
|
|
894
|
-
# Timestamp: "2025-09-22 17:50:10 (ywatanabe)"
|
|
895
|
-
# File: ./src/scitex/ml/classification/timeseries/run_all.sh
|
|
896
|
-
|
|
897
|
-
THIS_DIR="$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)"
|
|
898
|
-
LOG_PATH="$THIS_DIR/.$(basename $0).log"
|
|
899
|
-
echo > "$LOG_PATH"
|
|
900
|
-
|
|
901
|
-
BLACK='\033[0;30m'
|
|
902
|
-
LIGHT_GRAY='\033[0;37m'
|
|
903
|
-
GREEN='\033[0;32m'
|
|
904
|
-
YELLOW='\033[0;33m'
|
|
905
|
-
RED='\033[0;31m'
|
|
906
|
-
NC='\033[0m' # No Color
|
|
907
|
-
|
|
908
|
-
echo_info() { echo -e "${LIGHT_GRAY}$1${NC}"; }
|
|
909
|
-
echo_success() { echo -e "${GREEN}$1${NC}"; }
|
|
910
|
-
echo_warning() { echo -e "${YELLOW}$1${NC}"; }
|
|
911
|
-
echo_error() { echo -e "${RED}$1${NC}"; }
|
|
912
|
-
# ---------------------------------------
|
|
913
|
-
|
|
914
|
-
python -m scitex.ai.classification.timeseries._TimeSeriesBlockingSplit
|
|
915
|
-
python -m scitex.ai.classification.timeseries._TimeSeriesCalendarSplit
|
|
916
|
-
python -m scitex.ai.classification.timeseries._TimeSeriesMetadata
|
|
917
|
-
python -m scitex.ai.classification.timeseries._TimeSeriesSlidingWindowSplit
|
|
918
|
-
python -m scitex.ai.classification.timeseries._TimeSeriesStrategy
|
|
919
|
-
python -m scitex.ai.classification.timeseries._TimeSeriesStratifiedSplit
|
|
920
|
-
|
|
921
|
-
# EOF
|
|
922
|
-
...
|
|
923
|
-
```
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
### `./classification/timeseries/_TimeSeriesBlockingSplit.py`
|
|
927
|
-
|
|
928
|
-
```python
|
|
929
|
-
#!/usr/bin/env python3
|
|
930
|
-
# -*- coding: utf-8 -*-
|
|
931
|
-
# Timestamp: "2025-09-22 17:10:00 (ywatanabe)"
|
|
932
|
-
# File: _TimeSeriesBlockingSplit.py
|
|
933
|
-
|
|
934
|
-
__FILE__ = "_TimeSeriesBlockingSplit.py"
|
|
935
|
-
|
|
936
|
-
"""
|
|
937
|
-
Functionalities:
|
|
938
|
-
- Implements time series split with blocking for multiple subjects/groups
|
|
939
|
-
- Ensures temporal integrity within each subject's timeline
|
|
940
|
-
- Allows cross-subject generalization while preventing data leakage
|
|
941
|
-
- Provides visualization with scatter plots and subject color coding
|
|
942
|
-
- Validates that no data mixing occurs between subjects
|
|
943
|
-
- Supports expanding window approach for more training data in later folds
|
|
944
|
-
|
|
945
|
-
Dependencies:
|
|
946
|
-
- packages:
|
|
947
|
-
- numpy
|
|
948
|
-
- sklearn
|
|
949
|
-
- matplotlib
|
|
950
|
-
- scitex
|
|
951
|
-
|
|
952
|
-
IO:
|
|
953
|
-
- input-files:
|
|
954
|
-
- None (generates synthetic multi-subject data for demonstration)
|
|
955
|
-
- output-files:
|
|
956
|
-
- ./blocking_splits_demo.png (visualization with scatter plots)
|
|
957
|
-
"""
|
|
958
|
-
|
|
959
|
-
"""Imports"""
|
|
960
|
-
import os
|
|
961
|
-
import sys
|
|
962
|
-
import argparse
|
|
963
|
-
import numpy as np
|
|
964
|
-
from typing import Iterator, Optional, Tuple
|
|
965
|
-
from sklearn.model_selection import BaseCrossValidator
|
|
966
|
-
import matplotlib.pyplot as plt
|
|
967
|
-
import matplotlib.patches as patches
|
|
968
|
-
import scitex as stx
|
|
969
|
-
from scitex import logging
|
|
970
|
-
|
|
971
|
-
logger = logging.getLogger(__name__)
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
class TimeSeriesBlockingSplit(BaseCrossValidator):
|
|
975
|
-
"""
|
|
976
|
-
Time series split with blocking to handle multiple subjects/groups.
|
|
977
|
-
|
|
978
|
-
This splitter ensures temporal integrity within each subject while allowing
|
|
979
|
-
|
|
980
|
-
...
|
|
981
|
-
```
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
### `./classification/timeseries/_TimeSeriesCalendarSplit.py`
|
|
985
|
-
|
|
986
|
-
```python
|
|
987
|
-
#!/usr/bin/env python3
|
|
988
|
-
# -*- coding: utf-8 -*-
|
|
989
|
-
# Timestamp: "2025-09-22 17:15:00 (ywatanabe)"
|
|
990
|
-
# File: _TimeSeriesCalendarSplit.py
|
|
991
|
-
|
|
992
|
-
__FILE__ = "_TimeSeriesCalendarSplit.py"
|
|
993
|
-
|
|
994
|
-
"""
|
|
995
|
-
Functionalities:
|
|
996
|
-
- Implements calendar-based time series cross-validation
|
|
997
|
-
- Splits data based on calendar intervals (monthly, weekly, daily)
|
|
998
|
-
- Ensures temporal order preservation with no data leakage
|
|
999
|
-
- Supports flexible interval definitions (D, W, M, Q, Y)
|
|
1000
|
-
- Provides visualization with scatter plots showing actual data points
|
|
1001
|
-
- Useful for financial data, sales forecasting, seasonal patterns
|
|
1002
|
-
|
|
1003
|
-
Dependencies:
|
|
1004
|
-
- packages:
|
|
1005
|
-
- numpy
|
|
1006
|
-
- pandas
|
|
1007
|
-
- sklearn
|
|
1008
|
-
- matplotlib
|
|
1009
|
-
- scitex
|
|
1010
|
-
|
|
1011
|
-
IO:
|
|
1012
|
-
- input-files:
|
|
1013
|
-
- None (generates synthetic calendar-based data for demonstration)
|
|
1014
|
-
- output-files:
|
|
1015
|
-
- ./calendar_splits_demo.png (visualization with scatter plots)
|
|
1016
|
-
"""
|
|
1017
|
-
|
|
1018
|
-
"""Imports"""
|
|
1019
|
-
import os
|
|
1020
|
-
import sys
|
|
1021
|
-
import argparse
|
|
1022
|
-
import numpy as np
|
|
1023
|
-
import pandas as pd
|
|
1024
|
-
from typing import Iterator, Optional, Tuple, Union, Literal
|
|
1025
|
-
from sklearn.model_selection import BaseCrossValidator
|
|
1026
|
-
from sklearn.utils.validation import _num_samples
|
|
1027
|
-
import matplotlib.pyplot as plt
|
|
1028
|
-
import matplotlib.patches as patches
|
|
1029
|
-
import scitex as stx
|
|
1030
|
-
from scitex import logging
|
|
1031
|
-
|
|
1032
|
-
# Import timestamp normalizer (internally uses to_datetime helper)
|
|
1033
|
-
from ._normalize_timestamp import normalize_timestamp, to_datetime
|
|
1034
|
-
|
|
1035
|
-
logger = logging.getLogger(__name__)
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
...
|
|
1039
|
-
```
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
### `./classification/timeseries/_TimeSeriesMetadata.py`
|
|
1043
|
-
|
|
1044
|
-
```python
|
|
1045
|
-
#!/usr/bin/env python3
|
|
1046
|
-
# -*- coding: utf-8 -*-
|
|
1047
|
-
# Timestamp: "2025-09-21 20:48:00 (ywatanabe)"
|
|
1048
|
-
# File: _TimeSeriesMetadata.py
|
|
1049
|
-
|
|
1050
|
-
"""
|
|
1051
|
-
Time series metadata dataclass.
|
|
1052
|
-
|
|
1053
|
-
Stores comprehensive metadata about time series datasets for informed
|
|
1054
|
-
cross-validation strategy selection.
|
|
1055
|
-
"""
|
|
1056
|
-
|
|
1057
|
-
from dataclasses import dataclass
|
|
1058
|
-
from typing import Optional, Dict, Tuple, Any
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
@dataclass
|
|
1062
|
-
class TimeSeriesMetadata:
|
|
1063
|
-
"""
|
|
1064
|
-
Metadata about the time series data.
|
|
1065
|
-
|
|
1066
|
-
This dataclass captures essential characteristics of time series data
|
|
1067
|
-
that inform the selection of appropriate cross-validation strategies.
|
|
1068
|
-
|
|
1069
|
-
Attributes
|
|
1070
|
-
----------
|
|
1071
|
-
n_samples : int
|
|
1072
|
-
Total number of samples in the dataset
|
|
1073
|
-
n_features : int
|
|
1074
|
-
Number of features per sample
|
|
1075
|
-
n_classes : Optional[int]
|
|
1076
|
-
Number of unique classes (None for regression)
|
|
1077
|
-
has_groups : bool
|
|
1078
|
-
Whether data contains group/subject identifiers
|
|
1079
|
-
group_sizes : Optional[Dict[Any, int]]
|
|
1080
|
-
Mapping of group IDs to their sample counts
|
|
1081
|
-
time_range : Optional[Tuple[float, float]]
|
|
1082
|
-
Minimum and maximum timestamp values
|
|
1083
|
-
sampling_rate : Optional[float]
|
|
1084
|
-
Samples per time unit (e.g., Hz for sensor data)
|
|
1085
|
-
has_gaps : bool
|
|
1086
|
-
Whether the time series has temporal gaps
|
|
1087
|
-
max_gap_size : Optional[float]
|
|
1088
|
-
Maximum gap between consecutive timestamps
|
|
1089
|
-
is_balanced : bool
|
|
1090
|
-
Whether classes are balanced (for classification)
|
|
1091
|
-
class_distribution : Optional[Dict[Any, float]]
|
|
1092
|
-
Mapping of class labels to their proportions
|
|
1093
|
-
|
|
1094
|
-
Examples
|
|
1095
|
-
|
|
1096
|
-
...
|
|
1097
|
-
```
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
### `./classification/timeseries/_TimeSeriesSlidingWindowSplit.py`
|
|
1101
|
-
|
|
1102
|
-
```python
|
|
1103
|
-
#!/usr/bin/env python3
|
|
1104
|
-
# -*- coding: utf-8 -*-
|
|
1105
|
-
# Timestamp: "2025-10-03 03:22:45 (ywatanabe)"
|
|
1106
|
-
# File: /ssh:sp:/home/ywatanabe/proj/scitex_repo/src/scitex/ml/classification/timeseries/_TimeSeriesSlidingWindowSplit.py
|
|
1107
|
-
# ----------------------------------------
|
|
1108
|
-
from __future__ import annotations
|
|
1109
|
-
import os
|
|
1110
|
-
__FILE__ = (
|
|
1111
|
-
"./src/scitex/ml/classification/timeseries/_TimeSeriesSlidingWindowSplit.py"
|
|
1112
|
-
)
|
|
1113
|
-
__DIR__ = os.path.dirname(__FILE__)
|
|
1114
|
-
# ----------------------------------------
|
|
1115
|
-
|
|
1116
|
-
"""
|
|
1117
|
-
Functionalities:
|
|
1118
|
-
- Implements sliding window cross-validation for time series
|
|
1119
|
-
- Creates overlapping train/test windows that slide through time
|
|
1120
|
-
- Supports temporal gaps between train and test sets
|
|
1121
|
-
- Provides visualization with scatter plots showing actual data points
|
|
1122
|
-
- Validates temporal order in all windows
|
|
1123
|
-
- Ensures no data leakage between train and test sets
|
|
1124
|
-
|
|
1125
|
-
Dependencies:
|
|
1126
|
-
- packages:
|
|
1127
|
-
- numpy
|
|
1128
|
-
- sklearn
|
|
1129
|
-
- matplotlib
|
|
1130
|
-
- scitex
|
|
1131
|
-
|
|
1132
|
-
IO:
|
|
1133
|
-
- input-files:
|
|
1134
|
-
- None (generates synthetic data for demonstration)
|
|
1135
|
-
- output-files:
|
|
1136
|
-
- ./sliding_window_demo.png (visualization with scatter plots)
|
|
1137
|
-
"""
|
|
1138
|
-
|
|
1139
|
-
"""Imports"""
|
|
1140
|
-
import argparse
|
|
1141
|
-
from typing import Iterator, Optional, Tuple
|
|
1142
|
-
|
|
1143
|
-
import matplotlib.patches as patches
|
|
1144
|
-
import matplotlib.pyplot as plt
|
|
1145
|
-
import numpy as np
|
|
1146
|
-
import scitex as stx
|
|
1147
|
-
from scitex import logging
|
|
1148
|
-
from sklearn.model_selection import BaseCrossValidator
|
|
1149
|
-
from sklearn.utils.validation import _num_samples
|
|
1150
|
-
|
|
1151
|
-
logger = logging.getLogger(__name__)
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
...
|
|
1155
|
-
```
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
### `./classification/timeseries/_TimeSeriesSlidingWindowSplit_v01-not-using-n_splits.py`
|
|
1159
|
-
|
|
1160
|
-
```python
|
|
1161
|
-
#!/usr/bin/env python3
|
|
1162
|
-
# -*- coding: utf-8 -*-
|
|
1163
|
-
# Timestamp: "2025-10-03 03:22:45 (ywatanabe)"
|
|
1164
|
-
# File: /ssh:sp:/home/ywatanabe/proj/scitex_repo/src/scitex/ml/classification/timeseries/_TimeSeriesSlidingWindowSplit.py
|
|
1165
|
-
# ----------------------------------------
|
|
1166
|
-
from __future__ import annotations
|
|
1167
|
-
import os
|
|
1168
|
-
__FILE__ = (
|
|
1169
|
-
"./src/scitex/ml/classification/timeseries/_TimeSeriesSlidingWindowSplit.py"
|
|
1170
|
-
)
|
|
1171
|
-
__DIR__ = os.path.dirname(__FILE__)
|
|
1172
|
-
# ----------------------------------------
|
|
1173
|
-
|
|
1174
|
-
"""
|
|
1175
|
-
Functionalities:
|
|
1176
|
-
- Implements sliding window cross-validation for time series
|
|
1177
|
-
- Creates overlapping train/test windows that slide through time
|
|
1178
|
-
- Supports temporal gaps between train and test sets
|
|
1179
|
-
- Provides visualization with scatter plots showing actual data points
|
|
1180
|
-
- Validates temporal order in all windows
|
|
1181
|
-
- Ensures no data leakage between train and test sets
|
|
1182
|
-
|
|
1183
|
-
Dependencies:
|
|
1184
|
-
- packages:
|
|
1185
|
-
- numpy
|
|
1186
|
-
- sklearn
|
|
1187
|
-
- matplotlib
|
|
1188
|
-
- scitex
|
|
1189
|
-
|
|
1190
|
-
IO:
|
|
1191
|
-
- input-files:
|
|
1192
|
-
- None (generates synthetic data for demonstration)
|
|
1193
|
-
- output-files:
|
|
1194
|
-
- ./sliding_window_demo.png (visualization with scatter plots)
|
|
1195
|
-
"""
|
|
1196
|
-
|
|
1197
|
-
"""Imports"""
|
|
1198
|
-
import argparse
|
|
1199
|
-
from typing import Iterator, Optional, Tuple
|
|
1200
|
-
|
|
1201
|
-
import matplotlib.patches as patches
|
|
1202
|
-
import matplotlib.pyplot as plt
|
|
1203
|
-
import numpy as np
|
|
1204
|
-
import scitex as stx
|
|
1205
|
-
from scitex import logging
|
|
1206
|
-
from sklearn.model_selection import BaseCrossValidator
|
|
1207
|
-
from sklearn.utils.validation import _num_samples
|
|
1208
|
-
|
|
1209
|
-
logger = logging.getLogger(__name__)
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
...
|
|
1213
|
-
```
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
### `./classification/timeseries/_TimeSeriesStrategy.py`
|
|
1217
|
-
|
|
1218
|
-
```python
|
|
1219
|
-
#!/usr/bin/env python3
|
|
1220
|
-
# -*- coding: utf-8 -*-
|
|
1221
|
-
# Timestamp: "2025-09-21 20:45:00 (ywatanabe)"
|
|
1222
|
-
# File: _TimeSeriesStrategy.py
|
|
1223
|
-
|
|
1224
|
-
"""
|
|
1225
|
-
Time series cross-validation strategy enumeration.
|
|
1226
|
-
|
|
1227
|
-
Defines available strategies for time series CV.
|
|
1228
|
-
"""
|
|
1229
|
-
|
|
1230
|
-
from enum import Enum
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
class TimeSeriesStrategy(Enum):
|
|
1234
|
-
"""
|
|
1235
|
-
Available time series CV strategies.
|
|
1236
|
-
|
|
1237
|
-
Attributes
|
|
1238
|
-
----------
|
|
1239
|
-
STRATIFIED : str
|
|
1240
|
-
Single time series with class balance preservation
|
|
1241
|
-
BLOCKING : str
|
|
1242
|
-
Multiple independent time series (e.g., different patients)
|
|
1243
|
-
SLIDING : str
|
|
1244
|
-
Sliding window approach with fixed-size windows
|
|
1245
|
-
EXPANDING : str
|
|
1246
|
-
Expanding window where training set grows over time
|
|
1247
|
-
FIXED : str
|
|
1248
|
-
Fixed train/test split at specific time point
|
|
1249
|
-
"""
|
|
1250
|
-
|
|
1251
|
-
STRATIFIED = "stratified" # Single time series with class balance
|
|
1252
|
-
BLOCKING = "blocking" # Multiple time series (e.g., patients)
|
|
1253
|
-
SLIDING = "sliding" # Sliding window approach
|
|
1254
|
-
EXPANDING = "expanding" # Expanding window (train grows)
|
|
1255
|
-
FIXED = "fixed" # Fixed train/test split
|
|
1256
|
-
|
|
1257
|
-
@classmethod
|
|
1258
|
-
def from_string(cls, value: str) -> 'TimeSeriesStrategy':
|
|
1259
|
-
"""
|
|
1260
|
-
Create strategy from string value.
|
|
1261
|
-
|
|
1262
|
-
Parameters
|
|
1263
|
-
----------
|
|
1264
|
-
value : str
|
|
1265
|
-
String representation of strategy
|
|
1266
|
-
|
|
1267
|
-
Returns
|
|
1268
|
-
-------
|
|
1269
|
-
|
|
1270
|
-
...
|
|
1271
|
-
```
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
### `./classification/timeseries/_TimeSeriesStratifiedSplit.py`
|
|
1275
|
-
|
|
1276
|
-
```python
|
|
1277
|
-
#!/usr/bin/env python3
|
|
1278
|
-
# -*- coding: utf-8 -*-
|
|
1279
|
-
# Timestamp: "2025-09-22 16:50:00 (ywatanabe)"
|
|
1280
|
-
# File: _TimeSeriesStratifiedSplit.py
|
|
1281
|
-
|
|
1282
|
-
__FILE__ = "_TimeSeriesStratifiedSplit.py"
|
|
1283
|
-
|
|
1284
|
-
"""
|
|
1285
|
-
Functionalities:
|
|
1286
|
-
- Implements time series cross-validation with stratification support
|
|
1287
|
-
- Ensures chronological order (test data always after training data)
|
|
1288
|
-
- Supports optional validation set between train and test
|
|
1289
|
-
- Maintains temporal gaps to prevent data leakage
|
|
1290
|
-
- Provides visualization with scatter plots for verification
|
|
1291
|
-
- Validates temporal integrity in all splits
|
|
1292
|
-
|
|
1293
|
-
Dependencies:
|
|
1294
|
-
- packages:
|
|
1295
|
-
- numpy
|
|
1296
|
-
- sklearn
|
|
1297
|
-
- matplotlib
|
|
1298
|
-
|
|
1299
|
-
IO:
|
|
1300
|
-
- input-files:
|
|
1301
|
-
- None (generates synthetic data for demonstration)
|
|
1302
|
-
- output-files:
|
|
1303
|
-
- ./stratified_splits_demo.png (visualization)
|
|
1304
|
-
"""
|
|
1305
|
-
|
|
1306
|
-
"""Imports"""
|
|
1307
|
-
import os
|
|
1308
|
-
import sys
|
|
1309
|
-
import argparse
|
|
1310
|
-
import numpy as np
|
|
1311
|
-
from typing import Iterator, Optional, Tuple
|
|
1312
|
-
from sklearn.model_selection import BaseCrossValidator
|
|
1313
|
-
from sklearn.utils.validation import _num_samples
|
|
1314
|
-
import matplotlib.pyplot as plt
|
|
1315
|
-
import matplotlib.patches as patches
|
|
1316
|
-
import scitex as stx
|
|
1317
|
-
from scitex import logging
|
|
1318
|
-
|
|
1319
|
-
logger = logging.getLogger(__name__)
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
class TimeSeriesStratifiedSplit(BaseCrossValidator):
|
|
1323
|
-
"""
|
|
1324
|
-
Time series cross-validation with stratification support.
|
|
1325
|
-
|
|
1326
|
-
This splitter ensures:
|
|
1327
|
-
|
|
1328
|
-
...
|
|
1329
|
-
```
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
### `./clustering/__init__.py`
|
|
1333
|
-
|
|
1334
|
-
```python
|
|
1335
|
-
#!/usr/bin/env python3
|
|
1336
|
-
"""Scitex clustering module."""
|
|
1337
|
-
|
|
1338
|
-
from ._pca import pca
|
|
1339
|
-
from ._umap import main, umap
|
|
1340
|
-
|
|
1341
|
-
__all__ = [
|
|
1342
|
-
"main",
|
|
1343
|
-
"pca",
|
|
1344
|
-
"umap",
|
|
1345
|
-
]
|
|
1346
|
-
|
|
1347
|
-
...
|
|
1348
|
-
```
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
### `./clustering/_pca.py`
|
|
1352
|
-
|
|
1353
|
-
```python
|
|
1354
|
-
#!/usr/bin/env python3
|
|
1355
|
-
# -*- coding: utf-8 -*-
|
|
1356
|
-
# Time-stamp: "2024-05-14 00:58:26 (ywatanabe)"
|
|
1357
|
-
|
|
1358
|
-
import matplotlib.pyplot as plt
|
|
1359
|
-
import scitex
|
|
1360
|
-
import numpy as np
|
|
1361
|
-
import seaborn as sns
|
|
1362
|
-
from natsort import natsorted
|
|
1363
|
-
from sklearn.decomposition import PCA
|
|
1364
|
-
from sklearn.preprocessing import LabelEncoder
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
def pca(
|
|
1368
|
-
data_all,
|
|
1369
|
-
labels_all,
|
|
1370
|
-
axes_titles=None,
|
|
1371
|
-
title="PCA Clustering",
|
|
1372
|
-
alpha=0.1,
|
|
1373
|
-
s=3,
|
|
1374
|
-
use_independent_legend=False,
|
|
1375
|
-
add_super_imposed=False,
|
|
1376
|
-
palette="viridis",
|
|
1377
|
-
):
|
|
1378
|
-
|
|
1379
|
-
assert len(data_all) == len(labels_all)
|
|
1380
|
-
|
|
1381
|
-
if isinstance(data_all, list):
|
|
1382
|
-
data_all = list(data_all)
|
|
1383
|
-
labels_all = list(labels_all)
|
|
1384
|
-
|
|
1385
|
-
le = LabelEncoder()
|
|
1386
|
-
# le.fit(np.hstack(labels_all))
|
|
1387
|
-
le.fit(natsorted(np.hstack(labels_all)))
|
|
1388
|
-
labels_all = [le.transform(labels) for labels in labels_all]
|
|
1389
|
-
|
|
1390
|
-
pca_model = PCA(n_components=2)
|
|
1391
|
-
|
|
1392
|
-
ncols = len(data_all) + 1 if add_super_imposed else len(data_all)
|
|
1393
|
-
share = True if ncols > 1 else False
|
|
1394
|
-
fig, axes = plt.subplots(ncols=ncols, sharex=share, sharey=share)
|
|
1395
|
-
|
|
1396
|
-
fig.suptitle(title)
|
|
1397
|
-
fig.supxlabel("PCA 1")
|
|
1398
|
-
fig.supylabel("PCA 2")
|
|
1399
|
-
|
|
1400
|
-
for ii, (data, labels) in enumerate(zip(data_all, labels_all)):
|
|
1401
|
-
if ii == 0:
|
|
1402
|
-
_pca = pca_model.fit(data)
|
|
1403
|
-
embedding = _pca.transform(data)
|
|
1404
|
-
|
|
1405
|
-
...
|
|
1406
|
-
```
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
### `./clustering/_umap.py`
|
|
1410
|
-
|
|
1411
|
-
```python
|
|
1412
|
-
#!./env/bin/python3
|
|
1413
|
-
# -*- coding: utf-8 -*-
|
|
1414
|
-
# Time-stamp: "2024-09-12 05:37:55 (ywatanabe)"
|
|
1415
|
-
# _umap_dev.py
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
"""
|
|
1419
|
-
This script does XYZ.
|
|
1420
|
-
"""
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
"""
|
|
1424
|
-
Imports
|
|
1425
|
-
"""
|
|
1426
|
-
import sys
|
|
1427
|
-
|
|
1428
|
-
import matplotlib.pyplot as plt
|
|
1429
|
-
import scitex
|
|
1430
|
-
import numpy as np
|
|
1431
|
-
import umap.umap_ as umap_orig
|
|
1432
|
-
from natsort import natsorted
|
|
1433
|
-
from sklearn.preprocessing import LabelEncoder
|
|
1434
|
-
|
|
1435
|
-
# sys.path = ["."] + sys.path
|
|
1436
|
-
# from scripts import utils, load
|
|
1437
|
-
|
|
1438
|
-
"""
|
|
1439
|
-
Warnings
|
|
1440
|
-
"""
|
|
1441
|
-
# warnings.simplefilter("ignore", UserWarning)
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
"""
|
|
1445
|
-
Config
|
|
1446
|
-
"""
|
|
1447
|
-
# CONFIG = scitex.gen.load_configs()
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
"""
|
|
1451
|
-
Functions & Classes
|
|
1452
|
-
"""
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
def umap(
|
|
1456
|
-
data,
|
|
1457
|
-
labels,
|
|
1458
|
-
hues=None,
|
|
1459
|
-
hues_colors=None,
|
|
1460
|
-
axes=None,
|
|
1461
|
-
axes_titles=None,
|
|
1462
|
-
|
|
1463
|
-
...
|
|
1464
|
-
```
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
### `./feature_extraction/__init__.py`
|
|
1468
|
-
|
|
1469
|
-
```python
|
|
1470
|
-
#!/usr/bin/env python3
|
|
1471
|
-
# -*- coding: utf-8 -*-
|
|
1472
|
-
# Time-stamp: "2024-11-20 10:53:22 (ywatanabe)"
|
|
1473
|
-
# File: ./scitex_repo/src/scitex/ai/feature_extraction/__init__.py
|
|
1474
|
-
|
|
1475
|
-
THIS_FILE = "/home/ywatanabe/proj/scitex_repo/src/scitex/ai/feature_extraction/__init__.py"
|
|
1476
|
-
|
|
1477
|
-
#!/usr/bin/env python3
|
|
1478
|
-
# -*- coding: utf-8 -*-
|
|
1479
|
-
# Time-stamp: "2024-10-22 19:51:47 (ywatanabe)"
|
|
1480
|
-
# File: __init__.py
|
|
1481
|
-
|
|
1482
|
-
import os as __os
|
|
1483
|
-
import importlib as __importlib
|
|
1484
|
-
import inspect as __inspect
|
|
1485
|
-
import warnings as __warnings
|
|
1486
|
-
|
|
1487
|
-
# Get the current directory
|
|
1488
|
-
current_dir = __os.path.dirname(__file__)
|
|
1489
|
-
|
|
1490
|
-
# Iterate through all Python files in the current directory
|
|
1491
|
-
for filename in __os.listdir(current_dir):
|
|
1492
|
-
if filename.endswith(".py") and not filename.startswith("__"):
|
|
1493
|
-
module_name = filename[:-3] # Remove .py extension
|
|
1494
|
-
try:
|
|
1495
|
-
module = __importlib.import_module(f".{module_name}", package=__name__)
|
|
1496
|
-
|
|
1497
|
-
# Import only functions and classes from the module
|
|
1498
|
-
for name, obj in __inspect.getmembers(module):
|
|
1499
|
-
if __inspect.isfunction(obj) or __inspect.isclass(obj):
|
|
1500
|
-
if not name.startswith("_"):
|
|
1501
|
-
globals()[name] = obj
|
|
1502
|
-
except ImportError as e:
|
|
1503
|
-
# Warn about modules that couldn't be imported due to missing dependencies
|
|
1504
|
-
__warnings.warn(
|
|
1505
|
-
f"Could not import {module_name} from scitex.ai.feature_extraction: {str(e)}. "
|
|
1506
|
-
f"Some functionality may be unavailable. "
|
|
1507
|
-
f"Consider installing missing dependencies if you need this module.",
|
|
1508
|
-
ImportWarning,
|
|
1509
|
-
stacklevel=2
|
|
1510
|
-
)
|
|
1511
|
-
|
|
1512
|
-
# Clean up temporary variables
|
|
1513
|
-
del __os, __importlib, __inspect, __warnings, current_dir
|
|
1514
|
-
if 'filename' in locals():
|
|
1515
|
-
del filename
|
|
1516
|
-
if 'module_name' in locals():
|
|
1517
|
-
del module_name
|
|
1518
|
-
if 'module' in locals():
|
|
1519
|
-
del module
|
|
1520
|
-
|
|
1521
|
-
...
|
|
1522
|
-
```
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
### `./feature_extraction/vit.py`
|
|
1526
|
-
|
|
1527
|
-
```python
|
|
1528
|
-
#!/usr/bin/env python3
|
|
1529
|
-
# -*- coding: utf-8 -*-
|
|
1530
|
-
# Time-stamp: "2024-11-27 21:36:51 (ywatanabe)"
|
|
1531
|
-
# File: ./scitex_repo/src/scitex/ai/feature_extraction/vit.py
|
|
1532
|
-
|
|
1533
|
-
THIS_FILE = "/home/ywatanabe/proj/scitex_repo/src/scitex/ai/feature_extraction/vit.py"
|
|
1534
|
-
|
|
1535
|
-
"""
|
|
1536
|
-
Functionality:
|
|
1537
|
-
Extracts features from images using Vision Transformer (ViT) models
|
|
1538
|
-
Input:
|
|
1539
|
-
Image arrays of arbitrary dimensions
|
|
1540
|
-
Output:
|
|
1541
|
-
Feature vectors (1000-dimensional embeddings)
|
|
1542
|
-
Prerequisites:
|
|
1543
|
-
torch, PIL, torchvision
|
|
1544
|
-
"""
|
|
1545
|
-
|
|
1546
|
-
import os as _os
|
|
1547
|
-
from typing import Tuple, Union
|
|
1548
|
-
|
|
1549
|
-
import torch
|
|
1550
|
-
import torch as _torch
|
|
1551
|
-
import numpy as np
|
|
1552
|
-
from pytorch_pretrained_vit import ViT
|
|
1553
|
-
from torchvision import transforms as _transforms
|
|
1554
|
-
|
|
1555
|
-
# from ...decorators import batch_torch_fn
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
def _setup_device(device: Union[str, None]) -> str:
|
|
1559
|
-
if device is None:
|
|
1560
|
-
device = "cuda" if _torch.cuda.is_available() else "cpu"
|
|
1561
|
-
return device
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
class VitFeatureExtractor:
|
|
1565
|
-
def __init__(
|
|
1566
|
-
self,
|
|
1567
|
-
model_name="B_16",
|
|
1568
|
-
torch_home="./models",
|
|
1569
|
-
device=None,
|
|
1570
|
-
):
|
|
1571
|
-
self.valid_models = [
|
|
1572
|
-
"B_16",
|
|
1573
|
-
"B_32",
|
|
1574
|
-
"L_16",
|
|
1575
|
-
"L_32",
|
|
1576
|
-
"B_16_imagenet1k",
|
|
1577
|
-
"B_32_imagenet1k",
|
|
1578
|
-
|
|
1579
|
-
...
|
|
1580
|
-
```
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
### `./_gen_ai/_Anthropic.py`
|
|
1584
|
-
|
|
1585
|
-
```python
|
|
1586
|
-
#!/usr/bin/env python3
|
|
1587
|
-
# -*- coding: utf-8 -*-
|
|
1588
|
-
# Timestamp: "2025-06-24 19:20:24 (ywatanabe)"
|
|
1589
|
-
# File: /home/ywatanabe/proj/scitex_repo/src/scitex/ai/_gen_ai/_Anthropic.py
|
|
1590
|
-
# ----------------------------------------
|
|
1591
|
-
import os
|
|
1592
|
-
__FILE__ = __file__
|
|
1593
|
-
__DIR__ = os.path.dirname(__FILE__)
|
|
1594
|
-
# ----------------------------------------
|
|
1595
|
-
|
|
1596
|
-
"""
|
|
1597
|
-
Functionality:
|
|
1598
|
-
- Implements Anthropic AI (Claude) interface
|
|
1599
|
-
- Handles both streaming and static text generation
|
|
1600
|
-
Input:
|
|
1601
|
-
- User prompts and chat history
|
|
1602
|
-
- Model configurations and API credentials
|
|
1603
|
-
Output:
|
|
1604
|
-
- Generated text responses from Claude models
|
|
1605
|
-
- Token usage statistics
|
|
1606
|
-
Prerequisites:
|
|
1607
|
-
- Anthropic API key (ANTHROPIC_API_KEY environment variable)
|
|
1608
|
-
- anthropic package
|
|
1609
|
-
"""
|
|
1610
|
-
|
|
1611
|
-
"""Imports"""
|
|
1612
|
-
import sys
|
|
1613
|
-
from typing import Dict, Generator, List, Optional
|
|
1614
|
-
|
|
1615
|
-
import anthropic
|
|
1616
|
-
import matplotlib.pyplot as plt
|
|
1617
|
-
|
|
1618
|
-
from ._BaseGenAI import BaseGenAI
|
|
1619
|
-
|
|
1620
|
-
"""Functions & Classes"""
|
|
1621
|
-
class Anthropic(BaseGenAI):
|
|
1622
|
-
def __init__(
|
|
1623
|
-
self,
|
|
1624
|
-
system_setting: str = "",
|
|
1625
|
-
api_key: Optional[str] = os.getenv("ANTHROPIC_API_KEY"),
|
|
1626
|
-
model: str = "claude-3-opus-20240229",
|
|
1627
|
-
stream: bool = False,
|
|
1628
|
-
seed: Optional[int] = None,
|
|
1629
|
-
n_keep: int = 1,
|
|
1630
|
-
temperature: float = 1.0,
|
|
1631
|
-
chat_history: Optional[List[Dict[str, str]]] = None,
|
|
1632
|
-
max_tokens: int = 100_000,
|
|
1633
|
-
) -> None:
|
|
1634
|
-
|
|
1635
|
-
if model == "claude-3-7-sonnet-2025-0219":
|
|
1636
|
-
|
|
1637
|
-
...
|
|
1638
|
-
```
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
### `./_gen_ai/_BaseGenAI.py`
|
|
1642
|
-
|
|
1643
|
-
```python
|
|
1644
|
-
#!/usr/bin/env python3
|
|
1645
|
-
# -*- coding: utf-8 -*-
|
|
1646
|
-
# Timestamp: "2025-05-03 11:55:54 (ywatanabe)"
|
|
1647
|
-
# File: /home/ywatanabe/proj/scitex_repo/src/scitex/ai/_gen_ai/_BaseGenAI.py
|
|
1648
|
-
# ----------------------------------------
|
|
1649
|
-
import os
|
|
1650
|
-
|
|
1651
|
-
__FILE__ = "./src/scitex/ai/_gen_ai/_BaseGenAI.py"
|
|
1652
|
-
__DIR__ = os.path.dirname(__FILE__)
|
|
1653
|
-
# ----------------------------------------
|
|
1654
|
-
|
|
1655
|
-
import base64
|
|
1656
|
-
import sys
|
|
1657
|
-
from abc import ABC, abstractmethod
|
|
1658
|
-
from typing import Any, Dict, Generator, List, Optional, Union
|
|
1659
|
-
|
|
1660
|
-
import matplotlib.pyplot as plt
|
|
1661
|
-
import numpy as np
|
|
1662
|
-
|
|
1663
|
-
from ...io._load import load
|
|
1664
|
-
from ._calc_cost import calc_cost
|
|
1665
|
-
from ._format_output_func import format_output_func
|
|
1666
|
-
from ._PARAMS import MODELS
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
class BaseGenAI(ABC):
|
|
1670
|
-
def __init__(
|
|
1671
|
-
self,
|
|
1672
|
-
system_setting: str = "",
|
|
1673
|
-
model: str = "",
|
|
1674
|
-
api_key: str = "",
|
|
1675
|
-
stream: bool = False,
|
|
1676
|
-
seed: Optional[int] = None,
|
|
1677
|
-
n_keep: int = 1,
|
|
1678
|
-
temperature: float = 1.0,
|
|
1679
|
-
provider: str = "",
|
|
1680
|
-
chat_history: Optional[List[Dict[str, str]]] = None,
|
|
1681
|
-
max_tokens: int = 4_096,
|
|
1682
|
-
) -> None:
|
|
1683
|
-
self.provider = provider
|
|
1684
|
-
self.system_setting = system_setting
|
|
1685
|
-
self.model = model
|
|
1686
|
-
self.api_key = api_key
|
|
1687
|
-
self.stream = stream
|
|
1688
|
-
self.seed = seed
|
|
1689
|
-
self.n_keep = n_keep
|
|
1690
|
-
self.temperature = temperature
|
|
1691
|
-
self.max_tokens = max_tokens
|
|
1692
|
-
self.input_tokens = 0
|
|
1693
|
-
self.output_tokens = 0
|
|
1694
|
-
|
|
1695
|
-
...
|
|
1696
|
-
```
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
### `./_gen_ai/_calc_cost.py`
|
|
1700
|
-
|
|
1701
|
-
```python
|
|
1702
|
-
#!/usr/bin/env python3
|
|
1703
|
-
# -*- coding: utf-8 -*-
|
|
1704
|
-
# Time-stamp: "2024-11-04 01:37:36 (ywatanabe)"
|
|
1705
|
-
# File: ./scitex_repo/src/scitex/ai/_gen_ai/_calc_cost.py
|
|
1706
|
-
|
|
1707
|
-
"""
|
|
1708
|
-
Functionality:
|
|
1709
|
-
- Calculates usage costs for AI model API calls
|
|
1710
|
-
- Handles token-based pricing for different models
|
|
1711
|
-
Input:
|
|
1712
|
-
- Model name
|
|
1713
|
-
- Number of input and output tokens used
|
|
1714
|
-
Output:
|
|
1715
|
-
- Total cost in USD based on token usage
|
|
1716
|
-
Prerequisites:
|
|
1717
|
-
- MODELS parameter dictionary with pricing information
|
|
1718
|
-
- pandas package
|
|
1719
|
-
"""
|
|
1720
|
-
|
|
1721
|
-
from typing import Union, Any
|
|
1722
|
-
import pandas as pd
|
|
1723
|
-
|
|
1724
|
-
from ._PARAMS import MODELS
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
def calc_cost(model: str, input_tokens: int, output_tokens: int) -> float:
|
|
1728
|
-
"""Calculates API usage cost based on token count.
|
|
1729
|
-
|
|
1730
|
-
Example
|
|
1731
|
-
-------
|
|
1732
|
-
>>> cost = calc_cost("gpt-4", 100, 50)
|
|
1733
|
-
>>> print(f"${cost:.4f}")
|
|
1734
|
-
$0.0030
|
|
1735
|
-
|
|
1736
|
-
Parameters
|
|
1737
|
-
----------
|
|
1738
|
-
model : str
|
|
1739
|
-
Name of the AI model
|
|
1740
|
-
input_tokens : int
|
|
1741
|
-
Number of input tokens used
|
|
1742
|
-
output_tokens : int
|
|
1743
|
-
Number of output tokens used
|
|
1744
|
-
|
|
1745
|
-
Returns
|
|
1746
|
-
-------
|
|
1747
|
-
float
|
|
1748
|
-
Total cost in USD
|
|
1749
|
-
|
|
1750
|
-
Raises
|
|
1751
|
-
------
|
|
1752
|
-
|
|
1753
|
-
...
|
|
1754
|
-
```
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
### `./_gen_ai/_DeepSeek.py`
|
|
1758
|
-
|
|
1759
|
-
```python
|
|
1760
|
-
#!/usr/bin/env python3
|
|
1761
|
-
# -*- coding: utf-8 -*-
|
|
1762
|
-
# Time-stamp: "2024-11-08 20:33:49 (ywatanabe)"
|
|
1763
|
-
# File: ./scitex_repo/src/scitex/ai/_gen_ai/_DeepSeek.py
|
|
1764
|
-
|
|
1765
|
-
"""
|
|
1766
|
-
1. Functionality:
|
|
1767
|
-
- Implements DeepSeek Code LLM API interface
|
|
1768
|
-
2. Input:
|
|
1769
|
-
- Text prompts for code generation
|
|
1770
|
-
3. Output:
|
|
1771
|
-
- Generated code responses (streaming or static)
|
|
1772
|
-
4. Prerequisites:
|
|
1773
|
-
- DEEPSEEK_API_KEY environment variable
|
|
1774
|
-
- requests library
|
|
1775
|
-
"""
|
|
1776
|
-
|
|
1777
|
-
"""Imports"""
|
|
1778
|
-
import json
|
|
1779
|
-
import os
|
|
1780
|
-
import sys
|
|
1781
|
-
from typing import Dict, Generator, List, Optional
|
|
1782
|
-
|
|
1783
|
-
import scitex
|
|
1784
|
-
import requests
|
|
1785
|
-
|
|
1786
|
-
from ._BaseGenAI import BaseGenAI
|
|
1787
|
-
|
|
1788
|
-
"""Warnings"""
|
|
1789
|
-
# scitex.pd.ignore_SettingWithCopyWarning()
|
|
1790
|
-
# warnings.simplefilter("ignore", UserWarning)
|
|
1791
|
-
# with warnings.catch_warnings():
|
|
1792
|
-
# warnings.simplefilter("ignore", UserWarning)
|
|
1793
|
-
|
|
1794
|
-
"""Parameters"""
|
|
1795
|
-
# from scitex.io import load_configs
|
|
1796
|
-
# CONFIG = load_configs()
|
|
1797
|
-
|
|
1798
|
-
"""Functions & Classes"""
|
|
1799
|
-
from openai import OpenAI as _OpenAI
|
|
1800
|
-
|
|
1801
|
-
"""Functions & Classes"""
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
class DeepSeek(BaseGenAI):
|
|
1805
|
-
def __init__(
|
|
1806
|
-
self,
|
|
1807
|
-
system_setting="",
|
|
1808
|
-
model="deepseek-chat",
|
|
1809
|
-
api_key="",
|
|
1810
|
-
|
|
1811
|
-
...
|
|
1812
|
-
```
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
### `./_gen_ai/_format_output_func.py`
|
|
1816
|
-
|
|
1817
|
-
```python
|
|
1818
|
-
#!/usr/bin/env python3
|
|
1819
|
-
# -*- coding: utf-8 -*-
|
|
1820
|
-
# Time-stamp: "2024-11-04 01:39:25 (ywatanabe)"
|
|
1821
|
-
# File: ./scitex_repo/src/scitex/ai/_gen_ai/_format_output_func.py
|
|
1822
|
-
|
|
1823
|
-
"""
|
|
1824
|
-
Functionality:
|
|
1825
|
-
- Formats AI model output text
|
|
1826
|
-
- Wraps URLs in HTML anchor tags
|
|
1827
|
-
- Converts markdown to HTML
|
|
1828
|
-
- Handles DOI links specially
|
|
1829
|
-
Input:
|
|
1830
|
-
- Raw text output from AI models
|
|
1831
|
-
- Optional API key for masking
|
|
1832
|
-
Output:
|
|
1833
|
-
- Formatted HTML text with proper link handling
|
|
1834
|
-
Prerequisites:
|
|
1835
|
-
- markdown2 package
|
|
1836
|
-
- Regular expressions support
|
|
1837
|
-
"""
|
|
1838
|
-
|
|
1839
|
-
"""Imports"""
|
|
1840
|
-
import re
|
|
1841
|
-
import sys
|
|
1842
|
-
from typing import List, Optional
|
|
1843
|
-
|
|
1844
|
-
import markdown2
|
|
1845
|
-
import matplotlib.pyplot as plt
|
|
1846
|
-
import scitex
|
|
1847
|
-
|
|
1848
|
-
"""Functions & Classes"""
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
def format_output_func(out_text: str) -> str:
|
|
1852
|
-
"""Formats AI output text with proper link handling and markdown conversion.
|
|
1853
|
-
|
|
1854
|
-
Example
|
|
1855
|
-
-------
|
|
1856
|
-
>>> text = "Check https://example.com or doi:10.1234/abc"
|
|
1857
|
-
>>> print(format_output_func(text))
|
|
1858
|
-
Check <a href="https://example.com">https://example.com</a> or <a href="https://doi.org/10.1234/abc">https://doi.org/10.1234/abc</a>
|
|
1859
|
-
|
|
1860
|
-
Parameters
|
|
1861
|
-
----------
|
|
1862
|
-
out_text : str
|
|
1863
|
-
Raw text output from AI model
|
|
1864
|
-
|
|
1865
|
-
Returns
|
|
1866
|
-
-------
|
|
1867
|
-
str
|
|
1868
|
-
|
|
1869
|
-
...
|
|
1870
|
-
```
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
### `./_gen_ai/_genai_factory.py`
|
|
1874
|
-
|
|
1875
|
-
```python
|
|
1876
|
-
#!/usr/bin/env python3
|
|
1877
|
-
# -*- coding: utf-8 -*-
|
|
1878
|
-
# Timestamp: "2025-05-03 11:57:10 (ywatanabe)"
|
|
1879
|
-
# File: /home/ywatanabe/proj/scitex_repo/src/scitex/ai/_gen_ai/_genai_factory.py
|
|
1880
|
-
# ----------------------------------------
|
|
1881
|
-
import os
|
|
1882
|
-
|
|
1883
|
-
__FILE__ = "./src/scitex/ai/_gen_ai/_genai_factory.py"
|
|
1884
|
-
__DIR__ = os.path.dirname(__FILE__)
|
|
1885
|
-
# ----------------------------------------
|
|
1886
|
-
|
|
1887
|
-
import random
|
|
1888
|
-
|
|
1889
|
-
from ._Anthropic import Anthropic
|
|
1890
|
-
from ._DeepSeek import DeepSeek
|
|
1891
|
-
from ._Google import Google
|
|
1892
|
-
from ._Groq import Groq
|
|
1893
|
-
from ._Llama import Llama
|
|
1894
|
-
from ._OpenAI import OpenAI
|
|
1895
|
-
from ._PARAMS import MODELS
|
|
1896
|
-
from ._Perplexity import Perplexity
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
def genai_factory(
|
|
1900
|
-
model="gpt-3.5-turbo",
|
|
1901
|
-
stream=False,
|
|
1902
|
-
api_key=None,
|
|
1903
|
-
seed=None,
|
|
1904
|
-
temperature=1.0,
|
|
1905
|
-
n_keep=1,
|
|
1906
|
-
chat_history=None,
|
|
1907
|
-
max_tokens=4096,
|
|
1908
|
-
):
|
|
1909
|
-
"""Factory function to create an instance of an AI model handler."""
|
|
1910
|
-
AVAILABLE_MODELS = MODELS.name.tolist()
|
|
1911
|
-
|
|
1912
|
-
if model not in AVAILABLE_MODELS:
|
|
1913
|
-
raise ValueError(
|
|
1914
|
-
f'Model "{model}" is not available. Please choose from:{MODELS.name.tolist()}'
|
|
1915
|
-
)
|
|
1916
|
-
|
|
1917
|
-
provider = MODELS[MODELS.name == model].provider.iloc[0]
|
|
1918
|
-
|
|
1919
|
-
# model_class = globals()[provider]
|
|
1920
|
-
model_class = {
|
|
1921
|
-
"OpenAI": OpenAI,
|
|
1922
|
-
"Anthropic": Anthropic,
|
|
1923
|
-
"Google": Google,
|
|
1924
|
-
"Llama": Llama,
|
|
1925
|
-
"Perplexity": Perplexity,
|
|
1926
|
-
|
|
1927
|
-
...
|
|
1928
|
-
```
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
### `./_gen_ai/_Google.py`
|
|
1932
|
-
|
|
1933
|
-
```python
|
|
1934
|
-
#!/usr/bin/env python3
|
|
1935
|
-
# -*- coding: utf-8 -*-
|
|
1936
|
-
# Timestamp: "2025-02-06 13:47:23 (ywatanabe)"
|
|
1937
|
-
# File: _Google.py
|
|
1938
|
-
|
|
1939
|
-
THIS_FILE = "/home/ywatanabe/proj/scitex_repo/src/scitex/ai/_gen_ai/_Google.py"
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
"""
|
|
1943
|
-
Functionality:
|
|
1944
|
-
- Implements Google's Generative AI (Gemini) interface
|
|
1945
|
-
- Handles both streaming and static text generation
|
|
1946
|
-
Input:
|
|
1947
|
-
- User prompts and chat history
|
|
1948
|
-
- Model configurations and API credentials
|
|
1949
|
-
Output:
|
|
1950
|
-
- Generated text responses from Gemini models
|
|
1951
|
-
- Token usage statistics
|
|
1952
|
-
Prerequisites:
|
|
1953
|
-
- Google API key (GOOGLE_API_KEY environment variable)
|
|
1954
|
-
- google.generativeai package
|
|
1955
|
-
"""
|
|
1956
|
-
|
|
1957
|
-
"""Imports"""
|
|
1958
|
-
import os
|
|
1959
|
-
import sys
|
|
1960
|
-
from pprint import pprint
|
|
1961
|
-
from typing import Any, Dict, Generator, List, Optional
|
|
1962
|
-
|
|
1963
|
-
import matplotlib.pyplot as plt
|
|
1964
|
-
import scitex
|
|
1965
|
-
|
|
1966
|
-
try:
|
|
1967
|
-
from google import genai
|
|
1968
|
-
except ImportError:
|
|
1969
|
-
genai = None
|
|
1970
|
-
|
|
1971
|
-
from ._BaseGenAI import BaseGenAI
|
|
1972
|
-
|
|
1973
|
-
"""Functions & Classes"""
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
class Google(BaseGenAI):
|
|
1977
|
-
def __init__(
|
|
1978
|
-
self,
|
|
1979
|
-
system_setting: str = "",
|
|
1980
|
-
api_key: Optional[str] = os.getenv("GOOGLE_API_KEY"),
|
|
1981
|
-
model: str = "gemini-1.5-pro-latest",
|
|
1982
|
-
stream: bool = False,
|
|
1983
|
-
seed: Optional[int] = None,
|
|
1984
|
-
|
|
1985
|
-
...
|
|
1986
|
-
```
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
### `./_gen_ai/_Groq.py`
|
|
1990
|
-
|
|
1991
|
-
```python
|
|
1992
|
-
#!/usr/bin/env python3
|
|
1993
|
-
# -*- coding: utf-8 -*-
|
|
1994
|
-
# Time-stamp: "2024-11-28 02:47:54 (ywatanabe)"
|
|
1995
|
-
# File: ./scitex_repo/src/scitex/ai/_gen_ai/_Groq.py
|
|
1996
|
-
|
|
1997
|
-
THIS_FILE = "/home/ywatanabe/proj/scitex_repo/src/scitex/ai/_gen_ai/_Groq.py"
|
|
1998
|
-
|
|
1999
|
-
"""
|
|
2000
|
-
Functionality:
|
|
2001
|
-
- Implements GLOQ AI interface
|
|
2002
|
-
- Handles both streaming and static text generation
|
|
2003
|
-
Input:
|
|
2004
|
-
- User prompts and chat history
|
|
2005
|
-
- Model configurations and API credentials
|
|
2006
|
-
Output:
|
|
2007
|
-
- Generated text responses
|
|
2008
|
-
- Token usage statistics
|
|
2009
|
-
Prerequisites:
|
|
2010
|
-
- GLOQ API key (GLOQ_API_KEY environment variable)
|
|
2011
|
-
- gloq package
|
|
2012
|
-
"""
|
|
2013
|
-
|
|
2014
|
-
"""Imports"""
|
|
2015
|
-
import os
|
|
2016
|
-
import sys
|
|
2017
|
-
from typing import Any, Dict, Generator, List, Optional, Union
|
|
2018
|
-
|
|
2019
|
-
from groq import Groq as _Groq
|
|
2020
|
-
import matplotlib.pyplot as plt
|
|
2021
|
-
|
|
2022
|
-
from ._BaseGenAI import BaseGenAI
|
|
2023
|
-
|
|
2024
|
-
"""Functions & Classes"""
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
class Groq(BaseGenAI):
|
|
2028
|
-
def __init__(
|
|
2029
|
-
self,
|
|
2030
|
-
system_setting: str = "",
|
|
2031
|
-
api_key: Optional[str] = os.getenv("GROQ_API_KEY"),
|
|
2032
|
-
model: str = "llama3-8b-8192",
|
|
2033
|
-
stream: bool = False,
|
|
2034
|
-
seed: Optional[int] = None,
|
|
2035
|
-
n_keep: int = 1,
|
|
2036
|
-
temperature: float = 0.5,
|
|
2037
|
-
chat_history: Optional[List[Dict[str, str]]] = None,
|
|
2038
|
-
max_tokens: int = 8000,
|
|
2039
|
-
) -> None:
|
|
2040
|
-
max_tokens = min(max_tokens, 8000)
|
|
2041
|
-
if not api_key:
|
|
2042
|
-
|
|
2043
|
-
...
|
|
2044
|
-
```
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
### `./_gen_ai/__init__.py`
|
|
2048
|
-
|
|
2049
|
-
```python
|
|
2050
|
-
#!/usr/bin/env python3
|
|
2051
|
-
# -*- coding: utf-8 -*-
|
|
2052
|
-
# Timestamp: "2025-07-14 13:51:57 (ywatanabe)"
|
|
2053
|
-
# File: /ssh:sp:/home/ywatanabe/proj/scitex_repo/src/scitex/ai/_gen_ai/__init__.py
|
|
2054
|
-
# ----------------------------------------
|
|
2055
|
-
import os
|
|
2056
|
-
__FILE__ = __file__
|
|
2057
|
-
__DIR__ = os.path.dirname(__FILE__)
|
|
2058
|
-
# ----------------------------------------
|
|
2059
|
-
#!./env/bin/python3
|
|
2060
|
-
# Time-stamp: "2024-07-29 14:55:00 (ywatanabe)"
|
|
2061
|
-
# /home/ywatanabe/proj/scitex/src/scitex/ml/_gen_ai/__init__.py
|
|
2062
|
-
|
|
2063
|
-
from ._PARAMS import MODELS
|
|
2064
|
-
from ._BaseGenAI import BaseGenAI
|
|
2065
|
-
from ._Anthropic import Anthropic
|
|
2066
|
-
from ._DeepSeek import DeepSeek
|
|
2067
|
-
from ._Google import Google
|
|
2068
|
-
from ._Groq import Groq
|
|
2069
|
-
from ._Llama import Llama
|
|
2070
|
-
from ._OpenAI import OpenAI
|
|
2071
|
-
from ._Perplexity import Perplexity
|
|
2072
|
-
from ._calc_cost import calc_cost
|
|
2073
|
-
from ._format_output_func import format_output_func
|
|
2074
|
-
from ._genai_factory import genai_factory as GenAI
|
|
2075
|
-
|
|
2076
|
-
__all__ = [
|
|
2077
|
-
"GenAI"
|
|
2078
|
-
# "MODELS",
|
|
2079
|
-
# "BaseGenAI",
|
|
2080
|
-
# "Anthropic",
|
|
2081
|
-
# "DeepSeek",
|
|
2082
|
-
# "Google",
|
|
2083
|
-
# "Groq",
|
|
2084
|
-
# "Llama",
|
|
2085
|
-
# "OpenAI",
|
|
2086
|
-
# "Perplexity",
|
|
2087
|
-
# "calc_cost",
|
|
2088
|
-
# "format_output_func",
|
|
2089
|
-
# "genai_factory",
|
|
2090
|
-
]
|
|
2091
|
-
|
|
2092
|
-
# EOF
|
|
2093
|
-
|
|
2094
|
-
...
|
|
2095
|
-
```
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
### `./_gen_ai/_Llama.py`
|
|
2099
|
-
|
|
2100
|
-
```python
|
|
2101
|
-
#!/usr/bin/env python3
|
|
2102
|
-
# -*- coding: utf-8 -*-
|
|
2103
|
-
# Time-stamp: "2024-11-05 21:11:08 (ywatanabe)"
|
|
2104
|
-
# File: ./scitex_repo/src/scitex/ai/_gen_ai/_Llama.py
|
|
2105
|
-
|
|
2106
|
-
"""Imports"""
|
|
2107
|
-
import os
|
|
2108
|
-
import sys
|
|
2109
|
-
from typing import List, Optional
|
|
2110
|
-
|
|
2111
|
-
import matplotlib.pyplot as plt
|
|
2112
|
-
import scitex
|
|
2113
|
-
|
|
2114
|
-
try:
|
|
2115
|
-
from llama import Dialog
|
|
2116
|
-
from llama import Llama as _Llama
|
|
2117
|
-
except:
|
|
2118
|
-
pass
|
|
2119
|
-
|
|
2120
|
-
from ._BaseGenAI import BaseGenAI
|
|
2121
|
-
|
|
2122
|
-
"""Functions & Classes"""
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
def print_envs():
|
|
2126
|
-
settings = {
|
|
2127
|
-
"MASTER_ADDR": os.getenv("MASTER_ADDR", "localhost"),
|
|
2128
|
-
"MASTER_PORT": os.getenv("MASTER_PORT", "12355"),
|
|
2129
|
-
"WORLD_SIZE": os.getenv("WORLD_SIZE", "1"),
|
|
2130
|
-
"RANK": os.getenv("RANK", "0"),
|
|
2131
|
-
}
|
|
2132
|
-
|
|
2133
|
-
print("Environment Variable Settings:")
|
|
2134
|
-
for key, value in settings.items():
|
|
2135
|
-
print(f"{key}: {value}")
|
|
2136
|
-
print()
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
class Llama(BaseGenAI):
|
|
2140
|
-
def __init__(
|
|
2141
|
-
self,
|
|
2142
|
-
ckpt_dir: str = "",
|
|
2143
|
-
tokenizer_path: str = "",
|
|
2144
|
-
system_setting: str = "",
|
|
2145
|
-
model: str = "Meta-Llama-3-8B",
|
|
2146
|
-
max_seq_len: int = 32_768,
|
|
2147
|
-
max_batch_size: int = 4,
|
|
2148
|
-
max_gen_len: Optional[int] = None,
|
|
2149
|
-
stream: bool = False,
|
|
2150
|
-
seed: Optional[int] = None,
|
|
2151
|
-
|
|
2152
|
-
...
|
|
2153
|
-
```
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
### `./_gen_ai/_OpenAI.py`
|
|
2157
|
-
|
|
2158
|
-
```python
|
|
2159
|
-
#!/usr/bin/env python3
|
|
2160
|
-
# -*- coding: utf-8 -*-
|
|
2161
|
-
# Timestamp: "2025-01-22 01:21:11 (ywatanabe)"
|
|
2162
|
-
# File: _OpenAI.py
|
|
2163
|
-
|
|
2164
|
-
THIS_FILE = "/home/ywatanabe/proj/scitex_repo/src/scitex/ai/_gen_ai/_OpenAI.py"
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
"""Imports"""
|
|
2168
|
-
import os
|
|
2169
|
-
from openai import OpenAI as _OpenAI
|
|
2170
|
-
from ._BaseGenAI import BaseGenAI
|
|
2171
|
-
|
|
2172
|
-
"""Functions & Classes"""
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
class OpenAI(BaseGenAI):
|
|
2176
|
-
def __init__(
|
|
2177
|
-
self,
|
|
2178
|
-
system_setting="",
|
|
2179
|
-
model="",
|
|
2180
|
-
api_key=os.getenv("OPENAI_API_KEY"),
|
|
2181
|
-
stream=False,
|
|
2182
|
-
seed=None,
|
|
2183
|
-
n_keep=1,
|
|
2184
|
-
temperature=1.0,
|
|
2185
|
-
chat_history=None,
|
|
2186
|
-
max_tokens=None,
|
|
2187
|
-
):
|
|
2188
|
-
self.passed_model = model
|
|
2189
|
-
|
|
2190
|
-
# import scitex
|
|
2191
|
-
# scitex.str.print_debug()
|
|
2192
|
-
# scitex.gen.printc(model)
|
|
2193
|
-
|
|
2194
|
-
if model.startswith("o"):
|
|
2195
|
-
for reasoning_effort in ["low", "midium", "high"]:
|
|
2196
|
-
model = model.replace(f"-{reasoning_effort}", "")
|
|
2197
|
-
|
|
2198
|
-
# Set max_tokens based on model
|
|
2199
|
-
if max_tokens is None:
|
|
2200
|
-
if "gpt-4-turbo" in model:
|
|
2201
|
-
max_tokens = 128_000
|
|
2202
|
-
elif "gpt-4" in model:
|
|
2203
|
-
max_tokens = 8_192
|
|
2204
|
-
elif "gpt-3.5-turbo-16k" in model:
|
|
2205
|
-
max_tokens = 16_384
|
|
2206
|
-
elif "gpt-3.5" in model:
|
|
2207
|
-
max_tokens = 4_096
|
|
2208
|
-
else:
|
|
2209
|
-
|
|
2210
|
-
...
|
|
2211
|
-
```
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
### `./_gen_ai/_PARAMS.py`
|
|
2215
|
-
|
|
2216
|
-
```python
|
|
2217
|
-
#!/usr/bin/env python3
|
|
2218
|
-
# -*- coding: utf-8 -*-
|
|
2219
|
-
# Timestamp: "2025-09-30 06:38:18 (ywatanabe)"
|
|
2220
|
-
# File: /home/ywatanabe/proj/scitex_repo/src/scitex/ai/_gen_ai/_PARAMS.py
|
|
2221
|
-
# ----------------------------------------
|
|
2222
|
-
from __future__ import annotations
|
|
2223
|
-
import os
|
|
2224
|
-
__FILE__ = __file__
|
|
2225
|
-
__DIR__ = os.path.dirname(__FILE__)
|
|
2226
|
-
# ----------------------------------------
|
|
2227
|
-
|
|
2228
|
-
THIS_FILE = "/home/ywatanabe/proj/scitex_repo/src/scitex/ai/_gen_ai/PARAMS.py"
|
|
2229
|
-
|
|
2230
|
-
import pandas as pd
|
|
2231
|
-
|
|
2232
|
-
# https://api-docs.deepseek.com/quick_start/pricing
|
|
2233
|
-
DEEPSEEK_MODELS = [
|
|
2234
|
-
{
|
|
2235
|
-
"name": "deepseek-reasoner",
|
|
2236
|
-
"input_cost": 0.14,
|
|
2237
|
-
"output_cost": 2.19,
|
|
2238
|
-
"api_key_env": "DEEPSEEK_API_KEY",
|
|
2239
|
-
"provider": "DeepSeek",
|
|
2240
|
-
},
|
|
2241
|
-
{
|
|
2242
|
-
"name": "deepseek-chat",
|
|
2243
|
-
"input_cost": 0.014,
|
|
2244
|
-
"output_cost": 0.28,
|
|
2245
|
-
"api_key_env": "DEEPSEEK_API_KEY",
|
|
2246
|
-
"provider": "DeepSeek",
|
|
2247
|
-
},
|
|
2248
|
-
{
|
|
2249
|
-
"name": "deepseek-coder",
|
|
2250
|
-
"input_cost": 0.014,
|
|
2251
|
-
"output_cost": 0.28,
|
|
2252
|
-
"api_key_env": "DEEPSEEK_API_KEY",
|
|
2253
|
-
"provider": "DeepSeek",
|
|
2254
|
-
},
|
|
2255
|
-
]
|
|
2256
|
-
|
|
2257
|
-
# https://openai.com/api/pricing/
|
|
2258
|
-
OPENAI_MODELS = [
|
|
2259
|
-
# o3
|
|
2260
|
-
{
|
|
2261
|
-
"name": "o3",
|
|
2262
|
-
"input_cost": 10.00,
|
|
2263
|
-
"output_cost": 40.00,
|
|
2264
|
-
"api_key_env": "OPENAI_API_KEY",
|
|
2265
|
-
"provider": "OpenAI",
|
|
2266
|
-
},
|
|
2267
|
-
|
|
2268
|
-
...
|
|
2269
|
-
```
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
### `./_gen_ai/_Perplexity.py`
|
|
2273
|
-
|
|
2274
|
-
```python
|
|
2275
|
-
#!/usr/bin/env python3
|
|
2276
|
-
# -*- coding: utf-8 -*-
|
|
2277
|
-
# Time-stamp: "2024-11-11 04:11:10 (ywatanabe)"
|
|
2278
|
-
# File: ./scitex_repo/src/scitex/ai/_gen_ai/_Perplexity.py
|
|
2279
|
-
|
|
2280
|
-
"""
|
|
2281
|
-
Functionality:
|
|
2282
|
-
- Implements Perplexity AI interface using OpenAI-compatible API
|
|
2283
|
-
- Provides access to Llama and Mixtral models
|
|
2284
|
-
Input:
|
|
2285
|
-
- User prompts and chat history
|
|
2286
|
-
- Model configurations and API credentials
|
|
2287
|
-
Output:
|
|
2288
|
-
- Generated text responses from Perplexity models
|
|
2289
|
-
- Token usage statistics
|
|
2290
|
-
Prerequisites:
|
|
2291
|
-
- Perplexity API key
|
|
2292
|
-
- openai package
|
|
2293
|
-
"""
|
|
2294
|
-
|
|
2295
|
-
"""Imports"""
|
|
2296
|
-
import os
|
|
2297
|
-
import sys
|
|
2298
|
-
from pprint import pprint
|
|
2299
|
-
from typing import Dict, Generator, List, Optional
|
|
2300
|
-
|
|
2301
|
-
import matplotlib.pyplot as plt
|
|
2302
|
-
from openai import OpenAI
|
|
2303
|
-
|
|
2304
|
-
from ._BaseGenAI import BaseGenAI
|
|
2305
|
-
|
|
2306
|
-
"""Functions & Classes"""
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
class Perplexity(BaseGenAI):
|
|
2310
|
-
def __init__(
|
|
2311
|
-
self,
|
|
2312
|
-
system_setting: str = "",
|
|
2313
|
-
model: str = "",
|
|
2314
|
-
api_key: str = "",
|
|
2315
|
-
stream: bool = False,
|
|
2316
|
-
seed: Optional[int] = None,
|
|
2317
|
-
n_keep: int = 1,
|
|
2318
|
-
temperature: float = 1.0,
|
|
2319
|
-
chat_history: Optional[List[Dict[str, str]]] = None,
|
|
2320
|
-
max_tokens: Optional[int] = None, # Added parameter
|
|
2321
|
-
) -> None:
|
|
2322
|
-
# Set max_tokens based on model if not provided
|
|
2323
|
-
if max_tokens is None:
|
|
2324
|
-
max_tokens = 128_000 if "128k" in model else 32_000
|
|
2325
|
-
|
|
2326
|
-
...
|
|
2327
|
-
```
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
### `./__init__.py`
|
|
2331
|
-
|
|
2332
|
-
```python
|
|
2333
|
-
#!/usr/bin/env python3
|
|
2334
|
-
# -*- coding: utf-8 -*-
|
|
2335
|
-
# Timestamp: "2025-07-19 10:50:54 (ywatanabe)"
|
|
2336
|
-
# File: /home/ywatanabe/proj/scitex_repo/src/scitex/ai/__init__.py
|
|
2337
|
-
# ----------------------------------------
|
|
2338
|
-
import os
|
|
2339
|
-
__FILE__ = __file__
|
|
2340
|
-
__DIR__ = os.path.dirname(__FILE__)
|
|
2341
|
-
# ----------------------------------------
|
|
2342
|
-
"""Scitex AI module for machine learning and artificial intelligence utilities."""
|
|
2343
|
-
|
|
2344
|
-
# Lazy imports to avoid loading heavy dependencies eagerly
|
|
2345
|
-
from .classification import ClassificationReporter
|
|
2346
|
-
from .training._LearningCurveLogger import LearningCurveLogger
|
|
2347
|
-
from .training._EarlyStopping import EarlyStopping
|
|
2348
|
-
from .loss import MultiTaskLoss
|
|
2349
|
-
from .classification import Classifier
|
|
2350
|
-
from .optim import get_optimizer, set_optimizer
|
|
2351
|
-
|
|
2352
|
-
# Import submodules to make them accessible
|
|
2353
|
-
from . import activation
|
|
2354
|
-
from . import classification
|
|
2355
|
-
from . import clustering
|
|
2356
|
-
from . import feature_extraction
|
|
2357
|
-
# from . import layer
|
|
2358
|
-
from . import loss
|
|
2359
|
-
from . import metrics
|
|
2360
|
-
from . import optim
|
|
2361
|
-
from . import plt
|
|
2362
|
-
from . import sampling
|
|
2363
|
-
from . import sklearn
|
|
2364
|
-
from . import training
|
|
2365
|
-
from . import utils
|
|
2366
|
-
|
|
2367
|
-
# Lazy import for GenAI (heavy anthropic dependency)
|
|
2368
|
-
def __getattr__(name):
|
|
2369
|
-
if name == "GenAI":
|
|
2370
|
-
from ._gen_ai import GenAI
|
|
2371
|
-
return GenAI
|
|
2372
|
-
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
2373
|
-
|
|
2374
|
-
__all__ = [
|
|
2375
|
-
# "Classifiers", # Moved to .old directory
|
|
2376
|
-
"LearningCurveLogger",
|
|
2377
|
-
"ClassificationReporter",
|
|
2378
|
-
"EarlyStopping",
|
|
2379
|
-
"MultiTaskLoss",
|
|
2380
|
-
"GenAI", # Lazy loaded
|
|
2381
|
-
"Classifier",
|
|
2382
|
-
"get_optimizer",
|
|
2383
|
-
|
|
2384
|
-
...
|
|
2385
|
-
```
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
### `./loss/__init__.py`
|
|
2389
|
-
|
|
2390
|
-
```python
|
|
2391
|
-
#!/usr/bin/env python3
|
|
2392
|
-
"""Scitex loss module."""
|
|
2393
|
-
|
|
2394
|
-
from ._L1L2Losses import elastic, l1, l2
|
|
2395
|
-
from .multi_task_loss import MultiTaskLoss
|
|
2396
|
-
|
|
2397
|
-
__all__ = [
|
|
2398
|
-
"elastic",
|
|
2399
|
-
"l1",
|
|
2400
|
-
"l2",
|
|
2401
|
-
"MultiTaskLoss",
|
|
2402
|
-
]
|
|
2403
|
-
|
|
2404
|
-
...
|
|
2405
|
-
```
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
### `./loss/_L1L2Losses.py`
|
|
2409
|
-
|
|
2410
|
-
```python
|
|
2411
|
-
#!/usr/bin/env python3
|
|
2412
|
-
# -*- coding: utf-8 -*-
|
|
2413
|
-
# Time-stamp: "2024-11-07 18:53:03 (ywatanabe)"
|
|
2414
|
-
# File: ./scitex_repo/src/scitex/ai/loss/_L1L2Losses.py
|
|
2415
|
-
|
|
2416
|
-
import torch
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
def l1(model, lambda_l1=0.01):
|
|
2420
|
-
lambda_l1 = torch.tensor(lambda_l1)
|
|
2421
|
-
l1 = torch.tensor(0.0).cuda()
|
|
2422
|
-
for param in model.parameters(): # fixme; is this OK?
|
|
2423
|
-
l1 += torch.abs(param).sum()
|
|
2424
|
-
return l1
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
def l2(model, lambda_l2=0.01):
|
|
2428
|
-
lambda_l2 = torch.tensor(lambda_l2)
|
|
2429
|
-
l2 = torch.tensor(0.0).cuda()
|
|
2430
|
-
for param in model.parameters(): # fixme; is this OK?
|
|
2431
|
-
l2 += torch.norm(param).sum()
|
|
2432
|
-
return l2
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
def elastic(model, alpha=1.0, l1_ratio=0.5):
|
|
2436
|
-
assert 0 <= l1_ratio <= 1
|
|
2437
|
-
|
|
2438
|
-
L1 = l1(model)
|
|
2439
|
-
L2 = l2(model)
|
|
2440
|
-
|
|
2441
|
-
return alpha * (l1_ratio * L1 + (1 - l1_ratio) * L2)
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
# EOF
|
|
2445
|
-
|
|
2446
|
-
...
|
|
2447
|
-
```
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
### `./loss/multi_task_loss.py`
|
|
2451
|
-
|
|
2452
|
-
```python
|
|
2453
|
-
#!/usr/bin/env python3
|
|
2454
|
-
# -*- coding: utf-8 -*-
|
|
2455
|
-
# Time-stamp: "2024-11-07 19:07:29 (ywatanabe)"
|
|
2456
|
-
# File: ./scitex_repo/src/scitex/ai/loss/MultiTaskLoss.py
|
|
2457
|
-
|
|
2458
|
-
import numpy as np
|
|
2459
|
-
import torch
|
|
2460
|
-
import torch.nn as nn
|
|
2461
|
-
|
|
2462
|
-
from ...repro import fix_seeds
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
class MultiTaskLoss(nn.Module):
|
|
2466
|
-
"""
|
|
2467
|
-
# https://openaccess.thecvf.com/content_cvpr_2018/papers/Kendall_Multi-Task_Learning_Using_CVPR_2018_paper.pdf
|
|
2468
|
-
|
|
2469
|
-
Example:
|
|
2470
|
-
are_regression = [False, False]
|
|
2471
|
-
mtl = MultiTaskLoss(are_regression)
|
|
2472
|
-
losses = [torch.rand(1, requires_grad=True) for _ in range(len(are_regression))]
|
|
2473
|
-
loss = mtl(losses)
|
|
2474
|
-
print(loss)
|
|
2475
|
-
# [tensor([0.4215], grad_fn=<AddBackward0>), tensor([0.6190], grad_fn=<AddBackward0>)]
|
|
2476
|
-
"""
|
|
2477
|
-
|
|
2478
|
-
def __init__(self, are_regression=[False, False], reduction="none"):
|
|
2479
|
-
super().__init__()
|
|
2480
|
-
fix_seeds(np=np, torch=torch, show=False)
|
|
2481
|
-
n_tasks = len(are_regression)
|
|
2482
|
-
|
|
2483
|
-
self.register_buffer("are_regression", torch.tensor(are_regression))
|
|
2484
|
-
|
|
2485
|
-
# for the numercal stability, log(variables) are learned.
|
|
2486
|
-
self.log_vars = torch.nn.Parameter(torch.zeros(n_tasks))
|
|
2487
|
-
self.reduction = reduction
|
|
2488
|
-
|
|
2489
|
-
def forward(self, losses):
|
|
2490
|
-
vars = torch.exp(self.log_vars).type_as(losses[0])
|
|
2491
|
-
stds = vars ** (1 / 2)
|
|
2492
|
-
coeffs = 1 / ((self.are_regression + 1) * vars)
|
|
2493
|
-
scaled_losses = [
|
|
2494
|
-
coeffs[i] * losses[i] + torch.log(stds[i]) for i in range(len(losses))
|
|
2495
|
-
]
|
|
2496
|
-
return scaled_losses
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
# EOF
|
|
2500
|
-
|
|
2501
|
-
...
|
|
2502
|
-
```
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
### `./metrics/_calc_bacc_from_conf_mat.py`
|
|
2506
|
-
|
|
2507
|
-
```python
|
|
2508
|
-
#!/usr/bin/env python3
|
|
2509
|
-
# -*- coding: utf-8 -*-
|
|
2510
|
-
# Timestamp: "2025-10-02 (ywatanabe)"
|
|
2511
|
-
# File: /home/ywatanabe/proj/scitex_repo/src/scitex/ml/metrics/_calc_bacc_from_conf_mat.py
|
|
2512
|
-
|
|
2513
|
-
"""Calculate balanced accuracy from confusion matrix."""
|
|
2514
|
-
|
|
2515
|
-
__FILE__ = __file__
|
|
2516
|
-
|
|
2517
|
-
import numpy as np
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
def calc_bacc_from_conf_mat(cm: np.ndarray) -> float:
|
|
2521
|
-
"""
|
|
2522
|
-
Calculate balanced accuracy from confusion matrix.
|
|
2523
|
-
|
|
2524
|
-
Parameters
|
|
2525
|
-
----------
|
|
2526
|
-
cm : np.ndarray
|
|
2527
|
-
Confusion matrix
|
|
2528
|
-
|
|
2529
|
-
Returns
|
|
2530
|
-
-------
|
|
2531
|
-
float
|
|
2532
|
-
Balanced accuracy
|
|
2533
|
-
"""
|
|
2534
|
-
try:
|
|
2535
|
-
per_class = np.diag(cm) / np.sum(cm, axis=1)
|
|
2536
|
-
return float(np.nanmean(per_class))
|
|
2537
|
-
except:
|
|
2538
|
-
return np.nan
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
# Convenience aliases
|
|
2542
|
-
bACC_from_conf_mat = calc_bacc_from_conf_mat
|
|
2543
|
-
balanced_accuracy_from_conf_mat = calc_bacc_from_conf_mat
|
|
2544
|
-
|
|
2545
|
-
# EOF
|
|
2546
|
-
|
|
2547
|
-
...
|
|
2548
|
-
```
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
### `./metrics/_calc_bacc.py`
|
|
2552
|
-
|
|
2553
|
-
```python
|
|
2554
|
-
#!/usr/bin/env python3
|
|
2555
|
-
# -*- coding: utf-8 -*-
|
|
2556
|
-
# Timestamp: "2025-10-02 (ywatanabe)"
|
|
2557
|
-
# File: /home/ywatanabe/proj/scitex_repo/src/scitex/ml/metrics/_calc_bacc.py
|
|
2558
|
-
|
|
2559
|
-
"""Calculate balanced accuracy metric."""
|
|
2560
|
-
|
|
2561
|
-
__FILE__ = __file__
|
|
2562
|
-
|
|
2563
|
-
from typing import Any, Dict, List, Optional
|
|
2564
|
-
import numpy as np
|
|
2565
|
-
from sklearn.metrics import balanced_accuracy_score
|
|
2566
|
-
from ._normalize_labels import normalize_labels
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
def calc_bacc(
|
|
2570
|
-
y_true: np.ndarray,
|
|
2571
|
-
y_pred: np.ndarray,
|
|
2572
|
-
labels: Optional[List] = None,
|
|
2573
|
-
fold: Optional[int] = None,
|
|
2574
|
-
) -> Dict[str, Any]:
|
|
2575
|
-
"""
|
|
2576
|
-
Calculate balanced accuracy with robust label handling.
|
|
2577
|
-
|
|
2578
|
-
Parameters
|
|
2579
|
-
----------
|
|
2580
|
-
y_true : np.ndarray
|
|
2581
|
-
True labels (can be str or int)
|
|
2582
|
-
y_pred : np.ndarray
|
|
2583
|
-
Predicted labels (can be str or int)
|
|
2584
|
-
labels : List, optional
|
|
2585
|
-
Expected label list
|
|
2586
|
-
fold : int, optional
|
|
2587
|
-
Fold number for tracking
|
|
2588
|
-
|
|
2589
|
-
Returns
|
|
2590
|
-
-------
|
|
2591
|
-
Dict[str, Any]
|
|
2592
|
-
{'metric': 'balanced_accuracy', 'value': float, 'fold': int}
|
|
2593
|
-
"""
|
|
2594
|
-
try:
|
|
2595
|
-
y_true_norm, y_pred_norm, label_names, _ = normalize_labels(
|
|
2596
|
-
y_true, y_pred, labels
|
|
2597
|
-
)
|
|
2598
|
-
value = balanced_accuracy_score(y_true_norm, y_pred_norm)
|
|
2599
|
-
return {
|
|
2600
|
-
"metric": "balanced_accuracy",
|
|
2601
|
-
"value": float(value),
|
|
2602
|
-
"fold": fold,
|
|
2603
|
-
"labels": label_names,
|
|
2604
|
-
|
|
2605
|
-
...
|
|
2606
|
-
```
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
### `./metrics/_calc_clf_report.py`
|
|
2610
|
-
|
|
2611
|
-
```python
|
|
2612
|
-
#!/usr/bin/env python3
|
|
2613
|
-
# -*- coding: utf-8 -*-
|
|
2614
|
-
# Timestamp: "2025-10-02 (ywatanabe)"
|
|
2615
|
-
# File: /home/ywatanabe/proj/scitex_repo/src/scitex/ml/metrics/_calc_clf_report.py
|
|
2616
|
-
|
|
2617
|
-
"""Generate classification report."""
|
|
2618
|
-
|
|
2619
|
-
__FILE__ = __file__
|
|
2620
|
-
|
|
2621
|
-
from typing import Any, Dict, List, Optional
|
|
2622
|
-
import pandas as pd
|
|
2623
|
-
from sklearn.metrics import classification_report
|
|
2624
|
-
from ._normalize_labels import normalize_labels
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
def calc_clf_report(
|
|
2628
|
-
y_true,
|
|
2629
|
-
y_pred,
|
|
2630
|
-
labels: Optional[List] = None,
|
|
2631
|
-
fold: Optional[int] = None,
|
|
2632
|
-
) -> Dict[str, Any]:
|
|
2633
|
-
"""
|
|
2634
|
-
Generate classification report with robust label handling.
|
|
2635
|
-
|
|
2636
|
-
Parameters
|
|
2637
|
-
----------
|
|
2638
|
-
y_true : np.ndarray
|
|
2639
|
-
True labels (can be str or int)
|
|
2640
|
-
y_pred : np.ndarray
|
|
2641
|
-
Predicted labels (can be str or int)
|
|
2642
|
-
labels : List, optional
|
|
2643
|
-
Expected label list
|
|
2644
|
-
fold : int, optional
|
|
2645
|
-
Fold number for tracking
|
|
2646
|
-
|
|
2647
|
-
Returns
|
|
2648
|
-
-------
|
|
2649
|
-
Dict[str, Any]
|
|
2650
|
-
{
|
|
2651
|
-
'metric': 'classification_report',
|
|
2652
|
-
'value': pd.DataFrame,
|
|
2653
|
-
'fold': int,
|
|
2654
|
-
'labels': list
|
|
2655
|
-
}
|
|
2656
|
-
"""
|
|
2657
|
-
try:
|
|
2658
|
-
y_true_norm, y_pred_norm, label_names, _ = normalize_labels(
|
|
2659
|
-
y_true, y_pred, labels
|
|
2660
|
-
)
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
...
|
|
2664
|
-
```
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
### `./metrics/_calc_conf_mat.py`
|
|
2668
|
-
|
|
2669
|
-
```python
|
|
2670
|
-
#!/usr/bin/env python3
|
|
2671
|
-
# -*- coding: utf-8 -*-
|
|
2672
|
-
# Timestamp: "2025-10-02 (ywatanabe)"
|
|
2673
|
-
# File: /home/ywatanabe/proj/scitex_repo/src/scitex/ml/metrics/_calc_conf_mat.py
|
|
2674
|
-
|
|
2675
|
-
"""Calculate confusion matrix."""
|
|
2676
|
-
|
|
2677
|
-
__FILE__ = __file__
|
|
2678
|
-
|
|
2679
|
-
from typing import Any, Dict, List, Optional
|
|
2680
|
-
import numpy as np
|
|
2681
|
-
import pandas as pd
|
|
2682
|
-
from sklearn.metrics import confusion_matrix as sklearn_confusion_matrix
|
|
2683
|
-
from ._normalize_labels import normalize_labels
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
def calc_conf_mat(
|
|
2687
|
-
y_true: np.ndarray,
|
|
2688
|
-
y_pred: np.ndarray,
|
|
2689
|
-
labels: Optional[List] = None,
|
|
2690
|
-
fold: Optional[int] = None,
|
|
2691
|
-
normalize: Optional[str] = None,
|
|
2692
|
-
) -> Dict[str, Any]:
|
|
2693
|
-
"""
|
|
2694
|
-
Calculate confusion matrix with robust label handling.
|
|
2695
|
-
|
|
2696
|
-
Parameters
|
|
2697
|
-
----------
|
|
2698
|
-
y_true : np.ndarray
|
|
2699
|
-
True labels (can be str or int)
|
|
2700
|
-
y_pred : np.ndarray
|
|
2701
|
-
Predicted labels (can be str or int)
|
|
2702
|
-
labels : List, optional
|
|
2703
|
-
Expected label list
|
|
2704
|
-
fold : int, optional
|
|
2705
|
-
Fold number for tracking
|
|
2706
|
-
normalize : str, optional
|
|
2707
|
-
'true', 'pred', 'all', or None
|
|
2708
|
-
|
|
2709
|
-
Returns
|
|
2710
|
-
-------
|
|
2711
|
-
Dict[str, Any]
|
|
2712
|
-
{
|
|
2713
|
-
'metric': 'confusion_matrix',
|
|
2714
|
-
'value': pd.DataFrame,
|
|
2715
|
-
'fold': int,
|
|
2716
|
-
'labels': list
|
|
2717
|
-
}
|
|
2718
|
-
"""
|
|
2719
|
-
try:
|
|
2720
|
-
|
|
2721
|
-
...
|
|
2722
|
-
```
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
### `./metrics/_calc_feature_importance.py`
|
|
2726
|
-
|
|
2727
|
-
```python
|
|
2728
|
-
#!/usr/bin/env python3
|
|
2729
|
-
# -*- coding: utf-8 -*-
|
|
2730
|
-
# Timestamp: "2025-10-03 04:00:00 (ywatanabe)"
|
|
2731
|
-
# File: /ssh:sp:/home/ywatanabe/proj/scitex_repo/src/scitex/ml/metrics/_calc_feature_importance.py
|
|
2732
|
-
|
|
2733
|
-
"""
|
|
2734
|
-
Calculate feature importance from trained models.
|
|
2735
|
-
|
|
2736
|
-
This module provides a unified interface for extracting feature importance
|
|
2737
|
-
from various model types (tree-based, linear models, etc.).
|
|
2738
|
-
"""
|
|
2739
|
-
|
|
2740
|
-
from typing import Dict, List, Optional, Tuple
|
|
2741
|
-
import numpy as np
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
def calc_feature_importance(
|
|
2745
|
-
model,
|
|
2746
|
-
feature_names: Optional[List[str]] = None,
|
|
2747
|
-
top_n: Optional[int] = None,
|
|
2748
|
-
) -> Tuple[Dict[str, float], np.ndarray]:
|
|
2749
|
-
"""
|
|
2750
|
-
Calculate feature importance from a trained model.
|
|
2751
|
-
|
|
2752
|
-
Parameters
|
|
2753
|
-
----------
|
|
2754
|
-
model : object
|
|
2755
|
-
Trained model with feature importance attributes
|
|
2756
|
-
Supports:
|
|
2757
|
-
- Tree-based: feature_importances_ (RandomForest, XGBoost, etc.)
|
|
2758
|
-
- Linear: coef_ (LogisticRegression, LinearSVC, etc.)
|
|
2759
|
-
feature_names : List[str], optional
|
|
2760
|
-
Names of features. If None, uses feature_0, feature_1, ...
|
|
2761
|
-
top_n : int, optional
|
|
2762
|
-
Return only top N most important features
|
|
2763
|
-
|
|
2764
|
-
Returns
|
|
2765
|
-
-------
|
|
2766
|
-
importance_dict : Dict[str, float]
|
|
2767
|
-
Dictionary mapping feature names to importance scores
|
|
2768
|
-
importance_array : np.ndarray
|
|
2769
|
-
Array of importance scores (same order as feature_names)
|
|
2770
|
-
|
|
2771
|
-
Raises
|
|
2772
|
-
------
|
|
2773
|
-
ValueError
|
|
2774
|
-
If model doesn't support feature importance extraction
|
|
2775
|
-
|
|
2776
|
-
Examples
|
|
2777
|
-
--------
|
|
2778
|
-
|
|
2779
|
-
...
|
|
2780
|
-
```
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
### `./metrics/_calc_mcc.py`
|
|
2784
|
-
|
|
2785
|
-
```python
|
|
2786
|
-
#!/usr/bin/env python3
|
|
2787
|
-
# -*- coding: utf-8 -*-
|
|
2788
|
-
# Timestamp: "2025-10-02 (ywatanabe)"
|
|
2789
|
-
# File: /home/ywatanabe/proj/scitex_repo/src/scitex/ml/metrics/_calc_mcc.py
|
|
2790
|
-
|
|
2791
|
-
"""Calculate Matthews Correlation Coefficient."""
|
|
2792
|
-
|
|
2793
|
-
__FILE__ = __file__
|
|
2794
|
-
|
|
2795
|
-
from typing import Any, Dict, List, Optional
|
|
2796
|
-
import numpy as np
|
|
2797
|
-
from sklearn.metrics import matthews_corrcoef
|
|
2798
|
-
from ._normalize_labels import normalize_labels
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
def calc_mcc(
|
|
2802
|
-
y_true: np.ndarray,
|
|
2803
|
-
y_pred: np.ndarray,
|
|
2804
|
-
labels: Optional[List] = None,
|
|
2805
|
-
fold: Optional[int] = None,
|
|
2806
|
-
) -> Dict[str, Any]:
|
|
2807
|
-
"""
|
|
2808
|
-
Calculate Matthews Correlation Coefficient with robust label handling.
|
|
2809
|
-
|
|
2810
|
-
Parameters
|
|
2811
|
-
----------
|
|
2812
|
-
y_true : np.ndarray
|
|
2813
|
-
True labels (can be str or int)
|
|
2814
|
-
y_pred : np.ndarray
|
|
2815
|
-
Predicted labels (can be str or int)
|
|
2816
|
-
labels : List, optional
|
|
2817
|
-
Expected label list
|
|
2818
|
-
fold : int, optional
|
|
2819
|
-
Fold number for tracking
|
|
2820
|
-
|
|
2821
|
-
Returns
|
|
2822
|
-
-------
|
|
2823
|
-
Dict[str, Any]
|
|
2824
|
-
{'metric': 'mcc', 'value': float, 'fold': int}
|
|
2825
|
-
"""
|
|
2826
|
-
try:
|
|
2827
|
-
y_true_norm, y_pred_norm, label_names, _ = normalize_labels(
|
|
2828
|
-
y_true, y_pred, labels
|
|
2829
|
-
)
|
|
2830
|
-
value = matthews_corrcoef(y_true_norm, y_pred_norm)
|
|
2831
|
-
return {
|
|
2832
|
-
"metric": "mcc",
|
|
2833
|
-
"value": float(value),
|
|
2834
|
-
"fold": fold,
|
|
2835
|
-
"labels": label_names,
|
|
2836
|
-
|
|
2837
|
-
...
|
|
2838
|
-
```
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
### `./metrics/_calc_pre_rec_auc.py`
|
|
2842
|
-
|
|
2843
|
-
```python
|
|
2844
|
-
#!/usr/bin/env python3
|
|
2845
|
-
# -*- coding: utf-8 -*-
|
|
2846
|
-
# Timestamp: "2025-10-02 (ywatanabe)"
|
|
2847
|
-
# File: /home/ywatanabe/proj/scitex_repo/src/scitex/ml/metrics/_calc_pre_rec_auc.py
|
|
2848
|
-
|
|
2849
|
-
"""Calculate Precision-Recall AUC."""
|
|
2850
|
-
|
|
2851
|
-
__FILE__ = __file__
|
|
2852
|
-
|
|
2853
|
-
from typing import Any, Dict, List, Optional
|
|
2854
|
-
import numpy as np
|
|
2855
|
-
from sklearn.metrics import average_precision_score, precision_recall_curve
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
def calc_pre_rec_auc(
|
|
2859
|
-
y_true: np.ndarray,
|
|
2860
|
-
y_proba: np.ndarray,
|
|
2861
|
-
labels: Optional[List] = None,
|
|
2862
|
-
fold: Optional[int] = None,
|
|
2863
|
-
return_curve: bool = False,
|
|
2864
|
-
) -> Dict[str, Any]:
|
|
2865
|
-
"""
|
|
2866
|
-
Calculate Precision-Recall AUC with robust handling.
|
|
2867
|
-
|
|
2868
|
-
Parameters
|
|
2869
|
-
----------
|
|
2870
|
-
y_true : np.ndarray
|
|
2871
|
-
True labels (can be str or int)
|
|
2872
|
-
y_proba : np.ndarray
|
|
2873
|
-
Predicted probabilities
|
|
2874
|
-
labels : List, optional
|
|
2875
|
-
Expected label list
|
|
2876
|
-
fold : int, optional
|
|
2877
|
-
Fold number for tracking
|
|
2878
|
-
return_curve : bool
|
|
2879
|
-
Whether to return PR curve data
|
|
2880
|
-
|
|
2881
|
-
Returns
|
|
2882
|
-
-------
|
|
2883
|
-
Dict[str, Any]
|
|
2884
|
-
{'metric': 'pr_auc', 'value': float, 'fold': int}
|
|
2885
|
-
"""
|
|
2886
|
-
try:
|
|
2887
|
-
# Normalize labels
|
|
2888
|
-
if labels is not None:
|
|
2889
|
-
unique_labels = np.unique(y_true)
|
|
2890
|
-
label_names = labels
|
|
2891
|
-
# If data contains integers, assume they map to label indices
|
|
2892
|
-
if isinstance(unique_labels[0], (int, np.integer)):
|
|
2893
|
-
y_true_norm = y_true.astype(int)
|
|
2894
|
-
|
|
2895
|
-
...
|
|
2896
|
-
```
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
### `./metrics/_calc_roc_auc.py`
|
|
2900
|
-
|
|
2901
|
-
```python
|
|
2902
|
-
#!/usr/bin/env python3
|
|
2903
|
-
# -*- coding: utf-8 -*-
|
|
2904
|
-
# Timestamp: "2025-10-02 (ywatanabe)"
|
|
2905
|
-
# File: /home/ywatanabe/proj/scitex_repo/src/scitex/ml/metrics/_calc_roc_auc.py
|
|
2906
|
-
|
|
2907
|
-
"""Calculate ROC AUC score."""
|
|
2908
|
-
|
|
2909
|
-
__FILE__ = __file__
|
|
2910
|
-
|
|
2911
|
-
from typing import Any, Dict, List, Optional
|
|
2912
|
-
import numpy as np
|
|
2913
|
-
from sklearn.metrics import roc_auc_score, roc_curve
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
def calc_roc_auc(
|
|
2917
|
-
y_true: np.ndarray,
|
|
2918
|
-
y_proba: np.ndarray,
|
|
2919
|
-
labels: Optional[List] = None,
|
|
2920
|
-
fold: Optional[int] = None,
|
|
2921
|
-
return_curve: bool = False,
|
|
2922
|
-
) -> Dict[str, Any]:
|
|
2923
|
-
"""
|
|
2924
|
-
Calculate ROC AUC score with robust handling.
|
|
2925
|
-
|
|
2926
|
-
Parameters
|
|
2927
|
-
----------
|
|
2928
|
-
y_true : np.ndarray
|
|
2929
|
-
True labels (can be str or int)
|
|
2930
|
-
y_proba : np.ndarray
|
|
2931
|
-
Predicted probabilities
|
|
2932
|
-
labels : List, optional
|
|
2933
|
-
Expected label list
|
|
2934
|
-
fold : int, optional
|
|
2935
|
-
Fold number for tracking
|
|
2936
|
-
return_curve : bool
|
|
2937
|
-
Whether to return ROC curve data
|
|
2938
|
-
|
|
2939
|
-
Returns
|
|
2940
|
-
-------
|
|
2941
|
-
Dict[str, Any]
|
|
2942
|
-
{'metric': 'roc_auc', 'value': float, 'fold': int}
|
|
2943
|
-
"""
|
|
2944
|
-
try:
|
|
2945
|
-
# Normalize labels
|
|
2946
|
-
if labels is not None:
|
|
2947
|
-
unique_labels = np.unique(y_true)
|
|
2948
|
-
label_names = labels
|
|
2949
|
-
# If data contains integers, assume they map to label indices
|
|
2950
|
-
if isinstance(unique_labels[0], (int, np.integer)):
|
|
2951
|
-
y_true_norm = y_true.astype(int)
|
|
2952
|
-
|
|
2953
|
-
...
|
|
2954
|
-
```
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
### `./metrics/_calc_seizure_prediction_metrics.py`
|
|
2958
|
-
|
|
2959
|
-
```python
|
|
2960
|
-
#!/usr/bin/env python3
|
|
2961
|
-
# -*- coding: utf-8 -*-
|
|
2962
|
-
# Timestamp: "2025-10-03 01:56:15 (ywatanabe)"
|
|
2963
|
-
# File: /ssh:sp:/home/ywatanabe/proj/scitex_repo/src/scitex/ml/metrics/_calc_seizure_prediction_metrics.py
|
|
2964
|
-
"""Calculate clinical seizure prediction metrics.
|
|
2965
|
-
|
|
2966
|
-
This module provides both window-based and event-based seizure prediction metrics
|
|
2967
|
-
following FDA/clinical guidelines.
|
|
2968
|
-
|
|
2969
|
-
Two Approaches:
|
|
2970
|
-
1. Window-based: Measures % of seizure time windows detected
|
|
2971
|
-
2. Event-based: Measures % of seizure events detected (≥1 alarm per event)
|
|
2972
|
-
|
|
2973
|
-
Key Metrics:
|
|
2974
|
-
- seizure_sensitivity: % detected (interpretation depends on window vs event-based)
|
|
2975
|
-
- fp_per_hour: False positives per hour during interictal periods
|
|
2976
|
-
- time_in_warning: % of total time in alarm state
|
|
2977
|
-
|
|
2978
|
-
Clinical Targets (FDA guidelines):
|
|
2979
|
-
- Sensitivity ≥ 90%
|
|
2980
|
-
- FP/h ≤ 0.2
|
|
2981
|
-
- Time in warning ≤ 20%
|
|
2982
|
-
"""
|
|
2983
|
-
from __future__ import annotations
|
|
2984
|
-
from typing import Dict
|
|
2985
|
-
import numpy as np
|
|
2986
|
-
import pandas as pd
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
def calc_seizure_window_prediction_metrics(
|
|
2990
|
-
y_true: np.ndarray,
|
|
2991
|
-
y_pred: np.ndarray,
|
|
2992
|
-
metadata: pd.DataFrame,
|
|
2993
|
-
window_duration_min: float = 1.0,
|
|
2994
|
-
) -> Dict[str, float]:
|
|
2995
|
-
"""Calculate clinical seizure prediction metrics (window-based).
|
|
2996
|
-
|
|
2997
|
-
This function calculates window-based sensitivity, meaning it measures
|
|
2998
|
-
the percentage of seizure time windows that were correctly identified.
|
|
2999
|
-
This is NOT event-based sensitivity (which would measure % of seizure
|
|
3000
|
-
events detected regardless of how many windows within each event).
|
|
3001
|
-
|
|
3002
|
-
Parameters
|
|
3003
|
-
----------
|
|
3004
|
-
y_true : np.ndarray
|
|
3005
|
-
True labels (string: 'seizure' or 'interictal_control')
|
|
3006
|
-
y_pred : np.ndarray
|
|
3007
|
-
Predicted labels (string: 'seizure' or 'interictal_control')
|
|
3008
|
-
metadata : pd.DataFrame
|
|
3009
|
-
Metadata with 'seizure_type' column indicating seizure/interictal periods
|
|
3010
|
-
|
|
3011
|
-
...
|
|
3012
|
-
```
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
### `./metrics/_calc_silhouette_score.py`
|
|
3016
|
-
|
|
3017
|
-
```python
|
|
3018
|
-
#!/usr/bin/env python3
|
|
3019
|
-
# -*- coding: utf-8 -*-
|
|
3020
|
-
# Time-stamp: "2024-11-20 00:22:25 (ywatanabe)"
|
|
3021
|
-
# File: ./scitex_repo/src/scitex/ai/silhoute_score_block.py
|
|
3022
|
-
|
|
3023
|
-
THIS_FILE = "/data/gpfs/projects/punim2354/ywatanabe/scitex_repo/src/scitex/ai/silhoute_score_block.py"
|
|
3024
|
-
|
|
3025
|
-
#!/usr/bin/env python3
|
|
3026
|
-
# -*- coding: utf-8 -*-
|
|
3027
|
-
# Time-stamp: "2024-11-03 03:03:13 (ywatanabe)"
|
|
3028
|
-
# File: ./scitex_repo/src/scitex/ai/silhoute_score_block.py
|
|
3029
|
-
|
|
3030
|
-
# https://gist.github.com/AlexandreAbraham/5544803
|
|
3031
|
-
|
|
3032
|
-
""" Unsupervised evaluation metrics. """
|
|
3033
|
-
|
|
3034
|
-
# License: BSD Style.
|
|
3035
|
-
|
|
3036
|
-
from itertools import combinations as _combinations
|
|
3037
|
-
|
|
3038
|
-
import numpy as _np
|
|
3039
|
-
|
|
3040
|
-
# from sklearn.externals.joblib import Parallel, delayed
|
|
3041
|
-
from joblib import Parallel as _Parallel
|
|
3042
|
-
from joblib import delayed as _delayed
|
|
3043
|
-
from sklearn.metrics.pairwise import distance_metrics as _distance_metrics
|
|
3044
|
-
from sklearn.metrics.pairwise import pairwise_distances as _pairwise_distances
|
|
3045
|
-
from sklearn.utils import check_random_state as _check_random_state
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
def calc_silhouette_score_slow(
|
|
3049
|
-
X, labels, metric="euclidean", sample_size=None, random_state=None, **kwds
|
|
3050
|
-
):
|
|
3051
|
-
"""Compute the mean Silhouette Coefficient of all samples.
|
|
3052
|
-
|
|
3053
|
-
This method is computationally expensive compared to the reference one.
|
|
3054
|
-
|
|
3055
|
-
The Silhouette Coefficient is calculated using the mean intra-cluster
|
|
3056
|
-
distance (a) and the mean nearest-cluster distance (b) for each sample.
|
|
3057
|
-
The Silhouette Coefficient for a sample is ``(b - a) / max(a, b)``.
|
|
3058
|
-
To clarrify, b is the distance between a sample and the nearest cluster
|
|
3059
|
-
that b is not a part of.
|
|
3060
|
-
|
|
3061
|
-
This function returns the mean Silhoeutte Coefficient over all samples.
|
|
3062
|
-
To obtain the values for each sample, use silhouette_samples
|
|
3063
|
-
|
|
3064
|
-
The best value is 1 and the worst value is -1. Values near 0 indicate
|
|
3065
|
-
overlapping clusters. Negative values genly indicate that a sample has
|
|
3066
|
-
been assigned to the wrong cluster, as a different cluster is more similar.
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
...
|
|
3070
|
-
```
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
### `./metrics/__init__.py`
|
|
3074
|
-
|
|
3075
|
-
```python
|
|
3076
|
-
#!/usr/bin/env python3
|
|
3077
|
-
"""Scitex metrics module.
|
|
3078
|
-
|
|
3079
|
-
Standardized naming convention:
|
|
3080
|
-
- calc_* functions: Modern standardized metric calculations
|
|
3081
|
-
- Legacy names (bACC, balanced_accuracy, etc.): For backward compatibility
|
|
3082
|
-
"""
|
|
3083
|
-
|
|
3084
|
-
# Modern standardized calc_* functions
|
|
3085
|
-
from ._normalize_labels import normalize_labels as _normalize_labels
|
|
3086
|
-
from ._calc_bacc import calc_bacc
|
|
3087
|
-
from ._calc_mcc import calc_mcc
|
|
3088
|
-
from ._calc_conf_mat import calc_conf_mat
|
|
3089
|
-
from ._calc_clf_report import calc_clf_report
|
|
3090
|
-
from ._calc_roc_auc import calc_roc_auc
|
|
3091
|
-
from ._calc_pre_rec_auc import calc_pre_rec_auc
|
|
3092
|
-
from ._calc_bacc_from_conf_mat import calc_bacc_from_conf_mat
|
|
3093
|
-
from ._calc_seizure_prediction_metrics import (
|
|
3094
|
-
calc_seizure_window_prediction_metrics,
|
|
3095
|
-
calc_seizure_event_prediction_metrics,
|
|
3096
|
-
calc_seizure_prediction_metrics, # backward compat alias
|
|
3097
|
-
)
|
|
3098
|
-
from ._calc_silhouette_score import (
|
|
3099
|
-
calc_silhouette_score_slow,
|
|
3100
|
-
calc_silhouette_samples_slow,
|
|
3101
|
-
calc_silhouette_score_block,
|
|
3102
|
-
calc_silhouette_samples_block,
|
|
3103
|
-
)
|
|
3104
|
-
from ._calc_feature_importance import (
|
|
3105
|
-
calc_feature_importance,
|
|
3106
|
-
calc_permutation_importance,
|
|
3107
|
-
)
|
|
3108
|
-
|
|
3109
|
-
__all__ = [
|
|
3110
|
-
"calc_bacc",
|
|
3111
|
-
"calc_mcc",
|
|
3112
|
-
"calc_conf_mat",
|
|
3113
|
-
"calc_clf_report",
|
|
3114
|
-
"calc_roc_auc",
|
|
3115
|
-
"calc_pre_rec_auc",
|
|
3116
|
-
"calc_bacc_from_conf_mat",
|
|
3117
|
-
"calc_seizure_window_prediction_metrics",
|
|
3118
|
-
"calc_seizure_event_prediction_metrics",
|
|
3119
|
-
"calc_seizure_prediction_metrics", # backward compat alias
|
|
3120
|
-
"calc_silhouette_score_slow",
|
|
3121
|
-
"calc_silhouette_samples_slow",
|
|
3122
|
-
"calc_silhouette_score_block",
|
|
3123
|
-
"calc_silhouette_samples_block",
|
|
3124
|
-
"calc_feature_importance",
|
|
3125
|
-
"calc_permutation_importance",
|
|
3126
|
-
|
|
3127
|
-
...
|
|
3128
|
-
```
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
### `./metrics/_normalize_labels.py`
|
|
3132
|
-
|
|
3133
|
-
```python
|
|
3134
|
-
#!/usr/bin/env python3
|
|
3135
|
-
# -*- coding: utf-8 -*-
|
|
3136
|
-
# Timestamp: "2025-10-02 (ywatanabe)"
|
|
3137
|
-
# File: /home/ywatanabe/proj/scitex_repo/src/scitex/ml/metrics/_normalize_labels.py
|
|
3138
|
-
|
|
3139
|
-
"""Label normalization utility for classification metrics."""
|
|
3140
|
-
|
|
3141
|
-
__FILE__ = __file__
|
|
3142
|
-
|
|
3143
|
-
from typing import List, Optional, Tuple
|
|
3144
|
-
import numpy as np
|
|
3145
|
-
from sklearn.preprocessing import LabelEncoder
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
def normalize_labels(
|
|
3149
|
-
y_true: np.ndarray,
|
|
3150
|
-
y_pred: np.ndarray,
|
|
3151
|
-
labels: Optional[List] = None,
|
|
3152
|
-
) -> Tuple[np.ndarray, np.ndarray, List, LabelEncoder]:
|
|
3153
|
-
"""
|
|
3154
|
-
Normalize labels using sklearn.preprocessing.LabelEncoder.
|
|
3155
|
-
|
|
3156
|
-
Parameters
|
|
3157
|
-
----------
|
|
3158
|
-
y_true : np.ndarray
|
|
3159
|
-
True labels (can be str or int)
|
|
3160
|
-
y_pred : np.ndarray
|
|
3161
|
-
Predicted labels (can be str or int)
|
|
3162
|
-
labels : List, optional
|
|
3163
|
-
Expected label list. If provided, will be used as display names.
|
|
3164
|
-
|
|
3165
|
-
Returns
|
|
3166
|
-
-------
|
|
3167
|
-
y_true_norm : np.ndarray
|
|
3168
|
-
Normalized true labels (integers 0, 1, 2, ...)
|
|
3169
|
-
y_pred_norm : np.ndarray
|
|
3170
|
-
Normalized predicted labels (integers 0, 1, 2, ...)
|
|
3171
|
-
label_names : List
|
|
3172
|
-
List of label names in order
|
|
3173
|
-
encoder : LabelEncoder
|
|
3174
|
-
Fitted encoder for inverse transform
|
|
3175
|
-
|
|
3176
|
-
Notes
|
|
3177
|
-
-----
|
|
3178
|
-
Uses sklearn.preprocessing.LabelEncoder for robust label handling.
|
|
3179
|
-
Handles the edge case where data contains integers but labels are strings
|
|
3180
|
-
(e.g., y_true=[0,1,0,1] with labels=['Negative', 'Positive']).
|
|
3181
|
-
"""
|
|
3182
|
-
# Get unique values from data
|
|
3183
|
-
all_data_labels = np.unique(np.concatenate([y_true, y_pred]))
|
|
3184
|
-
|
|
3185
|
-
...
|
|
3186
|
-
```
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
### `./optim/_get_set.py`
|
|
3190
|
-
|
|
3191
|
-
```python
|
|
3192
|
-
#!/usr/bin/env python3
|
|
3193
|
-
"""Optimizer utilities - legacy interface maintained for compatibility."""
|
|
3194
|
-
|
|
3195
|
-
import warnings
|
|
3196
|
-
from ._optimizers import get_optimizer, set_optimizer
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
def set(models, optim_str, lr):
|
|
3200
|
-
"""Sets an optimizer to models.
|
|
3201
|
-
|
|
3202
|
-
DEPRECATED: Use set_optimizer instead.
|
|
3203
|
-
"""
|
|
3204
|
-
warnings.warn(
|
|
3205
|
-
"scitex.ai.optim.set is deprecated. Use scitex.ai.optim.set_optimizer instead.",
|
|
3206
|
-
DeprecationWarning,
|
|
3207
|
-
stacklevel=2,
|
|
3208
|
-
)
|
|
3209
|
-
return set_optimizer(models, optim_str, lr)
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
def get(optim_str):
|
|
3213
|
-
"""Get optimizer class by name.
|
|
3214
|
-
|
|
3215
|
-
DEPRECATED: Use get_optimizer instead.
|
|
3216
|
-
"""
|
|
3217
|
-
warnings.warn(
|
|
3218
|
-
"scitex.ai.optim.get is deprecated. Use scitex.ai.optim.get_optimizer instead.",
|
|
3219
|
-
DeprecationWarning,
|
|
3220
|
-
stacklevel=2,
|
|
3221
|
-
)
|
|
3222
|
-
return get_optimizer(optim_str)
|
|
3223
|
-
|
|
3224
|
-
...
|
|
3225
|
-
```
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
### `./optim/__init__.py`
|
|
3229
|
-
|
|
3230
|
-
```python
|
|
3231
|
-
#!/usr/bin/env python3
|
|
3232
|
-
"""Scitex optim module."""
|
|
3233
|
-
|
|
3234
|
-
from ._get_set import get, set
|
|
3235
|
-
from ._optimizers import get_optimizer, set_optimizer, RANGER_AVAILABLE
|
|
3236
|
-
|
|
3237
|
-
__all__ = [
|
|
3238
|
-
"get",
|
|
3239
|
-
"get_optimizer",
|
|
3240
|
-
"set",
|
|
3241
|
-
"set_optimizer",
|
|
3242
|
-
"RANGER_AVAILABLE",
|
|
3243
|
-
]
|
|
3244
|
-
|
|
3245
|
-
...
|
|
3246
|
-
```
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
### `./optim/MIGRATION.md`
|
|
3250
|
-
|
|
3251
|
-
```markdown
|
|
3252
|
-
# Ranger Optimizer Migration Guide
|
|
3253
|
-
|
|
3254
|
-
## Overview
|
|
3255
|
-
The Ranger optimizer has been migrated from a vendored implementation to use the external `pytorch-optimizer` package.
|
|
3256
|
-
|
|
3257
|
-
## Changes
|
|
3258
|
-
|
|
3259
|
-
### Before
|
|
3260
|
-
```python
|
|
3261
|
-
from scitex.ai.optim.Ranger_Deep_Learning_Optimizer.ranger.ranger2020 import Ranger
|
|
3262
|
-
```
|
|
3263
|
-
|
|
3264
|
-
### After
|
|
3265
|
-
```python
|
|
3266
|
-
from pytorch_optimizer import Ranger21 as Ranger
|
|
3267
|
-
```
|
|
3268
|
-
|
|
3269
|
-
## Installation
|
|
3270
|
-
```bash
|
|
3271
|
-
pip install pytorch-optimizer
|
|
3272
|
-
```
|
|
3273
|
-
|
|
3274
|
-
## Backward Compatibility
|
|
3275
|
-
- The old API (`scitex.ai.optim.get` and `scitex.ai.optim.set`) still works but shows deprecation warnings
|
|
3276
|
-
- The vendored Ranger code is used as fallback if pytorch-optimizer is not installed
|
|
3277
|
-
- New code should use `get_optimizer` and `set_optimizer`
|
|
3278
|
-
|
|
3279
|
-
## Example Usage
|
|
3280
|
-
|
|
3281
|
-
### Old API (deprecated)
|
|
3282
|
-
```python
|
|
3283
|
-
optimizer = scitex.ai.optim.set(model, 'ranger', lr=0.001)
|
|
3284
|
-
```
|
|
3285
|
-
|
|
3286
|
-
### New API
|
|
3287
|
-
```python
|
|
3288
|
-
optimizer = scitex.ai.optim.set_optimizer(model, 'ranger', lr=0.001)
|
|
3289
|
-
```
|
|
3290
|
-
|
|
3291
|
-
## Removal Timeline
|
|
3292
|
-
- Version 1.12.0: Deprecation warnings added
|
|
3293
|
-
- Version 2.0.0: Vendored Ranger code will be removed
|
|
3294
|
-
- Users must install pytorch-optimizer for Ranger support
|
|
3295
|
-
|
|
3296
|
-
...
|
|
3297
|
-
```
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
### `./optim/_optimizers.py`
|
|
3301
|
-
|
|
3302
|
-
```python
|
|
3303
|
-
#!/usr/bin/env python3
|
|
3304
|
-
"""Optimizer utilities using external packages."""
|
|
3305
|
-
|
|
3306
|
-
import torch.optim as optim
|
|
3307
|
-
|
|
3308
|
-
# Use pytorch-optimizer package for Ranger when available
|
|
3309
|
-
try:
|
|
3310
|
-
from pytorch_optimizer import Ranger21 as Ranger
|
|
3311
|
-
|
|
3312
|
-
RANGER_AVAILABLE = True
|
|
3313
|
-
except ImportError:
|
|
3314
|
-
# Fallback to vendored version temporarily
|
|
3315
|
-
try:
|
|
3316
|
-
from .Ranger_Deep_Learning_Optimizer.ranger.ranger2020 import Ranger
|
|
3317
|
-
|
|
3318
|
-
RANGER_AVAILABLE = True
|
|
3319
|
-
except ImportError:
|
|
3320
|
-
RANGER_AVAILABLE = False
|
|
3321
|
-
Ranger = None
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
def get_optimizer(name: str):
|
|
3325
|
-
"""Get optimizer class by name.
|
|
3326
|
-
|
|
3327
|
-
Args:
|
|
3328
|
-
name: Optimizer name (adam, ranger, rmsprop, sgd)
|
|
3329
|
-
|
|
3330
|
-
Returns:
|
|
3331
|
-
Optimizer class
|
|
3332
|
-
|
|
3333
|
-
Raises:
|
|
3334
|
-
ValueError: If optimizer name is not supported
|
|
3335
|
-
"""
|
|
3336
|
-
optimizers = {"adam": optim.Adam, "rmsprop": optim.RMSprop, "sgd": optim.SGD}
|
|
3337
|
-
|
|
3338
|
-
if name == "ranger":
|
|
3339
|
-
if not RANGER_AVAILABLE:
|
|
3340
|
-
raise ImportError(
|
|
3341
|
-
"Ranger optimizer not available. "
|
|
3342
|
-
"Please install pytorch-optimizer: pip install pytorch-optimizer"
|
|
3343
|
-
)
|
|
3344
|
-
optimizers["ranger"] = Ranger
|
|
3345
|
-
|
|
3346
|
-
if name not in optimizers:
|
|
3347
|
-
raise ValueError(
|
|
3348
|
-
f"Unknown optimizer: {name}. " f"Available: {list(optimizers.keys())}"
|
|
3349
|
-
)
|
|
3350
|
-
|
|
3351
|
-
return optimizers[name]
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
...
|
|
3355
|
-
```
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
### `./optim/Ranger_Deep_Learning_Optimizer/__init__.py`
|
|
3359
|
-
|
|
3360
|
-
```python
|
|
3361
|
-
|
|
3362
|
-
...
|
|
3363
|
-
```
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
### `./optim/Ranger_Deep_Learning_Optimizer/LICENSE`
|
|
3367
|
-
|
|
3368
|
-
```plaintext
|
|
3369
|
-
Apache License
|
|
3370
|
-
Version 2.0, January 2004
|
|
3371
|
-
http://www.apache.org/licenses/
|
|
3372
|
-
|
|
3373
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
3374
|
-
|
|
3375
|
-
1. Definitions.
|
|
3376
|
-
|
|
3377
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
3378
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
3379
|
-
|
|
3380
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
3381
|
-
the copyright owner that is granting the License.
|
|
3382
|
-
|
|
3383
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
3384
|
-
other entities that control, are controlled by, or are under common
|
|
3385
|
-
control with that entity. For the purposes of this definition,
|
|
3386
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
3387
|
-
direction or management of such entity, whether by contract or
|
|
3388
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
3389
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
3390
|
-
|
|
3391
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
3392
|
-
exercising permissions granted by this License.
|
|
3393
|
-
|
|
3394
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
3395
|
-
including but not limited to software source code, documentation
|
|
3396
|
-
source, and configuration files.
|
|
3397
|
-
|
|
3398
|
-
"Object" form shall mean any form resulting from mechanical
|
|
3399
|
-
transformation or translation of a Source form, including but
|
|
3400
|
-
not limited to compiled object code, generated documentation,
|
|
3401
|
-
and conversions to other media types.
|
|
3402
|
-
|
|
3403
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
3404
|
-
Object form, made available under the License, as indicated by a
|
|
3405
|
-
copyright notice that is included in or attached to the work
|
|
3406
|
-
(an example is provided in the Appendix below).
|
|
3407
|
-
|
|
3408
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
3409
|
-
form, that is based on (or derived from) the Work and for which the
|
|
3410
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
3411
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
3412
|
-
of this License, Derivative Works shall not include works that remain
|
|
3413
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
3414
|
-
the Work and Derivative Works thereof.
|
|
3415
|
-
|
|
3416
|
-
"Contribution" shall mean any work of authorship, including
|
|
3417
|
-
the original version of the Work and any modifications or additions
|
|
3418
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
3419
|
-
|
|
3420
|
-
...
|
|
3421
|
-
```
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
### `./optim/Ranger_Deep_Learning_Optimizer/README.md`
|
|
3425
|
-
|
|
3426
|
-
```markdown
|
|
3427
|
-
# Ranger-Deep-Learning-Optimizer
|
|
3428
|
-
</br>
|
|
3429
|
-
Ranger - a synergistic optimizer combining RAdam (Rectified Adam) and LookAhead, and now GC (gradient centralization) in one optimizer.
|
|
3430
|
-
</br>
|
|
3431
|
-
|
|
3432
|
-
#### quick note - Ranger21 is now in beta and is Ranger with a host of new improvements.
|
|
3433
|
-
Recommend you compare results with Ranger21: https://github.com/lessw2020/Ranger21
|
|
3434
|
-
|
|
3435
|
-
### Latest version 20.9.4 - updates Gradient Centralization to GC2 (thanks to GC developer) and removes addcmul_ deprecation warnings in PyTorch 1.60.
|
|
3436
|
-
</br> </br>
|
|
3437
|
-
*Latest version is in ranger2020.py - looking at a few other additions before integrating into the main ranger.py.
|
|
3438
|
-
|
|
3439
|
-
What is Gradient Centralization? = "GC can be viewed as a projected gradient descent method with a constrained loss function. The Lipschitzness of the constrained loss function and its gradient is better so that the training process becomes more efficient and stable." Source paper: https://arxiv.org/abs/2004.01461v2
|
|
3440
|
-
</br>
|
|
3441
|
-
Ranger now uses Gradient Centralization by default, and applies it to all conv and fc layers by default. However, everything is customizable so you can test with and without on your own datasets. (Turn on off via "use_gc" flag at init).
|
|
3442
|
-
</br>
|
|
3443
|
-
### Best training results - use a 75% flat lr, then step down and run lower lr for 25%, or cosine descend last 25%.
|
|
3444
|
-
|
|
3445
|
-
</br> Per extensive testing - It's important to note that simply running one learning rate the entire time will not produce optimal results.
|
|
3446
|
-
Effectively Ranger will end up 'hovering' around the optimal zone, but can't descend into it unless it has some additional run time at a lower rate to drop down into the optimal valley.
|
|
3447
|
-
|
|
3448
|
-
### Full customization at init:
|
|
3449
|
-
<div align="center"><img src="ranger-with-gc-options.jpg" height="80%" width="80%" alt=""/></div>
|
|
3450
|
-
</br>
|
|
3451
|
-
Ranger will now print out id and gc settings at init so you can confirm the optimizer settings at train time:
|
|
3452
|
-
<div align="center"><img src="ranger-init.jpg" height="80%" width="80%" alt=""/></div>
|
|
3453
|
-
|
|
3454
|
-
/////////////////////
|
|
3455
|
-
|
|
3456
|
-
Medium article with more info:
|
|
3457
|
-
https://medium.com/@lessw/new-deep-learning-optimizer-ranger-synergistic-combination-of-radam-lookahead-for-the-best-of-2dc83f79a48d
|
|
3458
|
-
|
|
3459
|
-
Multiple updates:
|
|
3460
|
-
1 - Ranger is the optimizer we used to beat the high scores for 12 different categories on the FastAI leaderboards! (Previous records all held with AdamW optimizer).
|
|
3461
|
-
|
|
3462
|
-
2 - Highly recommend combining Ranger with: Mish activation function, and flat+ cosine anneal training curve.
|
|
3463
|
-
|
|
3464
|
-
3 - Based on that, also found .95 is better than .90 for beta1 (momentum) param (ala betas=(0.95, 0.999)).
|
|
3465
|
-
|
|
3466
|
-
Fixes:
|
|
3467
|
-
1 - Differential Group learning rates now supported. This was fix in RAdam and ported here thanks to @sholderbach.
|
|
3468
|
-
2 - save and then load may leave first run weights stranded in memory, slowing down future runs = fixed.
|
|
3469
|
-
|
|
3470
|
-
### Installation
|
|
3471
|
-
Clone the repo, cd into it and install it in editable mode (`-e` option).
|
|
3472
|
-
That way, these is no more need to re-install the package after modification.
|
|
3473
|
-
```bash
|
|
3474
|
-
git clone https://github.com/lessw2020/Ranger-Deep-Learning-Optimizer
|
|
3475
|
-
cd Ranger-Deep-Learning-Optimizer
|
|
3476
|
-
pip install -e .
|
|
3477
|
-
```
|
|
3478
|
-
|
|
3479
|
-
...
|
|
3480
|
-
```
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
### `./optim/Ranger_Deep_Learning_Optimizer/setup.py`
|
|
3484
|
-
|
|
3485
|
-
```python
|
|
3486
|
-
#!/usr/bin/env python
|
|
3487
|
-
|
|
3488
|
-
import os
|
|
3489
|
-
from setuptools import find_packages, setup
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
def read(fname):
|
|
3493
|
-
with open(os.path.join(os.path.dirname(__file__), fname)) as f:
|
|
3494
|
-
return f.read()
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
setup(
|
|
3498
|
-
name="ranger",
|
|
3499
|
-
version="0.1.dev0",
|
|
3500
|
-
packages=find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"]),
|
|
3501
|
-
package_dir={"ranger": os.path.join(".", "ranger")},
|
|
3502
|
-
description="Ranger - a synergistic optimizer using RAdam "
|
|
3503
|
-
"(Rectified Adam) and LookAhead in one codebase ",
|
|
3504
|
-
long_description=read("README.md"),
|
|
3505
|
-
long_description_content_type="text/markdown",
|
|
3506
|
-
author="Less Wright",
|
|
3507
|
-
license="Apache",
|
|
3508
|
-
install_requires=["torch"],
|
|
3509
|
-
)
|
|
3510
|
-
|
|
3511
|
-
...
|
|
3512
|
-
```
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
### `./plt/__init__.py`
|
|
3516
|
-
|
|
3517
|
-
```python
|
|
3518
|
-
#!/usr/bin/env python3
|
|
3519
|
-
"""Scitex centralized plotting module.
|
|
3520
|
-
|
|
3521
|
-
Note: Metric calculation functions (calc_*) are imported from scitex.ai.metrics
|
|
3522
|
-
but re-exported here for backward compatibility. New code should import directly
|
|
3523
|
-
from scitex.ai.metrics instead.
|
|
3524
|
-
"""
|
|
3525
|
-
|
|
3526
|
-
from ._plot_conf_mat import calc_bACC_from_conf_mat, calc_bacc_from_conf_mat, plot_conf_mat, conf_mat
|
|
3527
|
-
from ._plot_learning_curve import (
|
|
3528
|
-
plot_learning_curve,
|
|
3529
|
-
_prepare_metrics_df,
|
|
3530
|
-
_configure_accuracy_axis,
|
|
3531
|
-
_plot_training_data,
|
|
3532
|
-
_plot_validation_data,
|
|
3533
|
-
_plot_test_data,
|
|
3534
|
-
_add_epoch_vlines,
|
|
3535
|
-
_select_epoch_ticks,
|
|
3536
|
-
)
|
|
3537
|
-
from ._plot_optuna_study import optuna_study, plot_optuna_study
|
|
3538
|
-
from ._plot_roc_curve import plot_roc_curve
|
|
3539
|
-
from ._plot_pre_rec_curve import plot_pre_rec_curve
|
|
3540
|
-
from ._plot_feature_importance import (
|
|
3541
|
-
plot_feature_importance,
|
|
3542
|
-
plot_feature_importance_cv_summary,
|
|
3543
|
-
)
|
|
3544
|
-
|
|
3545
|
-
# Backward compatibility aliases
|
|
3546
|
-
learning_curve = plot_learning_curve
|
|
3547
|
-
plot_tra = _plot_training_data
|
|
3548
|
-
process_i_global = _prepare_metrics_df
|
|
3549
|
-
scatter_tes = _plot_test_data
|
|
3550
|
-
scatter_val = _plot_validation_data
|
|
3551
|
-
select_ticks = _select_epoch_ticks
|
|
3552
|
-
set_yaxis_for_acc = _configure_accuracy_axis
|
|
3553
|
-
vline_at_epochs = _add_epoch_vlines
|
|
3554
|
-
|
|
3555
|
-
__all__ = [
|
|
3556
|
-
# Plotting functions
|
|
3557
|
-
"plot_conf_mat",
|
|
3558
|
-
"conf_mat", # backward compat
|
|
3559
|
-
"plot_learning_curve",
|
|
3560
|
-
"learning_curve", # backward compat
|
|
3561
|
-
"optuna_study",
|
|
3562
|
-
"plot_optuna_study",
|
|
3563
|
-
"plot_roc_curve",
|
|
3564
|
-
"plot_pre_rec_curve",
|
|
3565
|
-
"plot_feature_importance",
|
|
3566
|
-
"plot_feature_importance_cv_summary",
|
|
3567
|
-
"plot_tra",
|
|
3568
|
-
|
|
3569
|
-
...
|
|
3570
|
-
```
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
### `./plt/_plot_conf_mat.py`
|
|
3574
|
-
|
|
3575
|
-
```python
|
|
3576
|
-
#!/usr/bin/env python3
|
|
3577
|
-
# -*- coding: utf-8 -*-
|
|
3578
|
-
# Timestamp: "2025-10-02 07:15:10 (ywatanabe)"
|
|
3579
|
-
# File: /ssh:sp:/home/ywatanabe/proj/scitex_repo/src/scitex/ml/plt/plot_conf_mat.py
|
|
3580
|
-
# ----------------------------------------
|
|
3581
|
-
from __future__ import annotations
|
|
3582
|
-
import os
|
|
3583
|
-
__FILE__ = __file__
|
|
3584
|
-
__DIR__ = os.path.dirname(__FILE__)
|
|
3585
|
-
# ----------------------------------------
|
|
3586
|
-
|
|
3587
|
-
import argparse
|
|
3588
|
-
|
|
3589
|
-
import matplotlib
|
|
3590
|
-
import numpy as np
|
|
3591
|
-
import pandas as pd
|
|
3592
|
-
import scitex
|
|
3593
|
-
import seaborn as sns
|
|
3594
|
-
from matplotlib import ticker
|
|
3595
|
-
from mpl_toolkits.axes_grid1 import make_axes_locatable
|
|
3596
|
-
from sklearn.metrics import balanced_accuracy_score
|
|
3597
|
-
from sklearn.metrics import confusion_matrix as sklearn_confusion_matrix
|
|
3598
|
-
|
|
3599
|
-
# Import metric calculation from centralized location (SoC: metrics in scitex.ai.metrics)
|
|
3600
|
-
from scitex.ai.metrics import calc_bacc_from_conf_mat
|
|
3601
|
-
|
|
3602
|
-
# Aliases for backward compatibility
|
|
3603
|
-
calc_bACC_from_conf_mat = calc_bacc_from_conf_mat
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
def plot_conf_mat(
|
|
3607
|
-
cm=None,
|
|
3608
|
-
y_true=None,
|
|
3609
|
-
y_pred=None,
|
|
3610
|
-
y_pred_proba=None,
|
|
3611
|
-
labels=None,
|
|
3612
|
-
sorted_labels=None,
|
|
3613
|
-
pred_labels=None,
|
|
3614
|
-
sorted_pred_labels=None,
|
|
3615
|
-
true_labels=None,
|
|
3616
|
-
sorted_true_labels=None,
|
|
3617
|
-
label_rotation_xy=(15, 15),
|
|
3618
|
-
title="Confusion Matrix",
|
|
3619
|
-
colorbar=True,
|
|
3620
|
-
x_extend_ratio=1.0,
|
|
3621
|
-
y_extend_ratio=1.0,
|
|
3622
|
-
ax=None,
|
|
3623
|
-
spath=None,
|
|
3624
|
-
):
|
|
3625
|
-
"""
|
|
3626
|
-
|
|
3627
|
-
...
|
|
3628
|
-
```
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
### `./plt/_plot_feature_importance.py`
|
|
3632
|
-
|
|
3633
|
-
```python
|
|
3634
|
-
#!/usr/bin/env python3
|
|
3635
|
-
# -*- coding: utf-8 -*-
|
|
3636
|
-
# Timestamp: "2025-10-03 04:10:00 (ywatanabe)"
|
|
3637
|
-
# File: /ssh:sp:/home/ywatanabe/proj/scitex_repo/src/scitex/ml/plt/plot_feature_importance.py
|
|
3638
|
-
|
|
3639
|
-
"""
|
|
3640
|
-
Plot feature importance from trained models.
|
|
3641
|
-
|
|
3642
|
-
This module provides visualization functions for feature importance,
|
|
3643
|
-
supporting both single-fold and cross-validation summary plots.
|
|
3644
|
-
"""
|
|
3645
|
-
|
|
3646
|
-
from pathlib import Path
|
|
3647
|
-
from typing import Dict, List, Optional, Union
|
|
3648
|
-
import numpy as np
|
|
3649
|
-
import matplotlib.pyplot as plt
|
|
3650
|
-
import scitex as stx
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
def plot_feature_importance(
|
|
3654
|
-
importance: Union[np.ndarray, Dict[str, float]],
|
|
3655
|
-
feature_names: Optional[List[str]] = None,
|
|
3656
|
-
top_n: int = 20,
|
|
3657
|
-
title: str = "Feature Importance",
|
|
3658
|
-
xlabel: str = "Importance",
|
|
3659
|
-
figsize: tuple = (10, 8),
|
|
3660
|
-
spath: Optional[Union[str, Path]] = None,
|
|
3661
|
-
) -> plt.Figure:
|
|
3662
|
-
"""
|
|
3663
|
-
Plot feature importance as a horizontal bar chart.
|
|
3664
|
-
|
|
3665
|
-
Parameters
|
|
3666
|
-
----------
|
|
3667
|
-
importance : np.ndarray or Dict[str, float]
|
|
3668
|
-
Feature importance values. If array, must match feature_names length.
|
|
3669
|
-
If dict, keys are feature names and values are importances.
|
|
3670
|
-
feature_names : List[str], optional
|
|
3671
|
-
Names of features (required if importance is array)
|
|
3672
|
-
top_n : int, default 20
|
|
3673
|
-
Number of top features to display
|
|
3674
|
-
title : str, default "Feature Importance"
|
|
3675
|
-
Plot title
|
|
3676
|
-
xlabel : str, default "Importance"
|
|
3677
|
-
X-axis label
|
|
3678
|
-
figsize : tuple, default (10, 8)
|
|
3679
|
-
Figure size
|
|
3680
|
-
spath : Union[str, Path], optional
|
|
3681
|
-
Path to save the figure
|
|
3682
|
-
|
|
3683
|
-
Returns
|
|
3684
|
-
|
|
3685
|
-
...
|
|
3686
|
-
```
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
### `./plt/_plot_learning_curve.py`
|
|
3690
|
-
|
|
3691
|
-
```python
|
|
3692
|
-
#!/usr/bin/env python3
|
|
3693
|
-
# -*- coding: utf-8 -*-
|
|
3694
|
-
# Timestamp: "2025-10-02 19:50:54 (ywatanabe)"
|
|
3695
|
-
# File: /ssh:sp:/home/ywatanabe/proj/scitex_repo/src/scitex/ml/plt/plot_learning_curve.py
|
|
3696
|
-
# ----------------------------------------
|
|
3697
|
-
from __future__ import annotations
|
|
3698
|
-
import os
|
|
3699
|
-
__FILE__ = __file__
|
|
3700
|
-
__DIR__ = os.path.dirname(__FILE__)
|
|
3701
|
-
# ----------------------------------------
|
|
3702
|
-
# Time-stamp: "2024-03-12 19:52:48 (ywatanabe)"
|
|
3703
|
-
|
|
3704
|
-
import argparse
|
|
3705
|
-
import re
|
|
3706
|
-
|
|
3707
|
-
import numpy as np
|
|
3708
|
-
import pandas as pd
|
|
3709
|
-
import scitex
|
|
3710
|
-
from scitex.plt.color import str2hex
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
def _prepare_metrics_df(metrics_df):
|
|
3714
|
-
"""Prepare metrics DataFrame with i_global as index."""
|
|
3715
|
-
if metrics_df.index.name != "i_global":
|
|
3716
|
-
try:
|
|
3717
|
-
metrics_df = metrics_df.set_index("i_global")
|
|
3718
|
-
except KeyError:
|
|
3719
|
-
print(
|
|
3720
|
-
"Error: The DataFrame does not contain a column named 'i_global'. "
|
|
3721
|
-
"Please check the column names."
|
|
3722
|
-
)
|
|
3723
|
-
except Exception as e:
|
|
3724
|
-
print(f"An unexpected error occurred: {e}")
|
|
3725
|
-
metrics_df["i_global"] = metrics_df.index # alias
|
|
3726
|
-
return metrics_df
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
def _configure_accuracy_axis(ax, metric_key):
|
|
3730
|
-
"""Configure y-axis for accuracy metrics."""
|
|
3731
|
-
if re.search("[aA][cC][cC]", metric_key):
|
|
3732
|
-
ax.set_ylim(0, 1)
|
|
3733
|
-
ax.set_yticks([0, 0.5, 1.0])
|
|
3734
|
-
return ax
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
def _plot_training_data(ax, metrics_df, metric_key, linewidth=1, color=None):
|
|
3738
|
-
"""Plot training phase data as line."""
|
|
3739
|
-
if color is None:
|
|
3740
|
-
color = str2hex("blue")
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
...
|
|
3744
|
-
```
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
### `./plt/_plot_optuna_study.py`
|
|
3748
|
-
|
|
3749
|
-
```python
|
|
3750
|
-
#!/usr/bin/env python3
|
|
3751
|
-
# -*- coding: utf-8 -*-
|
|
3752
|
-
# Timestamp: "2025-10-02 18:46:00 (ywatanabe)"
|
|
3753
|
-
# File: /home/ywatanabe/proj/scitex_repo/src/scitex/ml/plt/plot_optuna_study.py
|
|
3754
|
-
# ----------------------------------------
|
|
3755
|
-
from __future__ import annotations
|
|
3756
|
-
import os
|
|
3757
|
-
__FILE__ = __file__
|
|
3758
|
-
__DIR__ = os.path.dirname(__FILE__)
|
|
3759
|
-
# ----------------------------------------
|
|
3760
|
-
|
|
3761
|
-
"""
|
|
3762
|
-
Functionalities:
|
|
3763
|
-
- Loads Optuna study and generates various visualizations
|
|
3764
|
-
- Creates optimization history, parameter importances, slice plots
|
|
3765
|
-
- Saves study history and visualization results
|
|
3766
|
-
|
|
3767
|
-
Dependencies:
|
|
3768
|
-
- packages:
|
|
3769
|
-
- optuna
|
|
3770
|
-
- pandas
|
|
3771
|
-
- scitex
|
|
3772
|
-
|
|
3773
|
-
IO:
|
|
3774
|
-
- input-files:
|
|
3775
|
-
- Optuna study database (.db file)
|
|
3776
|
-
- output-files:
|
|
3777
|
-
- study_history.csv
|
|
3778
|
-
- optimization_history.png/html
|
|
3779
|
-
- param_importances.png/html
|
|
3780
|
-
- slice.png/html
|
|
3781
|
-
- contour.png/html
|
|
3782
|
-
- parallel_coordinate.png/html
|
|
3783
|
-
"""
|
|
3784
|
-
|
|
3785
|
-
"""Imports"""
|
|
3786
|
-
import argparse
|
|
3787
|
-
|
|
3788
|
-
import scitex as stx
|
|
3789
|
-
from scitex import logging
|
|
3790
|
-
|
|
3791
|
-
logger = logging.getLogger(__name__)
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
def plot_optuna_study(lpath, value_str, sort=False):
|
|
3795
|
-
"""
|
|
3796
|
-
Loads an Optuna study and generates various visualizations for each target metric.
|
|
3797
|
-
|
|
3798
|
-
Parameters:
|
|
3799
|
-
- lpath (str): Path to the Optuna study database.
|
|
3800
|
-
|
|
3801
|
-
...
|
|
3802
|
-
```
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
### `./plt/_plot_pre_rec_curve.py`
|
|
3806
|
-
|
|
3807
|
-
```python
|
|
3808
|
-
#!/usr/bin/env python3
|
|
3809
|
-
# -*- coding: utf-8 -*-
|
|
3810
|
-
# Timestamp: "2025-10-02 19:44:06 (ywatanabe)"
|
|
3811
|
-
# File: /ssh:sp:/home/ywatanabe/proj/scitex_repo/src/scitex/ml/plt/plot_pre_rec_curve.py
|
|
3812
|
-
# ----------------------------------------
|
|
3813
|
-
from __future__ import annotations
|
|
3814
|
-
import os
|
|
3815
|
-
__FILE__ = __file__
|
|
3816
|
-
__DIR__ = os.path.dirname(__FILE__)
|
|
3817
|
-
# ----------------------------------------
|
|
3818
|
-
|
|
3819
|
-
import argparse
|
|
3820
|
-
|
|
3821
|
-
import numpy as np
|
|
3822
|
-
from scitex.plt.color import get_colors_from_conf_matap
|
|
3823
|
-
from sklearn.metrics import average_precision_score, precision_recall_curve
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
def _solve_intersection(f1, a, b):
|
|
3827
|
-
"""Determine intersection of line (y = ax + b) and iso-f1 curve."""
|
|
3828
|
-
_a = 2 * a
|
|
3829
|
-
_b = -a * f1 + 2 * b - f1
|
|
3830
|
-
_c = -b * f1
|
|
3831
|
-
|
|
3832
|
-
x_f = (-_b + np.sqrt(_b**2 - 4 * _a * _c)) / (2 * _a)
|
|
3833
|
-
y_f = a * x_f + b
|
|
3834
|
-
|
|
3835
|
-
return (x_f, y_f)
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
def _to_onehot(class_indices, n_classes):
|
|
3839
|
-
"""Convert class indices to one-hot encoding."""
|
|
3840
|
-
eye = np.eye(n_classes, dtype=int)
|
|
3841
|
-
return eye[class_indices]
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
def plot_pre_rec_curve(true_class, pred_proba, labels, ax=None, spath=None):
|
|
3845
|
-
"""
|
|
3846
|
-
Plot precision-recall curve.
|
|
3847
|
-
|
|
3848
|
-
Parameters
|
|
3849
|
-
----------
|
|
3850
|
-
true_class : array-like
|
|
3851
|
-
True class labels
|
|
3852
|
-
pred_proba : array-like
|
|
3853
|
-
Predicted probabilities
|
|
3854
|
-
labels : list
|
|
3855
|
-
Class labels
|
|
3856
|
-
ax : matplotlib axis, optional
|
|
3857
|
-
Axis to plot on. If None, creates new figure
|
|
3858
|
-
|
|
3859
|
-
...
|
|
3860
|
-
```
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
### `./plt/_plot_roc_curve.py`
|
|
3864
|
-
|
|
3865
|
-
```python
|
|
3866
|
-
#!/usr/bin/env python3
|
|
3867
|
-
# -*- coding: utf-8 -*-
|
|
3868
|
-
# Timestamp: "2025-10-02 19:44:13 (ywatanabe)"
|
|
3869
|
-
# File: /ssh:sp:/home/ywatanabe/proj/scitex_repo/src/scitex/ml/plt/plot_roc_curve.py
|
|
3870
|
-
# ----------------------------------------
|
|
3871
|
-
from __future__ import annotations
|
|
3872
|
-
import os
|
|
3873
|
-
__FILE__ = __file__
|
|
3874
|
-
__DIR__ = os.path.dirname(__FILE__)
|
|
3875
|
-
# ----------------------------------------
|
|
3876
|
-
|
|
3877
|
-
import argparse
|
|
3878
|
-
|
|
3879
|
-
import numpy as np
|
|
3880
|
-
import scitex
|
|
3881
|
-
from scitex.plt.color import get_colors_from_conf_matap
|
|
3882
|
-
from sklearn.metrics import roc_auc_score, roc_curve
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
def _to_onehot(class_indices, n_classes):
|
|
3886
|
-
"""Convert class indices to one-hot encoding."""
|
|
3887
|
-
eye = np.eye(n_classes, dtype=int)
|
|
3888
|
-
return eye[class_indices]
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
def plot_roc_curve(true_class, pred_proba, labels, ax=None, spath=None):
|
|
3892
|
-
"""
|
|
3893
|
-
Plot ROC-AUC curve.
|
|
3894
|
-
|
|
3895
|
-
Parameters
|
|
3896
|
-
----------
|
|
3897
|
-
true_class : array-like
|
|
3898
|
-
True class labels
|
|
3899
|
-
pred_proba : array-like
|
|
3900
|
-
Predicted probabilities
|
|
3901
|
-
labels : list
|
|
3902
|
-
Class labels
|
|
3903
|
-
ax : matplotlib axis, optional
|
|
3904
|
-
Axis to plot on. If None, creates new figure
|
|
3905
|
-
spath : str, optional
|
|
3906
|
-
Path to save figure
|
|
3907
|
-
|
|
3908
|
-
Returns
|
|
3909
|
-
-------
|
|
3910
|
-
fig : matplotlib.figure.Figure
|
|
3911
|
-
Figure object
|
|
3912
|
-
metrics : dict
|
|
3913
|
-
ROC metrics
|
|
3914
|
-
"""
|
|
3915
|
-
import scitex as stx
|
|
3916
|
-
|
|
3917
|
-
...
|
|
3918
|
-
```
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
### `./README.md`
|
|
3922
|
-
|
|
3923
|
-
```markdown
|
|
3924
|
-
# SciTeX AI Module
|
|
3925
|
-
|
|
3926
|
-
The AI module provides machine learning and artificial intelligence utilities for the SciTeX framework.
|
|
3927
|
-
|
|
3928
|
-
## Overview
|
|
3929
|
-
|
|
3930
|
-
The AI module is organized into several submodules:
|
|
3931
|
-
|
|
3932
|
-
### Core Components
|
|
3933
|
-
|
|
3934
|
-
- **`genai`** - Generative AI integration with multiple providers (OpenAI, Anthropic, Google, etc.)
|
|
3935
|
-
- **`training`** - Training utilities (EarlyStopping, LearningCurveLogger)
|
|
3936
|
-
- **`classification`** - Classification tools (ClassificationReporter, Classifier)
|
|
3937
|
-
|
|
3938
|
-
### Neural Network Components
|
|
3939
|
-
|
|
3940
|
-
- **`layer`** - Custom neural network layers
|
|
3941
|
-
- **`loss`** - Loss functions for training
|
|
3942
|
-
- **`act`** - Activation functions
|
|
3943
|
-
- **`optim`** - Optimizers and optimization utilities
|
|
3944
|
-
|
|
3945
|
-
### Analysis & Visualization
|
|
3946
|
-
|
|
3947
|
-
- **`plt`** - AI-specific plotting utilities
|
|
3948
|
-
- **`metrics`** - Performance metrics
|
|
3949
|
-
- **`clustering`** - Clustering algorithms (UMAP, PCA)
|
|
3950
|
-
- **`feature_extraction`** - Feature extraction methods
|
|
3951
|
-
|
|
3952
|
-
### Utilities
|
|
3953
|
-
|
|
3954
|
-
- **`utils`** - General AI/ML utilities
|
|
3955
|
-
- **`sampling`** - Data sampling methods
|
|
3956
|
-
- **`sklearn`** - Scikit-learn integration
|
|
3957
|
-
|
|
3958
|
-
## Installation
|
|
3959
|
-
|
|
3960
|
-
```bash
|
|
3961
|
-
pip install scitex
|
|
3962
|
-
```
|
|
3963
|
-
|
|
3964
|
-
## Quick Start
|
|
3965
|
-
|
|
3966
|
-
### Generative AI (GenAI)
|
|
3967
|
-
|
|
3968
|
-
The GenAI module provides a unified interface for multiple AI providers:
|
|
3969
|
-
|
|
3970
|
-
```python
|
|
3971
|
-
from scitex.ai.genai import GenAI
|
|
3972
|
-
|
|
3973
|
-
# Basic usage
|
|
3974
|
-
```
|
|
3975
|
-
|
|
3976
|
-
...
|
|
3977
|
-
```
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
### `./sampling/undersample.py`
|
|
3981
|
-
|
|
3982
|
-
```python
|
|
3983
|
-
#!/usr/bin/env python3
|
|
3984
|
-
# -*- coding: utf-8 -*-
|
|
3985
|
-
# Time-stamp: "2024-11-24 10:13:17 (ywatanabe)"
|
|
3986
|
-
# File: ./scitex_repo/src/scitex/ai/sampling/undersample.py
|
|
3987
|
-
|
|
3988
|
-
THIS_FILE = "/home/ywatanabe/proj/scitex_repo/src/scitex/ai/sampling/undersample.py"
|
|
3989
|
-
|
|
3990
|
-
from typing import Tuple
|
|
3991
|
-
from ...types import ArrayLike
|
|
3992
|
-
|
|
3993
|
-
try:
|
|
3994
|
-
from imblearn.under_sampling import RandomUnderSampler
|
|
3995
|
-
IMBLEARN_AVAILABLE = True
|
|
3996
|
-
except ImportError:
|
|
3997
|
-
IMBLEARN_AVAILABLE = False
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
def undersample(
|
|
4001
|
-
X: ArrayLike, y: ArrayLike, random_state: int = 42
|
|
4002
|
-
) -> Tuple[ArrayLike, ArrayLike]:
|
|
4003
|
-
"""Undersample data preserving input type.
|
|
4004
|
-
|
|
4005
|
-
Args:
|
|
4006
|
-
X: Features array-like of shape (n_samples, n_features)
|
|
4007
|
-
y: Labels array-like of shape (n_samples,)
|
|
4008
|
-
Returns:
|
|
4009
|
-
Resampled X, y of same type as input
|
|
4010
|
-
|
|
4011
|
-
Raises:
|
|
4012
|
-
ImportError: If imblearn is not installed
|
|
4013
|
-
"""
|
|
4014
|
-
if not IMBLEARN_AVAILABLE:
|
|
4015
|
-
raise ImportError(
|
|
4016
|
-
"The undersample function requires the imbalanced-learn package. "
|
|
4017
|
-
"Install it with: pip install imbalanced-learn"
|
|
4018
|
-
)
|
|
4019
|
-
|
|
4020
|
-
rus = RandomUnderSampler(random_state=random_state)
|
|
4021
|
-
X_resampled, y_resampled = rus.fit_resample(X, y)
|
|
4022
|
-
return X_resampled, y_resampled
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
# EOF
|
|
4026
|
-
|
|
4027
|
-
...
|
|
4028
|
-
```
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
### `./sk/_clf.py`
|
|
4032
|
-
|
|
4033
|
-
```python
|
|
4034
|
-
#!/usr/bin/env python3
|
|
4035
|
-
# -*- coding: utf-8 -*-
|
|
4036
|
-
# Time-stamp: "2024-03-23 17:36:05 (ywatanabe)"
|
|
4037
|
-
|
|
4038
|
-
import numpy as np
|
|
4039
|
-
from sklearn.decomposition import PCA
|
|
4040
|
-
from sklearn.ensemble import GradientBoostingClassifier, RandomForestClassifier
|
|
4041
|
-
from sklearn.feature_selection import SelectKBest, f_classif
|
|
4042
|
-
from sklearn.linear_model import LogisticRegression, RidgeClassifierCV
|
|
4043
|
-
from sklearn.pipeline import make_pipeline
|
|
4044
|
-
from sklearn.svm import SVC, LinearSVC
|
|
4045
|
-
from sktime.classification.deep_learning.cnn import CNNClassifier
|
|
4046
|
-
from sktime.classification.deep_learning.inceptiontime import (
|
|
4047
|
-
InceptionTimeClassifier,
|
|
4048
|
-
)
|
|
4049
|
-
from sktime.classification.deep_learning.lstmfcn import LSTMFCNClassifier
|
|
4050
|
-
from sktime.classification.dummy import DummyClassifier
|
|
4051
|
-
from sktime.classification.feature_based import TSFreshClassifier
|
|
4052
|
-
from sktime.classification.hybrid import HIVECOTEV2
|
|
4053
|
-
from sktime.classification.interval_based import TimeSeriesForestClassifier
|
|
4054
|
-
from sktime.classification.kernel_based import RocketClassifier, TimeSeriesSVC
|
|
4055
|
-
from sktime.transformations.panel.reduce import Tabularizer
|
|
4056
|
-
from sktime.transformations.panel.rocket import Rocket
|
|
4057
|
-
|
|
4058
|
-
# _rocket_pipeline = make_pipeline(
|
|
4059
|
-
# Rocket(n_jobs=-1),
|
|
4060
|
-
# RidgeClassifierCV(alphas=np.logspace(-3, 3, 10)),
|
|
4061
|
-
# )
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
# def rocket_pipeline(*args, **kwargs):
|
|
4065
|
-
# return _rocket_pipeline
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
def rocket_pipeline(*args, **kwargs):
|
|
4069
|
-
return make_pipeline(
|
|
4070
|
-
Rocket(*args, **kwargs),
|
|
4071
|
-
LogisticRegression(
|
|
4072
|
-
max_iter=1000
|
|
4073
|
-
), # Increase max_iter if needed for convergence
|
|
4074
|
-
# RidgeClassifierCV(alphas=np.logspace(-3, 3, 10)),
|
|
4075
|
-
# SVC(probability=True, kernel="linear"),
|
|
4076
|
-
)
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
# def rocket_pipeline(*args, **kwargs):
|
|
4080
|
-
# return make_pipeline(
|
|
4081
|
-
# Rocket(*args, **kwargs),
|
|
4082
|
-
# SelectKBest(f_classif, k=500),
|
|
4083
|
-
# PCA(n_components=100),
|
|
4084
|
-
|
|
4085
|
-
...
|
|
4086
|
-
```
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
### `./sk/__init__.py`
|
|
4090
|
-
|
|
4091
|
-
```python
|
|
4092
|
-
#!/usr/bin/env python3
|
|
4093
|
-
"""Scitex sk module."""
|
|
4094
|
-
|
|
4095
|
-
from ._clf import GB_pipeline, rocket_pipeline
|
|
4096
|
-
from ._to_sktime import to_sktime_df
|
|
4097
|
-
|
|
4098
|
-
__all__ = [
|
|
4099
|
-
"GB_pipeline",
|
|
4100
|
-
"rocket_pipeline",
|
|
4101
|
-
"to_sktime_df",
|
|
4102
|
-
]
|
|
4103
|
-
|
|
4104
|
-
...
|
|
4105
|
-
```
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
### `./sk/_to_sktime.py`
|
|
4109
|
-
|
|
4110
|
-
```python
|
|
4111
|
-
#!/usr/bin/env python3
|
|
4112
|
-
# -*- coding: utf-8 -*-
|
|
4113
|
-
# Time-stamp: "2024-03-05 13:17:04 (ywatanabe)"
|
|
4114
|
-
|
|
4115
|
-
# import warnings
|
|
4116
|
-
|
|
4117
|
-
import numpy as np
|
|
4118
|
-
import pandas as pd
|
|
4119
|
-
import torch
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
def to_sktime_df(X):
|
|
4123
|
-
"""
|
|
4124
|
-
Converts a dataset to a format compatible with sktime, encapsulating each sample as a pandas DataFrame.
|
|
4125
|
-
|
|
4126
|
-
Arguments:
|
|
4127
|
-
- X (numpy.ndarray or torch.Tensor or pandas.DataFrame): The input dataset with shape (n_samples, n_chs, seq_len).
|
|
4128
|
-
It should be a 3D array-like structure containing the time series data.
|
|
4129
|
-
|
|
4130
|
-
Return:
|
|
4131
|
-
- sktime_df (pandas.DataFrame): A DataFrame where each element is a pandas Series representing a univariate time series.
|
|
4132
|
-
|
|
4133
|
-
Data Types and Shapes:
|
|
4134
|
-
- If X is a numpy.ndarray, it should have the shape (n_samples, n_chs, seq_len).
|
|
4135
|
-
- If X is a torch.Tensor, it should have the shape (n_samples, n_chs, seq_len) and will be converted to a numpy array.
|
|
4136
|
-
- If X is a pandas.DataFrame, it is assumed to already be in the correct format and will be returned as is.
|
|
4137
|
-
|
|
4138
|
-
References:
|
|
4139
|
-
- sktime: https://github.com/alan-turing-institute/sktime
|
|
4140
|
-
|
|
4141
|
-
Examples:
|
|
4142
|
-
--------
|
|
4143
|
-
>>> X_np = np.random.rand(64, 160, 1024)
|
|
4144
|
-
>>> sktime_df = to_sktime_df(X_np)
|
|
4145
|
-
>>> type(sktime_df)
|
|
4146
|
-
<class 'pandas.core.frame.DataFrame'>
|
|
4147
|
-
"""
|
|
4148
|
-
if isinstance(X, pd.DataFrame):
|
|
4149
|
-
return X
|
|
4150
|
-
elif torch.is_tensor(X):
|
|
4151
|
-
X = X.numpy()
|
|
4152
|
-
elif not isinstance(X, np.ndarray):
|
|
4153
|
-
raise ValueError(
|
|
4154
|
-
"Input X must be a numpy.ndarray, torch.Tensor, or pandas.DataFrame"
|
|
4155
|
-
)
|
|
4156
|
-
|
|
4157
|
-
X = X.astype(np.float64)
|
|
4158
|
-
|
|
4159
|
-
def _format_a_sample_for_sktime(x):
|
|
4160
|
-
"""
|
|
4161
|
-
|
|
4162
|
-
...
|
|
4163
|
-
```
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
### `./sklearn/clf.py`
|
|
4167
|
-
|
|
4168
|
-
```python
|
|
4169
|
-
#!/usr/bin/env python3
|
|
4170
|
-
# -*- coding: utf-8 -*-
|
|
4171
|
-
# Time-stamp: "2024-03-23 17:36:05 (ywatanabe)"
|
|
4172
|
-
|
|
4173
|
-
import numpy as np
|
|
4174
|
-
from sklearn.decomposition import PCA
|
|
4175
|
-
from sklearn.ensemble import GradientBoostingClassifier, RandomForestClassifier
|
|
4176
|
-
from sklearn.feature_selection import SelectKBest, f_classif
|
|
4177
|
-
from sklearn.linear_model import LogisticRegression, RidgeClassifierCV
|
|
4178
|
-
from sklearn.pipeline import make_pipeline
|
|
4179
|
-
from sklearn.svm import SVC, LinearSVC
|
|
4180
|
-
from sktime.classification.deep_learning.cnn import CNNClassifier
|
|
4181
|
-
from sktime.classification.deep_learning.inceptiontime import (
|
|
4182
|
-
InceptionTimeClassifier,
|
|
4183
|
-
)
|
|
4184
|
-
from sktime.classification.deep_learning.lstmfcn import LSTMFCNClassifier
|
|
4185
|
-
from sktime.classification.dummy import DummyClassifier
|
|
4186
|
-
from sktime.classification.feature_based import TSFreshClassifier
|
|
4187
|
-
from sktime.classification.hybrid import HIVECOTEV2
|
|
4188
|
-
from sktime.classification.interval_based import TimeSeriesForestClassifier
|
|
4189
|
-
from sktime.classification.kernel_based import RocketClassifier, TimeSeriesSVC
|
|
4190
|
-
from sktime.transformations.panel.reduce import Tabularizer
|
|
4191
|
-
from sktime.transformations.panel.rocket import Rocket
|
|
4192
|
-
|
|
4193
|
-
# _rocket_pipeline = make_pipeline(
|
|
4194
|
-
# Rocket(n_jobs=-1),
|
|
4195
|
-
# RidgeClassifierCV(alphas=np.logspace(-3, 3, 10)),
|
|
4196
|
-
# )
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
# def rocket_pipeline(*args, **kwargs):
|
|
4200
|
-
# return _rocket_pipeline
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
def rocket_pipeline(*args, **kwargs):
|
|
4204
|
-
return make_pipeline(
|
|
4205
|
-
Rocket(*args, **kwargs),
|
|
4206
|
-
LogisticRegression(
|
|
4207
|
-
max_iter=1000
|
|
4208
|
-
), # Increase max_iter if needed for convergence
|
|
4209
|
-
# RidgeClassifierCV(alphas=np.logspace(-3, 3, 10)),
|
|
4210
|
-
# SVC(probability=True, kernel="linear"),
|
|
4211
|
-
)
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
# def rocket_pipeline(*args, **kwargs):
|
|
4215
|
-
# return make_pipeline(
|
|
4216
|
-
# Rocket(*args, **kwargs),
|
|
4217
|
-
# SelectKBest(f_classif, k=500),
|
|
4218
|
-
# PCA(n_components=100),
|
|
4219
|
-
|
|
4220
|
-
...
|
|
4221
|
-
```
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
### `./sklearn/__init__.py`
|
|
4225
|
-
|
|
4226
|
-
```python
|
|
4227
|
-
#!/usr/bin/env python3
|
|
4228
|
-
"""Sklearn wrappers and utilities."""
|
|
4229
|
-
|
|
4230
|
-
import warnings
|
|
4231
|
-
|
|
4232
|
-
try:
|
|
4233
|
-
from .clf import *
|
|
4234
|
-
except ImportError as e:
|
|
4235
|
-
warnings.warn(
|
|
4236
|
-
f"Could not import clf from scitex.ai.sklearn: {str(e)}. "
|
|
4237
|
-
f"Some functionality may be unavailable. "
|
|
4238
|
-
f"Consider installing missing dependencies if you need this module.",
|
|
4239
|
-
ImportWarning,
|
|
4240
|
-
stacklevel=2
|
|
4241
|
-
)
|
|
4242
|
-
|
|
4243
|
-
try:
|
|
4244
|
-
from .to_sktime import *
|
|
4245
|
-
except ImportError as e:
|
|
4246
|
-
warnings.warn(
|
|
4247
|
-
f"Could not import to_sktime from scitex.ai.sklearn: {str(e)}. "
|
|
4248
|
-
f"Some functionality may be unavailable. "
|
|
4249
|
-
f"Consider installing missing dependencies if you need this module.",
|
|
4250
|
-
ImportWarning,
|
|
4251
|
-
stacklevel=2
|
|
4252
|
-
)
|
|
4253
|
-
|
|
4254
|
-
...
|
|
4255
|
-
```
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
### `./sklearn/to_sktime.py`
|
|
4259
|
-
|
|
4260
|
-
```python
|
|
4261
|
-
#!/usr/bin/env python3
|
|
4262
|
-
# -*- coding: utf-8 -*-
|
|
4263
|
-
# Time-stamp: "2024-03-05 13:17:04 (ywatanabe)"
|
|
4264
|
-
|
|
4265
|
-
# import warnings
|
|
4266
|
-
|
|
4267
|
-
import numpy as np
|
|
4268
|
-
import pandas as pd
|
|
4269
|
-
import torch
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
def to_sktime_df(X):
|
|
4273
|
-
"""
|
|
4274
|
-
Converts a dataset to a format compatible with sktime, encapsulating each sample as a pandas DataFrame.
|
|
4275
|
-
|
|
4276
|
-
Arguments:
|
|
4277
|
-
- X (numpy.ndarray or torch.Tensor or pandas.DataFrame): The input dataset with shape (n_samples, n_chs, seq_len).
|
|
4278
|
-
It should be a 3D array-like structure containing the time series data.
|
|
4279
|
-
|
|
4280
|
-
Return:
|
|
4281
|
-
- sktime_df (pandas.DataFrame): A DataFrame where each element is a pandas Series representing a univariate time series.
|
|
4282
|
-
|
|
4283
|
-
Data Types and Shapes:
|
|
4284
|
-
- If X is a numpy.ndarray, it should have the shape (n_samples, n_chs, seq_len).
|
|
4285
|
-
- If X is a torch.Tensor, it should have the shape (n_samples, n_chs, seq_len) and will be converted to a numpy array.
|
|
4286
|
-
- If X is a pandas.DataFrame, it is assumed to already be in the correct format and will be returned as is.
|
|
4287
|
-
|
|
4288
|
-
References:
|
|
4289
|
-
- sktime: https://github.com/alan-turing-institute/sktime
|
|
4290
|
-
|
|
4291
|
-
Examples:
|
|
4292
|
-
--------
|
|
4293
|
-
>>> X_np = np.random.rand(64, 160, 1024)
|
|
4294
|
-
>>> sktime_df = to_sktime_df(X_np)
|
|
4295
|
-
>>> type(sktime_df)
|
|
4296
|
-
<class 'pandas.core.frame.DataFrame'>
|
|
4297
|
-
"""
|
|
4298
|
-
if isinstance(X, pd.DataFrame):
|
|
4299
|
-
return X
|
|
4300
|
-
elif torch.is_tensor(X):
|
|
4301
|
-
X = X.detach().numpy()
|
|
4302
|
-
elif not isinstance(X, np.ndarray):
|
|
4303
|
-
raise ValueError(
|
|
4304
|
-
"Input X must be a numpy.ndarray, torch.Tensor, or pandas.DataFrame"
|
|
4305
|
-
)
|
|
4306
|
-
|
|
4307
|
-
X = X.astype(np.float64)
|
|
4308
|
-
|
|
4309
|
-
def _format_a_sample_for_sktime(x):
|
|
4310
|
-
"""
|
|
4311
|
-
|
|
4312
|
-
...
|
|
4313
|
-
```
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
### `./training/_EarlyStopping.py`
|
|
4317
|
-
|
|
4318
|
-
```python
|
|
4319
|
-
#!/usr/bin/env python3
|
|
4320
|
-
# Time-stamp: "2024-09-07 01:09:38 (ywatanabe)"
|
|
4321
|
-
|
|
4322
|
-
import os
|
|
4323
|
-
|
|
4324
|
-
import scitex
|
|
4325
|
-
import numpy as np
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
class EarlyStopping:
|
|
4329
|
-
"""
|
|
4330
|
-
Early stops the training if the validation score doesn't improve after a given patience period.
|
|
4331
|
-
|
|
4332
|
-
"""
|
|
4333
|
-
|
|
4334
|
-
def __init__(self, patience=7, verbose=False, delta=1e-5, direction="minimize"):
|
|
4335
|
-
"""
|
|
4336
|
-
Args:
|
|
4337
|
-
patience (int): How long to wait after last time validation score improved.
|
|
4338
|
-
Default: 7
|
|
4339
|
-
verbose (bool): If True, prints a message for each validation score improvement.
|
|
4340
|
-
Default: False
|
|
4341
|
-
delta (float): Minimum change in the monitored quantity to qualify as an improvement.
|
|
4342
|
-
Default: 0
|
|
4343
|
-
"""
|
|
4344
|
-
self.patience = patience
|
|
4345
|
-
self.verbose = verbose
|
|
4346
|
-
self.direction = direction
|
|
4347
|
-
|
|
4348
|
-
self.delta = delta
|
|
4349
|
-
|
|
4350
|
-
# default
|
|
4351
|
-
self.counter = 0
|
|
4352
|
-
self.best_score = np.inf if direction == "minimize" else -np.inf
|
|
4353
|
-
self.best_i_global = None
|
|
4354
|
-
self.models_spaths_dict = {}
|
|
4355
|
-
|
|
4356
|
-
def is_best(self, val_score):
|
|
4357
|
-
is_smaller = val_score < self.best_score - abs(self.delta)
|
|
4358
|
-
is_larger = self.best_score + abs(self.delta) < val_score
|
|
4359
|
-
return is_smaller if self.direction == "minimize" else is_larger
|
|
4360
|
-
|
|
4361
|
-
def __call__(self, current_score, models_spaths_dict, i_global):
|
|
4362
|
-
# The 1st call
|
|
4363
|
-
if self.best_score is None:
|
|
4364
|
-
self.save(current_score, models_spaths_dict, i_global)
|
|
4365
|
-
return False
|
|
4366
|
-
|
|
4367
|
-
# After the 2nd call
|
|
4368
|
-
if self.is_best(current_score):
|
|
4369
|
-
|
|
4370
|
-
...
|
|
4371
|
-
```
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
### `./training/__init__.py`
|
|
4375
|
-
|
|
4376
|
-
```python
|
|
4377
|
-
#!/usr/bin/env python3
|
|
4378
|
-
"""Training utilities."""
|
|
4379
|
-
|
|
4380
|
-
from ._EarlyStopping import EarlyStopping
|
|
4381
|
-
from ._LearningCurveLogger import LearningCurveLogger
|
|
4382
|
-
|
|
4383
|
-
__all__ = ["EarlyStopping", "LearningCurveLogger"]
|
|
4384
|
-
|
|
4385
|
-
...
|
|
4386
|
-
```
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
### `./training/_LearningCurveLogger.py`
|
|
4390
|
-
|
|
4391
|
-
```python
|
|
4392
|
-
#!/usr/bin/env python3
|
|
4393
|
-
# -*- coding: utf-8 -*-
|
|
4394
|
-
# Timestamp: "2024-11-20 08:49:50 (ywatanabe)"
|
|
4395
|
-
# File: /home/ywatanabe/proj/scitex_repo/src/scitex/ml/training/_LearningCurveLogger.py
|
|
4396
|
-
# ----------------------------------------
|
|
4397
|
-
from __future__ import annotations
|
|
4398
|
-
import os
|
|
4399
|
-
__FILE__ = __file__
|
|
4400
|
-
__DIR__ = os.path.dirname(__FILE__)
|
|
4401
|
-
# ----------------------------------------
|
|
4402
|
-
|
|
4403
|
-
"""
|
|
4404
|
-
Functionality:
|
|
4405
|
-
- Records and visualizes learning curves during model training
|
|
4406
|
-
- Supports tracking of multiple metrics across training/validation/test phases
|
|
4407
|
-
- Generates plots showing training progress over iterations and epochs
|
|
4408
|
-
- Delegates plotting to scitex.ai.plt.plot_learning_curve for consistency
|
|
4409
|
-
|
|
4410
|
-
Input:
|
|
4411
|
-
- Training metrics dictionary containing loss, accuracy, predictions etc.
|
|
4412
|
-
- Step information (Training/Validation/Test)
|
|
4413
|
-
|
|
4414
|
-
Output:
|
|
4415
|
-
- Learning curve plots via scitex.ai.plt.plot_learning_curve
|
|
4416
|
-
- DataFrames with recorded metrics
|
|
4417
|
-
- Training progress prints
|
|
4418
|
-
|
|
4419
|
-
Prerequisites:
|
|
4420
|
-
- PyTorch
|
|
4421
|
-
- scikit-learn
|
|
4422
|
-
- matplotlib
|
|
4423
|
-
- pandas
|
|
4424
|
-
- numpy
|
|
4425
|
-
- scitex
|
|
4426
|
-
"""
|
|
4427
|
-
|
|
4428
|
-
import re
|
|
4429
|
-
import warnings
|
|
4430
|
-
from collections import defaultdict
|
|
4431
|
-
from pprint import pprint
|
|
4432
|
-
from typing import Any, Dict, List, Optional, Union
|
|
4433
|
-
|
|
4434
|
-
import matplotlib
|
|
4435
|
-
import matplotlib.pyplot as plt
|
|
4436
|
-
import numpy as np
|
|
4437
|
-
import pandas as pd
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
class LearningCurveLogger:
|
|
4441
|
-
"""Records and visualizes learning metrics during model training.
|
|
4442
|
-
|
|
4443
|
-
...
|
|
4444
|
-
```
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
### `./training/legacy/early_stopping.py`
|
|
4448
|
-
|
|
4449
|
-
```python
|
|
4450
|
-
#!/usr/bin/env python3
|
|
4451
|
-
# Time-stamp: "2024-09-07 01:09:38 (ywatanabe)"
|
|
4452
|
-
|
|
4453
|
-
import os
|
|
4454
|
-
|
|
4455
|
-
import scitex
|
|
4456
|
-
import numpy as np
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
class EarlyStopping:
|
|
4460
|
-
"""
|
|
4461
|
-
Early stops the training if the validation score doesn't improve after a given patience period.
|
|
4462
|
-
|
|
4463
|
-
"""
|
|
4464
|
-
|
|
4465
|
-
def __init__(self, patience=7, verbose=False, delta=1e-5, direction="minimize"):
|
|
4466
|
-
"""
|
|
4467
|
-
Args:
|
|
4468
|
-
patience (int): How long to wait after last time validation score improved.
|
|
4469
|
-
Default: 7
|
|
4470
|
-
verbose (bool): If True, prints a message for each validation score improvement.
|
|
4471
|
-
Default: False
|
|
4472
|
-
delta (float): Minimum change in the monitored quantity to qualify as an improvement.
|
|
4473
|
-
Default: 0
|
|
4474
|
-
"""
|
|
4475
|
-
self.patience = patience
|
|
4476
|
-
self.verbose = verbose
|
|
4477
|
-
self.direction = direction
|
|
4478
|
-
|
|
4479
|
-
self.delta = delta
|
|
4480
|
-
|
|
4481
|
-
# default
|
|
4482
|
-
self.counter = 0
|
|
4483
|
-
self.best_score = np.inf if direction == "minimize" else -np.inf
|
|
4484
|
-
self.best_i_global = None
|
|
4485
|
-
self.models_spaths_dict = {}
|
|
4486
|
-
|
|
4487
|
-
def is_best(self, val_score):
|
|
4488
|
-
is_smaller = val_score < self.best_score - abs(self.delta)
|
|
4489
|
-
is_larger = self.best_score + abs(self.delta) < val_score
|
|
4490
|
-
return is_smaller if self.direction == "minimize" else is_larger
|
|
4491
|
-
|
|
4492
|
-
def __call__(self, current_score, models_spaths_dict, i_global):
|
|
4493
|
-
# The 1st call
|
|
4494
|
-
if self.best_score is None:
|
|
4495
|
-
self.save(current_score, models_spaths_dict, i_global)
|
|
4496
|
-
return False
|
|
4497
|
-
|
|
4498
|
-
# After the 2nd call
|
|
4499
|
-
if self.is_best(current_score):
|
|
4500
|
-
|
|
4501
|
-
...
|
|
4502
|
-
```
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
### `./training/legacy/learning_curve_logger.py`
|
|
4506
|
-
|
|
4507
|
-
```python
|
|
4508
|
-
#!/usr/bin/env python3
|
|
4509
|
-
# -*- coding: utf-8 -*-
|
|
4510
|
-
# Time-stamp: "2024-11-20 08:49:50 (ywatanabe)"
|
|
4511
|
-
# File: ./scitex_repo/src/scitex/ai/_LearningCurveLogger.py
|
|
4512
|
-
|
|
4513
|
-
THIS_FILE = "/home/ywatanabe/proj/scitex_repo/src/scitex/ai/_LearningCurveLogger.py"
|
|
4514
|
-
|
|
4515
|
-
"""
|
|
4516
|
-
Functionality:
|
|
4517
|
-
- Records and visualizes learning curves during model training
|
|
4518
|
-
- Supports tracking of multiple metrics across training/validation/test phases
|
|
4519
|
-
- Generates plots showing training progress over iterations and epochs
|
|
4520
|
-
|
|
4521
|
-
Input:
|
|
4522
|
-
- Training metrics dictionary containing loss, accuracy, predictions etc.
|
|
4523
|
-
- Step information (Training/Validation/Test)
|
|
4524
|
-
|
|
4525
|
-
Output:
|
|
4526
|
-
- Learning curve plots
|
|
4527
|
-
- Dataframes with recorded metrics
|
|
4528
|
-
- Training progress prints
|
|
4529
|
-
|
|
4530
|
-
Prerequisites:
|
|
4531
|
-
- PyTorch
|
|
4532
|
-
- scikit-learn
|
|
4533
|
-
- matplotlib
|
|
4534
|
-
- pandas
|
|
4535
|
-
- numpy
|
|
4536
|
-
"""
|
|
4537
|
-
|
|
4538
|
-
import re as _re
|
|
4539
|
-
from collections import defaultdict as _defaultdict
|
|
4540
|
-
from pprint import pprint as _pprint
|
|
4541
|
-
from typing import Dict as _Dict
|
|
4542
|
-
from typing import List as _List
|
|
4543
|
-
from typing import Union as _Union
|
|
4544
|
-
from typing import Optional as _Optional
|
|
4545
|
-
from typing import Any as _Any
|
|
4546
|
-
|
|
4547
|
-
import matplotlib as _matplotlib
|
|
4548
|
-
import matplotlib.figure
|
|
4549
|
-
import pandas as _pd
|
|
4550
|
-
import numpy as _np
|
|
4551
|
-
import warnings as _warnings
|
|
4552
|
-
import torch as _torch
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
class LearningCurveLogger:
|
|
4556
|
-
"""Records and visualizes learning metrics during model training.
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
...
|
|
4560
|
-
```
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
### `./utils/_check_params.py`
|
|
4564
|
-
|
|
4565
|
-
```python
|
|
4566
|
-
#!/usr/bin/env python3
|
|
4567
|
-
# Time-stamp: "2024-02-17 12:38:40 (ywatanabe)"
|
|
4568
|
-
|
|
4569
|
-
from pprint import pprint as _pprint
|
|
4570
|
-
from time import sleep
|
|
4571
|
-
|
|
4572
|
-
# def get_params(model, tgt_name=None, sleep_sec=2, show=False):
|
|
4573
|
-
|
|
4574
|
-
# name_shape_dict = {}
|
|
4575
|
-
# for name, param in model.named_parameters():
|
|
4576
|
-
# learnable = "Learnable" if param.requires_grad else "Freezed"
|
|
4577
|
-
|
|
4578
|
-
# if (tgt_name is not None) & (name == tgt_name):
|
|
4579
|
-
# return param
|
|
4580
|
-
# if tgt_name is None:
|
|
4581
|
-
# # print(f"\n{param}\n{param.shape}\nname: {name}\n")
|
|
4582
|
-
# if show is True:
|
|
4583
|
-
# print(
|
|
4584
|
-
# f"\n{param}: {param.shape}\nname: {name}\nStatus: {learnable}\n"
|
|
4585
|
-
# )
|
|
4586
|
-
# sleep(sleep_sec)
|
|
4587
|
-
# name_shape_dict[name] = list(param.shape)
|
|
4588
|
-
|
|
4589
|
-
# if tgt_name is None:
|
|
4590
|
-
# print()
|
|
4591
|
-
# _pprint(name_shape_dict)
|
|
4592
|
-
# print()
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
def check_params(model, tgt_name=None, show=False):
|
|
4596
|
-
|
|
4597
|
-
out_dict = {}
|
|
4598
|
-
|
|
4599
|
-
for name, param in model.named_parameters():
|
|
4600
|
-
learnable = "Learnable" if param.requires_grad else "Freezed"
|
|
4601
|
-
|
|
4602
|
-
if tgt_name is None:
|
|
4603
|
-
out_dict[name] = (param.shape, learnable)
|
|
4604
|
-
|
|
4605
|
-
elif (tgt_name is not None) & (name == tgt_name):
|
|
4606
|
-
out_dict[name] = (param.shape, learnable)
|
|
4607
|
-
|
|
4608
|
-
elif (tgt_name is not None) & (name != tgt_name):
|
|
4609
|
-
continue
|
|
4610
|
-
|
|
4611
|
-
if show:
|
|
4612
|
-
for k, v in out_dict.items():
|
|
4613
|
-
print(f"\n{k}\n{v}")
|
|
4614
|
-
|
|
4615
|
-
return out_dict
|
|
4616
|
-
|
|
4617
|
-
...
|
|
4618
|
-
```
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
### `./utils/_default_dataset.py`
|
|
4622
|
-
|
|
4623
|
-
```python
|
|
4624
|
-
#!/usr/bin/env python3
|
|
4625
|
-
|
|
4626
|
-
from torch.utils.data import Dataset
|
|
4627
|
-
import numpy as np
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
class DefaultDataset(Dataset):
|
|
4631
|
-
"""
|
|
4632
|
-
Apply transform for the first element of arrs_list
|
|
4633
|
-
|
|
4634
|
-
Example:
|
|
4635
|
-
n = 1024
|
|
4636
|
-
n_chs = 19
|
|
4637
|
-
X = np.random.rand(n, n_chs, 1000)
|
|
4638
|
-
T = np.random.randint(0, 4, size=(n, 1))
|
|
4639
|
-
S = np.random.randint(0, 999, size=(n, 1))
|
|
4640
|
-
Sr = np.random.randint(0, 4, size=(n, 1))
|
|
4641
|
-
|
|
4642
|
-
arrs_list = [X, T, S, Sr]
|
|
4643
|
-
transform = None
|
|
4644
|
-
ds = _DefaultDataset(arrs_list, transform=transform)
|
|
4645
|
-
len(ds) # 1024
|
|
4646
|
-
"""
|
|
4647
|
-
|
|
4648
|
-
def __init__(self, arrs_list, transform=None):
|
|
4649
|
-
self.arrs_list = arrs_list
|
|
4650
|
-
self.arrs = arrs_list # alias
|
|
4651
|
-
|
|
4652
|
-
assert np.all([len(arr) for arr in arrs_list])
|
|
4653
|
-
|
|
4654
|
-
self.length = len(arrs_list[0])
|
|
4655
|
-
self.transform = transform
|
|
4656
|
-
|
|
4657
|
-
def __len__(self):
|
|
4658
|
-
return self.length
|
|
4659
|
-
|
|
4660
|
-
def __getitem__(self, idx):
|
|
4661
|
-
arrs_list_idx = [arr[idx] for arr in self.arrs_list]
|
|
4662
|
-
|
|
4663
|
-
# Here, you might want to transform, or apply DA on X as a numpy array
|
|
4664
|
-
if self.transform:
|
|
4665
|
-
dtype_orig = arrs_list_idx[0].dtype
|
|
4666
|
-
arrs_list_idx[0] = self.transform(
|
|
4667
|
-
arrs_list_idx[0].astype(np.float64)
|
|
4668
|
-
).astype(dtype_orig)
|
|
4669
|
-
return arrs_list_idx
|
|
4670
|
-
|
|
4671
|
-
...
|
|
4672
|
-
```
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
### `./utils/_format_samples_for_sktime.py`
|
|
4676
|
-
|
|
4677
|
-
```python
|
|
4678
|
-
import pandas as pd
|
|
4679
|
-
import torch
|
|
4680
|
-
import numpy as np
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
def _format_a_sample_for_sktime(x):
|
|
4684
|
-
"""
|
|
4685
|
-
x.shape: (n_chs, seq_len)
|
|
4686
|
-
"""
|
|
4687
|
-
dims = pd.Series(
|
|
4688
|
-
[pd.Series(x[d], name=f"dim_{d}") for d in range(len(x))],
|
|
4689
|
-
index=[f"dim_{i}" for i in np.arange(len(x))],
|
|
4690
|
-
)
|
|
4691
|
-
return dims
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
def format_samples_for_sktime(X):
|
|
4695
|
-
"""
|
|
4696
|
-
X.shape: (n_samples, n_chs, seq_len)
|
|
4697
|
-
"""
|
|
4698
|
-
if torch.is_tensor(X):
|
|
4699
|
-
X = X.numpy() # (64, 160, 1024)
|
|
4700
|
-
|
|
4701
|
-
X = X.astype(np.float64)
|
|
4702
|
-
|
|
4703
|
-
return pd.DataFrame([_format_a_sample_for_sktime(X[i]) for i in range(len(X))])
|
|
4704
|
-
|
|
4705
|
-
...
|
|
4706
|
-
```
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
### `./utils/grid_search.py`
|
|
4710
|
-
|
|
4711
|
-
```python
|
|
4712
|
-
#!./env/bin/python3
|
|
4713
|
-
# -*- coding: utf-8 -*-
|
|
4714
|
-
# Time-stamp: "2024-04-22 23:54:02"
|
|
4715
|
-
# Author: Yusuke Watanabe (ywata1989@gmail.com)
|
|
4716
|
-
|
|
4717
|
-
"""
|
|
4718
|
-
This script defines scitex.ai.utils.grid_search
|
|
4719
|
-
"""
|
|
4720
|
-
|
|
4721
|
-
# Imports
|
|
4722
|
-
import itertools as _itertools
|
|
4723
|
-
import random as _random
|
|
4724
|
-
import sys as _sys
|
|
4725
|
-
|
|
4726
|
-
import matplotlib.pyplot as _plt
|
|
4727
|
-
import scitex as _scitex
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
# Functions
|
|
4731
|
-
def yield_grids(params_grid: dict, random=False):
|
|
4732
|
-
"""
|
|
4733
|
-
Generator function that yields combinations of parameters from a grid.
|
|
4734
|
-
|
|
4735
|
-
Args:
|
|
4736
|
-
params_grid (dict): A dictionary where keys are parameter names and values are lists of parameter values.
|
|
4737
|
-
random (bool): If True, yields the parameter combinations in random order.
|
|
4738
|
-
|
|
4739
|
-
Yields:
|
|
4740
|
-
dict: A dictionary of parameters for one set of conditions from the grid.
|
|
4741
|
-
|
|
4742
|
-
Example:
|
|
4743
|
-
# Parameters
|
|
4744
|
-
params_grid = {
|
|
4745
|
-
"batch_size": [2**i for i in range(7)],
|
|
4746
|
-
"n_chs": [2**i for i in range(7)],
|
|
4747
|
-
"seq_len": [2**i for i in range(15)],
|
|
4748
|
-
"fs": [2**i for i in range(8, 11)],
|
|
4749
|
-
"n_segments": [2**i for i in range(6)],
|
|
4750
|
-
"n_bands_pha": [2**i for i in range(7)],
|
|
4751
|
-
"n_bands_amp": [2**i for i in range(7)],
|
|
4752
|
-
"precision": ['fp16', 'fp32'],
|
|
4753
|
-
"device": ['cpu', 'cuda'],
|
|
4754
|
-
"package": ['tensorpac', 'scitex'],
|
|
4755
|
-
}
|
|
4756
|
-
|
|
4757
|
-
# Example of using the generator
|
|
4758
|
-
for param_dict in yield_grids(params_grid, random=True):
|
|
4759
|
-
print(param_dict)
|
|
4760
|
-
"""
|
|
4761
|
-
combinations = list(_itertools.product(*params_grid.values()))
|
|
4762
|
-
|
|
4763
|
-
...
|
|
4764
|
-
```
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
### `./utils/__init__.py`
|
|
4768
|
-
|
|
4769
|
-
```python
|
|
4770
|
-
#!/usr/bin/env python3
|
|
4771
|
-
"""Scitex utils module."""
|
|
4772
|
-
|
|
4773
|
-
from ._check_params import check_params
|
|
4774
|
-
from ._default_dataset import DefaultDataset
|
|
4775
|
-
from ._format_samples_for_sktime import format_samples_for_sktime
|
|
4776
|
-
from ._label_encoder import LabelEncoder
|
|
4777
|
-
from ._merge_labels import merge_labels
|
|
4778
|
-
from ._sliding_window_data_augmentation import sliding_window_data_augmentation
|
|
4779
|
-
from ._under_sample import under_sample
|
|
4780
|
-
from ._verify_n_gpus import verify_n_gpus
|
|
4781
|
-
|
|
4782
|
-
__all__ = [
|
|
4783
|
-
"DefaultDataset",
|
|
4784
|
-
"LabelEncoder",
|
|
4785
|
-
"check_params",
|
|
4786
|
-
"format_samples_for_sktime",
|
|
4787
|
-
"merge_labels",
|
|
4788
|
-
"sliding_window_data_augmentation",
|
|
4789
|
-
"under_sample",
|
|
4790
|
-
"verify_n_gpus",
|
|
4791
|
-
]
|
|
4792
|
-
|
|
4793
|
-
...
|
|
4794
|
-
```
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
### `./utils/_label_encoder.py`
|
|
4798
|
-
|
|
4799
|
-
```python
|
|
4800
|
-
#!/usr/bin/env python3
|
|
4801
|
-
# -*- coding: utf-8 -*-
|
|
4802
|
-
# Time-stamp: "2024-03-02 09:52:28 (ywatanabe)"
|
|
4803
|
-
|
|
4804
|
-
from warnings import warn
|
|
4805
|
-
|
|
4806
|
-
import numpy as np
|
|
4807
|
-
import pandas as pd
|
|
4808
|
-
import torch
|
|
4809
|
-
from sklearn.preprocessing import LabelEncoder as SklearnLabelEncoder
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
class LabelEncoder(SklearnLabelEncoder):
|
|
4813
|
-
"""
|
|
4814
|
-
An extension of the sklearn.preprocessing.LabelEncoder that supports incremental learning.
|
|
4815
|
-
This means it can handle new classes without forgetting the old ones.
|
|
4816
|
-
|
|
4817
|
-
Attributes:
|
|
4818
|
-
classes_ (np.ndarray): Holds the label for each class.
|
|
4819
|
-
|
|
4820
|
-
Example usage:
|
|
4821
|
-
encoder = IncrementalLabelEncoder()
|
|
4822
|
-
encoder.fit(np.array(["apple", "banana"]))
|
|
4823
|
-
encoded_labels = encoder.transform(["apple", "banana"]) # This will give you the encoded labels
|
|
4824
|
-
|
|
4825
|
-
encoder.fit(["cherry"]) # Incrementally add "cherry"
|
|
4826
|
-
encoder.transform(["apple", "banana", "cherry"]) # Now it works, including "cherry"
|
|
4827
|
-
|
|
4828
|
-
# Now you can use inverse_transform with the encoded labels
|
|
4829
|
-
print(encoder.classes_)
|
|
4830
|
-
original_labels = encoder.inverse_transform(encoded_labels)
|
|
4831
|
-
print(original_labels) # This should print ['apple', 'banana']
|
|
4832
|
-
"""
|
|
4833
|
-
|
|
4834
|
-
def __init__(self):
|
|
4835
|
-
super().__init__()
|
|
4836
|
-
self.classes_ = np.array([])
|
|
4837
|
-
|
|
4838
|
-
def _check_input(self, y):
|
|
4839
|
-
"""
|
|
4840
|
-
Check and convert the input to a NumPy array if it is a list, tuple, pandas.Series, pandas.DataFrame, or torch.Tensor.
|
|
4841
|
-
|
|
4842
|
-
Arguments:
|
|
4843
|
-
y (list, tuple, pd.Series, pd.DataFrame, torch.Tensor): The input labels.
|
|
4844
|
-
|
|
4845
|
-
Returns:
|
|
4846
|
-
np.ndarray: The input labels converted to a NumPy array.
|
|
4847
|
-
"""
|
|
4848
|
-
if isinstance(y, (list, tuple)):
|
|
4849
|
-
y = np.array(y)
|
|
4850
|
-
|
|
4851
|
-
...
|
|
4852
|
-
```
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
### `./utils/_merge_labels.py`
|
|
4856
|
-
|
|
4857
|
-
```python
|
|
4858
|
-
#!/usr/bin/env python3
|
|
4859
|
-
|
|
4860
|
-
import scitex
|
|
4861
|
-
import numpy as np
|
|
4862
|
-
|
|
4863
|
-
# y1, y2 = T_tra, M_tra
|
|
4864
|
-
# def merge_labels(y1, y2):
|
|
4865
|
-
# y = [str(z1) + "-" + str(z2) for z1, z2 in zip(y1, y2)]
|
|
4866
|
-
# conv_d = {z: i for i, z in enumerate(np.unique(y))}
|
|
4867
|
-
# y = [conv_d[z] for z in y]
|
|
4868
|
-
# return y
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
def merge_labels(*ys, to_int=False):
|
|
4872
|
-
if not len(ys) > 1: # Check if more than two arguments are passed
|
|
4873
|
-
return ys[0]
|
|
4874
|
-
else:
|
|
4875
|
-
y = [scitex.gen.connect_nums(zs) for zs in zip(*ys)]
|
|
4876
|
-
if to_int:
|
|
4877
|
-
conv_d = {z: i for i, z in enumerate(np.unique(y))}
|
|
4878
|
-
y = [conv_d[z] for z in y]
|
|
4879
|
-
return np.array(y)
|
|
4880
|
-
|
|
4881
|
-
...
|
|
4882
|
-
```
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
### `./utils/_sliding_window_data_augmentation.py`
|
|
4886
|
-
|
|
4887
|
-
```python
|
|
4888
|
-
#!/usr/bin/env python3
|
|
4889
|
-
# -*- coding: utf-8 -*-
|
|
4890
|
-
# Time-stamp: "2024-01-24 13:56:36 (ywatanabe)"
|
|
4891
|
-
|
|
4892
|
-
import random
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
def sliding_window_data_augmentation(x, window_size_pts):
|
|
4896
|
-
start = random.randint(0, x.shape[-1] - window_size_pts)
|
|
4897
|
-
end = start + window_size_pts
|
|
4898
|
-
return x[..., start:end]
|
|
4899
|
-
|
|
4900
|
-
...
|
|
4901
|
-
```
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
### `./utils/_under_sample.py`
|
|
4905
|
-
|
|
4906
|
-
```python
|
|
4907
|
-
#!/usr/bin/env python3
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
from collections import Counter
|
|
4911
|
-
|
|
4912
|
-
import numpy as np
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
def under_sample(y, replace=False):
|
|
4916
|
-
"""
|
|
4917
|
-
Input:
|
|
4918
|
-
Labels
|
|
4919
|
-
Return:
|
|
4920
|
-
Indices
|
|
4921
|
-
|
|
4922
|
-
Example:
|
|
4923
|
-
t = ['a', 'b', 'c', 'b', 'c', 'a', 'c']
|
|
4924
|
-
print(under_sample(t))
|
|
4925
|
-
# [5 0 1 3 4 6]
|
|
4926
|
-
print(under_sample(t))
|
|
4927
|
-
# [5 0 1 3 6 2]
|
|
4928
|
-
"""
|
|
4929
|
-
|
|
4930
|
-
# find the minority and majority classes
|
|
4931
|
-
class_counts = Counter(y)
|
|
4932
|
-
# majority_class = max(class_counts, key=class_counts.get)
|
|
4933
|
-
minority_class = min(class_counts, key=class_counts.get)
|
|
4934
|
-
|
|
4935
|
-
# compute the number of sample to draw from the majority class using
|
|
4936
|
-
# a negative binomial distribution
|
|
4937
|
-
n_minority_class = class_counts[minority_class]
|
|
4938
|
-
n_majority_resampled = n_minority_class
|
|
4939
|
-
|
|
4940
|
-
# draw randomly with or without replacement
|
|
4941
|
-
indices = np.hstack(
|
|
4942
|
-
[
|
|
4943
|
-
np.random.choice(
|
|
4944
|
-
np.flatnonzero(y == k),
|
|
4945
|
-
size=n_majority_resampled,
|
|
4946
|
-
replace=replace,
|
|
4947
|
-
)
|
|
4948
|
-
for k in class_counts.keys()
|
|
4949
|
-
]
|
|
4950
|
-
)
|
|
4951
|
-
|
|
4952
|
-
return indices
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
if __name__ == "__main__":
|
|
4956
|
-
t = np.array(["a", "b", "c", "b", "c", "a", "c"])
|
|
4957
|
-
|
|
4958
|
-
...
|
|
4959
|
-
```
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
### `./utils/_verify_n_gpus.py`
|
|
4963
|
-
|
|
4964
|
-
```python
|
|
4965
|
-
import torch
|
|
4966
|
-
import warnings
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
def verify_n_gpus(n_gpus):
|
|
4970
|
-
if torch.cuda.device_count() < n_gpus:
|
|
4971
|
-
warnings.warn(
|
|
4972
|
-
f"N_GPUS ({n_gpus}) is larger "
|
|
4973
|
-
f"than n_gpus torch can acesses (= {torch.cuda.device_count()})"
|
|
4974
|
-
f"Please check $CUDA_VISIBLE_DEVICES and your setting in this script.",
|
|
4975
|
-
UserWarning,
|
|
4976
|
-
)
|
|
4977
|
-
return torch.cuda.device_count()
|
|
4978
|
-
|
|
4979
|
-
else:
|
|
4980
|
-
return n_gpus
|
|
4981
|
-
|
|
4982
|
-
...
|
|
4983
|
-
```
|
|
4984
|
-
|