osbad.config ============ .. py:module:: osbad.config Module Contents --------------- .. py:data:: DataSource .. py:data:: HP_DATA_SOURCE :type: DataSource :value: 'severson' .. py:data:: PIPELINE_OUTPUT_DIR Global directory path for storing pipeline artifacts. All figures, plots, and intermediate artifacts generated by the pipeline or Jupyter notebooks are written to this directory. If the directory does not already exist, it will be created at runtime. .. note:: ``PIPELINE_OUTPUT_DIR`` defines the root location where all results (per-cell artifacts, exported plots, metrics, and hyperparameters) are stored. Ensure this path points to a valid writable location before running the pipeline. .. py:function:: artifacts_output_dir(selected_cell_label: str) -> pathlib.PosixPath Ensure and return the artifacts directory for a given cell. Creates (if missing) a per-cell subdirectory under ``PIPELINE_OUTPUT_DIR`` and returns its path. All figures and artifacts for the selected cell should be written to this location. :param selected_cell_label: Identifier of the evaluated cell used to name the subdirectory. :type selected_cell_label: str :returns: Path to the cell-specific artifacts directory. :rtype: pathlib.PosixPath .. py:function:: create_json_hp_config(output_json_filepath: str, hp_dict: dict) Create and save a JSON file containing hyperparameter settings. This function writes a dictionary of hyperparameter configurations to a JSON file at the specified path. :param output_json_filepath: Path to save the output JSON file. :type output_json_filepath: str :param hp_dict: Dictionary containing hyperparameter configurations with labeled keys. :type hp_dict: dict :returns: A JSON file is written to the specified location. :rtype: None .. rubric:: Example .. code-block:: hp_schema_iforest = { "contamination": {"low": 0.0, "high": 0.5}, "n_estimators": {"low": 100, "high": 500}, "max_samples": {"low": 100, "high": total_cycle_count}, "threshold": {"low": 0.0, "high": 1.0} } iforest_hp_config_filepath = ( Path.cwd() .parent.parent.parent .joinpath( "machine_learning", "hp_config_schema", "iforest_hp_config.json")) bconf.create_json_hp_config( iforest_hp_config_filepath, hp_dict=hp_schema_iforest) .. py:function:: load_json_hp_config(input_json_filepath: str) -> dict Load hyperparameter configuration from a JSON file. This function reads a JSON file containing hyperparameter configurations and returns the contents as a dictionary. :param input_json_filepath: Path to the JSON file containing hyperparameter configuration. :type input_json_filepath: str :returns: Dictionary containing the loaded hyperparameter configurations. :rtype: dict .. rubric:: Example .. code-block:: iforest_hp_config_filepath = ( Path(__file__) .parent.parent.parent .joinpath( "machine_learning", "hp_config_schema", "iforest_hp_config.json")) bconf.load_json_hp_config(iforest_hp_config_filepath) .. py:function:: load_model_hp_configs(models: Iterable[str], data_source: str, schema_base_dir: pathlib.Path | None = None) -> Mapping[str, Any] Load hyperparameter JSON configs for the given models from a specific data source. :param models: iterable of str Model names (e.g., "iforest", "knn", "gmm", ...). :param data_source: str Subdirectory under hp_config_schema ("tohoku_hp_config", "severson_hp_config"). :param schema_base_dir: Path or None Base directory containing the 'machine_learning/hp_config_schema' folder. Defaults to three levels up from this file. :returns: dict[str, Any] Mapping of model name. .. py:data:: models :value: ['iforest', 'knn', 'gmm', 'lof', 'pca', 'autoencoder'] .. py:data:: severson_hp_configs .. py:data:: iforest_hp_config_severson .. py:data:: knn_hp_config_severson .. py:data:: gmm_hp_config_severson .. py:data:: lof_hp_config_severson .. py:data:: pca_hp_config_severson .. py:data:: autoencoder_hp_config_severson .. py:data:: tohoku_hp_configs .. py:data:: iforest_hp_config_tohoku .. py:data:: knn_hp_config_tohoku .. py:data:: gmm_hp_config_tohoku .. py:data:: lof_hp_config_tohoku .. py:data:: pca_hp_config_tohoku .. py:data:: autoencoder_hp_config_tohoku .. py:class:: CustomFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None) Bases: :py:obj:`logging.Formatter` Custom logging formatter with colorized output. This formatter applies ANSI escape codes to add colors for different logging levels and customizes the format string for messages. INFO messages are displayed as plain text, while DEBUG, WARNING, ERROR, and CRITICAL messages include timestamps, file names, and line numbers for better context. Logging level styles: - INFO: Grey text, message only. - DEBUG: Red text with timestamp, name, file, and line number. - WARNING: Bold red text with extended debug-style format. - ERROR: Bold red text with extended debug-style format. - CRITICAL: Bold red text with extended debug-style format. .. py:attribute:: grey :value: '\x1b[38;21m' .. py:attribute:: yellow :value: '\x1b[33;21m' .. py:attribute:: red :value: '\x1b[31;21m' .. py:attribute:: bold_red :value: '\x1b[31;1m' .. py:attribute:: reset :value: '\x1b[0m' .. py:attribute:: debug_format :value: Multiline-String .. raw:: html
Show Value .. code-block:: python """%(asctime)s - %(name)s - %(levelname)s %(message)s (%(filename)s:%(lineno)d)""" .. raw:: html
.. py:attribute:: info_format :value: '%(message)s' .. py:attribute:: FORMATS .. py:method:: format(record) Format the specified record as text. The record's attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.