From 80dc641ffe48c94d0e30d021bfbe16b70aefac1c Mon Sep 17 00:00:00 2001 From: croelofs <25582572+roelofsc@users.noreply.github.com> Date: Wed, 9 Sep 2026 16:21:24 +0200 Subject: [PATCH 01/18] Migrate config from Cerberus to Pydantic with Config wrapper Replace the Cerberus-based BaseConfig/Config with a clean Pydantic design: - ConfigModel is the top-level Pydantic model with section models for each config section (train, predict, root_cause_analysis, etc.) - Config is a plain wrapper class holding a ConfigModel instance (self._model) - _SubscriptableModel mixin provides __getitem__/__contains__/get for backward compatibility during migration from dict-style to attribute-style access - Extra validators (_parse_timedelta, _validate_early_stopping, _validate_sequence_fit_on_val) run as a @model_validator(mode='after') - config_dict property rebuilds from the model on every call (model is source of truth, not a cached mutable dict) - Convenience properties now read from self._model instead of config_dict - Delete base_config.py (consolidated into config.py) - Fix configuration.py and care2compare.py consumers to use model attributes instead of .setdefault() on dict-like objects - Update pyproject.toml: cerberus -> pydantic>=2.0 --- docs/conf.py | 1 - energy_fault_detector/config/__init__.py | 6 +- energy_fault_detector/config/base_config.py | 163 ---- energy_fault_detector/config/config.py | 757 +++++++++++++----- .../evaluation/care2compare.py | 15 +- .../quick_fault_detection/configuration.py | 18 +- pyproject.toml | 2 +- tests/test_fault_detector.py | 4 +- 8 files changed, 597 insertions(+), 369 deletions(-) delete mode 100644 energy_fault_detector/config/base_config.py diff --git a/docs/conf.py b/docs/conf.py index ed69f7f7..b03e86c3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -264,7 +264,6 @@ def run_apidoc(app): # internal utilities str(pkg_dir / "utils" / "index_utils.py"), # config internals - str(pkg_dir / "config" / "base_config.py"), str(pkg_dir / "config" / "config.py"), str(pkg_dir / "config" / "quickstart_config.py"), # Class specific files (documented directly under the top module) diff --git a/energy_fault_detector/config/__init__.py b/energy_fault_detector/config/__init__.py index a7b6bc61..328d7dfe 100644 --- a/energy_fault_detector/config/__init__.py +++ b/energy_fault_detector/config/__init__.py @@ -1,10 +1,10 @@ """Configuration of the fault-detection pipeline, loaded and validated from YAML.""" -from energy_fault_detector.config.config import Config -from energy_fault_detector.config.base_config import InvalidConfigFile +from energy_fault_detector.config.config import Config, InvalidConfigFile from energy_fault_detector.config.quickstart_config import generate_quickstart_config __all__ = [ "Config", - "generate_quickstart_config" + "InvalidConfigFile", + "generate_quickstart_config", ] diff --git a/energy_fault_detector/config/base_config.py b/energy_fault_detector/config/base_config.py deleted file mode 100644 index 46ab9f84..00000000 --- a/energy_fault_detector/config/base_config.py +++ /dev/null @@ -1,163 +0,0 @@ -"""Base config class template""" - -import os -import logging -from typing import Dict, Optional, List, Any, Callable -import datetime -from abc import ABC -from copy import deepcopy - -import yaml -import numpy as np -from cerberus import Validator - -logger = logging.getLogger('energy_fault_detector') - -SCHEMA = {'allow_unknown': True} - - -def _format_timedelta(value: np.timedelta64) -> str: - """Format np.timedelta64 as a compact string like '30s' for YAML.""" - # Store everything in seconds - total_seconds = int(value.astype('timedelta64[s]').astype(int)) - return f"{total_seconds}s" - - -class InvalidConfigFile(Exception): - """Raise when config file is not valid""" - - -class BaseConfig(ABC): - """Base configuration class. - either config_filename or config_dict must be provided. - """ - - def __init__(self, config_filename: str = None, config_dict: Dict[str, Any] = None): - - self.configuration_file: str = config_filename - self.config_dict: Optional[Dict] = config_dict - - # config schema - define in the subclasses - self._schema: Dict = None - self._extra_validation_checks = None - # call self.read_config() - - def __getitem__(self, item) -> Any: - return self.config_dict[item] - - def __contains__(self, item): - return item in self.config_dict.keys() - - def __repr__(self): - return self.config_dict.__repr__() - - def read_config(self, part: str = None) -> None: - """Read and validate the configuration.""" - - if self.configuration_file is not None: - with open(self.configuration_file, 'r', encoding='utf-8') as f: - self.config_dict = yaml.safe_load(f) - - if self.config_dict is None: - raise InvalidConfigFile('The configuration file is empty!') - - # backwards compatibility - if part is not None: - if part in self.config_dict: - self.config_dict = self.config_dict[part] - - if self._schema is None: - raise ValueError('The `_schema` attribute is missing...') - - self._validate_config(self.config_dict, schema=self._schema, extra_checks=self._extra_validation_checks) - - def update_config(self, new_config_dict: Dict[str, Any]) -> None: - """Update the configuration. Sets the configuration_file path to None. - - Args: - new_config_dict: dictionary with the new configuration. - """ - # TODO: consider returning a new instance - new_config = self.config_dict.copy() - new_config.update(new_config_dict) - self._validate_config(new_config, self._schema, extra_checks=self._extra_validation_checks) - self.configuration_file = None - - def write_config(self, file_name: Optional[str] = None, overwrite: bool = False) -> None: - """Write the configuration to a yaml file""" - - # make copy to not modify the original config - conf_dict_to_save = deepcopy(self.config_dict) - - if file_name is None and self.configuration_file is None: - raise ValueError('No file name given and no known configuration file to overwrite.') - - file_name = file_name if file_name is not None else self.configuration_file - if os.path.exists(file_name) and not overwrite: - raise FileExistsError(f'File {file_name} already exists and overwrite is set to False.') - - ae_params = conf_dict_to_save.get('train', {}).get('autoencoder', {}).get('params', {}) - seq_builder = ae_params.get('sequence_builder') - if isinstance(seq_builder, dict): - sb_ts_freq = seq_builder.get('ts_freq') - if isinstance(sb_ts_freq, np.timedelta64): - seq_builder['ts_freq'] = _format_timedelta(sb_ts_freq) - conf_dict_to_save['train']['autoencoder']['params']['sequence_builder'] = seq_builder - - with open(file_name, 'w', encoding='utf-8') as f: - yaml.safe_dump(conf_dict_to_save, f) - - def save(self, file_name: str, overwrite: bool = False) -> None: - """Save the configuration to a yaml file. - - Wrapper for write_config so API is similar to other objects. - """ - self.write_config(file_name, overwrite) - - @staticmethod - def _parse_dates(dates: List, dt_format: str = '%Y-%m-%d') -> List: - """Parse given string dates""" - - parsed = [] - for date in dates: - if isinstance(date, str): - date = datetime.datetime.strptime(date, dt_format).date() - elif isinstance(date, datetime.date): - pass - else: - raise ValueError('Given date %s of type %s cannot be parsed' % date, type(date)) - parsed.append(date) - - return parsed - - def _validate_config(self, config_dict: Dict[str, Any], schema: Dict[str, str], - extra_checks: List[Callable[[Dict], None]] = None) -> None: - """Check whether the provided configuraton has all expected keys. - If the given file is a valid configuration, the config_dict attribute is set. - - Args: - config_dict: dictionary containing the configuration - schema: Cerberus schema to validate against - extra_checks: list of extra validation checks to run. Should be functions that take the configuration - dictionary as input and return the (updated) config_dict or raise InvalidConfigFile - """ - - validator = Validator(allow_unknown=True) # allow_unknown for backwards compat - if not validator.validate(config_dict, schema): - raise InvalidConfigFile(f'Configuration is not valid: {validator.errors}') - - for key in list(config_dict.keys()): - if key not in schema: - logger.info('Key `%s` is an unknown field and will be ignored.', key) - config_dict.pop(key) - - if config_dict == {}: - raise InvalidConfigFile(f'The configuration file is empty for {self.__class__.__name__}.') - - config_dict = validator.normalized(config_dict) - - if extra_checks is not None: - for extra_check in extra_checks: - config_dict = extra_check(config_dict) - - self.config_dict = config_dict diff --git a/energy_fault_detector/config/config.py b/energy_fault_detector/config/config.py index 998099a4..e9924f13 100644 --- a/energy_fault_detector/config/config.py +++ b/energy_fault_detector/config/config.py @@ -1,176 +1,333 @@ -"""Configuration object for anomaly detection""" +"""Configuration object for anomaly detection. + +The configuration is defined by a set of Pydantic models (section models plus a +top-level :class:`ConfigModel`) that validate the YAML/dict input. The public +:class:`Config` class is a thin wrapper around :class:`ConfigModel` that adds +file I/O, serialization, and backward-compat dict-style access. + +``Config`` is **not** itself a Pydantic model – it holds a validated +``ConfigModel`` instance via ``self._model``. Section models inherit +:class:`_SubscriptableModel` so that ``config['train']['autoencoder']`` keeps +working during the migration from dict-based to typed access. +""" import logging -from pathlib import Path -from typing import Dict, Optional, List, Callable, Any import warnings +from pathlib import Path +from typing import Any, Dict, List, Literal, Optional -from energy_fault_detector.config.base_config import BaseConfig, InvalidConfigFile +import numpy as np +import yaml +from pydantic import BaseModel, ConfigDict, ValidationError, model_validator logger = logging.getLogger('energy_fault_detector') -# TODO: Clearer error/validation messages -# Consider pydantic or data classes instead of cerberus -TRAIN_SCHEMA = { - 'anomaly_score': { - 'type': 'dict', - 'required': True, - 'schema': { - 'name': {'type': 'string', 'required': True}, - 'params': {'type': 'dict', 'required': False}, - } - }, - 'autoencoder': { - 'type': 'dict', - 'required': True, - 'schema': { - 'name': {'type': 'string', 'required': True}, - 'params': {'type': ['dict', 'list'], 'required': True}, - 'verbose': {'type': 'integer', 'required': False}, - } - }, - 'data_preprocessor': { - 'type': 'dict', - 'required': True, - 'allow_unknown': False, - 'nullable': True, # if not specified, create default pipeline - 'schema': { - 'params': {'type': 'dict', 'required': False, 'nullable': True,}, - 'steps': { - 'type': 'list', - 'required': False, - 'nullable': True, - 'schema': { - 'type': 'dict', - 'allow_unknown': True - } - }, - } - }, - 'threshold_selector': { - 'type': 'dict', - 'required': True, - 'schema': { - 'name': {'type': 'string', 'required': True}, - 'fit_on_val': {'type': 'boolean', 'required': False, 'default': False}, - 'params': {'type': 'dict', 'required': False}, - } - }, - 'data_clipping': { - 'type': 'dict', - 'required': False, # no data clipping if not specified - 'schema': { - 'lower_percentile': {'type': 'float', 'required': False}, - 'upper_percentile': {'type': 'float', 'required': False}, - 'features_to_exclude': {'type': 'list', 'required': False, 'schema': {'type': 'string'}}, - 'features_to_clip': {'type': 'list', 'required': False, 'schema': {'type': 'string'}}, - } - }, - 'data_splitter': { - 'type': 'dict', - 'required': False, # defaults if not specified - 'schema': { - 'type': {'type': 'string', 'required': False, 'default': 'BlockDataSplitter', - 'allowed': ['DataSplitter', 'BlockDataSplitter', 'blocks', 'sklearn', 'train_test_split', 'train_val_split']}, - 'train_block_size': {'type': 'integer', 'required': False, 'dependencies': {'type': ['DataSplitter', 'BlockDataSplitter', 'blocks']}}, - 'val_block_size': {'type': 'integer', 'required': False, 'dependencies': {'type': ['DataSplitter', 'BlockDataSplitter', 'blocks']}}, - 'validation_split': {'type': 'float', 'required': False, 'dependencies': {'type': ['sklearn', 'train_test_split', 'train_val_split']}}, - 'shuffle': {'type': 'boolean', 'required': False, 'dependencies': {'type': ['sklearn', 'train_test_split']}}, - } - }, - 'protect_conditional_features': {'type': 'boolean', 'required': False, 'default': False}, -} - -ROOT_CAUSE_ANALYSIS_SCHEMA = { - 'alpha': {'type': 'float', 'required': False}, - 'init_x_bias': {'type': 'string', 'required': False}, - 'num_iter': {'type': 'integer', 'required': False}, - 'epsilon': {'type': 'float', 'required': False}, - 'verbose': {'type': 'boolean', 'required': False}, - 'max_sample_threshold': {'type': 'integer', 'required': False}, -} - -PREDICT_SCHEMA = { - 'criticality': {'type': 'dict', 'required': False, 'schema': { - 'max_criticality': {'type': 'integer', 'required': False} - }} -} - -CONFIG_SCHEMA = { - 'train': {'type': 'dict', 'schema': TRAIN_SCHEMA, 'required': False, 'allow_unknown': True}, - 'predict': {'type': 'dict', 'schema': PREDICT_SCHEMA, 'required': False}, - 'root_cause_analysis': {'type': 'dict', 'schema': ROOT_CAUSE_ANALYSIS_SCHEMA, 'required': False}, - 'dtype': {'type': 'string', 'required': False, 'allowed': ['float32', 'float64']} -} - - -def _validate_early_stopping(config_dict: Dict[str, Any]) -> Dict[str, Any]: - """Check whether early_stopping settings are ok.""" - - train_config = config_dict.get('train', {}) - early_stopping = train_config.get('autoencoder', {}).get('params', {}).get('early_stopping', False) - - data_splitter = train_config.get('data_splitter', {}) - validation_split = data_splitter.get('validation_split', 0.0) - val_block_size = data_splitter.get('val_block_size', 0) - if not isinstance(validation_split, float): - validation_split = 0.0 +class InvalidConfigFile(Exception): + """Raise when the configuration file is not valid.""" - validation = 0 < validation_split < 1 or val_block_size > 0 - if early_stopping and not validation: - msg = f'Configuration is not valid: If early_stopping is enabled either validation_split or ' \ - f'val_block_size must be given. If validation_split is used, it must be a float >0 and <1.' - raise InvalidConfigFile(msg) +def _format_timedelta(value: np.timedelta64) -> str: + """Format an :class:`np.timedelta64` as a compact string like ``'30s'``. + + Args: + value: timedelta to format. + + Returns: + Compact string representation suitable for YAML round-tripping. + """ + total_seconds = int(value.astype('timedelta64[s]').astype(int)) + return f"{total_seconds}s" + + +class _SubscriptableModel(BaseModel): + """Pydantic ``BaseModel`` with dict-style access for backward compatibility. + + Allows ``config['train']`` instead of ``config.train`` during the migration + from dict-based config to typed Pydantic models. All section models and the + top-level :class:`ConfigModel` inherit from this class. + + ``__getitem__`` delegates to :func:`getattr`; ``__contains__`` checks whether + *key* is a declared field that is "present": + + * **required** fields (no default) are always present, even when their value + is ``None`` (e.g. ``train.data_preprocessor`` which is required but + nullable); + * **optional** fields (have a default) are present only when their value is + not ``None`` (e.g. ``data_clipping``). + + ``get(key, default)`` mirrors ``dict.get``: returns the value when the key is + present, otherwise *default*. + """ + + def __getitem__(self, key: str) -> Any: + return getattr(self, key) + + def __contains__(self, key: str) -> bool: + field = type(self).model_fields.get(key) + if field is None: + return False + if field.is_required(): + return True + return getattr(self, key) is not None + + def get(self, key: str, default: Any = None) -> Any: + """Return the field value if present, otherwise *default*. + + Mirrors ``dict.get`` semantics using :meth:`__contains__`. + """ + if key in self: + return getattr(self, key) + return default + + +def _dump_value(value: Any) -> Any: + """Recursively dump nested models/lists; plain dicts/lists are kept as-is.""" + if isinstance(value, BaseModel): + return _model_to_config_dict(value) + if isinstance(value, list): + return [_dump_value(item) for item in value] + return value + + +def _model_to_config_dict(model: BaseModel) -> Dict[str, Any]: + """Serialize a validated Pydantic model back to a plain configuration dict. + + Reproduces the structure ``cerberus.Validator.normalized`` produced: + + * fields that are *required* (no default) are always included, even when + their value is ``None`` (e.g. ``train.data_preprocessor`` which is + required but nullable); + * fields that are *optional* (have a default) are included only when their + value is not ``None`` (falsy defaults such as ``False`` are kept because + ``False is not None``); + * unknown fields kept via ``extra='allow'`` are merged back in. + + Args: + model: The validated configuration model. + + Returns: + Plain (mutable) dictionary representation. + """ + result: Dict[str, Any] = {} + for name, field in type(model).model_fields.items(): + value = getattr(model, name) + if not field.is_required() and value is None: + continue + result[name] = _dump_value(value) + extra = getattr(model, '__pydantic_extra__', None) + if extra: + result.update(extra) + return result + + +# --- Section models ---------------------------------------------------------- +# extra='allow' mirrors the former Cerberus Validator(allow_unknown=True) which +# let unknown keys survive at every nested level. The sole exception is +# DataPreprocessorConfig (extra='forbid') because its Cerberus schema explicitly +# set allow_unknown: False. Leaves (params, steps items) are left as plain +# mutable dicts -- the package never validated their internals with Cerberus +# either, so this is strict parity. + + +class AnomalyScoreConfig(_SubscriptableModel): + """``train.anomaly_score`` section.""" + + model_config = ConfigDict(extra='allow') + name: str + params: Optional[Dict[str, Any]] = None + + +class AutoencoderConfig(_SubscriptableModel): + """``train.autoencoder`` section. + + ``params`` accepts a dict or a list (the Cerberus schema allowed both) and is + left opaque: step/autoencoder-specific keys (including ``sequence_builder``) + are not modeled here and are consumed by the registry/model factory. + """ + + model_config = ConfigDict(extra='allow') + name: str + params: Dict[str, Any] | List[Any] + verbose: Optional[int] = None + + +class DataPreprocessorConfig(_SubscriptableModel): + """``train.data_preprocessor`` section (``extra='forbid'``).""" + + model_config = ConfigDict(extra='forbid') + params: Optional[Dict[str, Any]] = None + steps: Optional[List[Dict[str, Any]]] = None + + +class ThresholdSelectorConfig(_SubscriptableModel): + """``train.threshold_selector`` section.""" + + model_config = ConfigDict(extra='allow') + name: str + fit_on_val: bool = False + params: Optional[Dict[str, Any]] = None + + +class DataClippingConfig(_SubscriptableModel): + """``train.data_clipping`` section.""" + + model_config = ConfigDict(extra='allow') + lower_percentile: Optional[float] = None + upper_percentile: Optional[float] = None + features_to_exclude: Optional[List[str]] = None + features_to_clip: Optional[List[str]] = None + + +class DataSplitterConfig(_SubscriptableModel): + """``train.data_splitter`` section. + + Reproduces the Cerberus ``dependencies`` rules: block-size fields require a + block-style ``type`` and the split/shuffle fields require an sklearn-style + ``type``. The default for ``type`` is applied before the ``mode='after'`` + validator runs (Pydantic applies field defaults first), matching Cerberus + which also applied the default during validation. + """ + + model_config = ConfigDict(extra='allow') + type: Literal['DataSplitter', 'BlockDataSplitter', 'blocks', 'sklearn', + 'train_test_split', 'train_val_split'] = 'BlockDataSplitter' + train_block_size: Optional[int] = None + val_block_size: Optional[int] = None + validation_split: Optional[float] = None + shuffle: Optional[bool] = None + + @model_validator(mode='after') + def _check_dependencies(self) -> 'DataSplitterConfig': + block_types = {'DataSplitter', 'BlockDataSplitter', 'blocks'} + split_types = {'sklearn', 'train_test_split', 'train_val_split'} + if self.train_block_size is not None and self.type not in block_types: + raise ValueError( + "train_block_size depends on type in ['DataSplitter', 'BlockDataSplitter', 'blocks']") + if self.val_block_size is not None and self.type not in block_types: + raise ValueError( + "val_block_size depends on type in ['DataSplitter', 'BlockDataSplitter', 'blocks']") + if self.validation_split is not None and self.type not in split_types: + raise ValueError( + "validation_split depends on type in ['sklearn', 'train_test_split', 'train_val_split']") + if self.shuffle is not None and self.type not in {'sklearn', 'train_test_split'}: + raise ValueError("shuffle depends on type in ['sklearn', 'train_test_split']") + return self + + +class TrainConfig(_SubscriptableModel): + """``train`` section.""" + + model_config = ConfigDict(extra='allow') + anomaly_score: AnomalyScoreConfig + autoencoder: AutoencoderConfig + data_preprocessor: Optional[DataPreprocessorConfig] # required but nullable -> keep None + threshold_selector: ThresholdSelectorConfig + data_clipping: Optional[DataClippingConfig] = None + data_splitter: Optional[DataSplitterConfig] = None + protect_conditional_features: bool = False + + +class RootCauseAnalysisConfig(_SubscriptableModel): + """``root_cause_analysis`` section.""" + + model_config = ConfigDict(extra='allow') + alpha: Optional[float] = None + init_x_bias: Optional[str] = None + num_iter: Optional[int] = None + epsilon: Optional[float] = None + verbose: Optional[bool] = None + max_sample_threshold: Optional[int] = None + + +class CriticalityConfig(_SubscriptableModel): + """``predict.criticality`` section.""" + + model_config = ConfigDict(extra='allow') + max_criticality: Optional[int] = None + + +class PredictConfig(_SubscriptableModel): + """``predict`` section.""" + + model_config = ConfigDict(extra='allow') + criticality: Optional[CriticalityConfig] = None - return config_dict +# --- Extra validation helpers ------------------------------------------------ -def _parse_timedelta(config_dict: Dict[str, Any]) -> Dict[str, Any]: - """Parse sequence_builder.ts_freq from a compact string (e.g. '10m') to np.timedelta64. - Expects `ts_freq` under: train.autoencoder.params.sequence_builder.ts_freq - and supports strings like '10m', '1h', '30s'. +def _ae_params(model: 'ConfigModel') -> Optional[Dict[str, Any]]: + """Return the autoencoder params dict, or ``None`` if not applicable. + + ``params`` can be a dict or a list; only dict params are relevant for the + extra checks (``sequence_builder``, ``early_stopping`` live inside dicts). """ - UNIT_MAP = {"min": "m", "sec": "s", "hr": "h", "hour": "h"} + if model.train is None or model.train.autoencoder is None: + return None + params = model.train.autoencoder.params + if isinstance(params, dict): + return params + return None + - train_cfg = config_dict.get("train", {}) - ae_cfg = train_cfg.get("autoencoder", {}) or {} - params_cfg = ae_cfg.get("params", {}) or {} - seq_builder_cfg = params_cfg.get("sequence_builder", {}) or {} - ts_freq = seq_builder_cfg.get("ts_freq") +def _parse_timedelta(model: 'ConfigModel') -> None: + """Parse ``sequence_builder.ts_freq`` from a compact string to ``np.timedelta64``. + Expects ``ts_freq`` under ``train.autoencoder.params.sequence_builder.ts_freq`` + and supports strings like ``'10m'``, ``'1h'``, ``'30s'``. + """ + unit_map = {"min": "m", "sec": "s", "hr": "h", "hour": "h"} + params = _ae_params(model) + if params is None: + return + seq_builder = params.get("sequence_builder") + if not isinstance(seq_builder, dict): + return + ts_freq = seq_builder.get("ts_freq") if isinstance(ts_freq, str): - # Parse '10m', '1h', etc. digits = "".join(ch for ch in ts_freq if ch.isdigit()) unit = "".join(ch for ch in ts_freq if not ch.isdigit()) - unit = UNIT_MAP.get(unit, unit) + unit = unit_map.get(unit, unit) if not digits or not unit: - raise ValueError(f"Unexpected value for `ts_freq`: {ts_freq!r}. Expected format like '10m', '1h'.") - import numpy as np # noqa: F401 - value = int(digits) - seq_builder_cfg["ts_freq"] = np.timedelta64(value, unit) - params_cfg["sequence_builder"] = seq_builder_cfg - ae_cfg["params"] = params_cfg - train_cfg["autoencoder"] = ae_cfg - config_dict["train"] = train_cfg + raise ValueError( + f"Unexpected value for `ts_freq`: {ts_freq!r}. Expected format like '10m', '1h'.") + seq_builder["ts_freq"] = np.timedelta64(int(digits), unit) + + +def _validate_early_stopping(model: 'ConfigModel') -> None: + """Check whether early_stopping settings are consistent with the data splitter.""" + params = _ae_params(model) + if params is None: + return + early_stopping = params.get('early_stopping', False) + + splitter = model.train.data_splitter + validation_split = getattr(splitter, 'validation_split', 0.0) or 0.0 + val_block_size = getattr(splitter, 'val_block_size', 0) or 0 + + if not isinstance(validation_split, float): + validation_split = 0.0 - return config_dict + validation = 0 < validation_split < 1 or val_block_size > 0 + if early_stopping and not validation: + msg = ('Configuration is not valid: If early_stopping is enabled either validation_split or ' + 'val_block_size must be given. If validation_split is used, it must be a float >0 and <1.') + raise InvalidConfigFile(msg) -def _validate_sequence_fit_on_val(config_dict: Dict[str, Any]) -> Dict[str, Any]: - """Warn if fit_on_val=True with a sequence model and shuffle=True.""" - train_cfg = config_dict.get("train", {}) - has_sequence_builder = "sequence_builder" in ( - train_cfg.get("autoencoder", {}).get("params", {}) or {} - ) - fit_on_val = train_cfg.get("threshold_selector", {}).get("fit_on_val", False) - shuffle = train_cfg.get("data_splitter", {}).get("shuffle", False) +def _validate_sequence_fit_on_val(model: 'ConfigModel') -> None: + """Warn if ``fit_on_val=True`` with a sequence model and ``shuffle=True``.""" + params = _ae_params(model) + if params is None: + return + has_sequence_builder = "sequence_builder" in params + fit_on_val = model.train.threshold_selector.fit_on_val + splitter = model.train.data_splitter + shuffle = getattr(splitter, 'shuffle', False) if has_sequence_builder and fit_on_val and shuffle: - import warnings warnings.warn( "Using 'fit_on_val=True' with a sequence model and 'shuffle=True' may result in " "non-contiguous validation timestamps. The sequence builder will drop windows that " @@ -180,34 +337,240 @@ def _validate_sequence_fit_on_val(config_dict: Dict[str, Any]) -> Dict[str, Any] stacklevel=2, ) - return config_dict +# --- Top-level model --------------------------------------------------------- + + +class ConfigModel(_SubscriptableModel): + """Top-level Pydantic model for the anomaly-detection pipeline configuration. + + The top-level uses ``extra='ignore'`` (unknown top-level keys are dropped and + logged) mirroring the former Cerberus behaviour. Section models use + ``extra='allow'`` (or ``extra='forbid'`` for the data preprocessor). + """ + + model_config = ConfigDict(extra='ignore', validate_default=True) + train: Optional[TrainConfig] = None + predict: Optional[PredictConfig] = None + root_cause_analysis: Optional[RootCauseAnalysisConfig] = None + dtype: Literal['float32', 'float64'] = 'float32' + + @model_validator(mode='after') + def _run_extra_checks(self) -> 'ConfigModel': + """Run the three post-validation checks formerly handled by Cerberus extras.""" + _parse_timedelta(self) + _validate_early_stopping(self) + _validate_sequence_fit_on_val(self) + return self -class Config(BaseConfig): - """Configuration class. Either config_filename or config_dict must be provided. - Reads a yaml file with the anomaly detection configuration and sets corresponding settings. + +# --- Config wrapper ---------------------------------------------------------- + + +class Config: + """Configuration for the anomaly-detection pipeline. + + Loads and validates a YAML configuration file (or an inline dict) using + Pydantic models. The top-level sections are exposed as typed attributes + (``config.train``, ``config.predict``, …); dict-style access + (``config['train']``) is supported for backward compatibility via + :class:`_SubscriptableModel`. + + Example: + + .. code-block:: python + + from energy_fault_detector.config import Config + + # from YAML file + config = Config.from_yaml('config.yaml') + + # from dict + config = Config.from_dict({'train': {...}}) + + # legacy constructor (still supported) + config = Config('config.yaml') + config = Config(config_dict={'train': {...}}) + + Args: + config_filename: Path to a YAML configuration file. + config_dict: Inline configuration dictionary. """ - def __init__(self, config_filename: str | Path = None, config_dict: Dict[str, Any] = None): - super().__init__(config_filename=config_filename, config_dict=config_dict) - self._schema = CONFIG_SCHEMA - self._extra_validation_checks: List[Callable[[Dict], Dict]] = [_parse_timedelta, - _validate_early_stopping, - _validate_sequence_fit_on_val] - self.read_config() + def __init__(self, config_filename: str | Path = None, + config_dict: Dict[str, Any] = None) -> None: + self._model: Optional[ConfigModel] = None + self._configuration_file: Optional[str] = None + if config_filename is not None or config_dict is not None: + self._configuration_file = str(config_filename) if config_filename else None + self.read_config(config_dict=config_dict) + + # --- factory classmethods ------------------------------------------------- + + @classmethod + def from_yaml(cls, path: str | Path) -> 'Config': + """Load configuration from a YAML file. + + Args: + path: Path to the YAML configuration file. + + Returns: + Validated configuration instance. + + Raises: + InvalidConfigFile: If the file is empty or fails validation. + """ + return cls(config_filename=path) + + @classmethod + def from_dict(cls, config_dict: Dict[str, Any]) -> 'Config': + """Create a configuration from an inline dictionary. + + Args: + config_dict: Configuration dictionary. - def __getitem__(self, item) -> Any: - return self.config_dict[item] + Returns: + Validated configuration instance. - def __contains__(self, item): - return item in self.config_dict + Raises: + InvalidConfigFile: If the dictionary is None or fails validation. + """ + if config_dict is None: + raise InvalidConfigFile('The configuration file is empty!') + return cls(config_dict=config_dict) + + # --- loading / validation ------------------------------------------------- + + def read_config(self, config_dict: Dict[str, Any] = None, part: str = None) -> None: + """Read and validate the configuration from file or dict. + + Args: + config_dict: Inline configuration dictionary. If ``None``, reads + from :attr:`_configuration_file`. + part: If given, extract only this top-level section (legacy compat). + """ + if config_dict is not None: + data = config_dict + elif self._configuration_file is not None: + with open(self._configuration_file, 'r', encoding='utf-8') as f: + data = yaml.safe_load(f) + else: + raise InvalidConfigFile('The configuration file is empty!') + + if data is None: + raise InvalidConfigFile('The configuration file is empty!') + + if part is not None and isinstance(data, dict) and part in data: + data = data[part] + + self._load_and_validate(data) + + def _load_and_validate(self, data: Dict[str, Any]) -> None: + """Validate *data* with Pydantic and store the resulting model.""" + # Drop and log unknown top-level keys (extra='ignore' discards them). + if isinstance(data, dict): + known_keys = set(ConfigModel.model_fields.keys()) + for key in list(data.keys()): + if key not in known_keys: + logger.info('Key `%s` is an unknown field and will be ignored.', key) + + try: + self._model = ConfigModel.model_validate(data) + except ValidationError as exc: + lines = [] + for err in exc.errors(): + loc = '.'.join(str(p) for p in err['loc']) + lines.append(f"{loc}: {err['msg']}") + raise InvalidConfigFile('Configuration is not valid: ' + '; '.join(lines)) from exc + + if not self.config_dict: + raise InvalidConfigFile(f'The configuration file is empty for {type(self).__name__}.') + + # --- dict-style access ---------------------------------------------------- + + def __getitem__(self, key: str) -> Any: + return self._model[key] + + def __contains__(self, key: str) -> bool: + return key in self._model + + def __repr__(self) -> str: + return self.config_dict.__repr__() + + # --- serialization -------------------------------------------------------- + + @property + def config_dict(self) -> Dict[str, Any]: + """Return a plain (mutable) dictionary representation of the config. + + The dict is rebuilt from the underlying Pydantic model on every call, so + it always reflects the current model state. Leaf dicts (``params``, + ``steps``) are the same mutable objects stored on the model, so + in-place mutations (``config['train']['autoencoder']['params'].update(...)``) + persist. + """ + return _model_to_config_dict(self._model) + + # --- write / save -------------------------------------------------------- + + def write_config(self, file_name: Optional[str] = None, overwrite: bool = False) -> None: + """Write the configuration to a YAML file. + + Args: + file_name: Target path. If ``None``, uses the original configuration file. + overwrite: If ``False``, raises :class:`FileExistsError` when the file + already exists. + """ + from copy import deepcopy + + if file_name is None and self._configuration_file is None: + raise ValueError('No file name given and no known configuration file to overwrite.') + + file_name = file_name if file_name is not None else self._configuration_file + if Path(file_name).exists() and not overwrite: + raise FileExistsError(f'File {file_name} already exists and overwrite is set to False.') + + conf_dict = deepcopy(self.config_dict) + + ae_params = conf_dict.get('train', {}).get('autoencoder', {}).get('params', {}) + seq_builder = ae_params.get('sequence_builder') + if isinstance(seq_builder, dict): + sb_ts_freq = seq_builder.get('ts_freq') + if isinstance(sb_ts_freq, np.timedelta64): + seq_builder['ts_freq'] = _format_timedelta(sb_ts_freq) + + with open(file_name, 'w', encoding='utf-8') as f: + yaml.safe_dump(conf_dict, f) + + def save(self, file_name: str, overwrite: bool = False) -> None: + """Save the configuration to a YAML file. Wrapper for :meth:`write_config`.""" + self.write_config(file_name, overwrite) + + def update_config(self, new_config_dict: Dict[str, Any]) -> None: + """Update the configuration with *new_config_dict* and re-validate. + + Args: + new_config_dict: Dictionary with new/updated configuration values. + """ + merged = self.config_dict + merged.update(new_config_dict) + self._load_and_validate(merged) + self._configuration_file = None + + # --- convenience properties ----------------------------------------------- @property def data_preprocessor_steps(self) -> List[Dict[str, Any]]: - """Get the data preprocessor steps.""" - data_prep = self.config_dict.get('train', {}).get('data_preprocessor', {}) or {} - params = data_prep.get('params') or {} - steps = data_prep.get('steps') or [] + """Get the data preprocessor steps. + + If ``data_preprocessor.steps`` is provided it takes precedence over the + deprecated ``data_preprocessor.params`` style. + """ + if self._model.train is None or self._model.train.data_preprocessor is None: + return [] + dp = self._model.train.data_preprocessor + params = dp.params or {} + steps = dp.steps or [] if steps and params: warnings.warn( @@ -232,60 +595,78 @@ def data_preprocessor_steps(self) -> List[Dict[str, Any]]: @property def root_cause_analysis(self) -> bool: - """Whether to run ARCANA.""" - return 'root_cause_analysis' in self.config_dict + """Whether the ``root_cause_analysis`` section is configured.""" + return self._model.root_cause_analysis is not None @property def arcana_params(self) -> Dict[str, Any]: - """Get the ARCANA parameters.""" - return self.config_dict.get('root_cause_analysis', {}) + """Get the ARCANA parameters as a plain dict.""" + if self._model.root_cause_analysis is None: + return {} + return _model_to_config_dict(self._model.root_cause_analysis) @property def data_split_params(self) -> Dict[str, Any]: """DataSplitter or train_test_split parameters.""" - return self.config_dict.get('train', {}).get('data_splitter', {}) + if self._model.train is None or self._model.train.data_splitter is None: + return {} + return _model_to_config_dict(self._model.train.data_splitter) @property def data_clipping(self) -> bool: """Whether to clip training data.""" - return 'data_clipping' in self.config_dict.get('train', {}) + return (self._model.train is not None + and self._model.train.data_clipping is not None) @property def data_clipping_params(self) -> Dict[str, Any]: """Data clipping parameters.""" - return self.config_dict.get('train', {}).get('data_clipping', {}) + if self._model.train is None or self._model.train.data_clipping is None: + return {} + return _model_to_config_dict(self._model.train.data_clipping) @property def max_criticality(self) -> Optional[int]: - """Max criticality value.""" - return self.config_dict.get('predict', {}).get('criticality', {}).get('max_criticality', 144) + """Max criticality value (default 144 when not configured).""" + if self._model.predict is None or self._model.predict.criticality is None: + return 144 + mc = self._model.predict.criticality.max_criticality + return mc if mc is not None else 144 @property def fit_threshold_on_val(self) -> bool: """Whether to fit threshold on validation data only.""" - return self.config_dict.get('train', {}).get('threshold_selector', {}).get('fit_on_val', False) - - @property - def dtype(self): - """Data type, float32 by default.""" - return self.config_dict.get('dtype', 'float32') + if self._model.train is None or self._model.train.threshold_selector is None: + return False + return self._model.train.threshold_selector.fit_on_val @property def protect_conditional_features(self) -> bool: """Whether to protect conditional features from being dropped by preprocessing.""" - return self.config_dict.get('train', {}).get('protect_conditional_features', False) + if self._model.train is None: + return False + return self._model.train.protect_conditional_features + + @property + def dtype(self) -> str: + """Configured numeric dtype (``'float32'`` or ``'float64'``).""" + return self._model.dtype def _data_preprocessor_params_to_steps(params: Dict[str, Any]) -> List[Dict[str, Any]]: - """Translate old data_preprocessor params into a 'steps' specification. + """Translate old ``data_preprocessor.params`` into a ``steps`` specification. + + Args: + params: Legacy params dict. Returns: - List of step-spec dicts to be passed to the DataPreprocessor, e.g.: - [ - {"name": "duplicate_to_nan", "params": {...}}, - {"name": "counter_diff_transformer", "params": {...}}, - ... - ] + List of step-spec dicts to be passed to the DataPreprocessor, e.g.:: + + [ + {"name": "duplicate_to_nan", "params": {...}}, + {"name": "counter_diff_transformer", "params": {...}}, + ... + ] """ p = params or {} diff --git a/energy_fault_detector/evaluation/care2compare.py b/energy_fault_detector/evaluation/care2compare.py index 37ebe18d..2b718a9d 100644 --- a/energy_fault_detector/evaluation/care2compare.py +++ b/energy_fault_detector/evaluation/care2compare.py @@ -7,6 +7,7 @@ import pandas as pd from energy_fault_detector.config import Config +from energy_fault_detector.config.config import DataPreprocessorConfig from energy_fault_detector.utils.data_downloads import download_zenodo_data logger = logging.getLogger('energy_fault_detector') @@ -291,15 +292,21 @@ def find_step(names: List[str]) -> dict | None: angle_columns = get_columns(angles) to_exclude_columns = get_columns(to_exclude) - # old: - dp = config['train'].setdefault('data_preprocessor', {}) + train = config['train'] + dp = train.data_preprocessor + if dp is None: + dp = DataPreprocessorConfig(steps=[]) + train.data_preprocessor = dp + params = dp.get('params') steps = dp.get('steps') if params: params['angles'] = merge_unique(params.get('angles', []), angle_columns) params['features_to_exclude'] = merge_unique(params.get('features_to_exclude', []), to_exclude_columns) - # new else: + if steps is None: + dp.steps = [] + steps = dp.steps angle_step = find_step(['angle_transformer', 'angle_transform']) if angle_step is None: steps.append({'name': 'angle_transformer', 'params': {'angles': angle_columns}}) @@ -314,8 +321,6 @@ def find_step(names: List[str]) -> dict | None: colsel_params['features_to_exclude'] = merge_unique( colsel_params.get('features_to_exclude', []), to_exclude_columns) - config.update_config(config.config_dict) - def _get_column_map(self, wind_farm: str) -> Dict[str, str]: """Maps anonymized columns to human-readable format using feature descriptions""" diff --git a/energy_fault_detector/quick_fault_detection/configuration.py b/energy_fault_detector/quick_fault_detection/configuration.py index d851ee66..1c2b4267 100644 --- a/energy_fault_detector/quick_fault_detection/configuration.py +++ b/energy_fault_detector/quick_fault_detection/configuration.py @@ -72,13 +72,17 @@ def update_preprocessor_config(config: Config, features_to_exclude: Union[List[s Config: Updated config object. """ + dp = config['train']['data_preprocessor'] + if features_to_exclude is not None: - if config['train']['data_preprocessor'].get('params'): + if dp.get('params'): # old data preprocessing configuration style - config['train']['data_preprocessor']['params']['features_to_exclude'] = features_to_exclude + dp['params']['features_to_exclude'] = features_to_exclude else: # new configuration style - steps = config['train']['data_preprocessor'].setdefault('steps', []) + if dp.steps is None: + dp.steps = [] + steps = dp.steps column_selector_found = False for step in steps: if step['name'] == 'column_selector': @@ -88,12 +92,14 @@ def update_preprocessor_config(config: Config, features_to_exclude: Union[List[s if not column_selector_found: steps.append({'name': 'column_selector', 'params': {'features_to_exclude': features_to_exclude}}) if angles is not None: - if config['train']['data_preprocessor'].get('params'): + if dp.get('params'): # old data preprocessing configuration style - config['train']['data_preprocessor']['params']['angles'] = angles + dp['params']['angles'] = angles else: # new configuration style - steps = config['train']['data_preprocessor'].setdefault('steps', []) + if dp.steps is None: + dp.steps = [] + steps = dp.steps angle_transformer_found = False for step in steps: if step['name'] == 'angle_transformer': diff --git a/pyproject.toml b/pyproject.toml index 06273656..59157cf3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ dependencies = [ "pyyaml", "scikit-learn>=1.5.2,<=1.7.0", "pandas>=2.0,<3.0", - "cerberus", + "pydantic>=2.0", "matplotlib>=3.9.0", "optuna>=4.0", "chardet>=5.0", diff --git a/tests/test_fault_detector.py b/tests/test_fault_detector.py index 8a259320..0d8abc69 100644 --- a/tests/test_fault_detector.py +++ b/tests/test_fault_detector.py @@ -694,7 +694,7 @@ def setUp(self) -> None: self.config_path = os.path.join(PROJECT_ROOT, 'tests/test_data/test_conditional_ae_config.yaml') self.conf = Config(self.config_path) # Set protect_conditional_features to False - self.conf.config_dict['train']['protect_conditional_features'] = False + self.conf['train'].protect_conditional_features = False self.test_dir = tempfile.mkdtemp() np.random.seed(42) @@ -733,7 +733,7 @@ def test_conditional_features_can_be_dropped_when_unprotected(self): def test_protect_true_keeps_constant_conditional(self): """When protect=True (default), constant conditional features are kept.""" - self.conf.config_dict['train']['protect_conditional_features'] = True + self.conf['train'].protect_conditional_features = True fd = FaultDetector(config=self.conf, model_directory=self.test_dir) fd.fit(sensor_data=self.sensor_data, normal_index=self.normal_index, save_models=False) From 6e486620d59eb2965b65209fbf006c1f4918418e Mon Sep 17 00:00:00 2001 From: croelofs <25582572+roelofsc@users.noreply.github.com> Date: Wed, 9 Sep 2026 16:57:26 +0200 Subject: [PATCH 02/18] Remove backward-compat dict-style access, migrate consumers to attribute access Remove _SubscriptableModel mixin (__getitem__/__contains__/get) from all section models and Config. Section models now inherit BaseModel directly. Config.__getattr__ delegates top-level model fields (train, predict, etc.) for natural attribute access (config.train.autoencoder.params). Remove trivial convenience properties that were thin wrappers over model fields: protect_conditional_features, fit_threshold_on_val, data_clipping (bool), max_criticality, root_cause_analysis (bool), dtype. The latter two resolve via __getattr__ delegation to ConfigModel fields. Keep properties with real logic: data_preprocessor_steps (handles params->steps migration + deprecation warnings), arcana_params, data_split_params, data_clipping_params (all return plain dicts via _model_to_config_dict for **-unpacking consumers). Migrate all consumers: - model_factory.py: config['train'] -> config.train, .get('params', {}) -> .params or {} - fault_detector.py: config.fit_threshold_on_val -> config.train.threshold_selector.fit_on_val, config.data_clipping -> config.train.data_clipping is not None, etc. - configuration.py: config['train']['data_preprocessor'] -> config.train.data_preprocessor, dp.get('params') -> dp.params, dp['params']['key'] -> dp.params['key'] - care2compare.py: same pattern - All test files: conf['train']['autoencoder']['params']['x'] -> conf.train.autoencoder.params['x'] --- energy_fault_detector/config/config.py | 157 +++++------------- energy_fault_detector/core/model_factory.py | 22 +-- .../evaluation/care2compare.py | 6 +- energy_fault_detector/fault_detector.py | 11 +- .../quick_fault_detection/configuration.py | 14 +- tests/config/test_config.py | 10 +- tests/config/test_quickstart_config.py | 20 +-- .../test_configuration.py | 14 +- .../test_quick_fault_detector.py | 2 +- tests/test_fault_detector.py | 14 +- 10 files changed, 98 insertions(+), 172 deletions(-) diff --git a/energy_fault_detector/config/config.py b/energy_fault_detector/config/config.py index e9924f13..8184b769 100644 --- a/energy_fault_detector/config/config.py +++ b/energy_fault_detector/config/config.py @@ -3,12 +3,10 @@ The configuration is defined by a set of Pydantic models (section models plus a top-level :class:`ConfigModel`) that validate the YAML/dict input. The public :class:`Config` class is a thin wrapper around :class:`ConfigModel` that adds -file I/O, serialization, and backward-compat dict-style access. - -``Config`` is **not** itself a Pydantic model – it holds a validated -``ConfigModel`` instance via ``self._model``. Section models inherit -:class:`_SubscriptableModel` so that ``config['train']['autoencoder']`` keeps -working during the migration from dict-based to typed access. +file I/O and serialization. Model fields (``train``, ``predict``, +``root_cause_analysis``, ``dtype``) are accessible via normal attribute access +on the :class:`Config` wrapper (delegated to the underlying model through +``__getattr__``). """ import logging @@ -40,47 +38,6 @@ def _format_timedelta(value: np.timedelta64) -> str: return f"{total_seconds}s" -class _SubscriptableModel(BaseModel): - """Pydantic ``BaseModel`` with dict-style access for backward compatibility. - - Allows ``config['train']`` instead of ``config.train`` during the migration - from dict-based config to typed Pydantic models. All section models and the - top-level :class:`ConfigModel` inherit from this class. - - ``__getitem__`` delegates to :func:`getattr`; ``__contains__`` checks whether - *key* is a declared field that is "present": - - * **required** fields (no default) are always present, even when their value - is ``None`` (e.g. ``train.data_preprocessor`` which is required but - nullable); - * **optional** fields (have a default) are present only when their value is - not ``None`` (e.g. ``data_clipping``). - - ``get(key, default)`` mirrors ``dict.get``: returns the value when the key is - present, otherwise *default*. - """ - - def __getitem__(self, key: str) -> Any: - return getattr(self, key) - - def __contains__(self, key: str) -> bool: - field = type(self).model_fields.get(key) - if field is None: - return False - if field.is_required(): - return True - return getattr(self, key) is not None - - def get(self, key: str, default: Any = None) -> Any: - """Return the field value if present, otherwise *default*. - - Mirrors ``dict.get`` semantics using :meth:`__contains__`. - """ - if key in self: - return getattr(self, key) - return default - - def _dump_value(value: Any) -> Any: """Recursively dump nested models/lists; plain dicts/lists are kept as-is.""" if isinstance(value, BaseModel): @@ -130,7 +87,7 @@ def _model_to_config_dict(model: BaseModel) -> Dict[str, Any]: # either, so this is strict parity. -class AnomalyScoreConfig(_SubscriptableModel): +class AnomalyScoreConfig(BaseModel): """``train.anomaly_score`` section.""" model_config = ConfigDict(extra='allow') @@ -138,7 +95,7 @@ class AnomalyScoreConfig(_SubscriptableModel): params: Optional[Dict[str, Any]] = None -class AutoencoderConfig(_SubscriptableModel): +class AutoencoderConfig(BaseModel): """``train.autoencoder`` section. ``params`` accepts a dict or a list (the Cerberus schema allowed both) and is @@ -152,7 +109,7 @@ class AutoencoderConfig(_SubscriptableModel): verbose: Optional[int] = None -class DataPreprocessorConfig(_SubscriptableModel): +class DataPreprocessorConfig(BaseModel): """``train.data_preprocessor`` section (``extra='forbid'``).""" model_config = ConfigDict(extra='forbid') @@ -160,7 +117,7 @@ class DataPreprocessorConfig(_SubscriptableModel): steps: Optional[List[Dict[str, Any]]] = None -class ThresholdSelectorConfig(_SubscriptableModel): +class ThresholdSelectorConfig(BaseModel): """``train.threshold_selector`` section.""" model_config = ConfigDict(extra='allow') @@ -169,7 +126,7 @@ class ThresholdSelectorConfig(_SubscriptableModel): params: Optional[Dict[str, Any]] = None -class DataClippingConfig(_SubscriptableModel): +class DataClippingConfig(BaseModel): """``train.data_clipping`` section.""" model_config = ConfigDict(extra='allow') @@ -179,7 +136,7 @@ class DataClippingConfig(_SubscriptableModel): features_to_clip: Optional[List[str]] = None -class DataSplitterConfig(_SubscriptableModel): +class DataSplitterConfig(BaseModel): """``train.data_splitter`` section. Reproduces the Cerberus ``dependencies`` rules: block-size fields require a @@ -215,7 +172,7 @@ def _check_dependencies(self) -> 'DataSplitterConfig': return self -class TrainConfig(_SubscriptableModel): +class TrainConfig(BaseModel): """``train`` section.""" model_config = ConfigDict(extra='allow') @@ -228,7 +185,7 @@ class TrainConfig(_SubscriptableModel): protect_conditional_features: bool = False -class RootCauseAnalysisConfig(_SubscriptableModel): +class RootCauseAnalysisConfig(BaseModel): """``root_cause_analysis`` section.""" model_config = ConfigDict(extra='allow') @@ -240,14 +197,14 @@ class RootCauseAnalysisConfig(_SubscriptableModel): max_sample_threshold: Optional[int] = None -class CriticalityConfig(_SubscriptableModel): +class CriticalityConfig(BaseModel): """``predict.criticality`` section.""" model_config = ConfigDict(extra='allow') max_criticality: Optional[int] = None -class PredictConfig(_SubscriptableModel): +class PredictConfig(BaseModel): """``predict`` section.""" model_config = ConfigDict(extra='allow') @@ -341,7 +298,7 @@ def _validate_sequence_fit_on_val(model: 'ConfigModel') -> None: # --- Top-level model --------------------------------------------------------- -class ConfigModel(_SubscriptableModel): +class ConfigModel(BaseModel): """Top-level Pydantic model for the anomaly-detection pipeline configuration. The top-level uses ``extra='ignore'`` (unknown top-level keys are dropped and @@ -371,10 +328,9 @@ class Config: """Configuration for the anomaly-detection pipeline. Loads and validates a YAML configuration file (or an inline dict) using - Pydantic models. The top-level sections are exposed as typed attributes - (``config.train``, ``config.predict``, …); dict-style access - (``config['train']``) is supported for backward compatibility via - :class:`_SubscriptableModel`. + Pydantic models. Top-level model fields (``train``, ``predict``, + ``root_cause_analysis``, ``dtype``) are accessible via attribute access on + the wrapper (e.g. ``config.train`` returns a :class:`TrainConfig` model). Example: @@ -405,6 +361,24 @@ def __init__(self, config_filename: str | Path = None, self._configuration_file = str(config_filename) if config_filename else None self.read_config(config_dict=config_dict) + # --- attribute delegation ------------------------------------------------- + + def __getattr__(self, name: str) -> Any: + """Delegate attribute access to the underlying :class:`ConfigModel`. + + ``__getattr__`` is only called when the attribute is not found through + normal lookup, so properties/methods defined on :class:`Config` take + precedence. Only model fields (``train``, ``predict``, etc.) are + delegated. + """ + model = self.__dict__.get('_model') + if model is not None and name in type(model).model_fields: + return getattr(model, name) + raise AttributeError(f"'{type(self).__name__}' has no attribute '{name}'") + + def __repr__(self) -> str: + return self.config_dict.__repr__() + # --- factory classmethods ------------------------------------------------- @classmethod @@ -486,17 +460,6 @@ def _load_and_validate(self, data: Dict[str, Any]) -> None: if not self.config_dict: raise InvalidConfigFile(f'The configuration file is empty for {type(self).__name__}.') - # --- dict-style access ---------------------------------------------------- - - def __getitem__(self, key: str) -> Any: - return self._model[key] - - def __contains__(self, key: str) -> bool: - return key in self._model - - def __repr__(self) -> str: - return self.config_dict.__repr__() - # --- serialization -------------------------------------------------------- @property @@ -506,7 +469,7 @@ def config_dict(self) -> Dict[str, Any]: The dict is rebuilt from the underlying Pydantic model on every call, so it always reflects the current model state. Leaf dicts (``params``, ``steps``) are the same mutable objects stored on the model, so - in-place mutations (``config['train']['autoencoder']['params'].update(...)``) + in-place mutations (``config.train.autoencoder.params.update(...)``) persist. """ return _model_to_config_dict(self._model) @@ -557,7 +520,7 @@ def update_config(self, new_config_dict: Dict[str, Any]) -> None: self._load_and_validate(merged) self._configuration_file = None - # --- convenience properties ----------------------------------------------- + # --- properties with real logic ------------------------------------------- @property def data_preprocessor_steps(self) -> List[Dict[str, Any]]: @@ -593,65 +556,27 @@ def data_preprocessor_steps(self) -> List[Dict[str, Any]]: return steps or [] - @property - def root_cause_analysis(self) -> bool: - """Whether the ``root_cause_analysis`` section is configured.""" - return self._model.root_cause_analysis is not None - @property def arcana_params(self) -> Dict[str, Any]: - """Get the ARCANA parameters as a plain dict.""" + """Get the ARCANA parameters as a plain dict (for ``**`` unpacking).""" if self._model.root_cause_analysis is None: return {} return _model_to_config_dict(self._model.root_cause_analysis) @property def data_split_params(self) -> Dict[str, Any]: - """DataSplitter or train_test_split parameters.""" + """DataSplitter or train_test_split parameters as a plain dict.""" if self._model.train is None or self._model.train.data_splitter is None: return {} return _model_to_config_dict(self._model.train.data_splitter) - @property - def data_clipping(self) -> bool: - """Whether to clip training data.""" - return (self._model.train is not None - and self._model.train.data_clipping is not None) - @property def data_clipping_params(self) -> Dict[str, Any]: - """Data clipping parameters.""" + """Data clipping parameters as a plain dict.""" if self._model.train is None or self._model.train.data_clipping is None: return {} return _model_to_config_dict(self._model.train.data_clipping) - @property - def max_criticality(self) -> Optional[int]: - """Max criticality value (default 144 when not configured).""" - if self._model.predict is None or self._model.predict.criticality is None: - return 144 - mc = self._model.predict.criticality.max_criticality - return mc if mc is not None else 144 - - @property - def fit_threshold_on_val(self) -> bool: - """Whether to fit threshold on validation data only.""" - if self._model.train is None or self._model.train.threshold_selector is None: - return False - return self._model.train.threshold_selector.fit_on_val - - @property - def protect_conditional_features(self) -> bool: - """Whether to protect conditional features from being dropped by preprocessing.""" - if self._model.train is None: - return False - return self._model.train.protect_conditional_features - - @property - def dtype(self) -> str: - """Configured numeric dtype (``'float32'`` or ``'float64'``).""" - return self._model.dtype - def _data_preprocessor_params_to_steps(params: Dict[str, Any]) -> List[Dict[str, Any]]: """Translate old ``data_preprocessor.params`` into a ``steps`` specification. diff --git a/energy_fault_detector/core/model_factory.py b/energy_fault_detector/core/model_factory.py index 463bfb5c..173cc94c 100644 --- a/energy_fault_detector/core/model_factory.py +++ b/energy_fault_detector/core/model_factory.py @@ -32,18 +32,18 @@ def _initialize_models(self) -> None: from energy_fault_detector.data_splitting.sequence_dataset import SequenceDatasetBuilder from energy_fault_detector.autoencoders.seq2one_autoencoder import SequenceAutoencoder - train_dict = self.config["train"] + train = self.config.train # Data preprocessor self._models["data_preprocessor"] = DataPreprocessor(steps=self.config.data_preprocessor_steps) # autoencoder - ae_params = train_dict.get("autoencoder") - ae_class = registry.get("autoencoder", ae_params["name"]) - ae_kwargs = dict(ae_params.get("params", {})) + ae_config = train.autoencoder + ae_class = registry.get("autoencoder", ae_config.name) + ae_kwargs = dict(ae_config.params) # Add verbose from config (train.autoencoder.verbose), defaulting to 1 - ae_verbose = ae_params.get("verbose", 1) + ae_verbose = ae_config.verbose if ae_config.verbose is not None else 1 ae_kwargs.setdefault("verbose", ae_verbose) # If this is a sequence AE, build the SequenceDatasetBuilder from config @@ -68,14 +68,14 @@ def _initialize_models(self) -> None: self._models["autoencoder"] = ae_class(**ae_kwargs) # anomaly_score - score_params = train_dict.get("anomaly_score") - score_class = registry.get("anomaly_score", score_params["name"]) - self._models["anomaly_score"] = score_class(**score_params.get("params", {})) + score_config = train.anomaly_score + score_class = registry.get("anomaly_score", score_config.name) + self._models["anomaly_score"] = score_class(**(score_config.params or {})) # threshold_selector - thresh_params = train_dict.get("threshold_selector") - thresh_class = registry.get("threshold_selector", thresh_params["name"]) - self._models["threshold_selector"] = thresh_class(**thresh_params.get("params", {})) + thresh_config = train.threshold_selector + thresh_class = registry.get("threshold_selector", thresh_config.name) + self._models["threshold_selector"] = thresh_class(**(thresh_config.params or {})) @property def data_preprocessor(self) -> DataPreprocessor: diff --git a/energy_fault_detector/evaluation/care2compare.py b/energy_fault_detector/evaluation/care2compare.py index 2b718a9d..22c94854 100644 --- a/energy_fault_detector/evaluation/care2compare.py +++ b/energy_fault_detector/evaluation/care2compare.py @@ -292,14 +292,14 @@ def find_step(names: List[str]) -> dict | None: angle_columns = get_columns(angles) to_exclude_columns = get_columns(to_exclude) - train = config['train'] + train = config.train dp = train.data_preprocessor if dp is None: dp = DataPreprocessorConfig(steps=[]) train.data_preprocessor = dp - params = dp.get('params') - steps = dp.get('steps') + params = dp.params + steps = dp.steps if params: params['angles'] = merge_unique(params.get('angles', []), angle_columns) params['features_to_exclude'] = merge_unique(params.get('features_to_exclude', []), to_exclude_columns) diff --git a/energy_fault_detector/fault_detector.py b/energy_fault_detector/fault_detector.py index ca7f953f..17aeea55 100644 --- a/energy_fault_detector/fault_detector.py +++ b/energy_fault_detector/fault_detector.py @@ -61,13 +61,13 @@ def preprocess_train_data(self, sensor_data: pd.DataFrame, normal_index: pd.Seri # TODO: add list of relevant features to config and protect relevant features (if present) as well. # Determine which features to protect based on config flag - protect = self.config.protect_conditional_features if self.config else True + protect = self.config.train.protect_conditional_features if self.config and self.config.train else True protected_features = ( self.autoencoder.conditional_features or [] ) if protect else [] # Data clipping (outlier clipping) - if self.config.data_clipping: + if self.config.train is not None and self.config.train.data_clipping is not None: logger.debug('Clip data before scaling.') clipper_params = self.config.data_clipping_params.copy() if protected_features: @@ -144,7 +144,8 @@ def fit(self, sensor_data: pd.DataFrame, normal_index: pd.Series = None, save_mo val_recon_error = self.autoencoder.get_reconstruction_error(x_val) if not fit_autoencoder_only: - self._fit_threshold(x=x, y=y, x_val=x_val, fit_on_validation=self.config.fit_threshold_on_val) + fit_on_val = self.config.train.threshold_selector.fit_on_val + self._fit_threshold(x=x, y=y, x_val=x_val, fit_on_validation=fit_on_val) if save_models: model_path, model_date = self.save(overwrite=overwrite_models) @@ -201,7 +202,7 @@ def tune(self, sensor_data: pd.DataFrame, normal_index: Optional[pd.Series] = No if tune_method not in ['threshold', 'decoder', 'full']: raise ValueError(f'Unknown tune method {tune_method}.') - fit_on_val = self.config.fit_threshold_on_val + fit_on_val = self.config.train.threshold_selector.fit_on_val if tune_method == 'threshold' and fit_on_val: logger.warning('Fine-tuning using only validation data for threshold does not make sense if only the' ' threshold is tuned! Setting fit_threshold_on_val to False.') @@ -518,7 +519,7 @@ def _fallback_if_no_conditionals(self) -> None: elif isinstance(self.autoencoder, ConditionalAE): logger.warning("All conditional features are unavailable. " "Falling back from ConditionalAE to MultilayerAutoencoder.") - ae_params = dict(self.config['train']['autoencoder'].get('params', {})) + ae_params = dict(self.config.train.autoencoder.params) ae_params.pop('conditional_features', None) self.autoencoder = MultilayerAutoencoder(**ae_params) diff --git a/energy_fault_detector/quick_fault_detection/configuration.py b/energy_fault_detector/quick_fault_detection/configuration.py index 1c2b4267..92d4d416 100644 --- a/energy_fault_detector/quick_fault_detection/configuration.py +++ b/energy_fault_detector/quick_fault_detection/configuration.py @@ -72,12 +72,12 @@ def update_preprocessor_config(config: Config, features_to_exclude: Union[List[s Config: Updated config object. """ - dp = config['train']['data_preprocessor'] + dp = config.train.data_preprocessor if features_to_exclude is not None: - if dp.get('params'): + if dp.params: # old data preprocessing configuration style - dp['params']['features_to_exclude'] = features_to_exclude + dp.params['features_to_exclude'] = features_to_exclude else: # new configuration style if dp.steps is None: @@ -92,9 +92,9 @@ def update_preprocessor_config(config: Config, features_to_exclude: Union[List[s if not column_selector_found: steps.append({'name': 'column_selector', 'params': {'features_to_exclude': features_to_exclude}}) if angles is not None: - if dp.get('params'): + if dp.params: # old data preprocessing configuration style - dp['params']['angles'] = angles + dp.params['angles'] = angles else: # new configuration style if dp.steps is None: @@ -121,7 +121,7 @@ def update_autoencoder_config(config: Config, autoencoder_params: dict) -> Confi Returns: Config: Updated config object. """ - config['train']['autoencoder']['params'].update(autoencoder_params) + config.train.autoencoder.params.update(autoencoder_params) return config @@ -143,5 +143,5 @@ def update_threshold_config(config: Config, quantile: float) -> Config: logger.warning(f'Quantile for reconstruction error threshold was specified as {quantile} which smaller than 0.' f'To avoid an exception quantile will be set to the default value 0.95') quantile = 0.95 - config['train']['threshold_selector']['params']['quantile'] = quantile + config.train.threshold_selector.params['quantile'] = quantile return config diff --git a/tests/config/test_config.py b/tests/config/test_config.py index 23b19735..130f463d 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -120,7 +120,7 @@ def test_sequence_builder_conf(self): 'pad_value': 0.0, } self.assertDictEqual( - conf['train']['autoencoder']['params']['sequence_builder'], expected + conf.train.autoencoder.params['sequence_builder'], expected ) def test_bidirectional_sequence_builder_conf(self): @@ -133,15 +133,15 @@ def test_bidirectional_sequence_builder_conf(self): 'pad_value': 0.0, } self.assertEqual( - conf['train']['autoencoder']['name'], + conf.train.autoencoder.name, 'BidirectionalLSTMSeq2OneAutoencoder' ) self.assertEqual( - conf['train']['autoencoder']['params']['merge_mode'], + conf.train.autoencoder.params['merge_mode'], 'sum' ) self.assertDictEqual( - conf['train']['autoencoder']['params']['sequence_builder'], + conf.train.autoencoder.params['sequence_builder'], expected ) @@ -155,5 +155,5 @@ def test_sequence_builder_conf(self): 'pad_value': 0.0, } self.assertDictEqual( - conf['train']['autoencoder']['params']['sequence_builder'], expected + conf.train.autoencoder.params['sequence_builder'], expected ) diff --git a/tests/config/test_quickstart_config.py b/tests/config/test_quickstart_config.py index 393c98a1..2f1c9ea9 100644 --- a/tests/config/test_quickstart_config.py +++ b/tests/config/test_quickstart_config.py @@ -27,17 +27,17 @@ def test_generate_quickstart_config_valid_dict(self) -> None: ) # Basic structure checks - self.assertIn("train", cfg) - train = cfg["train"] - self.assertIn("data_preprocessor", train) - self.assertIn("steps", train["data_preprocessor"]) - self.assertIn("autoencoder", train) - self.assertIn("params", train["autoencoder"]) - self.assertIn("threshold_selector", train) - self.assertIn("params", train["threshold_selector"]) + self.assertIsNotNone(cfg.train) + train = cfg.train + self.assertIsNotNone(train.data_preprocessor) + self.assertIsNotNone(train.data_preprocessor.steps) + self.assertIsNotNone(train.autoencoder) + self.assertIsNotNone(train.autoencoder.params) + self.assertIsNotNone(train.threshold_selector) + self.assertIsNotNone(train.threshold_selector.params) # Ensure certain steps exist - step_names = [s["name"] for s in train["data_preprocessor"]["steps"]] + step_names = [s["name"] for s in train.data_preprocessor.steps] self.assertIn("column_selector", step_names) self.assertIn("simple_imputer", step_names) self.assertIn("scaler", step_names) @@ -66,4 +66,4 @@ def test_save_load_quickstart_config(self) -> None: # Compare dictionaries self.assertEqual(cfg.config_dict, loaded_cfg.config_dict) - self.assertEqual(loaded_cfg["train"]["data_splitter"]["validation_split"], 0.25) + self.assertEqual(loaded_cfg.train.data_splitter.validation_split, 0.25) diff --git a/tests/quick_fault_detection/test_configuration.py b/tests/quick_fault_detection/test_configuration.py index 95ebcc00..a94cacea 100644 --- a/tests/quick_fault_detection/test_configuration.py +++ b/tests/quick_fault_detection/test_configuration.py @@ -24,16 +24,16 @@ def test_select_config_low_feature_number(self): angles=['angle'], automatic_optimization=False) - data_preprocessor_steps = config['train']['data_preprocessor']['steps'] + data_preprocessor_steps = config.train.data_preprocessor.steps for step in data_preprocessor_steps: if step['name'] == 'angle_transformer': self.assertListEqual(step['params']['angles'], ['angle']) if step['name'] == 'column_selector': self.assertListEqual(step['params']['features_to_exclude'], ['exclude_feature']) - self.assertEqual(config['train']['autoencoder']['params']['code_size'], expected_code_size) - self.assertListEqual(config['train']['autoencoder']['params']['layers'], expected_layers) - self.assertEqual(config['train']['threshold_selector']['params']['quantile'], 0.99) + self.assertEqual(config.train.autoencoder.params['code_size'], expected_code_size) + self.assertListEqual(config.train.autoencoder.params['layers'], expected_layers) + self.assertEqual(config.train.threshold_selector.params['quantile'], 0.99) def test_select_config_high_feature_number(self): num_features = 100 @@ -48,6 +48,6 @@ def test_select_config_high_feature_number(self): angles=None, automatic_optimization=False) - self.assertEqual(config['train']['autoencoder']['params']['code_size'], expected_code_size) - self.assertListEqual(config['train']['autoencoder']['params']['layers'], expected_layers) - self.assertEqual(config['train']['threshold_selector']['params']['quantile'], 0.99) + self.assertEqual(config.train.autoencoder.params['code_size'], expected_code_size) + self.assertListEqual(config.train.autoencoder.params['layers'], expected_layers) + self.assertEqual(config.train.threshold_selector.params['quantile'], 0.99) diff --git a/tests/quick_fault_detection/test_quick_fault_detector.py b/tests/quick_fault_detection/test_quick_fault_detector.py index c547e24d..1fb2e04e 100644 --- a/tests/quick_fault_detection/test_quick_fault_detector.py +++ b/tests/quick_fault_detection/test_quick_fault_detector.py @@ -148,7 +148,7 @@ def test_features_to_exclude_passed_to_config(self, MockFaultDetector, mock_plot call_kwargs = MockFaultDetector.call_args config = call_kwargs[1]["config"] if "config" in call_kwargs[1] else call_kwargs[0][0] # Check that column_selector step has sensor_0 excluded - steps = config["train"]["data_preprocessor"]["steps"] + steps = config.train.data_preprocessor.steps col_selector = next(s for s in steps if s["name"] == "column_selector") self.assertIn("sensor_0", col_selector["params"]["features_to_exclude"]) diff --git a/tests/test_fault_detector.py b/tests/test_fault_detector.py index 0d8abc69..ce48233b 100644 --- a/tests/test_fault_detector.py +++ b/tests/test_fault_detector.py @@ -616,7 +616,7 @@ def test_fallback_preserves_architecture_params(self): from energy_fault_detector.autoencoders import MultilayerAutoencoder fd = FaultDetector(config=self.conf, model_directory=self.test_dir) - ae_params = self.conf['train']['autoencoder'].get('params', {}) + ae_params = self.conf.train.autoencoder.params sensor_data_no_cond = self.sensor_data.drop(columns=['feature_a', 'feature_b']) fd._resolve_conditional_features(sensor_data_no_cond) @@ -694,7 +694,7 @@ def setUp(self) -> None: self.config_path = os.path.join(PROJECT_ROOT, 'tests/test_data/test_conditional_ae_config.yaml') self.conf = Config(self.config_path) # Set protect_conditional_features to False - self.conf['train'].protect_conditional_features = False + self.conf.train.protect_conditional_features = False self.test_dir = tempfile.mkdtemp() np.random.seed(42) @@ -718,7 +718,7 @@ def test_conditional_features_can_be_dropped_when_unprotected(self): self.conf.config_dict['train']['protect_conditional_features'] = False self.conf.config_dict['train']['data_preprocessor']['steps'].append({'name': 'low_unique_value_filter', 'params': {'min_unique_value_count': 2}}) fd = FaultDetector(config=self.conf, model_directory=self.test_dir) - self.assertFalse(fd.config.protect_conditional_features) + self.assertFalse(fd.config.train.protect_conditional_features) result = fd.fit(sensor_data=self.sensor_data, normal_index=self.normal_index, save_models=False) # feature_a was constant, should have been dropped, triggering fallback @@ -733,7 +733,7 @@ def test_conditional_features_can_be_dropped_when_unprotected(self): def test_protect_true_keeps_constant_conditional(self): """When protect=True (default), constant conditional features are kept.""" - self.conf['train'].protect_conditional_features = True + self.conf.train.protect_conditional_features = True fd = FaultDetector(config=self.conf, model_directory=self.test_dir) fd.fit(sensor_data=self.sensor_data, normal_index=self.normal_index, save_models=False) @@ -783,7 +783,7 @@ class TestProtectConditionalFeaturesConfigProperty(unittest.TestCase): def test_default_is_false(self): """Default value should be False when not specified.""" config = Config(os.path.join(PROJECT_ROOT, 'tests/test_data/test_config.yaml')) - self.assertFalse(config.protect_conditional_features) + self.assertFalse(config.train.protect_conditional_features) def test_explicit_false(self): """Explicit False in config should be respected.""" @@ -796,7 +796,7 @@ def test_explicit_false(self): 'threshold_selector': {'name': 'quantile', 'params': {'quantile': 0.95}}, } }) - self.assertFalse(config.protect_conditional_features) + self.assertFalse(config.train.protect_conditional_features) def test_explicit_true(self): """Explicit True in config should be respected.""" @@ -809,7 +809,7 @@ def test_explicit_true(self): 'threshold_selector': {'name': 'quantile', 'params': {'quantile': 0.95}}, } }) - self.assertTrue(config.protect_conditional_features) + self.assertTrue(config.train.protect_conditional_features) class TestHandleDuplicateIndex(unittest.TestCase): From c5dfae16bae322a16965ac7bcf0b94a29f1df738 Mon Sep 17 00:00:00 2001 From: croelofs <25582572+roelofsc@users.noreply.github.com> Date: Thu, 10 Sep 2026 11:59:47 +0200 Subject: [PATCH 03/18] Simplify Config: add defaults for all sections, use flat DataSplitterConfig fields, remove dead code - AutoencoderConfig: default name='default', params={} so Config() works with no args - DataSplitterConfig: replace params dict with flat fields (train_block_size, val_block_size, validation_split, shuffle) matching the YAML format - DataPreprocessorConfig: default steps=[] instead of None - Remove update_config (dead code, not called anywhere) - Remove dead None checks (train, data_preprocessor no longer Optional) - Simplify DataClipper usage: explicit kwargs instead of model_dump - Remove unused DataPreprocessorConfig import from care2compare.py - Clean up or {} guards in model_factory (params default to {}) - Remove orphaned test_criticality_config.yaml --- energy_fault_detector/config/config.py | 617 ++++++++---------- .../core/fault_detection_model.py | 26 +- energy_fault_detector/core/model_factory.py | 25 +- .../evaluation/care2compare.py | 40 +- energy_fault_detector/fault_detector.py | 18 +- tests/config/test_config.py | 40 +- tests/test_data/test_criticality_config.yaml | 43 -- tests/test_fault_detector.py | 16 +- 8 files changed, 347 insertions(+), 478 deletions(-) delete mode 100644 tests/test_data/test_criticality_config.yaml diff --git a/energy_fault_detector/config/config.py b/energy_fault_detector/config/config.py index 8184b769..25541273 100644 --- a/energy_fault_detector/config/config.py +++ b/energy_fault_detector/config/config.py @@ -1,12 +1,14 @@ """Configuration object for anomaly detection. -The configuration is defined by a set of Pydantic models (section models plus a -top-level :class:`ConfigModel`) that validate the YAML/dict input. The public -:class:`Config` class is a thin wrapper around :class:`ConfigModel` that adds -file I/O and serialization. Model fields (``train``, ``predict``, -``root_cause_analysis``, ``dtype``) are accessible via normal attribute access -on the :class:`Config` wrapper (delegated to the underlying model through -``__getattr__``). +The :class:`Config` class is a Pydantic ``BaseModel`` that validates YAML/dict +input. Top-level sections (``train``, ``root_cause_analysis``, ``dtype``) are +typed fields accessible via normal attribute access +(``config.train.autoencoder.params``). File I/O methods (``from_yaml``, +``write_config``, …) are provided as methods on the model itself. + +All sections have sensible defaults — ``Config()`` with no arguments produces a +ready-to-use configuration (MultilayerAutoencoder, RMSE anomaly score, quantile +threshold selector, default preprocessing pipeline, block data splitter). """ import logging @@ -14,9 +16,8 @@ from pathlib import Path from typing import Any, Dict, List, Literal, Optional -import numpy as np import yaml -from pydantic import BaseModel, ConfigDict, ValidationError, model_validator +from pydantic import BaseModel, ConfigDict, PrivateAttr, ValidationError, model_validator logger = logging.getLogger('energy_fault_detector') @@ -25,19 +26,6 @@ class InvalidConfigFile(Exception): """Raise when the configuration file is not valid.""" -def _format_timedelta(value: np.timedelta64) -> str: - """Format an :class:`np.timedelta64` as a compact string like ``'30s'``. - - Args: - value: timedelta to format. - - Returns: - Compact string representation suitable for YAML round-tripping. - """ - total_seconds = int(value.astype('timedelta64[s]').astype(int)) - return f"{total_seconds}s" - - def _dump_value(value: Any) -> Any: """Recursively dump nested models/lists; plain dicts/lists are kept as-is.""" if isinstance(value, BaseModel): @@ -50,11 +38,8 @@ def _dump_value(value: Any) -> Any: def _model_to_config_dict(model: BaseModel) -> Dict[str, Any]: """Serialize a validated Pydantic model back to a plain configuration dict. - Reproduces the structure ``cerberus.Validator.normalized`` produced: - * fields that are *required* (no default) are always included, even when - their value is ``None`` (e.g. ``train.data_preprocessor`` which is - required but nullable); + their value is ``None``; * fields that are *optional* (have a default) are included only when their value is not ``None`` (falsy defaults such as ``False`` are kept because ``False is not None``); @@ -79,57 +64,110 @@ def _model_to_config_dict(model: BaseModel) -> Dict[str, Any]: # --- Section models ---------------------------------------------------------- -# extra='allow' mirrors the former Cerberus Validator(allow_unknown=True) which -# let unknown keys survive at every nested level. The sole exception is -# DataPreprocessorConfig (extra='forbid') because its Cerberus schema explicitly -# set allow_unknown: False. Leaves (params, steps items) are left as plain -# mutable dicts -- the package never validated their internals with Cerberus -# either, so this is strict parity. +# extra='allow' lets unknown keys survive at every nested level (matching the +# former Cerberus allow_unknown=True). DataPreprocessorConfig uses +# extra='forbid' because its schema explicitly disallowed unknown keys. class AnomalyScoreConfig(BaseModel): """``train.anomaly_score`` section.""" - model_config = ConfigDict(extra='allow') - name: str - params: Optional[Dict[str, Any]] = None + model_config = ConfigDict(extra='allow', validate_assignment=True) + name: str = 'rmse' + params: Dict[str, Any] = {} + + @model_validator(mode='after') + def _none_params_to_empty(self) -> 'AnomalyScoreConfig': + if self.params is None: + self.params = {} + return self class AutoencoderConfig(BaseModel): """``train.autoencoder`` section. - ``params`` accepts a dict or a list (the Cerberus schema allowed both) and is - left opaque: step/autoencoder-specific keys (including ``sequence_builder``) - are not modeled here and are consumed by the registry/model factory. + ``params`` is an opaque dict consumed by the registry/model factory + (includes autoencoder-specific keys like ``sequence_builder``). """ - model_config = ConfigDict(extra='allow') - name: str - params: Dict[str, Any] | List[Any] + model_config = ConfigDict(extra='allow', validate_assignment=True) + name: str = 'default' + params: Dict[str, Any] = {} verbose: Optional[int] = None + @model_validator(mode='after') + def _none_params_to_empty(self) -> 'AutoencoderConfig': + if self.params is None: + self.params = {} + return self + class DataPreprocessorConfig(BaseModel): - """``train.data_preprocessor`` section (``extra='forbid'``).""" + """``train.data_preprocessor`` section (``extra='forbid'``). - model_config = ConfigDict(extra='forbid') + After validation, ``steps`` is always a list (converted from legacy + ``params`` if needed, or defaulted to ``[]``). The ``params`` field is + cleared after conversion so that ``write_config`` produces the ``steps`` + format. An empty ``steps`` list means "use the DataPreprocessor's built-in + default pipeline". + """ + + model_config = ConfigDict(extra='forbid', validate_assignment=True) params: Optional[Dict[str, Any]] = None - steps: Optional[List[Dict[str, Any]]] = None + steps: Optional[List[Dict[str, Any]]] = [] + + @model_validator(mode='before') + @classmethod + def _none_to_empty(cls, data: Any) -> Any: + """Treat ``data_preprocessor: null`` (or missing) as an empty config.""" + if data is None: + return {} + return data + + @model_validator(mode='after') + def _convert_params_to_steps(self) -> 'DataPreprocessorConfig': + if self.steps and self.params: + warnings.warn( + "Both 'data_preprocessor.steps' and 'data_preprocessor.params' provided in config; " + "'data_preprocessor.steps' take precedence and 'data_preprocessor.params' are ignored. " + "Note: 'data_preprocessor.params' will be removed in a future version.", + DeprecationWarning, + stacklevel=2, + ) + self.params = None + elif self.params and not self.steps: + warnings.warn( + "Using deprecated 'data_preprocessor.params' to create a DataPreprocessor. " + "Please update to 'steps'; 'data_preprocessor.params' will be removed in a future version.", + DeprecationWarning, + stacklevel=2, + ) + self.steps = _data_preprocessor_params_to_steps(self.params) + self.params = None + if self.steps is None: + self.steps = [] + return self class ThresholdSelectorConfig(BaseModel): """``train.threshold_selector`` section.""" - model_config = ConfigDict(extra='allow') - name: str + model_config = ConfigDict(extra='allow', validate_assignment=True) + name: str = 'quantile' fit_on_val: bool = False - params: Optional[Dict[str, Any]] = None + params: Dict[str, Any] = {} + + @model_validator(mode='after') + def _none_params_to_empty(self) -> 'ThresholdSelectorConfig': + if self.params is None: + self.params = {} + return self class DataClippingConfig(BaseModel): """``train.data_clipping`` section.""" - model_config = ConfigDict(extra='allow') + model_config = ConfigDict(extra='allow', validate_assignment=True) lower_percentile: Optional[float] = None upper_percentile: Optional[float] = None features_to_exclude: Optional[List[str]] = None @@ -139,14 +177,11 @@ class DataClippingConfig(BaseModel): class DataSplitterConfig(BaseModel): """``train.data_splitter`` section. - Reproduces the Cerberus ``dependencies`` rules: block-size fields require a - block-style ``type`` and the split/shuffle fields require an sklearn-style - ``type``. The default for ``type`` is applied before the ``mode='after'`` - validator runs (Pydantic applies field defaults first), matching Cerberus - which also applied the default during validation. + ``type`` selects block-style vs sklearn-style splitting. The remaining + fields are type-specific options that are validated against ``type``. """ - model_config = ConfigDict(extra='allow') + model_config = ConfigDict(extra='allow', validate_assignment=True) type: Literal['DataSplitter', 'BlockDataSplitter', 'blocks', 'sklearn', 'train_test_split', 'train_val_split'] = 'BlockDataSplitter' train_block_size: Optional[int] = None @@ -158,6 +193,7 @@ class DataSplitterConfig(BaseModel): def _check_dependencies(self) -> 'DataSplitterConfig': block_types = {'DataSplitter', 'BlockDataSplitter', 'blocks'} split_types = {'sklearn', 'train_test_split', 'train_val_split'} + if self.train_block_size is not None and self.type not in block_types: raise ValueError( "train_block_size depends on type in ['DataSplitter', 'BlockDataSplitter', 'blocks']") @@ -173,22 +209,31 @@ def _check_dependencies(self) -> 'DataSplitterConfig': class TrainConfig(BaseModel): - """``train`` section.""" + """``train`` section. - model_config = ConfigDict(extra='allow') - anomaly_score: AnomalyScoreConfig - autoencoder: AutoencoderConfig - data_preprocessor: Optional[DataPreprocessorConfig] # required but nullable -> keep None - threshold_selector: ThresholdSelectorConfig + All sub-sections have defaults; ``TrainConfig()`` produces a ready-to-use + configuration. + """ + + model_config = ConfigDict(extra='allow', validate_assignment=True) + autoencoder: AutoencoderConfig = AutoencoderConfig() + anomaly_score: AnomalyScoreConfig = AnomalyScoreConfig() + data_preprocessor: DataPreprocessorConfig = DataPreprocessorConfig() + threshold_selector: ThresholdSelectorConfig = ThresholdSelectorConfig() data_clipping: Optional[DataClippingConfig] = None - data_splitter: Optional[DataSplitterConfig] = None + data_splitter: DataSplitterConfig = DataSplitterConfig() protect_conditional_features: bool = False class RootCauseAnalysisConfig(BaseModel): - """``root_cause_analysis`` section.""" + """``root_cause_analysis`` section. + + The YAML keeps all ARCANA parameters flat (``alpha``, ``num_iter``, …) at the + section level. The :attr:`params` property returns them as a dict for easy + unpacking (``Arcana(**config.root_cause_analysis.params)``). + """ - model_config = ConfigDict(extra='allow') + model_config = ConfigDict(extra='allow', validate_assignment=True) alpha: Optional[float] = None init_x_bias: Optional[str] = None num_iter: Optional[int] = None @@ -196,72 +241,32 @@ class RootCauseAnalysisConfig(BaseModel): verbose: Optional[bool] = None max_sample_threshold: Optional[int] = None - -class CriticalityConfig(BaseModel): - """``predict.criticality`` section.""" - - model_config = ConfigDict(extra='allow') - max_criticality: Optional[int] = None - - -class PredictConfig(BaseModel): - """``predict`` section.""" - - model_config = ConfigDict(extra='allow') - criticality: Optional[CriticalityConfig] = None + @property + def params(self) -> Dict[str, Any]: + """Return all non-None RCA parameters as a dict (including extras).""" + result = {k: v for k, v in self.__dict__.items() if v is not None and not k.startswith('_')} + extra = getattr(self, '__pydantic_extra__', None) + if extra: + result.update({k: v for k, v in extra.items() if v is not None}) + return result # --- Extra validation helpers ------------------------------------------------ -def _ae_params(model: 'ConfigModel') -> Optional[Dict[str, Any]]: - """Return the autoencoder params dict, or ``None`` if not applicable. - - ``params`` can be a dict or a list; only dict params are relevant for the - extra checks (``sequence_builder``, ``early_stopping`` live inside dicts). - """ - if model.train is None or model.train.autoencoder is None: - return None - params = model.train.autoencoder.params - if isinstance(params, dict): - return params - return None - - -def _parse_timedelta(model: 'ConfigModel') -> None: - """Parse ``sequence_builder.ts_freq`` from a compact string to ``np.timedelta64``. - - Expects ``ts_freq`` under ``train.autoencoder.params.sequence_builder.ts_freq`` - and supports strings like ``'10m'``, ``'1h'``, ``'30s'``. - """ - unit_map = {"min": "m", "sec": "s", "hr": "h", "hour": "h"} - params = _ae_params(model) - if params is None: - return - seq_builder = params.get("sequence_builder") - if not isinstance(seq_builder, dict): - return - ts_freq = seq_builder.get("ts_freq") - if isinstance(ts_freq, str): - digits = "".join(ch for ch in ts_freq if ch.isdigit()) - unit = "".join(ch for ch in ts_freq if not ch.isdigit()) - unit = unit_map.get(unit, unit) - if not digits or not unit: - raise ValueError( - f"Unexpected value for `ts_freq`: {ts_freq!r}. Expected format like '10m', '1h'.") - seq_builder["ts_freq"] = np.timedelta64(int(digits), unit) +def _ae_params(model: 'Config') -> Dict[str, Any]: + """Return the autoencoder params dict.""" + return model.train.autoencoder.params -def _validate_early_stopping(model: 'ConfigModel') -> None: +def _validate_early_stopping(model: 'Config') -> None: """Check whether early_stopping settings are consistent with the data splitter.""" params = _ae_params(model) - if params is None: - return early_stopping = params.get('early_stopping', False) splitter = model.train.data_splitter - validation_split = getattr(splitter, 'validation_split', 0.0) or 0.0 - val_block_size = getattr(splitter, 'val_block_size', 0) or 0 + validation_split = splitter.validation_split or 0.0 + val_block_size = splitter.val_block_size or 0 if not isinstance(validation_split, float): validation_split = 0.0 @@ -274,15 +279,17 @@ def _validate_early_stopping(model: 'ConfigModel') -> None: raise InvalidConfigFile(msg) -def _validate_sequence_fit_on_val(model: 'ConfigModel') -> None: - """Warn if ``fit_on_val=True`` with a sequence model and ``shuffle=True``.""" +def _validate_sequence_fit_on_val(model: 'Config') -> None: + """Warn if ``fit_on_val=True`` with a sequence model and ``shuffle=True``. + + Sequence models need temporally contiguous validation data. Shuffling + breaks that contiguity, and the sequence builder will drop windows that cross + data gaps — potentially leaving no valid windows for threshold fitting. + """ params = _ae_params(model) - if params is None: - return has_sequence_builder = "sequence_builder" in params fit_on_val = model.train.threshold_selector.fit_on_val - splitter = model.train.data_splitter - shuffle = getattr(splitter, 'shuffle', False) + shuffle = model.train.data_splitter.shuffle or False if has_sequence_builder and fit_on_val and shuffle: warnings.warn( @@ -295,42 +302,108 @@ def _validate_sequence_fit_on_val(model: 'ConfigModel') -> None: ) -# --- Top-level model --------------------------------------------------------- +# --- DataPreprocessor params->steps translation ------------------------------ -class ConfigModel(BaseModel): - """Top-level Pydantic model for the anomaly-detection pipeline configuration. +def _data_preprocessor_params_to_steps(params: Dict[str, Any]) -> List[Dict[str, Any]]: + """Translate old ``data_preprocessor.params`` into a ``steps`` specification. + + Args: + params: Legacy params dict. - The top-level uses ``extra='ignore'`` (unknown top-level keys are dropped and - logged) mirroring the former Cerberus behaviour. Section models use - ``extra='allow'`` (or ``extra='forbid'`` for the data preprocessor). + Returns: + List of step-spec dicts to be passed to the DataPreprocessor, e.g.:: + + [ + {"name": "duplicate_to_nan", "params": {...}}, + {"name": "counter_diff_transformer", "params": {...}}, + ... + ] """ - model_config = ConfigDict(extra='ignore', validate_default=True) - train: Optional[TrainConfig] = None - predict: Optional[PredictConfig] = None - root_cause_analysis: Optional[RootCauseAnalysisConfig] = None - dtype: Literal['float32', 'float64'] = 'float32' + p = params or {} + steps: List[Dict[str, Any]] = [] - @model_validator(mode='after') - def _run_extra_checks(self) -> 'ConfigModel': - """Run the three post-validation checks formerly handled by Cerberus extras.""" - _parse_timedelta(self) - _validate_early_stopping(self) - _validate_sequence_fit_on_val(self) - return self + # 0. DuplicateValuesToNan + if p.get("include_duplicate_value_to_nan", False): + steps.append({ + "name": "duplicate_to_nan", + "params": { + "value_to_replace": p.get("value_to_replace", 0), + "n_max_duplicates": p.get("n_max_duplicates", 144), + "features_to_exclude": p.get("duplicate_features_to_exclude"), + }, + }) + # 1. CounterDiffTransformer + counter_cols = p.get("counter_columns_to_transform", []) or [] + if counter_cols: + steps.append({ + "name": "counter_diff_transformer", + "params": { + "counters": counter_cols, + "compute_rate": False, + "reset_strategy": "zero", + }, + }) -# --- Config wrapper ---------------------------------------------------------- + # 2. ColumnSelector + if p.get("include_column_selector", True): + steps.append({ + "name": "column_selector", + "params": { + "max_nan_frac_per_col": p.get("max_nan_frac_per_col", 0.05), + "features_to_exclude": p.get("features_to_exclude"), + }, + }) + # 3. LowUniqueValueFilter + if p.get("include_low_unique_value_filter", True): + steps.append({ + "name": "low_unique_value_filter", + "params": { + "min_unique_value_count": p.get("min_unique_value_count", 2), + "max_col_zero_frac": p.get("max_col_zero_frac", 1.0), + }, + }) + + # 4. AngleTransformer + angles = p.get("angles", []) or [] + if angles: + steps.append({ + "name": "angle_transformer", + "params": {"angles": angles}, + }) + + # 5. SimpleImputer + imputer_params: Dict[str, Any] = {"strategy": p.get("imputer_strategy", "mean")} + if imputer_params["strategy"] == "constant": + imputer_params["fill_value"] = p.get("imputer_fill_value", None) + steps.append({"name": "simple_imputer", "params": imputer_params}) -class Config: + # 6. Scaler + scale = p.get("scale", "standardize") + if scale in ["standardize", "standard", "standardscaler"]: + steps.append({"name": "scaler", "step_name": "scaler", "params": {"scaler_type": "standard"}}) + else: + steps.append({"name": "scaler", "step_name": "scaler", "params": {"scaler_type": "minmax"}}) + + return steps + + +# --- Config (top-level model) ------------------------------------------------ + + +class Config(BaseModel): """Configuration for the anomaly-detection pipeline. Loads and validates a YAML configuration file (or an inline dict) using - Pydantic models. Top-level model fields (``train``, ``predict``, - ``root_cause_analysis``, ``dtype``) are accessible via attribute access on - the wrapper (e.g. ``config.train`` returns a :class:`TrainConfig` model). + Pydantic models. Top-level sections (``train``, ``root_cause_analysis``, + ``dtype``) are accessible via normal attribute access + (e.g. ``config.train.autoencoder.params``). + + All sections have defaults — ``Config()`` with no arguments produces a + ready-to-use configuration. Example: @@ -353,31 +426,49 @@ class Config: config_dict: Inline configuration dictionary. """ - def __init__(self, config_filename: str | Path = None, - config_dict: Dict[str, Any] = None) -> None: - self._model: Optional[ConfigModel] = None - self._configuration_file: Optional[str] = None + model_config = ConfigDict(extra='ignore', validate_default=True, validate_assignment=True) + train: TrainConfig = TrainConfig() + root_cause_analysis: Optional[RootCauseAnalysisConfig] = None + dtype: Literal['float32', 'float64'] = 'float32' + + _configuration_file: Optional[str] = PrivateAttr(default=None) + + @model_validator(mode='after') + def _run_extra_checks(self) -> 'Config': + """Run post-validation checks.""" + _validate_early_stopping(self) + _validate_sequence_fit_on_val(self) + return self + + def __init__(self, config_filename: str | Path | Dict[str, Any] = None, + config_dict: Dict[str, Any] = None, **kwargs: Any) -> None: + if isinstance(config_filename, dict): + config_dict = config_filename + config_filename = None if config_filename is not None or config_dict is not None: self._configuration_file = str(config_filename) if config_filename else None self.read_config(config_dict=config_dict) + else: + super().__init__(**kwargs) - # --- attribute delegation ------------------------------------------------- - - def __getattr__(self, name: str) -> Any: - """Delegate attribute access to the underlying :class:`ConfigModel`. - - ``__getattr__`` is only called when the attribute is not found through - normal lookup, so properties/methods defined on :class:`Config` take - precedence. Only model fields (``train``, ``predict``, etc.) are - delegated. - """ - model = self.__dict__.get('_model') - if model is not None and name in type(model).model_fields: - return getattr(model, name) - raise AttributeError(f"'{type(self).__name__}' has no attribute '{name}'") + @staticmethod + def _log_unknown_keys(data: Any) -> None: + if isinstance(data, dict): + known_keys = set(Config.model_fields.keys()) + for key in list(data.keys()): + if key not in known_keys: + logger.info('Key `%s` is an unknown field and will be ignored.', key) - def __repr__(self) -> str: - return self.config_dict.__repr__() + @classmethod + def _validate(cls, data: Any) -> 'Config': + try: + return cls.model_validate(data) + except ValidationError as exc: + lines = [] + for err in exc.errors(): + loc = '.'.join(str(p) for p in err['loc']) + lines.append(f"{loc}: {err['msg']}") + raise InvalidConfigFile('Configuration is not valid: ' + '; '.join(lines)) from exc # --- factory classmethods ------------------------------------------------- @@ -437,28 +528,17 @@ def read_config(self, config_dict: Dict[str, Any] = None, part: str = None) -> N if part is not None and isinstance(data, dict) and part in data: data = data[part] - self._load_and_validate(data) - - def _load_and_validate(self, data: Dict[str, Any]) -> None: - """Validate *data* with Pydantic and store the resulting model.""" - # Drop and log unknown top-level keys (extra='ignore' discards them). - if isinstance(data, dict): - known_keys = set(ConfigModel.model_fields.keys()) - for key in list(data.keys()): - if key not in known_keys: - logger.info('Key `%s` is an unknown field and will be ignored.', key) - - try: - self._model = ConfigModel.model_validate(data) - except ValidationError as exc: - lines = [] - for err in exc.errors(): - loc = '.'.join(str(p) for p in err['loc']) - lines.append(f"{loc}: {err['msg']}") - raise InvalidConfigFile('Configuration is not valid: ' + '; '.join(lines)) from exc - - if not self.config_dict: + self._log_unknown_keys(data) + validated = self._validate(data) + if not _model_to_config_dict(validated): raise InvalidConfigFile(f'The configuration file is empty for {type(self).__name__}.') + for field_name in type(self).model_fields: + object.__setattr__(self, field_name, getattr(validated, field_name)) + object.__setattr__(self, '__pydantic_extra__', getattr(validated, '__pydantic_extra__', None)) + object.__setattr__(self, '__pydantic_fields_set__', set(validated.__pydantic_fields_set__)) + + def __repr__(self) -> str: + return self.config_dict.__repr__() # --- serialization -------------------------------------------------------- @@ -472,7 +552,7 @@ def config_dict(self) -> Dict[str, Any]: in-place mutations (``config.train.autoencoder.params.update(...)``) persist. """ - return _model_to_config_dict(self._model) + return _model_to_config_dict(self) # --- write / save -------------------------------------------------------- @@ -495,170 +575,9 @@ def write_config(self, file_name: Optional[str] = None, overwrite: bool = False) conf_dict = deepcopy(self.config_dict) - ae_params = conf_dict.get('train', {}).get('autoencoder', {}).get('params', {}) - seq_builder = ae_params.get('sequence_builder') - if isinstance(seq_builder, dict): - sb_ts_freq = seq_builder.get('ts_freq') - if isinstance(sb_ts_freq, np.timedelta64): - seq_builder['ts_freq'] = _format_timedelta(sb_ts_freq) - with open(file_name, 'w', encoding='utf-8') as f: yaml.safe_dump(conf_dict, f) def save(self, file_name: str, overwrite: bool = False) -> None: """Save the configuration to a YAML file. Wrapper for :meth:`write_config`.""" self.write_config(file_name, overwrite) - - def update_config(self, new_config_dict: Dict[str, Any]) -> None: - """Update the configuration with *new_config_dict* and re-validate. - - Args: - new_config_dict: Dictionary with new/updated configuration values. - """ - merged = self.config_dict - merged.update(new_config_dict) - self._load_and_validate(merged) - self._configuration_file = None - - # --- properties with real logic ------------------------------------------- - - @property - def data_preprocessor_steps(self) -> List[Dict[str, Any]]: - """Get the data preprocessor steps. - - If ``data_preprocessor.steps`` is provided it takes precedence over the - deprecated ``data_preprocessor.params`` style. - """ - if self._model.train is None or self._model.train.data_preprocessor is None: - return [] - dp = self._model.train.data_preprocessor - params = dp.params or {} - steps = dp.steps or [] - - if steps and params: - warnings.warn( - "Both 'data_preprocessor.steps' and 'data_preprocessor.params' provided in config; " - "'data_preprocessor.steps' take precedence and 'data_preprocessor.params' are ignored. " - "Note: 'data_preprocessor.params' will be removed in a future version.", - DeprecationWarning, - stacklevel=2, - ) - return steps - - if params and not steps: - warnings.warn( - "Using deprecated 'data_preprocessor.params' to create a DataPreprocessor. " - "Please update to 'steps'; 'data_preprocessor.params' will be removed in a future version.", - DeprecationWarning, - stacklevel=2, - ) - steps = _data_preprocessor_params_to_steps(params) - - return steps or [] - - @property - def arcana_params(self) -> Dict[str, Any]: - """Get the ARCANA parameters as a plain dict (for ``**`` unpacking).""" - if self._model.root_cause_analysis is None: - return {} - return _model_to_config_dict(self._model.root_cause_analysis) - - @property - def data_split_params(self) -> Dict[str, Any]: - """DataSplitter or train_test_split parameters as a plain dict.""" - if self._model.train is None or self._model.train.data_splitter is None: - return {} - return _model_to_config_dict(self._model.train.data_splitter) - - @property - def data_clipping_params(self) -> Dict[str, Any]: - """Data clipping parameters as a plain dict.""" - if self._model.train is None or self._model.train.data_clipping is None: - return {} - return _model_to_config_dict(self._model.train.data_clipping) - - -def _data_preprocessor_params_to_steps(params: Dict[str, Any]) -> List[Dict[str, Any]]: - """Translate old ``data_preprocessor.params`` into a ``steps`` specification. - - Args: - params: Legacy params dict. - - Returns: - List of step-spec dicts to be passed to the DataPreprocessor, e.g.:: - - [ - {"name": "duplicate_to_nan", "params": {...}}, - {"name": "counter_diff_transformer", "params": {...}}, - ... - ] - """ - - p = params or {} - steps: List[Dict[str, Any]] = [] - - # 0. DuplicateValuesToNan - if p.get("include_duplicate_value_to_nan", False): - steps.append({ - "name": "duplicate_to_nan", - "params": { - "value_to_replace": p.get("value_to_replace", 0), - "n_max_duplicates": p.get("n_max_duplicates", 144), - "features_to_exclude": p.get("duplicate_features_to_exclude"), - }, - }) - - # 1. CounterDiffTransformer - counter_cols = p.get("counter_columns_to_transform", []) or [] - if counter_cols: - steps.append({ - "name": "counter_diff_transformer", - "params": { - "counters": counter_cols, - "compute_rate": False, - "reset_strategy": "zero", - }, - }) - - # 2. ColumnSelector - if p.get("include_column_selector", True): - steps.append({ - "name": "column_selector", - "params": { - "max_nan_frac_per_col": p.get("max_nan_frac_per_col", 0.05), - "features_to_exclude": p.get("features_to_exclude"), - }, - }) - - # 3. LowUniqueValueFilter - if p.get("include_low_unique_value_filter", True): - steps.append({ - "name": "low_unique_value_filter", - "params": { - "min_unique_value_count": p.get("min_unique_value_count", 2), - "max_col_zero_frac": p.get("max_col_zero_frac", 1.0), - }, - }) - - # 4. AngleTransformer - angles = p.get("angles", []) or [] - if angles: - steps.append({ - "name": "angle_transformer", - "params": {"angles": angles}, - }) - - # 5. SimpleImputer - imputer_params: Dict[str, Any] = {"strategy": p.get("imputer_strategy", "mean")} - if imputer_params["strategy"] == "constant": - imputer_params["fill_value"] = p.get("imputer_fill_value", None) - steps.append({"name": "simple_imputer", "params": imputer_params}) - - # 6. Scaler - scale = p.get("scale", "standardize") - if scale in ["standardize", "standard", "standardscaler"]: - steps.append({"name": "scaler", "step_name": "scaler", "params": {"scaler_type": "standard"}}) - else: - steps.append({"name": "scaler", "step_name": "scaler", "params": {"scaler_type": "minmax"}}) - - return steps diff --git a/energy_fault_detector/core/fault_detection_model.py b/energy_fault_detector/core/fault_detection_model.py index d4b752b0..d18e9de1 100644 --- a/energy_fault_detector/core/fault_detection_model.py +++ b/energy_fault_detector/core/fault_detection_model.py @@ -195,27 +195,19 @@ def train_val_split(self, x: DataType) -> Tuple[DataType, DataType]: tuple: x_train, x_val """ - data_splitter_params = self.config.data_split_params + splitter = self.config.train.data_splitter - # Normalize aliases - data_splitter_type = data_splitter_params.get('type') - if data_splitter_type in ('sklearn', 'train_test_split', 'train_val_split'): - splitter_kind = 'sklearn' - else: - splitter_kind = 'blocks' - - if splitter_kind == 'blocks': - train_data, val_data = BlockDataSplitter( - train_block_size=data_splitter_params.get('train_block_size'), - val_block_size=data_splitter_params.get('val_block_size'), - ).split(x=x) - else: # 'sklearn' - shuffle = data_splitter_params.get('shuffle') + if splitter.type in ('sklearn', 'train_test_split', 'train_val_split'): train_data, val_data = train_test_split( x, - test_size=data_splitter_params['validation_split'], - shuffle=shuffle if shuffle is not None else False + test_size=splitter.validation_split, + shuffle=splitter.shuffle if splitter.shuffle is not None else False ) + else: + train_data, val_data = BlockDataSplitter( + train_block_size=splitter.train_block_size, + val_block_size=splitter.val_block_size, + ).split(x=x) return train_data, val_data diff --git a/energy_fault_detector/core/model_factory.py b/energy_fault_detector/core/model_factory.py index 173cc94c..841d390b 100644 --- a/energy_fault_detector/core/model_factory.py +++ b/energy_fault_detector/core/model_factory.py @@ -1,6 +1,8 @@ from typing import Union, Dict, TYPE_CHECKING +import numpy as np + from energy_fault_detector.registration import registry from energy_fault_detector.config import Config from energy_fault_detector.data_preprocessing import DataPreprocessor @@ -14,6 +16,19 @@ ModelType = Union["Autoencoder", AnomalyScore, ThresholdSelector, DataPreprocessor] +_TS_FREQ_UNIT_MAP = {"min": "m", "sec": "s", "hr": "h", "hour": "h"} + + +def _parse_ts_freq(ts_freq: str) -> np.timedelta64: + """Parse a compact frequency string like ``'30s'`` or ``'10m'`` to ``np.timedelta64``.""" + digits = "".join(ch for ch in ts_freq if ch.isdigit()) + unit = "".join(ch for ch in ts_freq if not ch.isdigit()) + unit = _TS_FREQ_UNIT_MAP.get(unit, unit) + if not digits or not unit: + raise ValueError( + f"Unexpected value for `ts_freq`: {ts_freq!r}. Expected format like '10m', '1h'.") + return np.timedelta64(int(digits), unit) + class ModelFactory: def __init__(self, config: Config) -> None: @@ -35,7 +50,7 @@ def _initialize_models(self) -> None: train = self.config.train # Data preprocessor - self._models["data_preprocessor"] = DataPreprocessor(steps=self.config.data_preprocessor_steps) + self._models["data_preprocessor"] = DataPreprocessor(steps=train.data_preprocessor.steps) # autoencoder ae_config = train.autoencoder @@ -54,7 +69,9 @@ def _initialize_models(self) -> None: f"sequence_builder config is required for sequence autoencoder {ae_class.__name__}" ) - ts_freq = builder_conf["ts_freq"] # already np.timedelta64 thanks to _parse_timedelta + ts_freq = builder_conf["ts_freq"] + if isinstance(ts_freq, str): + ts_freq = _parse_ts_freq(ts_freq) sequence_builder = SequenceDatasetBuilder( sequence_length=builder_conf["sequence_length"], ts_freq=ts_freq, @@ -70,12 +87,12 @@ def _initialize_models(self) -> None: # anomaly_score score_config = train.anomaly_score score_class = registry.get("anomaly_score", score_config.name) - self._models["anomaly_score"] = score_class(**(score_config.params or {})) + self._models["anomaly_score"] = score_class(**score_config.params) # threshold_selector thresh_config = train.threshold_selector thresh_class = registry.get("threshold_selector", thresh_config.name) - self._models["threshold_selector"] = thresh_class(**(thresh_config.params or {})) + self._models["threshold_selector"] = thresh_class(**thresh_config.params) @property def data_preprocessor(self) -> DataPreprocessor: diff --git a/energy_fault_detector/evaluation/care2compare.py b/energy_fault_detector/evaluation/care2compare.py index 22c94854..01baac68 100644 --- a/energy_fault_detector/evaluation/care2compare.py +++ b/energy_fault_detector/evaluation/care2compare.py @@ -7,7 +7,6 @@ import pandas as pd from energy_fault_detector.config import Config -from energy_fault_detector.config.config import DataPreprocessorConfig from energy_fault_detector.utils.data_downloads import download_zenodo_data logger = logging.getLogger('energy_fault_detector') @@ -294,32 +293,21 @@ def find_step(names: List[str]) -> dict | None: train = config.train dp = train.data_preprocessor - if dp is None: - dp = DataPreprocessorConfig(steps=[]) - train.data_preprocessor = dp - - params = dp.params - steps = dp.steps - if params: - params['angles'] = merge_unique(params.get('angles', []), angle_columns) - params['features_to_exclude'] = merge_unique(params.get('features_to_exclude', []), to_exclude_columns) + + steps = dp.steps or [] + angle_step = find_step(['angle_transformer', 'angle_transform']) + if angle_step is None: + steps.append({'name': 'angle_transformer', 'params': {'angles': angle_columns}}) else: - if steps is None: - dp.steps = [] - steps = dp.steps - angle_step = find_step(['angle_transformer', 'angle_transform']) - if angle_step is None: - steps.append({'name': 'angle_transformer', 'params': {'angles': angle_columns}}) - else: - angle_params = angle_step.setdefault('params', {}) - angle_params['angles'] = merge_unique(angle_params.get('angles', []), angle_columns) - colsel_step = find_step(['column_selector']) - if colsel_step is None: - steps.append({'name': 'column_selector', 'params': {'features_to_exclude': to_exclude_columns}}) - else: - colsel_params = colsel_step.setdefault('params', {}) - colsel_params['features_to_exclude'] = merge_unique( - colsel_params.get('features_to_exclude', []), to_exclude_columns) + angle_params = angle_step.setdefault('params', {}) + angle_params['angles'] = merge_unique(angle_params.get('angles', []), angle_columns) + colsel_step = find_step(['column_selector']) + if colsel_step is None: + steps.append({'name': 'column_selector', 'params': {'features_to_exclude': to_exclude_columns}}) + else: + colsel_params = colsel_step.setdefault('params', {}) + colsel_params['features_to_exclude'] = merge_unique( + colsel_params.get('features_to_exclude', []), to_exclude_columns) def _get_column_map(self, wind_farm: str) -> Dict[str, str]: """Maps anonymized columns to human-readable format using feature descriptions""" diff --git a/energy_fault_detector/fault_detector.py b/energy_fault_detector/fault_detector.py index 17aeea55..b12f00f0 100644 --- a/energy_fault_detector/fault_detector.py +++ b/energy_fault_detector/fault_detector.py @@ -67,14 +67,19 @@ def preprocess_train_data(self, sensor_data: pd.DataFrame, normal_index: pd.Seri ) if protect else [] # Data clipping (outlier clipping) - if self.config.train is not None and self.config.train.data_clipping is not None: + if self.config.train.data_clipping is not None: logger.debug('Clip data before scaling.') - clipper_params = self.config.data_clipping_params.copy() + clip = self.config.train.data_clipping + features_to_exclude = clip.features_to_exclude or [] if protected_features: - existing_exclusions = clipper_params.get('features_to_exclude', []) - clipper_params['features_to_exclude'] = list(set(existing_exclusions + protected_features)) + features_to_exclude = list(set(features_to_exclude + protected_features)) logger.debug(f'Excluding conditional features from clipping: {protected_features}') - data_clipper = DataClipper(**clipper_params) + data_clipper = DataClipper( + lower_percentile=clip.lower_percentile, + upper_percentile=clip.upper_percentile, + features_to_exclude=features_to_exclude or None, + features_to_clip=clip.features_to_clip, + ) data_clipper.fit(x=x) x = data_clipper.transform(x) @@ -403,7 +408,8 @@ def run_root_cause_analysis(self, sensor_data: pd.DataFrame, track_losses: bool # backwards compatibility, old models did not save config, just use default parameters rca = Arcana(model=self.autoencoder) else: - rca = Arcana(model=self.autoencoder, **self.config.arcana_params) + rca = Arcana(model=self.autoencoder, + **(self.config.root_cause_analysis.params or {})) df_arcana_bias, arcana_losses, tracked_bias = rca.find_arcana_bias(x=x_prepped, track_losses=track_losses, diff --git a/tests/config/test_config.py b/tests/config/test_config.py index 130f463d..965282da 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -3,8 +3,6 @@ import shutil import unittest -import numpy as np - from energy_fault_detector.config import Config, InvalidConfigFile PROJECT_ROOT = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), '..') @@ -23,7 +21,7 @@ def test_init(self): self.assertDictEqual(conf.config_dict['train'], { 'anomaly_score': {'name': 'mahalanobis', 'params': {'pca': True, 'pca_min_var': 0.85}}, - 'data_preprocessor': None, # unspecified, default pipeline + 'data_preprocessor': {'steps': []}, 'autoencoder': {'name': 'MultilayerAutoencoder', 'verbose': 0, 'params': {'layers': [300], @@ -37,7 +35,8 @@ def test_init(self): 'threshold_selector': {'name': 'FDR', 'params': {'target_false_discovery_rate': 0.8}, 'fit_on_val': False}, - 'data_splitter': {'train_block_size': 7, 'val_block_size': 3, 'type': 'BlockDataSplitter'}, + 'data_splitter': {'type': 'BlockDataSplitter', + 'train_block_size': 7, 'val_block_size': 3}, 'data_clipping': {'lower_percentile': 0.01, 'upper_percentile': 0.99}, 'protect_conditional_features': False, }) @@ -51,19 +50,13 @@ def test_arcana_config(self): conf = Config(os.path.join(PROJECT_ROOT, './tests/test_data/test_config.yaml')) self.assertTrue(conf.root_cause_analysis) self.assertDictEqual( - conf.arcana_params, + conf.root_cause_analysis.params, {'alpha': 0.8, 'num_iter': 200, 'init_x_bias': 'recon'} ) conf = Config(os.path.join(PROJECT_ROOT, './tests/test_data/test_config_no_rca.yaml')) self.assertFalse(conf.root_cause_analysis) - def test_criticality_config(self): - conf = Config(os.path.join(PROJECT_ROOT, './tests/test_data/test_criticality_config.yaml')) - self.assertDictEqual(conf.config_dict['predict'], { - 'criticality': {'max_criticality': 144} - }) - def test_early_stopping_val_split_config(self): conf = Config(os.path.join(PROJECT_ROOT, './tests/test_data/test_early_stopping_val_split_config.yaml')) self.assertDictEqual(conf.config_dict['train']['autoencoder']['params'], { @@ -115,7 +108,7 @@ def test_sequence_builder_conf(self): expected = { 'sequence_length': 36, 'stride': 1, - 'ts_freq': np.timedelta64(30, 's'), # parsed by _parse_timedelta into np.timedelta64(10, 'm') + 'ts_freq': '30s', 'pad_incomplete': False, 'pad_value': 0.0, } @@ -128,7 +121,7 @@ def test_bidirectional_sequence_builder_conf(self): expected = { 'sequence_length': 36, 'stride': 1, - 'ts_freq': np.timedelta64(30, 's'), + 'ts_freq': '30s', 'pad_incomplete': False, 'pad_value': 0.0, } @@ -145,15 +138,12 @@ def test_bidirectional_sequence_builder_conf(self): expected ) - def test_sequence_builder_conf(self): - conf = Config(os.path.join(PROJECT_ROOT, './tests/test_data/test_config_ts_freq.yaml')) - expected = { - 'sequence_length': 36, - 'stride': 1, - 'ts_freq': np.timedelta64(30, 's'), # parsed by _parse_timedelta into np.timedelta64(10, 'm') - 'pad_incomplete': False, - 'pad_value': 0.0, - } - self.assertDictEqual( - conf.train.autoencoder.params['sequence_builder'], expected - ) + def test_defaults_only_autoencoder(self): + """Config with only autoencoder should get sensible defaults for everything else.""" + conf = Config(config_dict={'train': {'autoencoder': {'name': 'MultilayerAutoencoder', + 'params': {'layers': [10]}}}}) + self.assertEqual(conf.train.anomaly_score.name, 'rmse') + self.assertEqual(conf.train.threshold_selector.name, 'quantile') + self.assertIsNotNone(conf.train.data_preprocessor) + self.assertEqual(conf.train.data_splitter.type, 'BlockDataSplitter') + self.assertFalse(conf.train.protect_conditional_features) diff --git a/tests/test_data/test_criticality_config.yaml b/tests/test_data/test_criticality_config.yaml deleted file mode 100644 index f366d4c7..00000000 --- a/tests/test_data/test_criticality_config.yaml +++ /dev/null @@ -1,43 +0,0 @@ -train: - anomaly_score: - name: 'mahalanobis' - params: - pca: true - pca_min_var: 0.85 - data_preprocessor: - steps: - - name: column_selector - params: - features_to_exclude: - - feature1 - - feature2 - autoencoder: - name: 'MultilayerAutoencoder' - params: - layers: [300] - code_size: 50 - learning_rate: 0.001 - decay_rate: 0.001 - decay_steps: 100 - batch_size: 144 - epochs: 10 - loss_name: 'mean_squared_error' - threshold_selector: - name: 'FDR' - params: - target_false_discovery_rate: 0.8 - data_splitter: - train_block_size: 7 - val_block_size: 3 - data_clipping: - lower_percentile: 0.01 - upper_percentile: 0.99 - -root_cause_analysis: - alpha: 0.8 - init_x_bias: recon - num_iter: 200 - -predict: - criticality: - max_criticality: 144 diff --git a/tests/test_fault_detector.py b/tests/test_fault_detector.py index ce48233b..aae7ad63 100644 --- a/tests/test_fault_detector.py +++ b/tests/test_fault_detector.py @@ -195,8 +195,8 @@ def test_init(self): self.assertEqual(fault_detector.model_directory, str(self.test_model_dir)) self.assertEqual(fault_detector.config, self.conf) - def test_save_models(self): - self.conf.write_config = MagicMock() + @patch.object(Config, 'write_config') + def test_save_models(self, mock_write_config): fault_detector = self._create_fault_detector(self.conf) asset_id = 1 @@ -209,8 +209,8 @@ def test_save_models(self): self.assertEqual(model_object.save.call_args[0][0], os.path.join(fault_detector.model_directory, str(asset_id), dt, name)) - fault_detector.config.write_config.assert_called_once() - self.assertEqual(fault_detector.config.write_config.call_args[0][0], + mock_write_config.assert_called_once() + self.assertEqual(mock_write_config.call_args[0][0], os.path.join(fault_detector.model_directory, str(asset_id), dt, 'config.yaml')) @patch("energy_fault_detector.core.fault_detection_model.FaultDetectionModel._load_pickled_model") @@ -233,8 +233,8 @@ def test_load_models(self, mock_load_pickled_model, mock_read_config): self.assertEqual(call_args[1]['model_type'], name) self.assertEqual(call_args[1]['model_directory'], os.path.join('path_to_saved_models', name)) - def test_train(self): - self.conf.write_config = MagicMock() + @patch.object(Config, 'write_config') + def test_train(self, mock_write_config): fault_detector = self._create_fault_detector(self.conf) mock_data_preprocessor.transform.side_effect = [self.sensor_data[self.normal_index], @@ -258,7 +258,7 @@ def test_train(self): mock_threshold.fit.assert_called_once() # saved models: mock_score.save.assert_called_once() - self.conf.write_config.assert_called_once() + mock_write_config.assert_called_once() model_dir = os.path.join(fault_detector.model_directory, fault_detector.save_timestamps[0]) model_date = results.model_date @@ -278,7 +278,7 @@ def test_train(self): save_models=False) mock_score.save.assert_not_called() - self.assertEqual(self.conf.write_config.call_count, 1) + self.assertEqual(mock_write_config.call_count, 1) def test_tune(self): mock_data_preprocessor.transform.side_effect = [self.sensor_data[self.normal_index], From 8f0706407f0ae7948ebe3c2fefe76a0f6132d063 Mon Sep 17 00:00:00 2001 From: croelofs <25582572+roelofsc@users.noreply.github.com> Date: Thu, 10 Sep 2026 12:00:06 +0200 Subject: [PATCH 04/18] Fix notebook API usage: migrate dict-style config access to attribute access - predist_utils.py: replace config['train']['autoencoder']['params'] with config.train.autoencoder.params and config['train']['data_preprocessor'] with config.train.data_preprocessor.steps - Example - Create new model classes.ipynb: migrate deprecated data_preprocessor.params to steps format --- .../Example - Create new model classes.ipynb | 15 ++++++-------- notebooks/PreDist/predist_utils.py | 20 +++++++------------ 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/notebooks/Example - Create new model classes.ipynb b/notebooks/Example - Create new model classes.ipynb index f8cfa9b3..0df49dd5 100644 --- a/notebooks/Example - Create new model classes.ipynb +++ b/notebooks/Example - Create new model classes.ipynb @@ -151,15 +151,12 @@ " 'upper_percentile': 0.999\n", " },\n", " 'data_preprocessor': {\n", - " 'params': {\n", - " 'include_column_selector': True,\n", - " 'include_low_unique_value_filter': True,\n", - " 'include_duplicate_value_to_nan': False,\n", - " 'max_col_zero_frac': 0.99,\n", - " 'max_nan_frac_per_col': 0.05,\n", - " 'min_unique_value_count': 10,\n", - " 'scale': 'minmax'\n", - " }\n", + " 'steps': [\n", + " {'name': 'column_selector', 'params': {'max_nan_frac_per_col': 0.05}},\n", + " {'name': 'low_unique_value_filter', 'params': {'min_unique_value_count': 10, 'max_col_zero_frac': 0.99}},\n", + " {'name': 'simple_imputer', 'params': {'strategy': 'mean'}},\n", + " {'name': 'scaler', 'params': {'scaler_type': 'minmax'}}\n", + " ]\n", " },\n", " 'data_splitter': {\n", " 'shuffle': True,\n", diff --git a/notebooks/PreDist/predist_utils.py b/notebooks/PreDist/predist_utils.py index d75fde3e..1cbf7ecf 100644 --- a/notebooks/PreDist/predist_utils.py +++ b/notebooks/PreDist/predist_utils.py @@ -59,7 +59,7 @@ def train_or_get_model(event_id: int, dataset: PreDistDataset, manufacturer: int # Add the code size to the AE configuration, based on the bottleneck ratio # code_size is part of the model configuration, so we overwrite the parameter of the underlying dictionary. bottleneck = calculate_bottleneck(train_data, local_conf, bottleneck_ratio) - local_conf['train']['autoencoder']['params']['code_size'] = bottleneck + local_conf.train.autoencoder.params['code_size'] = bottleneck # For the conditional autoencoders, add time features if ts_features: @@ -118,7 +118,7 @@ def calculate_bottleneck(df: pd.DataFrame, config: Config, ratio: float) -> int: """ # Get the conditional features from the config - ae_params = config['train']['autoencoder']['params'] + ae_params = config.train.autoencoder.params cond_features = ae_params.get('conditional_features', []) # Exclude conditions (not compressed) @@ -126,17 +126,11 @@ def calculate_bottleneck(df: pd.DataFrame, config: Config, ratio: float) -> int: # Check for feature exclusions in config excluded = [] - dp_config = config['train'].get('data_preprocessor', {}) - if dp_config.get('params'): - # params-based data prep config - excluded = dp_config.get('params').get('features_to_exclude', []) - else: - # steps-based data prep config - steps = config['train']['data_preprocessor'].get('steps', []) - for step in steps: - if step['name'] == 'column_selector': - excluded = step['params'].get('features_to_exclude', []) - break + steps = config.train.data_preprocessor.steps or [] + for step in steps: + if step['name'] == 'column_selector': + excluded = step.get('params', {}).get('features_to_exclude', []) + break # Remove the excluded features from the input dimension input_dim -= len([e for e in excluded if e in df.columns]) From 2be16b0aadc133ff2bfdc554287f4f6e5440b456 Mon Sep 17 00:00:00 2001 From: croelofs <25582572+roelofsc@users.noreply.github.com> Date: Thu, 10 Sep 2026 13:17:04 +0200 Subject: [PATCH 05/18] Update docs for config refactor: remove update_config reference and predict section - configuration.rst: replace update_config example with direct attribute access - configuration.rst: remove obsolete 'Prediction options' (predict section removed) - usage_examples.rst: remove reference to optional predict section - advanced_config.yaml: remove predict/criticality block - sequence_models.rst: fix ts_freq attribution (model factory, not config parser) - Remove orphaned old_config.yaml (deprecated data_preprocessor.params format) --- docs/configuration.rst | 14 ++++++-------- docs/examples/advanced_config.yaml | 4 ---- docs/examples/old_config.yaml | 26 -------------------------- docs/sequence_models.rst | 4 ++-- docs/usage_examples.rst | 1 - 5 files changed, 8 insertions(+), 41 deletions(-) delete mode 100644 docs/examples/old_config.yaml diff --git a/docs/configuration.rst b/docs/configuration.rst index 1bf2d481..5aaba8be 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -54,23 +54,21 @@ You can look up the names for the available model classes in the class registry: Configuration updates ^^^^^^^^^^^^^^^^^^^^^ -To update the configuration 'on the fly' (for example for hyperparameter optimization), you provide a new -configuration dictionary via the :py:obj:`Config.update_config ` method: +To update the configuration 'on the fly' (for example for hyperparameter optimization), modify the +attributes directly and create a new :class:`~energy_fault_detector.FaultDetector`: .. code-block:: python from energy_fault_detector.config import Config - from copy import deepcopy + from energy_fault_detector import FaultDetector config = Config('configs/base_config.yaml') # update some parameters: - new_config_dict = deepcopy(config.config_dict) - new_config_dict['train']['anomaly_score']['name'] = 'mahalanobis' - config = Config(new_config_dict) + config.train.anomaly_score.name = 'mahalanobis' - # or create a new configuration object and model - new_model = FaultDetector(Config(config_dict=new_config_dict)) + # create a new model with the updated config + new_model = FaultDetector(config) Detailed configuration ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/docs/examples/advanced_config.yaml b/docs/examples/advanced_config.yaml index 3ec6181c..792af351 100644 --- a/docs/examples/advanced_config.yaml +++ b/docs/examples/advanced_config.yaml @@ -120,7 +120,3 @@ root_cause_analysis: init_x_bias: recon num_iter: 1000 verbose: true - -predict: - criticality: - max_criticality: 144 diff --git a/docs/examples/old_config.yaml b/docs/examples/old_config.yaml deleted file mode 100644 index 4e0f454a..00000000 --- a/docs/examples/old_config.yaml +++ /dev/null @@ -1,26 +0,0 @@ -train: - # ... - - data_preprocessor: - # only imputation and scaling are done by default, other steps can be skipped. - params: - imputer_strategy: 'mean' - scale: 'standardize' # standard scaling or minmax scaling (minmax) - include_column_selector: true # whether to apply the ColumnSelector - max_nan_frac_per_col: 0.05 # ColumnSelector option - drop columns where >5% is NaN. - features_to_exclude: # ColumnSelector option - features to always exclude - - feature1 - - feature2 - angles: # list of angles to transform to sine/cosine values; skipped if none provided - - angle1 - - angle2 - include_low_unique_value_filter: true # whether to apply the LowVarianceFilter - min_unique_value_count: 2 # LowVarianceFilter option - drop columns with less than 3 unique values - max_col_zero_frac: 0.99 # LowVarianceFilter option - drop columns which are at least 90% zero - include_duplicate_value_to_nan: false # whether to apply the DuplicateValuesToNan - value_to_replace: 0 # DuplicateValuesToNan option - if duplicated, replace duplicates with NaN - n_max_duplicates: 6 # DuplicateValuesToNan option - if duplicated for n_max_duplicates, replace after 6th value with NaN - duplicate_features_to_exclude: # DuplicateValuesToNan option - list of feature to not transform with DuplicateValuesToNan - - do_not_replace_value_with_nan - - # ... diff --git a/docs/sequence_models.rst b/docs/sequence_models.rst index bcb9d726..6210c728 100644 --- a/docs/sequence_models.rst +++ b/docs/sequence_models.rst @@ -71,8 +71,8 @@ Important points: - ``stride``: - ``stride=1`` → heavily overlapping windows, - ``stride=sequence_length`` → disjoint windows. -- ``ts_freq``: expected sampling interval. The config parser converts - strings like ``"30s"``, ``"10m"`` into ``numpy.timedelta64``. +- ``ts_freq``: expected sampling interval. Strings like ``"30s"``, ``"10m"`` + are converted to ``numpy.timedelta64`` when the model is initialized. - ``pad_incomplete``: if ``true``, the data is resampled to a regular grid at ``ts_freq`` and missing timestamps are filled with ``pad_value``. diff --git a/docs/usage_examples.rst b/docs/usage_examples.rst index 1c80de25..a01afb10 100644 --- a/docs/usage_examples.rst +++ b/docs/usage_examples.rst @@ -206,7 +206,6 @@ The config typically has: - ``data_splitter``: how training/validation sets are split, - optional ``data_clipping``: outlier clipping on training data only. - an optional ``root_cause_analysis`` section for ARCANA. -- an optional ``predict`` section (e.g. criticality settings). For most users, the easiest way to create a valid configuration is via :func:`generate_quickstart_config `: From db7f2fe3ef0427f48fafc40a016af850cb4cda9c Mon Sep 17 00:00:00 2001 From: croelofs <25582572+roelofsc@users.noreply.github.com> Date: Thu, 10 Sep 2026 14:52:42 +0200 Subject: [PATCH 06/18] Simplify Config constructor and make early-stopping validation type-aware - Remove from_yaml/from_dict/read_config; the constructor now accepts a YAML path or an inline dict (Config('file.yaml'), Config({'train': {...}})). - Drop the _check_dependencies validator from DataSplitterConfig; the splitter ignores irrelevant fields. - Make _validate_early_stopping type-aware: check val_block_size for block splitters, validation_split for sklearn splitters. - Set DataSplitterConfig default to sklearn with validation_split=0.1 and shuffle=False so early stopping and fit_on_val work out of the box. - Revert DataPrepStepConfig to plain dicts (dict-style access in DataPreprocessor and other consumers). - Add _format_validation_error helper converting Pydantic ValidationError into InvalidConfigFile. - Update README quickstart to Config() and document default split behavior. --- README.md | 8 +- docs/configuration.rst | 4 +- energy_fault_detector/config/config.py | 178 ++++++++----------------- tests/config/test_config.py | 22 ++- tests/test_fault_detector.py | 6 +- 5 files changed, 86 insertions(+), 132 deletions(-) diff --git a/README.md b/README.md index 0a0042d5..00457c66 100644 --- a/README.md +++ b/README.md @@ -49,15 +49,14 @@ pip install energy-fault-detector[dev] ```python import pandas as pd from energy_fault_detector import FaultDetector, Config -from energy_fault_detector.config import generate_quickstart_config ### 1. Load your data df = pd.read_csv("my_data.csv", parse_dates=["timestamp"], index_col="timestamp") sensor_data = df[["power", "wind_speed", "pitch"]] normal_index = df["status"] == "normal" # optional boolean mask -### 2. Generate a default configuration -config = generate_quickstart_config() +### 2. Create a default configuration +config = Config() # MultilayerAutoencoder, RMSE score, quantile threshold, default preprocessing ### 3. Train a normal-behaviour model fault_detector = FaultDetector(config=config, model_directory="my_model") @@ -69,6 +68,9 @@ results = fault_detector.predict(sensor_data=sensor_data) print(results.predicted_anomalies.sum(), "anomalies detected") ``` +To generate a config YAML with custom preprocessing (angle columns, scaler, etc.), see +[`generate_quickstart_config`](https://aefdi.github.io/EnergyFaultDetector/configuration.html). + More examples: [Usage examples](https://aefdi.github.io/EnergyFaultDetector/usage_examples.html). ## Quick Fault Detection (CLI) diff --git a/docs/configuration.rst b/docs/configuration.rst index 5aaba8be..35f5594b 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -148,8 +148,8 @@ Other training configuration sections - Data splitter (``train.data_splitter``): - - ``type``: one of ``BlockDataSplitter`` (aliases: ``blocks``, ``DataSplitter``), or ``sklearn`` (alias ``train_test_split``). - - For sklearn: ``validation_split`` (float in (0, 1)) and ``shuffle`` (bool). + - ``type``: one of ``sklearn`` (alias ``train_test_split``) or ``BlockDataSplitter`` (aliases: ``blocks``, ``DataSplitter``). Default: ``sklearn``. + - For sklearn: ``validation_split`` (float in (0, 1), default 0.1 = last 10%) and ``shuffle`` (bool, default False). - For :py:obj:`BlockDataSplitter `: ``train_block_size`` and ``val_block_size``. - Early stopping guard: if ``train.autoencoder.params.early_stopping`` is true, you must either set a valid ``validation_split`` in (0, 1), or use :py:obj:`BlockDataSplitter ` diff --git a/energy_fault_detector/config/config.py b/energy_fault_detector/config/config.py index 25541273..873f67cd 100644 --- a/energy_fault_detector/config/config.py +++ b/energy_fault_detector/config/config.py @@ -3,12 +3,13 @@ The :class:`Config` class is a Pydantic ``BaseModel`` that validates YAML/dict input. Top-level sections (``train``, ``root_cause_analysis``, ``dtype``) are typed fields accessible via normal attribute access -(``config.train.autoencoder.params``). File I/O methods (``from_yaml``, -``write_config``, …) are provided as methods on the model itself. +(``config.train.autoencoder.params``). File I/O (``Config('file.yaml')``, +``write_config``) is built into the constructor and model methods. All sections have sensible defaults — ``Config()`` with no arguments produces a ready-to-use configuration (MultilayerAutoencoder, RMSE anomaly score, quantile -threshold selector, default preprocessing pipeline, block data splitter). +threshold selector, default preprocessing pipeline, sklearn data splitter with +10% validation split). """ import logging @@ -26,6 +27,15 @@ class InvalidConfigFile(Exception): """Raise when the configuration file is not valid.""" +def _format_validation_error(exc: ValidationError) -> InvalidConfigFile: + """Convert a Pydantic ``ValidationError`` into an :class:`InvalidConfigFile`.""" + lines = [] + for err in exc.errors(): + loc = '.'.join(str(p) for p in err['loc']) + lines.append(f"{loc}: {err['msg']}") + return InvalidConfigFile('Configuration is not valid: ' + '; '.join(lines)) + + def _dump_value(value: Any) -> Any: """Recursively dump nested models/lists; plain dicts/lists are kept as-is.""" if isinstance(value, BaseModel): @@ -178,34 +188,21 @@ class DataSplitterConfig(BaseModel): """``train.data_splitter`` section. ``type`` selects block-style vs sklearn-style splitting. The remaining - fields are type-specific options that are validated against ``type``. + fields are type-specific options; irrelevant ones are ignored by the + splitter implementation. + + Defaults: ``sklearn`` with ``validation_split=0.1`` and ``shuffle=False``, + i.e. the last 10% of the data (in original order) is used as a validation + set. This enables early stopping and ``fit_on_val`` out of the box. """ model_config = ConfigDict(extra='allow', validate_assignment=True) type: Literal['DataSplitter', 'BlockDataSplitter', 'blocks', 'sklearn', - 'train_test_split', 'train_val_split'] = 'BlockDataSplitter' + 'train_test_split', 'train_val_split'] = 'sklearn' train_block_size: Optional[int] = None val_block_size: Optional[int] = None - validation_split: Optional[float] = None - shuffle: Optional[bool] = None - - @model_validator(mode='after') - def _check_dependencies(self) -> 'DataSplitterConfig': - block_types = {'DataSplitter', 'BlockDataSplitter', 'blocks'} - split_types = {'sklearn', 'train_test_split', 'train_val_split'} - - if self.train_block_size is not None and self.type not in block_types: - raise ValueError( - "train_block_size depends on type in ['DataSplitter', 'BlockDataSplitter', 'blocks']") - if self.val_block_size is not None and self.type not in block_types: - raise ValueError( - "val_block_size depends on type in ['DataSplitter', 'BlockDataSplitter', 'blocks']") - if self.validation_split is not None and self.type not in split_types: - raise ValueError( - "validation_split depends on type in ['sklearn', 'train_test_split', 'train_val_split']") - if self.shuffle is not None and self.type not in {'sklearn', 'train_test_split'}: - raise ValueError("shuffle depends on type in ['sklearn', 'train_test_split']") - return self + validation_split: Optional[float] = 0.1 + shuffle: Optional[bool] = False class TrainConfig(BaseModel): @@ -265,13 +262,16 @@ def _validate_early_stopping(model: 'Config') -> None: early_stopping = params.get('early_stopping', False) splitter = model.train.data_splitter - validation_split = splitter.validation_split or 0.0 - val_block_size = splitter.val_block_size or 0 - - if not isinstance(validation_split, float): - validation_split = 0.0 + block_types = {'DataSplitter', 'BlockDataSplitter', 'blocks'} - validation = 0 < validation_split < 1 or val_block_size > 0 + if splitter.type in block_types: + val_block_size = splitter.val_block_size or 0 + validation = val_block_size > 0 + else: + validation_split = splitter.validation_split or 0.0 + if not isinstance(validation_split, float): + validation_split = 0.0 + validation = 0 < validation_split < 1 if early_stopping and not validation: msg = ('Configuration is not valid: If early_stopping is enabled either validation_split or ' @@ -411,19 +411,20 @@ class Config(BaseModel): from energy_fault_detector.config import Config + # defaults + config = Config() + # from YAML file - config = Config.from_yaml('config.yaml') + config = Config('config.yaml') # from dict - config = Config.from_dict({'train': {...}}) - - # legacy constructor (still supported) - config = Config('config.yaml') - config = Config(config_dict={'train': {...}}) + config = Config({'train': {...}}) Args: - config_filename: Path to a YAML configuration file. - config_dict: Inline configuration dictionary. + config_filename: Path to a YAML configuration file, or an inline + configuration dictionary. + config_dict: Inline configuration dictionary (alternative to passing + a dict as the first positional argument). """ model_config = ConfigDict(extra='ignore', validate_default=True, validate_assignment=True) @@ -445,9 +446,24 @@ def __init__(self, config_filename: str | Path | Dict[str, Any] = None, if isinstance(config_filename, dict): config_dict = config_filename config_filename = None - if config_filename is not None or config_dict is not None: - self._configuration_file = str(config_filename) if config_filename else None - self.read_config(config_dict=config_dict) + + if config_filename is not None: + with open(config_filename, 'r', encoding='utf-8') as f: + data = yaml.safe_load(f) + if data is None: + raise InvalidConfigFile('The configuration file is empty!') + self._log_unknown_keys(data) + try: + super().__init__(**data) + except ValidationError as exc: + raise _format_validation_error(exc) from exc + object.__setattr__(self, '_configuration_file', str(config_filename)) + elif config_dict is not None: + self._log_unknown_keys(config_dict) + try: + super().__init__(**config_dict) + except ValidationError as exc: + raise _format_validation_error(exc) from exc else: super().__init__(**kwargs) @@ -459,84 +475,6 @@ def _log_unknown_keys(data: Any) -> None: if key not in known_keys: logger.info('Key `%s` is an unknown field and will be ignored.', key) - @classmethod - def _validate(cls, data: Any) -> 'Config': - try: - return cls.model_validate(data) - except ValidationError as exc: - lines = [] - for err in exc.errors(): - loc = '.'.join(str(p) for p in err['loc']) - lines.append(f"{loc}: {err['msg']}") - raise InvalidConfigFile('Configuration is not valid: ' + '; '.join(lines)) from exc - - # --- factory classmethods ------------------------------------------------- - - @classmethod - def from_yaml(cls, path: str | Path) -> 'Config': - """Load configuration from a YAML file. - - Args: - path: Path to the YAML configuration file. - - Returns: - Validated configuration instance. - - Raises: - InvalidConfigFile: If the file is empty or fails validation. - """ - return cls(config_filename=path) - - @classmethod - def from_dict(cls, config_dict: Dict[str, Any]) -> 'Config': - """Create a configuration from an inline dictionary. - - Args: - config_dict: Configuration dictionary. - - Returns: - Validated configuration instance. - - Raises: - InvalidConfigFile: If the dictionary is None or fails validation. - """ - if config_dict is None: - raise InvalidConfigFile('The configuration file is empty!') - return cls(config_dict=config_dict) - - # --- loading / validation ------------------------------------------------- - - def read_config(self, config_dict: Dict[str, Any] = None, part: str = None) -> None: - """Read and validate the configuration from file or dict. - - Args: - config_dict: Inline configuration dictionary. If ``None``, reads - from :attr:`_configuration_file`. - part: If given, extract only this top-level section (legacy compat). - """ - if config_dict is not None: - data = config_dict - elif self._configuration_file is not None: - with open(self._configuration_file, 'r', encoding='utf-8') as f: - data = yaml.safe_load(f) - else: - raise InvalidConfigFile('The configuration file is empty!') - - if data is None: - raise InvalidConfigFile('The configuration file is empty!') - - if part is not None and isinstance(data, dict) and part in data: - data = data[part] - - self._log_unknown_keys(data) - validated = self._validate(data) - if not _model_to_config_dict(validated): - raise InvalidConfigFile(f'The configuration file is empty for {type(self).__name__}.') - for field_name in type(self).model_fields: - object.__setattr__(self, field_name, getattr(validated, field_name)) - object.__setattr__(self, '__pydantic_extra__', getattr(validated, '__pydantic_extra__', None)) - object.__setattr__(self, '__pydantic_fields_set__', set(validated.__pydantic_fields_set__)) - def __repr__(self) -> str: return self.config_dict.__repr__() diff --git a/tests/config/test_config.py b/tests/config/test_config.py index 965282da..bed22941 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -36,7 +36,8 @@ def test_init(self): 'params': {'target_false_discovery_rate': 0.8}, 'fit_on_val': False}, 'data_splitter': {'type': 'BlockDataSplitter', - 'train_block_size': 7, 'val_block_size': 3}, + 'train_block_size': 7, 'val_block_size': 3, + 'validation_split': 0.1, 'shuffle': False}, 'data_clipping': {'lower_percentile': 0.01, 'upper_percentile': 0.99}, 'protect_conditional_features': False, }) @@ -96,7 +97,9 @@ def test_early_stopping_val_block_config(self): self.assertDictEqual(conf.config_dict['train']['data_splitter'], { 'type': 'DataSplitter', 'train_block_size': 7, - 'val_block_size': 3 + 'val_block_size': 3, + 'validation_split': 0.1, + 'shuffle': False }) def test_bad_early_stopping_no_valconfig(self): @@ -145,5 +148,18 @@ def test_defaults_only_autoencoder(self): self.assertEqual(conf.train.anomaly_score.name, 'rmse') self.assertEqual(conf.train.threshold_selector.name, 'quantile') self.assertIsNotNone(conf.train.data_preprocessor) - self.assertEqual(conf.train.data_splitter.type, 'BlockDataSplitter') + self.assertEqual(conf.train.data_splitter.type, 'sklearn') + self.assertEqual(conf.train.data_splitter.validation_split, 0.1) + self.assertFalse(conf.train.data_splitter.shuffle) self.assertFalse(conf.train.protect_conditional_features) + + def test_empty_config_defaults(self): + """Config() with no arguments should produce a ready-to-use configuration.""" + conf = Config() + self.assertEqual(conf.train.autoencoder.name, 'default') + self.assertEqual(conf.train.anomaly_score.name, 'rmse') + self.assertEqual(conf.train.threshold_selector.name, 'quantile') + self.assertEqual(conf.train.data_splitter.type, 'sklearn') + self.assertEqual(conf.train.data_splitter.validation_split, 0.1) + self.assertFalse(conf.train.data_splitter.shuffle) + self.assertEqual(conf.dtype, 'float32') diff --git a/tests/test_fault_detector.py b/tests/test_fault_detector.py index aae7ad63..e4d79e85 100644 --- a/tests/test_fault_detector.py +++ b/tests/test_fault_detector.py @@ -159,7 +159,6 @@ def test_save_load_roundtrip_with_weighted_rmse(self): class TestFaultDetector(unittest.TestCase): def setUp(self) -> None: self.conf = Config(os.path.join(PROJECT_ROOT, './tests/test_data/test_config.yaml')) - self.conf.read_config() self.sensor_data = pd.DataFrame(data=[[1., 2., 3.], [4., 5., 6.], @@ -214,15 +213,14 @@ def test_save_models(self, mock_write_config): os.path.join(fault_detector.model_directory, str(asset_id), dt, 'config.yaml')) @patch("energy_fault_detector.core.fault_detection_model.FaultDetectionModel._load_pickled_model") - @patch("energy_fault_detector.config.Config.read_config") - def test_load_models(self, mock_load_pickled_model, mock_read_config): + @patch("energy_fault_detector.core.fault_detection_model.Config") + def test_load_models(self, mock_load_pickled_model, mock_config): mock_load_pickled_model.side_effect = [ mock_data_preprocessor, mock_autoencoder, mock_threshold, mock_score, ] - mock_read_config = MagicMock() fault_detector = FaultDetector.load("path_to_saved_models") From 11c0798225ac4cc42db72c43e5c64706b8592c7b Mon Sep 17 00:00:00 2001 From: croelofs <25582572+roelofsc@users.noreply.github.com> Date: Fri, 11 Sep 2026 08:47:24 +0200 Subject: [PATCH 07/18] Deprecate config_dict, use model_dump instead - Remove _model_to_config_dict and _dump_value helpers (45 lines); Pydantic's model_dump(exclude_none=True) produces identical output - write_config now uses model_dump instead of config_dict - config_dict property emits DeprecationWarning, delegates to model_dump - optimization.py: use config.train.autoencoder.params (attribute access) instead of config_dict['train']['autoencoder']['params'] - configuration.py: remove dead dp.params legacy branch (already converted to steps during config validation) - Tests: replace config_dict assertions with model_dump(exclude_none=True) --- energy_fault_detector/config/config.py | 61 ++++--------------- .../quick_fault_detection/configuration.py | 52 ++++++---------- .../quick_fault_detection/optimization.py | 4 +- tests/config/test_config.py | 16 ++--- tests/config/test_quickstart_config.py | 2 +- tests/test_fault_detector.py | 8 +-- 6 files changed, 48 insertions(+), 95 deletions(-) diff --git a/energy_fault_detector/config/config.py b/energy_fault_detector/config/config.py index 873f67cd..593eecb0 100644 --- a/energy_fault_detector/config/config.py +++ b/energy_fault_detector/config/config.py @@ -36,43 +36,6 @@ def _format_validation_error(exc: ValidationError) -> InvalidConfigFile: return InvalidConfigFile('Configuration is not valid: ' + '; '.join(lines)) -def _dump_value(value: Any) -> Any: - """Recursively dump nested models/lists; plain dicts/lists are kept as-is.""" - if isinstance(value, BaseModel): - return _model_to_config_dict(value) - if isinstance(value, list): - return [_dump_value(item) for item in value] - return value - - -def _model_to_config_dict(model: BaseModel) -> Dict[str, Any]: - """Serialize a validated Pydantic model back to a plain configuration dict. - - * fields that are *required* (no default) are always included, even when - their value is ``None``; - * fields that are *optional* (have a default) are included only when their - value is not ``None`` (falsy defaults such as ``False`` are kept because - ``False is not None``); - * unknown fields kept via ``extra='allow'`` are merged back in. - - Args: - model: The validated configuration model. - - Returns: - Plain (mutable) dictionary representation. - """ - result: Dict[str, Any] = {} - for name, field in type(model).model_fields.items(): - value = getattr(model, name) - if not field.is_required() and value is None: - continue - result[name] = _dump_value(value) - extra = getattr(model, '__pydantic_extra__', None) - if extra: - result.update(extra) - return result - - # --- Section models ---------------------------------------------------------- # extra='allow' lets unknown keys survive at every nested level (matching the # former Cerberus allow_unknown=True). DataPreprocessorConfig uses @@ -476,21 +439,25 @@ def _log_unknown_keys(data: Any) -> None: logger.info('Key `%s` is an unknown field and will be ignored.', key) def __repr__(self) -> str: - return self.config_dict.__repr__() + return repr(self.model_dump(exclude_none=True)) # --- serialization -------------------------------------------------------- @property def config_dict(self) -> Dict[str, Any]: - """Return a plain (mutable) dictionary representation of the config. + """Return a plain dictionary representation of the config. - The dict is rebuilt from the underlying Pydantic model on every call, so - it always reflects the current model state. Leaf dicts (``params``, - ``steps``) are the same mutable objects stored on the model, so - in-place mutations (``config.train.autoencoder.params.update(...)``) - persist. + .. deprecated:: + Use :meth:`model_dump` (Pydantic's built-in) or direct attribute + access instead. """ - return _model_to_config_dict(self) + warnings.warn( + "Config.config_dict is deprecated; use Config.model_dump() or " + "direct attribute access instead.", + DeprecationWarning, + stacklevel=2, + ) + return self.model_dump(exclude_none=True) # --- write / save -------------------------------------------------------- @@ -502,8 +469,6 @@ def write_config(self, file_name: Optional[str] = None, overwrite: bool = False) overwrite: If ``False``, raises :class:`FileExistsError` when the file already exists. """ - from copy import deepcopy - if file_name is None and self._configuration_file is None: raise ValueError('No file name given and no known configuration file to overwrite.') @@ -511,7 +476,7 @@ def write_config(self, file_name: Optional[str] = None, overwrite: bool = False) if Path(file_name).exists() and not overwrite: raise FileExistsError(f'File {file_name} already exists and overwrite is set to False.') - conf_dict = deepcopy(self.config_dict) + conf_dict = self.model_dump(exclude_none=True) with open(file_name, 'w', encoding='utf-8') as f: yaml.safe_dump(conf_dict, f) diff --git a/energy_fault_detector/quick_fault_detection/configuration.py b/energy_fault_detector/quick_fault_detection/configuration.py index 92d4d416..2484af7b 100644 --- a/energy_fault_detector/quick_fault_detection/configuration.py +++ b/energy_fault_detector/quick_fault_detection/configuration.py @@ -75,39 +75,27 @@ def update_preprocessor_config(config: Config, features_to_exclude: Union[List[s dp = config.train.data_preprocessor if features_to_exclude is not None: - if dp.params: - # old data preprocessing configuration style - dp.params['features_to_exclude'] = features_to_exclude - else: - # new configuration style - if dp.steps is None: - dp.steps = [] - steps = dp.steps - column_selector_found = False - for step in steps: - if step['name'] == 'column_selector': - step['params']['features_to_exclude'] = features_to_exclude - column_selector_found = True - break - if not column_selector_found: - steps.append({'name': 'column_selector', 'params': {'features_to_exclude': features_to_exclude}}) + if dp.steps is None: + dp.steps = [] + column_selector_found = False + for step in dp.steps: + if step['name'] == 'column_selector': + step['params']['features_to_exclude'] = features_to_exclude + column_selector_found = True + break + if not column_selector_found: + dp.steps.append({'name': 'column_selector', 'params': {'features_to_exclude': features_to_exclude}}) if angles is not None: - if dp.params: - # old data preprocessing configuration style - dp.params['angles'] = angles - else: - # new configuration style - if dp.steps is None: - dp.steps = [] - steps = dp.steps - angle_transformer_found = False - for step in steps: - if step['name'] == 'angle_transformer': - step['params']['angles'] = angles - angle_transformer_found = True - break - if not angle_transformer_found: - steps.append({'name': 'angle_transformer', 'params': {'angles': angles}}) + if dp.steps is None: + dp.steps = [] + angle_transformer_found = False + for step in dp.steps: + if step['name'] == 'angle_transformer': + step['params']['angles'] = angles + angle_transformer_found = True + break + if not angle_transformer_found: + dp.steps.append({'name': 'angle_transformer', 'params': {'angles': angles}}) return config diff --git a/energy_fault_detector/quick_fault_detection/optimization.py b/energy_fault_detector/quick_fault_detection/optimization.py index b367a1d7..3119571f 100644 --- a/energy_fault_detector/quick_fault_detection/optimization.py +++ b/energy_fault_detector/quick_fault_detection/optimization.py @@ -87,7 +87,7 @@ def reconstruction_mse(trial: op.Trial) -> float: Returns: MSE of the reconstruction on validation data. """ - trial_config_dict = deepcopy(config.config_dict) # make a copy of the config object, so we do not mutate the original config + trial_config_dict = deepcopy(config.model_dump(exclude_none=True)) # make a copy of the config object, so we do not mutate the original config params = trial_config_dict['train']['autoencoder']['params'] # sample new parameters @@ -137,7 +137,7 @@ def reconstruction_mse(trial: op.Trial) -> float: study_name='autoencoder_optimization', direction='minimize') - autoencoder_params = config.config_dict['train']['autoencoder']['params'] + autoencoder_params = config.train.autoencoder.params study.enqueue_trial(params={ 'batch_size': autoencoder_params['batch_size'], 'learning_rate': autoencoder_params['learning_rate'], diff --git a/tests/config/test_config.py b/tests/config/test_config.py index bed22941..d146106d 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -18,7 +18,7 @@ def tearDown(self) -> None: def test_init(self): conf = Config(os.path.join(PROJECT_ROOT, './tests/test_data/test_config.yaml')) - self.assertDictEqual(conf.config_dict['train'], { + self.assertDictEqual(conf.model_dump(exclude_none=True)['train'], { 'anomaly_score': {'name': 'mahalanobis', 'params': {'pca': True, 'pca_min_var': 0.85}}, 'data_preprocessor': {'steps': []}, @@ -33,15 +33,15 @@ def test_init(self): 'epochs': 10, 'loss_name': 'mean_squared_error'}}, 'threshold_selector': {'name': 'FDR', - 'params': {'target_false_discovery_rate': 0.8}, - 'fit_on_val': False}, + 'params': {'target_false_discovery_rate': 0.8}, + 'fit_on_val': False}, 'data_splitter': {'type': 'BlockDataSplitter', 'train_block_size': 7, 'val_block_size': 3, 'validation_split': 0.1, 'shuffle': False}, 'data_clipping': {'lower_percentile': 0.01, 'upper_percentile': 0.99}, 'protect_conditional_features': False, }) - self.assertDictEqual(conf.config_dict['root_cause_analysis'], + self.assertDictEqual(conf.model_dump(exclude_none=True)['root_cause_analysis'], {'alpha': 0.8, 'init_x_bias': 'recon', 'num_iter': 200} @@ -60,7 +60,7 @@ def test_arcana_config(self): def test_early_stopping_val_split_config(self): conf = Config(os.path.join(PROJECT_ROOT, './tests/test_data/test_early_stopping_val_split_config.yaml')) - self.assertDictEqual(conf.config_dict['train']['autoencoder']['params'], { + self.assertDictEqual(conf.model_dump(exclude_none=True)['train']['autoencoder']['params'], { 'layers': [300], 'code_size': 50, 'learning_rate': 0.001, @@ -73,7 +73,7 @@ def test_early_stopping_val_split_config(self): 'epochs': 100, 'loss_name': 'mean_squared_error' }) - self.assertDictEqual(conf.config_dict['train']['data_splitter'], { + self.assertDictEqual(conf.model_dump(exclude_none=True)['train']['data_splitter'], { 'type': 'sklearn', 'shuffle': True, 'validation_split': 0.25 @@ -81,7 +81,7 @@ def test_early_stopping_val_split_config(self): def test_early_stopping_val_block_config(self): conf = Config(os.path.join(PROJECT_ROOT, './tests/test_data/test_early_stopping_val_block_config.yaml')) - self.assertDictEqual(conf.config_dict['train']['autoencoder']['params'], { + self.assertDictEqual(conf.model_dump(exclude_none=True)['train']['autoencoder']['params'], { 'layers': [300], 'code_size': 50, 'learning_rate': 0.001, @@ -94,7 +94,7 @@ def test_early_stopping_val_block_config(self): 'epochs': 100, 'loss_name': 'mean_squared_error' }) - self.assertDictEqual(conf.config_dict['train']['data_splitter'], { + self.assertDictEqual(conf.model_dump(exclude_none=True)['train']['data_splitter'], { 'type': 'DataSplitter', 'train_block_size': 7, 'val_block_size': 3, diff --git a/tests/config/test_quickstart_config.py b/tests/config/test_quickstart_config.py index 2f1c9ea9..5fe8abef 100644 --- a/tests/config/test_quickstart_config.py +++ b/tests/config/test_quickstart_config.py @@ -65,5 +65,5 @@ def test_save_load_quickstart_config(self) -> None: loaded_cfg = Config(config_path) # Compare dictionaries - self.assertEqual(cfg.config_dict, loaded_cfg.config_dict) + self.assertEqual(cfg.model_dump(exclude_none=True), loaded_cfg.model_dump(exclude_none=True)) self.assertEqual(loaded_cfg.train.data_splitter.validation_split, 0.25) diff --git a/tests/test_fault_detector.py b/tests/test_fault_detector.py index e4d79e85..2817ce61 100644 --- a/tests/test_fault_detector.py +++ b/tests/test_fault_detector.py @@ -79,8 +79,8 @@ def test_save_load_models(self): self.assertEqual(original_threshold_params, loaded_threshold_params) # Check the configuration - self.assertDictEqual(self.fault_detector.config.config_dict, - loaded_fault_detector.config.config_dict) + self.assertDictEqual(self.fault_detector.config.model_dump(exclude_none=True), + loaded_fault_detector.config.model_dump(exclude_none=True)) # Check path when overwrite = True results = self.fault_detector.fit(sensor_data=self.sensor_data, normal_index=self.normal_index, @@ -445,7 +445,7 @@ def test_sequence_model_save_and_load_roundtrip(self) -> None: np.testing.assert_allclose(a, b, atol=1e-6) # Config should round-trip as well - self.assertDictEqual(fd.config.config_dict, fd2.config.config_dict) + self.assertDictEqual(fd.config.model_dump(exclude_none=True), fd2.config.model_dump(exclude_none=True)) class TestFaultDetectorBidirectionalSequenceSaveLoad(unittest.TestCase): @@ -496,7 +496,7 @@ def test_sequence_model_save_and_load_roundtrip(self) -> None: for a, b in zip(w1, w2): np.testing.assert_allclose(a, b, atol=1e-6) - self.assertDictEqual(fd.config.config_dict, fd2.config.config_dict) + self.assertDictEqual(fd.config.model_dump(exclude_none=True), fd2.config.model_dump(exclude_none=True)) class TestAutoencoderGetReconstructionError(unittest.TestCase): From 3c33b82a897bd7b0b6c6fe41564d53a81d049a0d Mon Sep 17 00:00:00 2001 From: croelofs <25582572+roelofsc@users.noreply.github.com> Date: Fri, 11 Sep 2026 09:06:52 +0200 Subject: [PATCH 08/18] Docs: mention Config() as primary entry point, keep generate_quickstart_config for custom preprocessing - usage_examples.rst: minimal example uses Config() not generate_quickstart_config - usage_examples.rst: Configuration section shows Config() first, quickstart second - configuration.rst: fix data_preprocessor: {} -> omitted/null - configuration.rst: add Config() snippet before generate_quickstart_config --- docs/configuration.rst | 12 ++++++++++-- docs/usage_examples.rst | 35 ++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 35f5594b..a235d34c 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -30,11 +30,19 @@ This setup: - Runs ARCANA with provided parameters when calling :py:obj:`FaultDetector.predict(..., root_cause_analysis=True) `. If not provided, default ARCANA parameters are used (see :py:obj:`ARCANA docs `). -If you leave out the data_preprocessor configuration (i.e., ``data_preprocessor: {}``), a default preprocessing pipeline +If you leave out the ``data_preprocessor`` section entirely (or set it to ``null``), a default preprocessing pipeline is generated, which drops constant and binary features, features where >5% of the data is missing, imputes remaining missing values with the mean value and scales the data to zero mean and unit standard deviation. -You can also generate this kind of configuration programmatically using +The simplest way to get started is ``Config()`` with no arguments, which uses all defaults: + +.. code-block:: python + + from energy_fault_detector.config import Config + + config = Config() # ready-to-use defaults + +For custom preprocessing (angle columns, scaler, etc.) or to generate a YAML file, use :func:`generate_quickstart_config `: .. code-block:: python diff --git a/docs/usage_examples.rst b/docs/usage_examples.rst index a01afb10..cd67454c 100644 --- a/docs/usage_examples.rst +++ b/docs/usage_examples.rst @@ -24,11 +24,11 @@ Throughout this documentation we use the following objects and conventions. predicted anomalies. * Configuration: :class:`FaultDetector ` behaviour - is controlled via a YAML configuration parsed by :class:`Config `. - For most users, the easiest entry point is - :func:`generate_quickstart_config `, - which returns a minimal, valid configuration. For more control, you can provide your own YAML file; see - :doc:`configuration` for examples. + is controlled via a :class:`Config ` object. + ``Config()`` with no arguments produces a ready-to-use default configuration; for custom + preprocessing (angle columns, scaler, etc.) use + :func:`generate_quickstart_config `. + See :doc:`configuration` for details. * ``sensor_data``: a :class:`pandas.DataFrame` in **wide format**. Each row is a timestamp (or index entry), each column a sensor or feature. @@ -61,7 +61,6 @@ create a configuration, train a model and predict. import pandas as pd from energy_fault_detector import FaultDetector, Config - from energy_fault_detector.config import generate_quickstart_config # 1. Load your data df = pd.read_csv("my_data.csv", parse_dates=["timestamp"], index_col="timestamp") @@ -73,9 +72,8 @@ create a configuration, train a model and predict. # This is optional; if omitted, all data is treated as normal normal_index = df["status"] == "normal" - # 2. Generate and load a base config - generate_quickstart_config(output_path="base_config.yaml") - config = Config("base_config.yaml") + # 2. Create a default configuration + config = Config() # MultilayerAutoencoder, RMSE score, quantile threshold, default preprocessing # 3. Train a normal-behavior model fault_detector = FaultDetector(config=config, model_directory="fault_detector_model") @@ -195,7 +193,7 @@ Configuration ^^^^^^^^^^^^^ The behaviour of the :py:class:`FaultDetector ` -is controlled by a YAML configuration, parsed by :py:class:`Config `. +is controlled by a :py:class:`Config ` object (a Pydantic model). The config typically has: - a ``train`` section: @@ -207,19 +205,22 @@ The config typically has: - optional ``data_clipping``: outlier clipping on training data only. - an optional ``root_cause_analysis`` section for ARCANA. -For most users, the easiest way to create a valid configuration is via :func:`generate_quickstart_config `: +``Config()`` with no arguments produces a ready-to-use default configuration. +For custom preprocessing (angle columns, scaler, etc.) or to generate a YAML file, use +:func:`generate_quickstart_config `: .. code-block:: python - from energy_fault_detector.config.quickstart_config import generate_quickstart_config + from energy_fault_detector import FaultDetector from energy_fault_detector.config import Config + from energy_fault_detector.config import generate_quickstart_config - # Create a minimal, valid config file - generate_quickstart_config(output_path="base_config.yaml") + # Simplest: use defaults + config = Config() + fd = FaultDetector(config=config) - # Load and use it - cfg = Config("base_config.yaml") - fd = FaultDetector(config=cfg) + # Or generate a config with custom preprocessing and save to YAML: + config = generate_quickstart_config(angle_columns=["wind_dir"], output_path="base_config.yaml") If you prefer to write the YAML yourself or need more control, see the :ref:`Configuration guide ` for a full reference and examples. From 6fa121836b8dbffdbee67bff097e84eb6fb7f3db Mon Sep 17 00:00:00 2001 From: croelofs <25582572+roelofsc@users.noreply.github.com> Date: Fri, 11 Sep 2026 09:22:58 +0200 Subject: [PATCH 09/18] Format config modules with black+ruff --- energy_fault_detector/config/config.py | 308 ++++++++++++++----------- 1 file changed, 169 insertions(+), 139 deletions(-) diff --git a/energy_fault_detector/config/config.py b/energy_fault_detector/config/config.py index 593eecb0..83a370ca 100644 --- a/energy_fault_detector/config/config.py +++ b/energy_fault_detector/config/config.py @@ -15,12 +15,18 @@ import logging import warnings from pathlib import Path -from typing import Any, Dict, List, Literal, Optional +from typing import Any, Literal import yaml -from pydantic import BaseModel, ConfigDict, PrivateAttr, ValidationError, model_validator +from pydantic import ( + BaseModel, + ConfigDict, + PrivateAttr, + ValidationError, + model_validator, +) -logger = logging.getLogger('energy_fault_detector') +logger = logging.getLogger("energy_fault_detector") class InvalidConfigFile(Exception): @@ -31,26 +37,20 @@ def _format_validation_error(exc: ValidationError) -> InvalidConfigFile: """Convert a Pydantic ``ValidationError`` into an :class:`InvalidConfigFile`.""" lines = [] for err in exc.errors(): - loc = '.'.join(str(p) for p in err['loc']) + loc = ".".join(str(p) for p in err["loc"]) lines.append(f"{loc}: {err['msg']}") - return InvalidConfigFile('Configuration is not valid: ' + '; '.join(lines)) - - -# --- Section models ---------------------------------------------------------- -# extra='allow' lets unknown keys survive at every nested level (matching the -# former Cerberus allow_unknown=True). DataPreprocessorConfig uses -# extra='forbid' because its schema explicitly disallowed unknown keys. + return InvalidConfigFile("Configuration is not valid: " + "; ".join(lines)) class AnomalyScoreConfig(BaseModel): """``train.anomaly_score`` section.""" - model_config = ConfigDict(extra='allow', validate_assignment=True) - name: str = 'rmse' - params: Dict[str, Any] = {} + model_config = ConfigDict(extra="allow", validate_assignment=True) + name: str = "rmse" + params: dict[str, Any] = {} - @model_validator(mode='after') - def _none_params_to_empty(self) -> 'AnomalyScoreConfig': + @model_validator(mode="after") + def _none_params_to_empty(self) -> "AnomalyScoreConfig": if self.params is None: self.params = {} return self @@ -63,13 +63,13 @@ class AutoencoderConfig(BaseModel): (includes autoencoder-specific keys like ``sequence_builder``). """ - model_config = ConfigDict(extra='allow', validate_assignment=True) - name: str = 'default' - params: Dict[str, Any] = {} - verbose: Optional[int] = None + model_config = ConfigDict(extra="allow", validate_assignment=True) + name: str = "default" + params: dict[str, Any] = {} + verbose: int | None = None - @model_validator(mode='after') - def _none_params_to_empty(self) -> 'AutoencoderConfig': + @model_validator(mode="after") + def _none_params_to_empty(self) -> "AutoencoderConfig": if self.params is None: self.params = {} return self @@ -85,11 +85,11 @@ class DataPreprocessorConfig(BaseModel): default pipeline". """ - model_config = ConfigDict(extra='forbid', validate_assignment=True) - params: Optional[Dict[str, Any]] = None - steps: Optional[List[Dict[str, Any]]] = [] + model_config = ConfigDict(extra="forbid", validate_assignment=True) + params: dict[str, Any] | None = None + steps: list[dict[str, Any]] | None = [] - @model_validator(mode='before') + @model_validator(mode="before") @classmethod def _none_to_empty(cls, data: Any) -> Any: """Treat ``data_preprocessor: null`` (or missing) as an empty config.""" @@ -97,8 +97,8 @@ def _none_to_empty(cls, data: Any) -> Any: return {} return data - @model_validator(mode='after') - def _convert_params_to_steps(self) -> 'DataPreprocessorConfig': + @model_validator(mode="after") + def _convert_params_to_steps(self) -> "DataPreprocessorConfig": if self.steps and self.params: warnings.warn( "Both 'data_preprocessor.steps' and 'data_preprocessor.params' provided in config; " @@ -125,13 +125,13 @@ def _convert_params_to_steps(self) -> 'DataPreprocessorConfig': class ThresholdSelectorConfig(BaseModel): """``train.threshold_selector`` section.""" - model_config = ConfigDict(extra='allow', validate_assignment=True) - name: str = 'quantile' + model_config = ConfigDict(extra="allow", validate_assignment=True) + name: str = "quantile" fit_on_val: bool = False - params: Dict[str, Any] = {} + params: dict[str, Any] = {} - @model_validator(mode='after') - def _none_params_to_empty(self) -> 'ThresholdSelectorConfig': + @model_validator(mode="after") + def _none_params_to_empty(self) -> "ThresholdSelectorConfig": if self.params is None: self.params = {} return self @@ -140,11 +140,11 @@ def _none_params_to_empty(self) -> 'ThresholdSelectorConfig': class DataClippingConfig(BaseModel): """``train.data_clipping`` section.""" - model_config = ConfigDict(extra='allow', validate_assignment=True) - lower_percentile: Optional[float] = None - upper_percentile: Optional[float] = None - features_to_exclude: Optional[List[str]] = None - features_to_clip: Optional[List[str]] = None + model_config = ConfigDict(extra="allow", validate_assignment=True) + lower_percentile: float | None = None + upper_percentile: float | None = None + features_to_exclude: list[str] | None = None + features_to_clip: list[str] | None = None class DataSplitterConfig(BaseModel): @@ -159,13 +159,19 @@ class DataSplitterConfig(BaseModel): set. This enables early stopping and ``fit_on_val`` out of the box. """ - model_config = ConfigDict(extra='allow', validate_assignment=True) - type: Literal['DataSplitter', 'BlockDataSplitter', 'blocks', 'sklearn', - 'train_test_split', 'train_val_split'] = 'sklearn' - train_block_size: Optional[int] = None - val_block_size: Optional[int] = None - validation_split: Optional[float] = 0.1 - shuffle: Optional[bool] = False + model_config = ConfigDict(extra="allow", validate_assignment=True) + type: Literal[ + "DataSplitter", + "BlockDataSplitter", + "blocks", + "sklearn", + "train_test_split", + "train_val_split", + ] = "sklearn" + train_block_size: int | None = None + val_block_size: int | None = None + validation_split: float | None = 0.1 + shuffle: bool | None = False class TrainConfig(BaseModel): @@ -175,12 +181,12 @@ class TrainConfig(BaseModel): configuration. """ - model_config = ConfigDict(extra='allow', validate_assignment=True) + model_config = ConfigDict(extra="allow", validate_assignment=True) autoencoder: AutoencoderConfig = AutoencoderConfig() anomaly_score: AnomalyScoreConfig = AnomalyScoreConfig() data_preprocessor: DataPreprocessorConfig = DataPreprocessorConfig() threshold_selector: ThresholdSelectorConfig = ThresholdSelectorConfig() - data_clipping: Optional[DataClippingConfig] = None + data_clipping: DataClippingConfig | None = None data_splitter: DataSplitterConfig = DataSplitterConfig() protect_conditional_features: bool = False @@ -193,39 +199,35 @@ class RootCauseAnalysisConfig(BaseModel): unpacking (``Arcana(**config.root_cause_analysis.params)``). """ - model_config = ConfigDict(extra='allow', validate_assignment=True) - alpha: Optional[float] = None - init_x_bias: Optional[str] = None - num_iter: Optional[int] = None - epsilon: Optional[float] = None - verbose: Optional[bool] = None - max_sample_threshold: Optional[int] = None + model_config = ConfigDict(extra="allow", validate_assignment=True) + alpha: float | None = None + init_x_bias: str | None = None + num_iter: int | None = None + epsilon: float | None = None + verbose: bool | None = None + max_sample_threshold: int | None = None @property - def params(self) -> Dict[str, Any]: + def params(self) -> dict[str, Any]: """Return all non-None RCA parameters as a dict (including extras).""" - result = {k: v for k, v in self.__dict__.items() if v is not None and not k.startswith('_')} - extra = getattr(self, '__pydantic_extra__', None) + result = { + k: v + for k, v in self.__dict__.items() + if v is not None and not k.startswith("_") + } + extra = getattr(self, "__pydantic_extra__", None) if extra: result.update({k: v for k, v in extra.items() if v is not None}) return result -# --- Extra validation helpers ------------------------------------------------ - - -def _ae_params(model: 'Config') -> Dict[str, Any]: - """Return the autoencoder params dict.""" - return model.train.autoencoder.params - - -def _validate_early_stopping(model: 'Config') -> None: +def _validate_early_stopping(model: "Config") -> None: """Check whether early_stopping settings are consistent with the data splitter.""" - params = _ae_params(model) - early_stopping = params.get('early_stopping', False) + params = model.train.autoencoder.params + early_stopping = params.get("early_stopping", False) splitter = model.train.data_splitter - block_types = {'DataSplitter', 'BlockDataSplitter', 'blocks'} + block_types = {"DataSplitter", "BlockDataSplitter", "blocks"} if splitter.type in block_types: val_block_size = splitter.val_block_size or 0 @@ -237,19 +239,21 @@ def _validate_early_stopping(model: 'Config') -> None: validation = 0 < validation_split < 1 if early_stopping and not validation: - msg = ('Configuration is not valid: If early_stopping is enabled either validation_split or ' - 'val_block_size must be given. If validation_split is used, it must be a float >0 and <1.') + msg = ( + "Configuration is not valid: If early_stopping is enabled either validation_split or " + "val_block_size must be given. If validation_split is used, it must be a float >0 and <1." + ) raise InvalidConfigFile(msg) -def _validate_sequence_fit_on_val(model: 'Config') -> None: +def _validate_sequence_fit_on_val(model: "Config") -> None: """Warn if ``fit_on_val=True`` with a sequence model and ``shuffle=True``. Sequence models need temporally contiguous validation data. Shuffling breaks that contiguity, and the sequence builder will drop windows that cross data gaps — potentially leaving no valid windows for threshold fitting. """ - params = _ae_params(model) + params = model.train.autoencoder.params has_sequence_builder = "sequence_builder" in params fit_on_val = model.train.threshold_selector.fit_on_val shuffle = model.train.data_splitter.shuffle or False @@ -265,10 +269,7 @@ def _validate_sequence_fit_on_val(model: 'Config') -> None: ) -# --- DataPreprocessor params->steps translation ------------------------------ - - -def _data_preprocessor_params_to_steps(params: Dict[str, Any]) -> List[Dict[str, Any]]: +def _data_preprocessor_params_to_steps(params: dict[str, Any]) -> list[dict[str, Any]]: """Translate old ``data_preprocessor.params`` into a ``steps`` specification. Args: @@ -285,61 +286,71 @@ def _data_preprocessor_params_to_steps(params: Dict[str, Any]) -> List[Dict[str, """ p = params or {} - steps: List[Dict[str, Any]] = [] + steps: list[dict[str, Any]] = [] # 0. DuplicateValuesToNan if p.get("include_duplicate_value_to_nan", False): - steps.append({ - "name": "duplicate_to_nan", - "params": { - "value_to_replace": p.get("value_to_replace", 0), - "n_max_duplicates": p.get("n_max_duplicates", 144), - "features_to_exclude": p.get("duplicate_features_to_exclude"), - }, - }) + steps.append( + { + "name": "duplicate_to_nan", + "params": { + "value_to_replace": p.get("value_to_replace", 0), + "n_max_duplicates": p.get("n_max_duplicates", 144), + "features_to_exclude": p.get("duplicate_features_to_exclude"), + }, + } + ) # 1. CounterDiffTransformer counter_cols = p.get("counter_columns_to_transform", []) or [] if counter_cols: - steps.append({ - "name": "counter_diff_transformer", - "params": { - "counters": counter_cols, - "compute_rate": False, - "reset_strategy": "zero", - }, - }) + steps.append( + { + "name": "counter_diff_transformer", + "params": { + "counters": counter_cols, + "compute_rate": False, + "reset_strategy": "zero", + }, + } + ) # 2. ColumnSelector if p.get("include_column_selector", True): - steps.append({ - "name": "column_selector", - "params": { - "max_nan_frac_per_col": p.get("max_nan_frac_per_col", 0.05), - "features_to_exclude": p.get("features_to_exclude"), - }, - }) + steps.append( + { + "name": "column_selector", + "params": { + "max_nan_frac_per_col": p.get("max_nan_frac_per_col", 0.05), + "features_to_exclude": p.get("features_to_exclude"), + }, + } + ) # 3. LowUniqueValueFilter if p.get("include_low_unique_value_filter", True): - steps.append({ - "name": "low_unique_value_filter", - "params": { - "min_unique_value_count": p.get("min_unique_value_count", 2), - "max_col_zero_frac": p.get("max_col_zero_frac", 1.0), - }, - }) + steps.append( + { + "name": "low_unique_value_filter", + "params": { + "min_unique_value_count": p.get("min_unique_value_count", 2), + "max_col_zero_frac": p.get("max_col_zero_frac", 1.0), + }, + } + ) # 4. AngleTransformer angles = p.get("angles", []) or [] if angles: - steps.append({ - "name": "angle_transformer", - "params": {"angles": angles}, - }) + steps.append( + { + "name": "angle_transformer", + "params": {"angles": angles}, + } + ) # 5. SimpleImputer - imputer_params: Dict[str, Any] = {"strategy": p.get("imputer_strategy", "mean")} + imputer_params: dict[str, Any] = {"strategy": p.get("imputer_strategy", "mean")} if imputer_params["strategy"] == "constant": imputer_params["fill_value"] = p.get("imputer_fill_value", None) steps.append({"name": "simple_imputer", "params": imputer_params}) @@ -347,16 +358,25 @@ def _data_preprocessor_params_to_steps(params: Dict[str, Any]) -> List[Dict[str, # 6. Scaler scale = p.get("scale", "standardize") if scale in ["standardize", "standard", "standardscaler"]: - steps.append({"name": "scaler", "step_name": "scaler", "params": {"scaler_type": "standard"}}) + steps.append( + { + "name": "scaler", + "step_name": "scaler", + "params": {"scaler_type": "standard"}, + } + ) else: - steps.append({"name": "scaler", "step_name": "scaler", "params": {"scaler_type": "minmax"}}) + steps.append( + { + "name": "scaler", + "step_name": "scaler", + "params": {"scaler_type": "minmax"}, + } + ) return steps -# --- Config (top-level model) ------------------------------------------------ - - class Config(BaseModel): """Configuration for the anomaly-detection pipeline. @@ -390,37 +410,43 @@ class Config(BaseModel): a dict as the first positional argument). """ - model_config = ConfigDict(extra='ignore', validate_default=True, validate_assignment=True) + model_config = ConfigDict( + extra="ignore", validate_default=True, validate_assignment=True + ) train: TrainConfig = TrainConfig() - root_cause_analysis: Optional[RootCauseAnalysisConfig] = None - dtype: Literal['float32', 'float64'] = 'float32' + root_cause_analysis: RootCauseAnalysisConfig | None = None + dtype: Literal["float32", "float64"] = "float32" - _configuration_file: Optional[str] = PrivateAttr(default=None) + _configuration_file: str | None = PrivateAttr(default=None) - @model_validator(mode='after') - def _run_extra_checks(self) -> 'Config': + @model_validator(mode="after") + def _run_extra_checks(self) -> "Config": """Run post-validation checks.""" _validate_early_stopping(self) _validate_sequence_fit_on_val(self) return self - def __init__(self, config_filename: str | Path | Dict[str, Any] = None, - config_dict: Dict[str, Any] = None, **kwargs: Any) -> None: + def __init__( + self, + config_filename: str | Path | dict[str, Any] | None = None, + config_dict: dict[str, Any] | None = None, + **kwargs: Any, + ) -> None: if isinstance(config_filename, dict): config_dict = config_filename config_filename = None if config_filename is not None: - with open(config_filename, 'r', encoding='utf-8') as f: + with open(config_filename, "r", encoding="utf-8") as f: data = yaml.safe_load(f) if data is None: - raise InvalidConfigFile('The configuration file is empty!') + raise InvalidConfigFile("The configuration file is empty!") self._log_unknown_keys(data) try: super().__init__(**data) except ValidationError as exc: raise _format_validation_error(exc) from exc - object.__setattr__(self, '_configuration_file', str(config_filename)) + object.__setattr__(self, "_configuration_file", str(config_filename)) elif config_dict is not None: self._log_unknown_keys(config_dict) try: @@ -436,15 +462,15 @@ def _log_unknown_keys(data: Any) -> None: known_keys = set(Config.model_fields.keys()) for key in list(data.keys()): if key not in known_keys: - logger.info('Key `%s` is an unknown field and will be ignored.', key) + logger.info( + "Key `%s` is an unknown field and will be ignored.", key + ) def __repr__(self) -> str: return repr(self.model_dump(exclude_none=True)) - # --- serialization -------------------------------------------------------- - @property - def config_dict(self) -> Dict[str, Any]: + def config_dict(self) -> dict[str, Any]: """Return a plain dictionary representation of the config. .. deprecated:: @@ -459,9 +485,9 @@ def config_dict(self) -> Dict[str, Any]: ) return self.model_dump(exclude_none=True) - # --- write / save -------------------------------------------------------- - - def write_config(self, file_name: Optional[str] = None, overwrite: bool = False) -> None: + def write_config( + self, file_name: str | None = None, overwrite: bool = False + ) -> None: """Write the configuration to a YAML file. Args: @@ -470,15 +496,19 @@ def write_config(self, file_name: Optional[str] = None, overwrite: bool = False) already exists. """ if file_name is None and self._configuration_file is None: - raise ValueError('No file name given and no known configuration file to overwrite.') + raise ValueError( + "No file name given and no known configuration file to overwrite." + ) file_name = file_name if file_name is not None else self._configuration_file if Path(file_name).exists() and not overwrite: - raise FileExistsError(f'File {file_name} already exists and overwrite is set to False.') + raise FileExistsError( + f"File {file_name} already exists and overwrite is set to False." + ) conf_dict = self.model_dump(exclude_none=True) - with open(file_name, 'w', encoding='utf-8') as f: + with open(file_name, "w", encoding="utf-8") as f: yaml.safe_dump(conf_dict, f) def save(self, file_name: str, overwrite: bool = False) -> None: From 04b7d9ddc5f2651ebd224d1d01f9bca8bc7ccdb7 Mon Sep 17 00:00:00 2001 From: croelofs <25582572+roelofsc@users.noreply.github.com> Date: Tue, 29 Sep 2026 17:11:42 +0200 Subject: [PATCH 10/18] Restore BlockDataSplitter as default data splitter Reverts the sklearn + validation_split=0.1 default from d005daa7 back to BlockDataSplitter with all optional fields None (splitter falls back to 5040/1680 samples). Re-adds update_config/configuration_file compat shims for old-model loading. Updates docstrings, docs, and test expectations. Adds _parse_ts_freq unit test. --- docs/configuration.rst | 6 +-- energy_fault_detector/config/config.py | 44 +++++++++++++++---- tests/config/test_config.py | 15 ++----- tests/core/test_model_factory.py | 17 ++++++- .../test_bad_early_stopping_config.yaml | 4 -- 5 files changed, 59 insertions(+), 27 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index a235d34c..4dd75733 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -156,9 +156,9 @@ Other training configuration sections - Data splitter (``train.data_splitter``): - - ``type``: one of ``sklearn`` (alias ``train_test_split``) or ``BlockDataSplitter`` (aliases: ``blocks``, ``DataSplitter``). Default: ``sklearn``. - - For sklearn: ``validation_split`` (float in (0, 1), default 0.1 = last 10%) and ``shuffle`` (bool, default False). - - For :py:obj:`BlockDataSplitter `: ``train_block_size`` and ``val_block_size``. + - ``type``: one of ``BlockDataSplitter`` (aliases: ``blocks``, ``DataSplitter``) or ``sklearn`` (alias ``train_test_split``). Default: ``BlockDataSplitter``. + - For :py:obj:`BlockDataSplitter `: ``train_block_size`` and ``val_block_size`` (both optional; the splitter falls back to 5040 / 1680 samples when left unset). + - For sklearn: ``validation_split`` (float in (0, 1)) and ``shuffle`` (bool). With ``shuffle`` false or unset, the last fraction of the data (in original order) is taken as the validation set. - Early stopping guard: if ``train.autoencoder.params.early_stopping`` is true, you must either set a valid ``validation_split`` in (0, 1), or use :py:obj:`BlockDataSplitter ` with a positive ``val_block_size``. diff --git a/energy_fault_detector/config/config.py b/energy_fault_detector/config/config.py index 83a370ca..59b6af7e 100644 --- a/energy_fault_detector/config/config.py +++ b/energy_fault_detector/config/config.py @@ -8,8 +8,7 @@ All sections have sensible defaults — ``Config()`` with no arguments produces a ready-to-use configuration (MultilayerAutoencoder, RMSE anomaly score, quantile -threshold selector, default preprocessing pipeline, sklearn data splitter with -10% validation split). +threshold selector, default preprocessing pipeline, BlockDataSplitter). """ import logging @@ -154,9 +153,13 @@ class DataSplitterConfig(BaseModel): fields are type-specific options; irrelevant ones are ignored by the splitter implementation. - Defaults: ``sklearn`` with ``validation_split=0.1`` and ``shuffle=False``, - i.e. the last 10% of the data (in original order) is used as a validation - set. This enables early stopping and ``fit_on_val`` out of the box. + Defaults to ``BlockDataSplitter`` with ``train_block_size``, ``val_block_size``, + ``validation_split`` and ``shuffle`` all ``None``; the + :py:obj:`BlockDataSplitter ` + then falls back to its own block-size defaults (5040 / 1680 samples). Early + stopping requires validation data to be configured explicitly: a positive + ``val_block_size`` for block splitters, or a ``validation_split`` in (0, 1) + for sklearn splitters. """ model_config = ConfigDict(extra="allow", validate_assignment=True) @@ -167,11 +170,11 @@ class DataSplitterConfig(BaseModel): "sklearn", "train_test_split", "train_val_split", - ] = "sklearn" + ] = "BlockDataSplitter" train_block_size: int | None = None val_block_size: int | None = None - validation_split: float | None = 0.1 - shuffle: bool | None = False + validation_split: float | None = None + shuffle: bool | None = None class TrainConfig(BaseModel): @@ -514,3 +517,28 @@ def write_config( def save(self, file_name: str, overwrite: bool = False) -> None: """Save the configuration to a YAML file. Wrapper for :meth:`write_config`.""" self.write_config(file_name, overwrite) + + @property + def configuration_file(self) -> str | None: + """Original YAML file path, if this config was loaded from one.""" + return self._configuration_file + + def update_config(self, new_config_dict: dict[str, Any]) -> None: + """Update configuration from a top-level partial dictionary. + + Deprecated: prefer direct typed attribute access or a new Config instance. + """ + warnings.warn( + "Config.update_config() is deprecated; use typed attribute access instead.", + DeprecationWarning, + stacklevel=2, + ) + + merged = self.model_dump(exclude_none=True) + merged.update(new_config_dict) # preserves old shallow-merge semantics + updated = Config(config_dict=merged) + + for name in self.__class__.model_fields: + setattr(self, name, getattr(updated, name)) + + object.__setattr__(self, "_configuration_file", None) diff --git a/tests/config/test_config.py b/tests/config/test_config.py index d146106d..852b55e4 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -36,8 +36,7 @@ def test_init(self): 'params': {'target_false_discovery_rate': 0.8}, 'fit_on_val': False}, 'data_splitter': {'type': 'BlockDataSplitter', - 'train_block_size': 7, 'val_block_size': 3, - 'validation_split': 0.1, 'shuffle': False}, + 'train_block_size': 7, 'val_block_size': 3}, 'data_clipping': {'lower_percentile': 0.01, 'upper_percentile': 0.99}, 'protect_conditional_features': False, }) @@ -97,9 +96,7 @@ def test_early_stopping_val_block_config(self): self.assertDictEqual(conf.model_dump(exclude_none=True)['train']['data_splitter'], { 'type': 'DataSplitter', 'train_block_size': 7, - 'val_block_size': 3, - 'validation_split': 0.1, - 'shuffle': False + 'val_block_size': 3 }) def test_bad_early_stopping_no_valconfig(self): @@ -148,9 +145,7 @@ def test_defaults_only_autoencoder(self): self.assertEqual(conf.train.anomaly_score.name, 'rmse') self.assertEqual(conf.train.threshold_selector.name, 'quantile') self.assertIsNotNone(conf.train.data_preprocessor) - self.assertEqual(conf.train.data_splitter.type, 'sklearn') - self.assertEqual(conf.train.data_splitter.validation_split, 0.1) - self.assertFalse(conf.train.data_splitter.shuffle) + self.assertEqual(conf.train.data_splitter.type, 'BlockDataSplitter') self.assertFalse(conf.train.protect_conditional_features) def test_empty_config_defaults(self): @@ -159,7 +154,5 @@ def test_empty_config_defaults(self): self.assertEqual(conf.train.autoencoder.name, 'default') self.assertEqual(conf.train.anomaly_score.name, 'rmse') self.assertEqual(conf.train.threshold_selector.name, 'quantile') - self.assertEqual(conf.train.data_splitter.type, 'sklearn') - self.assertEqual(conf.train.data_splitter.validation_split, 0.1) - self.assertFalse(conf.train.data_splitter.shuffle) + self.assertEqual(conf.train.data_splitter.type, 'BlockDataSplitter') self.assertEqual(conf.dtype, 'float32') diff --git a/tests/core/test_model_factory.py b/tests/core/test_model_factory.py index 28ffef5c..37c8683a 100644 --- a/tests/core/test_model_factory.py +++ b/tests/core/test_model_factory.py @@ -2,7 +2,9 @@ import os import unittest -from energy_fault_detector.core.model_factory import ModelFactory +import numpy as np + +from energy_fault_detector.core.model_factory import ModelFactory, _parse_ts_freq from energy_fault_detector.config import Config from energy_fault_detector.autoencoders import MultilayerAutoencoder from energy_fault_detector.anomaly_scores import MahalanobisScore @@ -36,3 +38,16 @@ def test_model_creation(self): # Test for anomaly score anomaly_score = model_factory.anomaly_score self.assertIsInstance(anomaly_score, MahalanobisScore) + + def test_parse_ts_freq_to_timedelta64(self): + """The model factory parses ts_freq strings into np.timedelta64 for the SequenceDatasetBuilder.""" + from energy_fault_detector.data_splitting.sequence_dataset import SequenceDatasetBuilder + + self.assertEqual(_parse_ts_freq('30s'), np.timedelta64(30, 's')) + self.assertEqual(_parse_ts_freq('10m'), np.timedelta64(10, 'm')) + + builder = SequenceDatasetBuilder( + sequence_length=36, ts_freq=_parse_ts_freq('30s'), stride=1 + ) + self.assertIsInstance(builder.ts_freq, np.timedelta64) + self.assertEqual(builder.ts_freq, np.timedelta64(30, 's')) diff --git a/tests/test_data/test_bad_early_stopping_config.yaml b/tests/test_data/test_bad_early_stopping_config.yaml index f6e92848..40684d82 100644 --- a/tests/test_data/test_bad_early_stopping_config.yaml +++ b/tests/test_data/test_bad_early_stopping_config.yaml @@ -35,7 +35,3 @@ root_cause_analysis: alpha: 0.8 init_x_bias: recon num_iter: 200 - -predict: - criticality: - max_criticality: 144 From e8e3db78a2693babe37f1c7e3c1ff85311b276df Mon Sep 17 00:00:00 2001 From: croelofs <25582572+roelofsc@users.noreply.github.com> Date: Wed, 30 Sep 2026 13:13:08 +0200 Subject: [PATCH 11/18] Add legacy model compatibility tests and fixture generator Adds saved-model fixtures for py311_efd060 (Keras 2.15) and py312_efd071 (Keras 3.14), the create_legacy_model_fixtures.py script that generated them, and test_model_compatibility.py which loads and predicts with each fixture on synthetic data. Keras 2 fixtures are marked expectedFailure due to keras.src.engine.functional module path change in Keras 3. --- .../create_legacy_model_fixtures.py | 302 ++++++++++++++++++ .../dense/anomaly_score/RMSEScore.pkl | Bin 0 -> 36 bytes .../autoencoder/MultilayerAutoencoder.attrs | Bin 0 -> 454 bytes .../MultilayerAutoencoder.encoder.keras | Bin 0 -> 17053 bytes .../MultilayerAutoencoder.model.keras | Bin 0 -> 44083 bytes .../old_models/py311_efd060/dense/config.yaml | 28 ++ .../data_preprocessor/DataPreprocessor.pkl | Bin 0 -> 1590 bytes .../QuantileThresholdSelector.pkl | Bin 0 -> 57 bytes .../old_models/py311_efd060/manifest.json | 22 ++ .../sequence/anomaly_score/RMSEScore.pkl | Bin 0 -> 36 bytes .../autoencoder/LSTMSeq2OneAutoencoder.attrs | Bin 0 -> 8141 bytes .../LSTMSeq2OneAutoencoder.decoder.keras | Bin 0 -> 11394 bytes .../LSTMSeq2OneAutoencoder.encoder.keras | Bin 0 -> 21058 bytes .../LSTMSeq2OneAutoencoder.model.keras | Bin 0 -> 55861 bytes .../py311_efd060/sequence/config.yaml | 39 +++ .../data_preprocessor/DataPreprocessor.pkl | Bin 0 -> 1132 bytes .../QuantileThresholdSelector.pkl | Bin 0 -> 57 bytes .../dense/anomaly_score/RMSEScore.pkl | Bin 0 -> 36 bytes .../autoencoder/MultilayerAutoencoder.attrs | Bin 0 -> 454 bytes .../MultilayerAutoencoder.encoder.keras | Bin 0 -> 23646 bytes .../MultilayerAutoencoder.model.keras | Bin 0 -> 46717 bytes .../old_models/py312_efd071/dense/config.yaml | 28 ++ .../data_preprocessor/DataPreprocessor.pkl | Bin 0 -> 3151 bytes .../QuantileThresholdSelector.pkl | Bin 0 -> 57 bytes .../old_models/py312_efd071/manifest.json | 22 ++ .../sequence/anomaly_score/RMSEScore.pkl | Bin 0 -> 36 bytes .../autoencoder/LSTMSeq2OneAutoencoder.attrs | Bin 0 -> 8141 bytes .../LSTMSeq2OneAutoencoder.decoder.keras | Bin 0 -> 17405 bytes .../LSTMSeq2OneAutoencoder.encoder.keras | Bin 0 -> 27565 bytes .../LSTMSeq2OneAutoencoder.model.keras | Bin 0 -> 59896 bytes .../py312_efd071/sequence/config.yaml | 36 +++ .../data_preprocessor/DataPreprocessor.pkl | Bin 0 -> 3471 bytes .../QuantileThresholdSelector.pkl | Bin 0 -> 57 bytes tests/test_model_compatibility.py | 199 ++++++++++++ 34 files changed, 676 insertions(+) create mode 100644 tests/test_data/old_models/create_legacy_model_fixtures.py create mode 100644 tests/test_data/old_models/py311_efd060/dense/anomaly_score/RMSEScore.pkl create mode 100644 tests/test_data/old_models/py311_efd060/dense/autoencoder/MultilayerAutoencoder.attrs create mode 100644 tests/test_data/old_models/py311_efd060/dense/autoencoder/MultilayerAutoencoder.encoder.keras create mode 100644 tests/test_data/old_models/py311_efd060/dense/autoencoder/MultilayerAutoencoder.model.keras create mode 100644 tests/test_data/old_models/py311_efd060/dense/config.yaml create mode 100644 tests/test_data/old_models/py311_efd060/dense/data_preprocessor/DataPreprocessor.pkl create mode 100644 tests/test_data/old_models/py311_efd060/dense/threshold_selector/QuantileThresholdSelector.pkl create mode 100644 tests/test_data/old_models/py311_efd060/manifest.json create mode 100644 tests/test_data/old_models/py311_efd060/sequence/anomaly_score/RMSEScore.pkl create mode 100644 tests/test_data/old_models/py311_efd060/sequence/autoencoder/LSTMSeq2OneAutoencoder.attrs create mode 100644 tests/test_data/old_models/py311_efd060/sequence/autoencoder/LSTMSeq2OneAutoencoder.decoder.keras create mode 100644 tests/test_data/old_models/py311_efd060/sequence/autoencoder/LSTMSeq2OneAutoencoder.encoder.keras create mode 100644 tests/test_data/old_models/py311_efd060/sequence/autoencoder/LSTMSeq2OneAutoencoder.model.keras create mode 100644 tests/test_data/old_models/py311_efd060/sequence/config.yaml create mode 100644 tests/test_data/old_models/py311_efd060/sequence/data_preprocessor/DataPreprocessor.pkl create mode 100644 tests/test_data/old_models/py311_efd060/sequence/threshold_selector/QuantileThresholdSelector.pkl create mode 100644 tests/test_data/old_models/py312_efd071/dense/anomaly_score/RMSEScore.pkl create mode 100644 tests/test_data/old_models/py312_efd071/dense/autoencoder/MultilayerAutoencoder.attrs create mode 100644 tests/test_data/old_models/py312_efd071/dense/autoencoder/MultilayerAutoencoder.encoder.keras create mode 100644 tests/test_data/old_models/py312_efd071/dense/autoencoder/MultilayerAutoencoder.model.keras create mode 100644 tests/test_data/old_models/py312_efd071/dense/config.yaml create mode 100644 tests/test_data/old_models/py312_efd071/dense/data_preprocessor/DataPreprocessor.pkl create mode 100644 tests/test_data/old_models/py312_efd071/dense/threshold_selector/QuantileThresholdSelector.pkl create mode 100644 tests/test_data/old_models/py312_efd071/manifest.json create mode 100644 tests/test_data/old_models/py312_efd071/sequence/anomaly_score/RMSEScore.pkl create mode 100644 tests/test_data/old_models/py312_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.attrs create mode 100644 tests/test_data/old_models/py312_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.decoder.keras create mode 100644 tests/test_data/old_models/py312_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.encoder.keras create mode 100644 tests/test_data/old_models/py312_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.model.keras create mode 100644 tests/test_data/old_models/py312_efd071/sequence/config.yaml create mode 100644 tests/test_data/old_models/py312_efd071/sequence/data_preprocessor/DataPreprocessor.pkl create mode 100644 tests/test_data/old_models/py312_efd071/sequence/threshold_selector/QuantileThresholdSelector.pkl create mode 100644 tests/test_model_compatibility.py diff --git a/tests/test_data/old_models/create_legacy_model_fixtures.py b/tests/test_data/old_models/create_legacy_model_fixtures.py new file mode 100644 index 00000000..a0323705 --- /dev/null +++ b/tests/test_data/old_models/create_legacy_model_fixtures.py @@ -0,0 +1,302 @@ +"""Create small saved-model fixtures for compatibility testing. + +1. Create a python environment with a previous version of energy-fault-detector. +2. Run this script: + python tests/test_data/old_models/create_legacy_model_fixtures.py \ + --output tests/test_data/old_models/py_efd \ + --purpose "Test compatibility for EFD models." + +It creates: + + old_models/ + ├── dense/ + ├── sequence/ + └── manifest.json + +""" + +from __future__ import annotations + +import argparse +import json +import platform +import shutil +import sys +from importlib.metadata import PackageNotFoundError, version +from pathlib import Path + +import numpy as np +import pandas as pd + +from energy_fault_detector import FaultDetector +from energy_fault_detector.config import Config + + +def make_dense_data(n_rows: int = 80) -> pd.DataFrame: + """Create deterministic tabular/time-series data for the dense model. + + Args: + n_rows: Number of samples to generate. + + Returns: + Numeric DataFrame with a 10-minute DatetimeIndex. + """ + rng = np.random.default_rng(42) + index = pd.date_range("2025-01-01", periods=n_rows, freq="10min") + phase = np.linspace(0, 4 * np.pi, n_rows) + + return pd.DataFrame( + { + "temperature": 50 + 3 * np.sin(phase) + rng.normal(0, 0.15, n_rows), + "pressure": 10 + 0.5 * np.cos(phase) + rng.normal(0, 0.05, n_rows), + "power": 100 + 8 * np.sin(phase / 2) + rng.normal(0, 0.3, n_rows), + }, + index=index, + ) + + +def make_sequence_data(n_rows: int = 120) -> pd.DataFrame: + """Create deterministic contiguous time-series data for a sequence model. + + Args: + n_rows: Number of samples to generate. + + Returns: + Numeric DataFrame with a regular 10-minute DatetimeIndex. + """ + rng = np.random.default_rng(123) + index = pd.date_range("2025-02-01", periods=n_rows, freq="10min") + phase = np.linspace(0, 6 * np.pi, n_rows) + + return pd.DataFrame( + { + "sensor_a": np.sin(phase) + rng.normal(0, 0.03, n_rows), + "sensor_b": np.cos(phase) + rng.normal(0, 0.03, n_rows), + "sensor_c": 0.3 * np.sin(phase / 2) + rng.normal(0, 0.02, n_rows), + }, + index=index, + ) + + +def dense_config() -> Config: + """Build a small dense-autoencoder configuration.""" + return Config( + config_dict={ + "train": { + "data_preprocessor": None, + "data_splitter": { + "type": "sklearn", + "validation_split": 0.2, + "shuffle": False, + }, + "autoencoder": { + "name": "default", + "verbose": 0, + "params": { + "layers": [8], + "code_size": 3, + "batch_size": 16, + "epochs": 1, + "learning_rate": 0.001, + "loss_name": "mean_squared_error", + "early_stopping": False, + }, + }, + "anomaly_score": { + "name": "rmse", + "params": {"scale": False}, + }, + "threshold_selector": { + "name": "quantile", + "fit_on_val": False, + "params": {"quantile": 0.95}, + }, + } + } + ) + + +def sequence_config() -> Config: + """Build a small LSTM seq2one configuration.""" + return Config( + config_dict={ + "train": { + "data_preprocessor": { + "steps": [ + {"name": "standard_scaler"}, + ] + }, + "data_splitter": { + "type": "sklearn", + "validation_split": 0.2, + "shuffle": False, + }, + "autoencoder": { + "name": "lstm_seq2one", + "verbose": 0, + "params": { + "sequence_builder": { + "sequence_length": 8, + "ts_freq": "10m", + "stride": 1, + "pad_incomplete": False, + "pad_value": 0.0, + }, + "layers": [8], + "decoder_layers": [8], + "code_size": 4, + "batch_size": 16, + "epochs": 1, + "learning_rate": 0.001, + "loss_name": "mean_squared_error", + "early_stopping": False, + }, + }, + "anomaly_score": { + "name": "rmse", + "params": {"scale": False}, + }, + "threshold_selector": { + "name": "quantile", + "fit_on_val": False, + "params": {"quantile": 0.95}, + }, + } + } + ) + + +def train_and_save( + name: str, + config: Config, + data: pd.DataFrame, + output_dir: Path, +) -> Path: + """Train, smoke-test, and save one model. + + Args: + name: Fixture name. + config: Model configuration. + data: Training and prediction data. + output_dir: Directory where the fixture should be saved. + + Returns: + Directory containing the saved model. + """ + fixture_dir = output_dir / name + detector = FaultDetector(config=config, model_directory=fixture_dir) + + normal_index = pd.Series(True, index=data.index) + metadata = detector.fit( + sensor_data=data, + normal_index=normal_index, + save_models=True, + overwrite_models=True, + ) + + result = detector.predict(data) + + if result.anomaly_score.empty: + raise RuntimeError(f"{name}: prediction unexpectedly produced no anomaly scores.") + + if not result.predicted_anomalies.index.equals(result.anomaly_score.index): + raise RuntimeError(f"{name}: anomaly predictions and scores have different indices.") + + saved_path = Path(metadata.model_path) + print(f"Created {name} fixture: {saved_path}") + print( + f" scores={len(result.anomaly_score)}, " + f"predicted_anomalies={int(result.predicted_anomalies.sum())}" + ) + + return saved_path + + +def installed_version(distribution: str) -> str | None: + """Return an installed package version if available.""" + try: + return version(distribution) + except PackageNotFoundError: + return None + + +def main() -> None: + """Create dense and sequence saved-model compatibility fixtures.""" + parser = argparse.ArgumentParser() + parser.add_argument( + "--purpose", + type=str, + default="test", + help="Purpose of the saved-model fixtures.", + ) + parser.add_argument( + "--output", + type=Path, + default=Path("tests/test_data/old_models"), + help="Output directory for saved fixtures.", + ) + parser.add_argument( + "--overwrite", + action="store_true", + help="Replace an existing output directory.", + ) + args = parser.parse_args() + + output_dir: Path = args.output.resolve() + + if output_dir.exists(): + if not args.overwrite: + raise FileExistsError( + f"{output_dir} already exists. Use --overwrite to replace it." + ) + shutil.rmtree(output_dir) + + output_dir.mkdir(parents=True) + + dense_path = train_and_save( + name="dense", + config=dense_config(), + data=make_dense_data(), + output_dir=output_dir, + ) + sequence_path = train_and_save( + name="sequence", + config=sequence_config(), + data=make_sequence_data(), + output_dir=output_dir, + ) + + manifest = { + "purpose": args.purpose, + "python": sys.version, + "platform": platform.platform(), + "package_versions": { + "energy-fault-detector": installed_version("energy-fault-detector"), + "tensorflow": installed_version("tensorflow"), + "keras": installed_version("keras"), + "pydantic": installed_version("pydantic"), + "scikit-learn": installed_version("scikit-learn"), + "pandas": installed_version("pandas"), + "numpy": installed_version("numpy"), + }, + "fixtures": { + "dense": str(dense_path.relative_to(output_dir)), + "sequence": str(sequence_path.relative_to(output_dir)), + }, + "data_generation": { + "dense": "make_dense_data(n_rows=80)", + "sequence": "make_sequence_data(n_rows=120)", + }, + } + + manifest_path = output_dir / "manifest.json" + manifest_path.write_text(json.dumps(manifest, indent=2), encoding="utf-8") + + print(f"\nManifest written to: {manifest_path}") + print("\nLater compatibility smoke test:") + print(f' FaultDetector.load("{dense_path}")') + print(f' FaultDetector.load("{sequence_path}")') + + +if __name__ == "__main__": + main() diff --git a/tests/test_data/old_models/py311_efd060/dense/anomaly_score/RMSEScore.pkl b/tests/test_data/old_models/py311_efd060/dense/anomaly_score/RMSEScore.pkl new file mode 100644 index 0000000000000000000000000000000000000000..efe894012aef228f829ce9a9723adc336084f9ba GIT binary patch literal 36 ncmZo*nJUQu0ku;!dRU8-6LV6hboQ{PWtNnrro>O_DAfZ1tTYQ# literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py311_efd060/dense/autoencoder/MultilayerAutoencoder.attrs b/tests/test_data/old_models/py311_efd060/dense/autoencoder/MultilayerAutoencoder.attrs new file mode 100644 index 0000000000000000000000000000000000000000..96c55e0f5688d2bf2bc15929c32910a32a810336 GIT binary patch literal 454 zcmZuuO-lnY5Z&63Z3~K2!N1_iv$r05SStPj3A5SJ4b3Js$rdUIJ$Mo381W?Z>TmF0 z_&XF4uO3X+QaqT`n>R0$H!rKs!%Hh^&aFSDU5Q|nP*===Lq8dx=hN5E=WjaXS{1?x ztw6F%1Xmlh{*3m7Wq(@!o`yL%UNS3g&}aM9!@1_A^;wGsQd`RuROo3`At+|AYcN&QqKQx+BBM>Q7D;EAzqLnwvfc2M5eTX)gR=J2 RmtY-hsGbxme3!3JegGX_t}Orn literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py311_efd060/dense/autoencoder/MultilayerAutoencoder.encoder.keras b/tests/test_data/old_models/py311_efd060/dense/autoencoder/MultilayerAutoencoder.encoder.keras new file mode 100644 index 0000000000000000000000000000000000000000..d0f9108ebfbc411a564f7ab747b63f6e5864419b GIT binary patch literal 17053 zcmeHPeQXp(6yIwpT>1W{0mb7)EmF>YKvO8af>3e@!4nY?Y_8khwq3j3J8$pGXQdE7 z3Nc8cF-8m_1QR00Ac+xkwr7Nx{(%sU8bS;ZF$y9`42k|jbY|zh`Wa^ol{z@sj3Kx7wSefT(#| zq<|*-RQm#(z1UGS&rxVEu-OTf)7MIQ`oIj^{{-UDN1#^oR%qy|Cx)Vgr z`lxB|rQw1=Un7X9I-goEH-MmKpEsmPl#?#fp#|z3lG-4vlA}JP)&+@pQK4e%6j9SW zs@SX(FH7vxIT9vY?MNW0bv~~Ypd*6;QC7uTT}m(zl1P&xZYHXc0UNg3`58c8lE~$% zKNMU^2kO&_iL4cab&VdGc6+o&(N8D1K@BNNfvu#Pu<-^r>uvUW#U}7n%v0Z5ool-BSuwDxI z*vz8xZ!Z%RC(aHjVgM8eN9*%R*`pg)4sQ0O>;<00nVRmjAhBgU%cKtDDN?J1WX0== zLxutPDHFtT6f{Y|+^~Uwm0mnW#D9hQ|JK&(>Ym}%y;@rNoB>|_#3mjkM0>l5SW)pe zihb>OCN!n{SXYvhh(aXb&~PAb(l7Gc1G?LuE2FlLdM?gdX0*v{orp7ED&NIi8}GYn z0%f*_#4p?w^zWpTzLI!71cA(Uyuq*1%bZC z(zKgoXNqH^BsVk$HAmyTU9P3eMh%}zGG%gDt-=tUO0Vf}|G`1W(*x_QCI~ffVu7+9 z%EMXg#3Il?LCAylaloIaTeG^VN+6WTA4?b}T+Cr-R%|fKL1h6~)nYeQ_$X-YhjQT) z?8FFXe?tGrVi?fF!icXcn=xtxTr&K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K$|$1!}f4Z`nT-KTX%mh<|_{U|J;EG-Xk6XcoiXcuXyI?<8|>fS6WLC z4zeyiuaxHPEVoYnrqa5P@$c^2JIbq%m-LPKT6gOoNBzXOc5knPwFepjZ~JWv_*QXy z@V*$Y$C)_8&(Pa>F?JIwFcWy`i@)M6NI%G5KL?_hU*?U!1;8KNy{`66Qovh0KS& zjY41iJ+=es;d3c&Z!qj12$1|mr*4X}0DmwFc>jbQ(0HGdjumb&B-gQY;4LnfWqbcXYucgl7#xljV z;T6si=iXL~jjXg!IjM4tm^(JDA@?cA#^=6pWVA#p{`OxZ()8icX|`pr*+(XBbEK|6 zu6Ta(c1Oj?32ATcPfTn1BF1@iSgm4fLu?x9@5_9K=sqF3?CPJ0jD9Y9^48tohxytT z`s(@%Y_TAQ#&t;sJi850UpvgSk#U`r2U{vBq*RR>w={{amMu$lk> literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py311_efd060/dense/config.yaml b/tests/test_data/old_models/py311_efd060/dense/config.yaml new file mode 100644 index 00000000..420b9f3f --- /dev/null +++ b/tests/test_data/old_models/py311_efd060/dense/config.yaml @@ -0,0 +1,28 @@ +train: + anomaly_score: + name: rmse + params: + scale: false + autoencoder: + name: default + params: + batch_size: 16 + code_size: 3 + early_stopping: false + epochs: 1 + layers: + - 8 + learning_rate: 0.001 + loss_name: mean_squared_error + verbose: 0 + data_preprocessor: null + data_splitter: + shuffle: false + type: sklearn + validation_split: 0.2 + protect_conditional_features: false + threshold_selector: + fit_on_val: false + name: quantile + params: + quantile: 0.95 diff --git a/tests/test_data/old_models/py311_efd060/dense/data_preprocessor/DataPreprocessor.pkl b/tests/test_data/old_models/py311_efd060/dense/data_preprocessor/DataPreprocessor.pkl new file mode 100644 index 0000000000000000000000000000000000000000..89e96022cf8a21aef52bd719c8bd0d4f223aac6f GIT binary patch literal 1590 zcmbVMON&%T80~pFj@s?KS`(MqOb9f(Qc>)VO=3)kQ8Oe2j1<-Pe%*DQ`$|>anQ75H z7Mkf$yZN$6K-`3Ye?bt;G7t!XKnMha3vnTW3m1Zm@vFK$ZI3U+ySUt{Ti>Zu=bW#; z9sTjW@q&9U;k?=u4 z6J@an%;lNd*+aHG$fF}lmrzWJX(eVzuHFg7-o}X7 zcMio{Pv_hLizxVskJx|6+SeUil}aIwnOQF!8;M>!3% zi~ByA<_8|P3GJGhC4iKXd75I{^M|G<6uGaV-9a-N0gus4lEz^UNVysHlC*l6vM5Y0Aj?7{1oRKLyeKk zD2|#jUw2ZlCBvreQg+>lA4|CKeqL6)bx^}QF%H^Q$ACu>W0s=u{2-l+|} zfBW$-8(-AWBJS>Y*fK~JBqZh7fy%+k{yfVi+QRDKGv)EnW_aJG*IRE0W^WBN#l_zG z#e8|+^X)5v7R-6IW+vP~X`d`QIOx)g5Ao3p#4FK7#%&7evIC%o6^G5Z<;W#DV&x15 z

MNI%37FPn^zESHLUes~NN8-dM-cWiDS;T)bJAJN}re{mO2hJ^$ye>hXL3PQ#;W zZh|8YuPXoj{C{(I|1Z@3zV^ez)dT-j-~Q{~o%>hIu3VfIU)sI|Q|jM|)I`*ql#%fW SqC|G+Ya1EdOsFrrS>*|FK!H5~ literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py311_efd060/dense/threshold_selector/QuantileThresholdSelector.pkl b/tests/test_data/old_models/py311_efd060/dense/threshold_selector/QuantileThresholdSelector.pkl new file mode 100644 index 0000000000000000000000000000000000000000..1c2d2b207ef4719b869a855c307ca8885a93244f GIT binary patch literal 57 zcmZo*nX1PC0ku;!dN@lmic*U+@^ezAxZ8hywdMYCbGsgn!qUXNlFXb`pxC=KFeudn E04xs`u>b%7 literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py311_efd060/manifest.json b/tests/test_data/old_models/py311_efd060/manifest.json new file mode 100644 index 00000000..e70c3646 --- /dev/null +++ b/tests/test_data/old_models/py311_efd060/manifest.json @@ -0,0 +1,22 @@ +{ + "purpose": "Saved-model compatibility fixtures created before the Pydantic config migration.", + "python": "3.11.8 (tags/v3.11.8:db85d51, Feb 6 2024, 22:03:32) [MSC v.1937 64 bit (AMD64)]", + "platform": "Windows-10-10.0.26100-SP0", + "package_versions": { + "energy-fault-detector": "0.6.0", + "tensorflow": "2.15.1", + "keras": "2.15.0", + "pydantic": "2.12.5", + "scikit-learn": "1.7.0", + "pandas": "2.2.3", + "numpy": "1.26.4" + }, + "fixtures": { + "dense": "dense", + "sequence": "sequence" + }, + "data_generation": { + "dense": "make_dense_data(seed=42, rows=80)", + "sequence": "make_sequence_data(seed=123, rows=120)" + } +} \ No newline at end of file diff --git a/tests/test_data/old_models/py311_efd060/sequence/anomaly_score/RMSEScore.pkl b/tests/test_data/old_models/py311_efd060/sequence/anomaly_score/RMSEScore.pkl new file mode 100644 index 0000000000000000000000000000000000000000..efe894012aef228f829ce9a9723adc336084f9ba GIT binary patch literal 36 ncmZo*nJUQu0ku;!dRU8-6LV6hboQ{PWtNnrro>O_DAfZ1tTYQ# literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py311_efd060/sequence/autoencoder/LSTMSeq2OneAutoencoder.attrs b/tests/test_data/old_models/py311_efd060/sequence/autoencoder/LSTMSeq2OneAutoencoder.attrs new file mode 100644 index 0000000000000000000000000000000000000000..ce5b1d97c6106d6accb6f7635c9313e85984e888 GIT binary patch literal 8141 zcmbW+Yitx%6bJAv6#Aeo%Ns@QS`c|?S%V4+rW;C9VzI7(2_}-++1=ajz&@rkvuLZx zqJlPzp{7$2AIX|%BEf2Ff(a&?1qGE4r0EBYqOfY>3zP-RLqzeM(nIQvlij)7q_e%9 z-=1^+XZoqB;_d_0uA$c^YmPZKDz`CBx7JyWrLtKSW}!rwY0`gA%kWInm3C$|7Mm4e zEukiohNQ^`vl^~`l*?sSX{;p~l{KYZHk3r%YN&g*{kw*DCqH3UMwzU|m3YfAsq+UP z7&x>0vN<`Fh=&!tTaHT2Og54l)2$}6O3|eezp^^a@}O*lBEvnn&9O{Pgd)1tSY(z( z6S^+N5!pvYH=&d#^8?v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;`0)*Y{!3!cxjQ0FRp@fGy62d7RQsGmI#yr|2*dcF@m?Sb;- z=c7KU9yveTecycWqApYW=ojdn)+6V=SoQF2;As!}`s7`D|Nbm`QRm)nL~r*@$Nz>V GYySnWSV5Ek literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py311_efd060/sequence/autoencoder/LSTMSeq2OneAutoencoder.decoder.keras b/tests/test_data/old_models/py311_efd060/sequence/autoencoder/LSTMSeq2OneAutoencoder.decoder.keras new file mode 100644 index 0000000000000000000000000000000000000000..84acbb0086bad93ffacd328588c820c411aba8d6 GIT binary patch literal 11394 zcmeHNdu&rx7(eZpR2ax(%7Q4hkT?;VuDmw3-Ogmg!F<$b&{50XdbeG;yB+u54#q+l z8g*z?ARuUrK@EaH3~GY1#al68_=7+24-*n!7!#fRK@bgMG{N)wy7shnFdieUw`rcY}3#BMK3_?n1w}?>$n58{|6%e_Itxj>wkmU2aD8PR|O(kj-$rVwh@F z_bhOG{N9qeUY}>C+k>f;uqn4I5!&zb&zt2do8>R7Dw(%nj(@@2`JT1G6j7SJrsA!U z2$An-EUGc8H>u5BP-`?2(-gvqiu9UBqgTrCi? z7ug_NjV)o742R7Yxs51Tug5fPrh85Zvx!(8w9nI|MP+NYpG-H~WWywcO|oVZjSRWD znR*mDzz_|)Telc{&ssvMG^?hi7)k`Z!DJ;&Pnm%ysCq**rekXC5NdM>v$=S?s}&t< ziutg06THmFGWa-?*)d(Uhzg~cos1W^T_y{RJFrz+j0lODO1MFl2@zi_j0;`Sume;} zl{Iw@_CHx@aoLi_O{#4QUhdbTM$~#jSDT_nt6+?&P{$K5X7?`{A$nb=9#1Pql&P1% z&;QHh*5gHwX|lns=L=5t$v8rNt6Cl5jH8?k%rb2tyNbjsF;$C%lfaQ> zClDq8>Ih&e4V(4#cylHpex}<;|2o%(LRSvA296HI_!tc^1P_-8;MsUeDu6W{vSb<> zau8-g8aC980^w4EzXXKSA(RQr0Q6)KhcFkmNBYxHM%0H0Wi)1y#F9*!CYo@kyCXw# z@T8{7i{7nCNqp(^m7(MNzX~j!h7kFVBj*L2Of>H*MQv`eOmEBF4Ykz^$Bddh3J)RV za-k8Fini#_1%8qFgV1Gu}k)_ zk-b8$Z1}CsW8*CxmkhuC`$NPpqt5*fR}YBzg*evD@dJJV{86w&=Vg?SJ@jz314s2@ z&f^TZX~Y-EDH_Y#r5y03tckwh0UPN0c-wV5BY^!;jBgIf1$05)Zo8TFgPm@^Uw}^B zKaBeN{mm8!M0*FyW4jAd{c`0{PNoyRK(*N zILgN>_|X8pAm3E+_N5l=eyl%_?dJdlz9Nn+LEVVy!K{|KnNYCO@t#bOFd3O6B>!ptjOVYma z#5;EAQv9$Z;C~Ipf8MlNI$b&=zTvx9?RSsg6aR6}9!Wm6&tAQ~S~~T^KeqF!DfXKu zj!2*WcGBKexl3yMbxOd$`D|il)e70i0(cFY$k)B+gmT z9{f3AyPIjUj1`IBp*_!TSzi%f8JZZV`Rf^btM*c*{oyWq{wodA-R_F`x=#++XKS|F zs~xulI?wEs{(QC|@WRLfdtJ?5yX5SQ_~Pg$X~L9ofwAX$q#a-Gl>S{+ZcivIj+ZSe z2)wb)^?BaPqJVf_?Vg%2JYxmoYLzGB@UZPn$8G9)wI83%MT5s_a2n$vJZMJO*Ln4W zW5wm~|MXywck0;QV4cHRh~P#j{oP#vO&1N8DR1(MQ^j|2`=_qJRrV4eeKR+CVy5?h c`X~BuND literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py311_efd060/sequence/autoencoder/LSTMSeq2OneAutoencoder.encoder.keras b/tests/test_data/old_models/py311_efd060/sequence/autoencoder/LSTMSeq2OneAutoencoder.encoder.keras new file mode 100644 index 0000000000000000000000000000000000000000..7e598349de0c0b397acf60e1ef2b45b17195e7d4 GIT binary patch literal 21058 zcmeHP2|!fU8XmwM*VHGjAgK>ga2R1&X3h_}zfi-B%9MryMrLG~!I^3jaHeI5lWNNeTq@9i+7Gv8I(pvoXTL-=ylG1PR>L&JellTUBNc}t|eqP?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|&Or_h|KppC!}^j%SYdTmm%DS zQ#0VVUzAKM{}W}x_Z{|G?&ZZv+j@o88Q8{<%k?Yz-92f&y)9JBjEY{XY2Ji*%8RRxhaWO^m{+!tYYN vKQ)S}a$gQ*{bt4L6Kne}jQbP6W&Ube_{|tWflZsS6n4zdcBY&@j&1!LTW@A8 literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py311_efd060/sequence/autoencoder/LSTMSeq2OneAutoencoder.model.keras b/tests/test_data/old_models/py311_efd060/sequence/autoencoder/LSTMSeq2OneAutoencoder.model.keras new file mode 100644 index 0000000000000000000000000000000000000000..c075a50758827edc8afe44e955154d5d39e4f18b GIT binary patch literal 55861 zcmeHQ2SC(F7hXgK5fK#?6$P;&%GP9CHUaCQSg@WQ7FYqLNfSF35Iar9hFDPS*kCu= z4XCK7*c&!PITfs^r^l)1{aKPxSwQZ%JM~vqm&u!Xc{B6o%X@ETlB~0ner+=r{b|d3 z9=hYG14U@R4XCfLB3SMr50+T~D3Ucw2`<62IE?ZVAkrFb^ z8Zc0D6{Y6|2g<$uM zO&;v-<>IX^b_w#52WXo&+AqY%r>m8?tCe7^R%5|aO0%uU`}oU)1$?c9pa6Mbkd}A6 z+$Tues6e@=XQ@g-#)qCz?Wg5i&(QKIJiUX06@dy5pbWaQk3Ij$PqBOZx%r3qQM{Bs zO1rFW5YVQ(iOw*2pOQ+^M#ds_};zo2nE} zjY$Q=UE%OmI5w4`w%?GU{dMpP>hTE*_SF_uFa{OjHBb>866og=q?i;!4PYshn5zkt z1XFh56FhtRyST~SCr*|JdT4P6P#vUY8z18HNmhtopuf+j8NuGZ3Kw7b1pmM?T;9Q2 zLDWTMEvM{4s9b9ss0{01xu2J|CxHt0kibBNU$9Hr@*rhAXz#$lU@w2q50>?#G4rHs2PKck=2FV~hb`yv zVZKDnP|2edf&R4aKeV@63YGBqVxdsP*Pa|g4Z909Xr7ATig7_%+Yldl zV5PYDq`U%L^eZ*>pMb%KPidFS=5i(UMS`ZA_(>y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f$udf^*`_RdaeKf literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py311_efd060/sequence/config.yaml b/tests/test_data/old_models/py311_efd060/sequence/config.yaml new file mode 100644 index 00000000..1c68506f --- /dev/null +++ b/tests/test_data/old_models/py311_efd060/sequence/config.yaml @@ -0,0 +1,39 @@ +train: + anomaly_score: + name: rmse + params: + scale: false + autoencoder: + name: lstm_seq2one + params: + batch_size: 16 + code_size: 4 + decoder_layers: + - 8 + early_stopping: false + epochs: 1 + layers: + - 8 + learning_rate: 0.001 + loss_name: mean_squared_error + sequence_builder: + pad_incomplete: false + pad_value: 0.0 + sequence_length: 8 + stride: 1 + ts_freq: 600s + verbose: 0 + data_preprocessor: + steps: + - name: standard_scaler + step_name: standard_scaler + data_splitter: + shuffle: false + type: sklearn + validation_split: 0.2 + protect_conditional_features: false + threshold_selector: + fit_on_val: false + name: quantile + params: + quantile: 0.95 diff --git a/tests/test_data/old_models/py311_efd060/sequence/data_preprocessor/DataPreprocessor.pkl b/tests/test_data/old_models/py311_efd060/sequence/data_preprocessor/DataPreprocessor.pkl new file mode 100644 index 0000000000000000000000000000000000000000..cfbf47e5f05d130d1bd71397ea9604476ddec78f GIT binary patch literal 1132 zcmbVLziSjh6uu;P$t5utMH6Cz;@NnySfhdw5f@D%dT;^H!bXO<-MP$?+aJu#Mh}cX zio`n@u*kDj5YpI~Mk~d_&dw@@V7e6k0}2-UX7@Z3krZw*%$#2f;*!FN zEB)K2d+tG{Qn~&UpX4ap3Tkabd0w(WhJsM&UTc4@4loSVg`mq(g1p?Phe+L1ByGn} z=-&FSb{GF@moZg_y8IJl5-mfOCza<&0{jR+W+vjtcg}OJJvWi5uD4&V)@=FyL+Q!- ziXD8Jy!mE)!v<4ve^-SiCZrdlT)ETMtTh91Z54PRuhb8u~h)Wd?T&Q-u zSxv3k_0ixRPjQmy-_rTyMJg9se5}RCmw`|4!;(+_8}vy-E4TP5K4ZA!XOOJXfJkbb zjVrf{WpqT)Jd!2LIG*(ECWO1@-Qrr$l= zvNsB6i<_Uf?5S__&T?@*B|QPo_Da7nu{m74zimH%{o==`wQc*>+v2OQnU6_2zs#=~ gahM+M?g@GdR|q}P?=wFXO}q`DptTTpy&YS>0LuKxKL7v# literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py311_efd060/sequence/threshold_selector/QuantileThresholdSelector.pkl b/tests/test_data/old_models/py311_efd060/sequence/threshold_selector/QuantileThresholdSelector.pkl new file mode 100644 index 0000000000000000000000000000000000000000..d68c4bb5d77f3ca7e8972ada3cf171386c4fdc35 GIT binary patch literal 57 zcmZo*nX1PC0ku;!dN@lmic*U+@^ezAxZ8i4n3=Hh+r%D@!qUXNlFXb`pxC=KFeudn E03)0ge*gdg literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py312_efd071/dense/anomaly_score/RMSEScore.pkl b/tests/test_data/old_models/py312_efd071/dense/anomaly_score/RMSEScore.pkl new file mode 100644 index 0000000000000000000000000000000000000000..efe894012aef228f829ce9a9723adc336084f9ba GIT binary patch literal 36 ncmZo*nJUQu0ku;!dRU8-6LV6hboQ{PWtNnrro>O_DAfZ1tTYQ# literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py312_efd071/dense/autoencoder/MultilayerAutoencoder.attrs b/tests/test_data/old_models/py312_efd071/dense/autoencoder/MultilayerAutoencoder.attrs new file mode 100644 index 0000000000000000000000000000000000000000..d221693877fbe26f2034e158a3575ad6cf67f85f GIT binary patch literal 454 zcmZuuJ5B>J5Z#b}BoGQnv`7?CaR8d6OR)lR0c6d32iA($4z@Q^kdSDRrZhcmDh@zH zuD}tv0VNUz_7X)DxO(&EdHm-2q4o6INa}O%PiR{r7$wvVGvLrqMwi+7`{(kT_PJKM za6&7P>>9yU2CcuK9bws@mVcx{296iZiaYe_E_HCGd0~CppuW`BG6f}i8kPu(+1m;X z<_wL|##6UMX9TzY%F|vgfXr%HIb17%+DZ!>jQv_p66(&;WI9l3LhVxLD1)mmDjuMT zFvkrngmv01eB87Z&4h<0Md5(n}y{hzmRdGz(M zI*h7{`W&RpfKTgXIuaIWB20S_dcoT|pe7BcXcS5&REQU3h%F@1FOVs1N|2tKz@4Y| V%%H41^(0uwYN{iJ3g6|c(;q(ctq=eJ literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py312_efd071/dense/autoencoder/MultilayerAutoencoder.encoder.keras b/tests/test_data/old_models/py312_efd071/dense/autoencoder/MultilayerAutoencoder.encoder.keras new file mode 100644 index 0000000000000000000000000000000000000000..bd2f2de38a306ce991588b4aec4da596256064d0 GIT binary patch literal 23646 zcmeHPacmpa89yh@a64cDs+Cp@TyImmF13=lP1=OUDWr{Q3s{9}*+O)_*w^I9!@80*> zzGq*ZxM`Bwcaih%z5Cw#-uu1Z``&looi4P$cGX&e9UFxi_su<>Btw7Kkl(OuNKwg< zeD~`yZPYs?CnQ}wA}4eurg_^uUcawto3F{+;PDbES=6N?a+H=gH#WCyZQQxFd1q%+ zOPhaNo4?sR7P6@N>7ma*|G~9_K!2YmsvBE%m3L_Iq;Y^&G`o{i*)JK9K~W!+;m;8WASgn8WWQt;`>SE?Fa8CwkcwS^$sYwIXmM4h5Rbwk#9dbuWP|6jPPRF&jmQ zrTzHnm87N^bc8#|xkPAmM55@C0@$o1PmOw zWcH`%6{tnnpqsO95VZ0u6}#~Dq@)?jadSGvERQaZ3Yo+Hq@qT1@}pkH?1EKChlvX) zOUVM-k9wuV0IYwjVG%{s4v7Y#b1Wf>90?2b5p~G!{8i2x86=A{mN-UG>4pB{YHn=s zH1>^+^^xjBN1-pHBu~0uNH;r+6gns$IK*`j#~v3GvZyBM)#YE1q!R=DL@j+>+na`9Kr8m1&jKnY+X~eXmi$vZXboR64&6~i> zM&BKjfAga+uBAmGZpnQ_G(C+ghPb%d_$i5<&BilIiCo+_p;szov$3vMbAd44u7vfP zGarkxVlTGUFjqV3Y&E5LzjC%3zh$e*o50IPUEBMiLQg5Tl5D9<_pQ8J8`G1^FCbhr z>k_e8(#YOMF}d7uS^Gt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z;}ZV9>Nv%STnux9l;gTOTBTRasjRm&A&EZbJw<>j%98}V{h9! zcK+89%9`rS^60hwm8la#I`w7xV#tRu6`_OE5&;Fjy}_4!3i%B(S7+riIV&feXE7P+ zraR5sdafGCF!0-xv;%2j2z<6b!(`0TXL~eEU9Fm1o0WS!4VQvlk4PuyFQ>M-! eT%^-y=U6SmocPoUUAsZ1&fwoZkRCVyss8~7LeE10 literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py312_efd071/dense/config.yaml b/tests/test_data/old_models/py312_efd071/dense/config.yaml new file mode 100644 index 00000000..420b9f3f --- /dev/null +++ b/tests/test_data/old_models/py312_efd071/dense/config.yaml @@ -0,0 +1,28 @@ +train: + anomaly_score: + name: rmse + params: + scale: false + autoencoder: + name: default + params: + batch_size: 16 + code_size: 3 + early_stopping: false + epochs: 1 + layers: + - 8 + learning_rate: 0.001 + loss_name: mean_squared_error + verbose: 0 + data_preprocessor: null + data_splitter: + shuffle: false + type: sklearn + validation_split: 0.2 + protect_conditional_features: false + threshold_selector: + fit_on_val: false + name: quantile + params: + quantile: 0.95 diff --git a/tests/test_data/old_models/py312_efd071/dense/data_preprocessor/DataPreprocessor.pkl b/tests/test_data/old_models/py312_efd071/dense/data_preprocessor/DataPreprocessor.pkl new file mode 100644 index 0000000000000000000000000000000000000000..50d17636271a4d69e731286e945f564dc3221e06 GIT binary patch literal 3151 zcmbW34{TLe9mik)Qd;_tLSci&B9O2|Ytf*CjrEl>2-H2hcA~P()7$sX>$&ZF_ukz< z{euM_AmzPrwiSE!2aK-SbViM=29p`*vKr^c5)x}dB1=HJM54V%)J*Z@f|BU}O$m*z>@R9~| zc!Eb=(^m2hZg9J2h{ZK8;j$Qa{q@F}=4#Bcxn-MC?l`*9)3`vis?}H4Ijd_--F`@s z0n3uwATupj>>E_Q9raN?$&RI=34jF{#qN7iQ5z=S0B&<(l;T#L(-u*Kh5 z$ub88(>6Irw?E1WaE%z;N;-ZP|Ragu9>lFOp>Y}$HMOXR#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Whunos}r<3`BEHwIX=K{9-TB zVrfvaV@lrYzxa5g(&9_7D}NHmtDF8ru!(Bi;sM``DZcL>;@ngAawgu0h zBUw-ut2(oG++eOalNP^9Q|Yc-Sdysu-S;u=tQsS&MvWa~FXtHD#5U<)p=MKoMitZN z3S!ZMf`~|IEo%=NehB3d-Y%gted^9u+^^Z6BwY1Ut6g!fHvAlW>4DxqPBw3Q`;Ddi zT654A1K)p=`0KqFm;dc@D183uhp!H9{B!fIe|r1MyFaM+#j_pn#)#swIyWq%-=XWF XiI*mM(zJ*0-y(G2ZW9wy#%uf^S%<~3 literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py312_efd071/dense/threshold_selector/QuantileThresholdSelector.pkl b/tests/test_data/old_models/py312_efd071/dense/threshold_selector/QuantileThresholdSelector.pkl new file mode 100644 index 0000000000000000000000000000000000000000..0329b0dc63680c2ac76fe5801c61e47b6097b903 GIT binary patch literal 57 zcmZo*nX1PC0ku;!dN@lmic*U+@^ezAxI2g^D1Q6dUfIJ@Selqul9`h_#ohj08W@!7 F0RRYd6pH`= literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py312_efd071/manifest.json b/tests/test_data/old_models/py312_efd071/manifest.json new file mode 100644 index 00000000..493176bf --- /dev/null +++ b/tests/test_data/old_models/py312_efd071/manifest.json @@ -0,0 +1,22 @@ +{ + "purpose": "Saved-model compatibility fixtures created before the Pydantic config migration.", + "python": "3.12.10 (tags/v3.12.10:0cc8128, Apr 8 2025, 12:21:36) [MSC v.1943 64 bit (AMD64)]", + "platform": "Windows-11-10.0.26100-SP0", + "package_versions": { + "energy-fault-detector": "0.7.1", + "tensorflow": "2.18.1", + "keras": "3.14.1", + "pydantic": "2.13.4", + "scikit-learn": "1.7.0", + "pandas": "2.2.3", + "numpy": "1.26.4" + }, + "fixtures": { + "dense": "dense", + "sequence": "sequence" + }, + "data_generation": { + "dense": "make_dense_data(seed=42, rows=80)", + "sequence": "make_sequence_data(seed=123, rows=120)" + } +} \ No newline at end of file diff --git a/tests/test_data/old_models/py312_efd071/sequence/anomaly_score/RMSEScore.pkl b/tests/test_data/old_models/py312_efd071/sequence/anomaly_score/RMSEScore.pkl new file mode 100644 index 0000000000000000000000000000000000000000..efe894012aef228f829ce9a9723adc336084f9ba GIT binary patch literal 36 ncmZo*nJUQu0ku;!dRU8-6LV6hboQ{PWtNnrro>O_DAfZ1tTYQ# literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py312_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.attrs b/tests/test_data/old_models/py312_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.attrs new file mode 100644 index 0000000000000000000000000000000000000000..253ea8eaaa7c0a59f2b893556857c95e7e55af54 GIT binary patch literal 8141 zcmbW+Yitx%6bJAv6#Aeo%Ns=PS{@>3*#s2?OgBPOVzI7(2_}-++1=aj$UdesvtX;h zA_6uJv8GcIAIXwnBGF1~f(a&?f`ZBi()0sHQCKy>7s^sApdffo=^^#T$?n{3(&^sL zZ_hdZGyT+5VaJh5*WhcDHOCwsm7AHSTkEX4V%e++vrr<;H0eL5C3q(3N(-~<3eB>x zmQWK(L(*h}S+zGl%H=XEG}f4m%9_$58%iQ>)z&=U@?GtF6Q425qfFM~O1yE1)cAvs z^j+A0)tneg#KQ{SEk~sWCL2kO=~lg2q3F`EUsj#H%>#QjWJuxYm zRHCpo%e;@pnbz1WHOR@RA%&U2LeN`vST2n@U)mkhAuT|tjRJb#gj3$xjK~4Sal34E3&4^&6YV@hlXX% zYPTR_yalddqgiEmG9tFfYJFj+waS_UPgTKEtG>Se;p^}k{8s0JJeL*3V8!@lSUW7k z3N9-y#VFtf?^j^~SZx^ARA5%9a#&JeLoqc9bHg)Jf+rAca@b~*L38{@B_2*}lnf=t zbVH7*x@1M>nq`s(&wd;}Fc~tSzsNmiQ9OKOkalDD87bw9PVJ_}b-ms)WCEA&q5k;`7)%PxS=w@=;$j;*?aMP1v$zIV{m9w<-Bh32C^sUA7k zmhB7w1TX5;6^lMW@3bDd%(!3cFM`jvPu}@Yz4qH9k^SiT zJo9zwg&%CX44(Gj)VT|klE1)gy(PYqAsv*>$~Wk z)+5(D``$%Yz~|d1?|j*_pPH-6u zjU&O+9w<+KKI)U|k?Z{^@CSNP=i519OCflt^~iPkkCl!BPkYGKC+|GBG{1sg)V2LE zuWB@SyIkz*k#lvP?nKY$nXgkfy!=2Bc-n(gm#JBP6uqePmt67}gQq=Ep8R~&C)Fd@ z)3^T{^rFuD#*>i}@J{QIOS7>9=xGnR`sAH^{*f)E;6+{PvN2{1c)MKe>XFMHzH>Kv zKF@qz;Ki@2%D~eeoVwmMyWT@D>U_8R7MFvkJy4$feAFk^BiHp~|55a!&eQ$YV-?_? z)+5)}vi4i_w1-@M^3Jt79zbuGi(Nf(nUiYD4W7?4U*}KHC>sZ!_Tbd@ zC?|KL7j@nRtuw}hr#(=f{Cw0W)gza_y5styhv&aii4+pP{$Q z#jYN?9@og#w}9vK%-4C3A3Tko_Tbc|+apg+2QTW}>!x2sPkW#|`T3|%sz)w0`^45; z!Hc@=`BeFB;GNbZ7dW(F4|>`|u0DC!``p=?w}TgTzLk5r(A(u=SC3rRq?Jo6!Si|M z>pW+!eTJU);MBFf-M!iaUevj?@EP>92g;M5kNTu~JAPkYGKC+~W8&##yPUetNz@Asg$%f+r9x%AwQSu?@&dFJcf1GU}gX%9|a>Z8Ax z&H^v$vO79IM^Ag8Jo)*kPpU^Q;18^s4PMmsPMeTH@3bB{-w#LE-wB@fkgHGLb-nxa zCG?`svti!0IpFPbv8zX}t>$#aUEujV^L4J0mtR9qdvNO1zGbuLf){m}*DrRXr#(=f z{Cw0W)g$L;`yZSKUexteKlufEr}fBrFIPN%H+b4Zu0DB}K72TXUevi?G@|!-rs97? HlhywMH>g6U literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py312_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.decoder.keras b/tests/test_data/old_models/py312_efd071/sequence/autoencoder/LSTMSeq2OneAut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UeD~7%t<31wlIti%5&8R&q>U}K F^dC8!H~atq literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py312_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.encoder.keras b/tests/test_data/old_models/py312_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.encoder.keras new file mode 100644 index 0000000000000000000000000000000000000000..cfae7afc0697108b92af776ac72e8e7efc9dbe2b GIT binary patch literal 27565 zcmeHQ30zah)(@Ma)(U7rTNg~VXw?{YFwB5EiVC=I7y<-{h6Iy9MMWuY2z9H^hZ}uL z6;V-ft(wfB6_r=lTJ&>iD_?CZ?Nc9WTWz)V-DO6S3zSOxo?EUzGIwUqoH_G9XU>^B zb4?<`?Ce{K_^YGHw|!((2$Ny|nlpb%N`oR!VNggW>$RF0;weghvnDM%>F? z>@D&1k$8%`yNekrrChH_RmQR9UQ#c=9@4-bUV$N=e!aYXdU^Yb(<3ap8r|HtquyC0 zV*i>kUBzlO@u~#UQIa+;MXh8xaa~IEx>yNQrc~=C@hO^E1Jk`i&2}5BR_OI|jUtI7 z9$;C=ab%dx5K{uBCYIr%V_O<@3YA6?!}Vg&r6`#qwIYof8q;9H46#rGQdgtPL7LF)U{@&hx{$75*0e)USd}Bk3P9xVVr=~E*!l6N|L#O0x z42-3lX(>S~k5R->>tb9aIpft{n*ASjM`aaOHdkWw+qH~q^K3TI_<)&z81R}!nratV^DiB zcuFNw&xT0u$C`qVr#~lowXvItz%VDCjl;Xv8g6c=3~BOOYsqwAMAmao%23U+y2sjT zxejZqh|_74nOV(`+hUdqYs`%Acj1XiQK{qPW~g$`zt-Tw@)0`U8t#3DSfNYc9Q_PI z1eMGA7;jK&^o&Q63*7A!gfpH`A`^zRx-?k@^8BFc-6P@_j!^|f}YBTF$avH6QarIO|^*Y~L zQ21|}NdT*88u86nJvGgQEE)cofiM=tSbWXsRo8N@o~4SMTgyH_=0KJtW{VX%ZJyd{ z#fMR}ZoNp}QK}LW4SGqU@50c21DZE|y(v>A5;;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-Uj!5j-=0H8FNi@S&>3D`Pz;>lFC0NyYeTD-0mHX8A43|? zezM5~3?6>++A@E8C-kr;3{D3a5#-dfm)6`1v^S4LkdfuhTPlI(*)QHj4!%C#Vg~9Y_bgJ}T-I3yjOr(^A)V*; zJzEW&II_{O8fazTA3=uK58t;2Xq?+Njtrjse9L{nSpV3ck!{Yl*0sQ?6{aZC{=u2f z`+<=+yRRe7T^pXO0S?+`4C{cp+!tR)isu{Ft_MbcdTku(Bu5|I0GzNq^%tb|hT(~C z0K=zFMUloA6z@09<=7P9aLv?ODpe~MwJ}B3x|!eOk%;-j_lrC_#Y4RjX z2EBlCYvWzZl6i})mbhtBl;p?nFxp`W+EGEFDY>b-QoHfxK@D)V5Lc>_N;!8lMfDv# zBXalf3dd+tXF$!-E@Z_`2LjxvS}`wS7VB^(eykW;5^>xSF8A93?so%t^qH2nbQBMd zeTf_>g1-bT3M2U2KnO@*ZmX&-AuHhl2d4nPaG+!?IZ&Wd8gjbhf=LI*31mAH=k&Fe zfxe5CzRLI^n`7O{pU>JNhT5u&)3dgU>pNY&RiklP5zqZsnQtn;m|wO3lI<7Ae|ht- zLzis3{!n%7L*1lio=^;TRuoZ-l7BWpFMw(Q5tQX4KEKoh-?Bl$wEIC}h60xV0YRT1 Ab^rhX literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py312_efd071/sequence/threshold_selector/QuantileThresholdSelector.pkl b/tests/test_data/old_models/py312_efd071/sequence/threshold_selector/QuantileThresholdSelector.pkl new file mode 100644 index 0000000000000000000000000000000000000000..83054a12277099593f0f01cba57d72ef9b6c8480 GIT binary patch literal 57 zcmZo*nX1PC0ku;!dN@lmic*U+@^ezAxZ8jJz3EtHu44~JVQFGsNoGzeQ0!eA7?kP( E04Ep~fB*mh literal 0 HcmV?d00001 diff --git a/tests/test_model_compatibility.py b/tests/test_model_compatibility.py new file mode 100644 index 00000000..f47000a1 --- /dev/null +++ b/tests/test_model_compatibility.py @@ -0,0 +1,199 @@ +"""Compatibility tests for loading and applying pre-Pydantic saved models. + +The fixtures under ``tests/test_data/old_models/`` were created with older +versions of ``energy-fault-detector`` (before the Pydantic config migration) +using the script ``tests/test_data/old_models/create_legacy_model_fixtures.py``. + +For Keras 3 fixtures (``py312_efd071``) the full pipeline is exercised: +``FaultDetector.load`` + ``predict``. For Keras 2 fixtures (``py311_efd060``) +the autoencoder cannot be loaded by Keras 3 (``keras.src.engine.functional`` +was renamed), so only the non-Keras components (config, data preprocessor, +threshold selector, anomaly score) are loaded and applied individually. +""" + +import os +import unittest + +import numpy as np +import pandas as pd + +from energy_fault_detector.anomaly_scores import RMSEScore +from energy_fault_detector.autoencoders import LSTMSeq2OneAutoencoder, MultilayerAutoencoder +from energy_fault_detector.config import Config +from energy_fault_detector.core import FaultDetectionResult +from energy_fault_detector.data_preprocessing import DataPreprocessor +from energy_fault_detector.fault_detector import FaultDetector +from energy_fault_detector.threshold_selectors import QuantileThresholdSelector + +PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +OLD_MODELS_DIR = os.path.join(PROJECT_ROOT, 'tests', 'test_data', 'old_models') + + +def make_dense_data(n_rows: int = 80) -> pd.DataFrame: + """Create deterministic tabular data matching the dense fixture training data. + + Args: + n_rows: Number of samples to generate. + + Returns: + Numeric DataFrame with a 10-minute DatetimeIndex. + """ + rng = np.random.default_rng(42) + index = pd.date_range("2025-01-01", periods=n_rows, freq="10min") + phase = np.linspace(0, 4 * np.pi, n_rows) + return pd.DataFrame( + { + "temperature": 50 + 3 * np.sin(phase) + rng.normal(0, 0.15, n_rows), + "pressure": 10 + 0.5 * np.cos(phase) + rng.normal(0, 0.05, n_rows), + "power": 100 + 8 * np.sin(phase / 2) + rng.normal(0, 0.3, n_rows), + }, + index=index, + ) + + +def make_sequence_data(n_rows: int = 120) -> pd.DataFrame: + """Create deterministic time-series data matching the sequence fixture training data. + + Args: + n_rows: Number of samples to generate. + + Returns: + Numeric DataFrame with a regular 10-minute DatetimeIndex. + """ + rng = np.random.default_rng(123) + index = pd.date_range("2025-02-01", periods=n_rows, freq="10min") + phase = np.linspace(0, 6 * np.pi, n_rows) + return pd.DataFrame( + { + "sensor_a": np.sin(phase) + rng.normal(0, 0.03, n_rows), + "sensor_b": np.cos(phase) + rng.normal(0, 0.03, n_rows), + "sensor_c": 0.3 * np.sin(phase / 2) + rng.normal(0, 0.02, n_rows), + }, + index=index, + ) + + +class TestLegacyModelCompatibility(unittest.TestCase): + """Load and apply saved-model fixtures created before the Pydantic config migration.""" + + def _assert_loaded_components(self, detector: FaultDetector) -> None: + """Verify all model components and config were loaded.""" + self.assertIsNotNone(detector.autoencoder) + self.assertIsNotNone(detector.data_preprocessor) + self.assertIsNotNone(detector.threshold_selector) + self.assertIsNotNone(detector.anomaly_score) + self.assertIsNotNone(detector.config) + + def _assert_predict_results(self, result: FaultDetectionResult, expected_len: int) -> None: + """Verify prediction results are sane and internally consistent. + + Args: + result: Output of ``FaultDetector.predict``. + expected_len: Expected number of rows in the anomaly score / predictions. + """ + self.assertFalse(result.anomaly_score.empty) + self.assertTrue(np.all(np.isfinite(result.anomaly_score.values))) + self.assertEqual(len(result.anomaly_score), expected_len) + self.assertIsInstance(result.predicted_anomalies, pd.Series) + self.assertEqual(result.predicted_anomalies.dtype, bool) + self.assertTrue(result.predicted_anomalies.index.equals(result.anomaly_score.index)) + + @staticmethod + def _load_non_keras_components(model_path: str) -> tuple: + """Load config, data preprocessor, threshold selector, and anomaly score. + + Bypasses ``FaultDetector.load`` (which also loads the Keras autoencoder) + so the non-Keras pickled components can be tested independently. + + Args: + model_path: Directory containing the saved model (config.yaml + sub-dirs). + + Returns: + Tuple of (Config, DataPreprocessor, QuantileThresholdSelector, RMSEScore). + """ + config = Config(os.path.join(model_path, 'config.yaml')) + + data_preprocessor = DataPreprocessor() + data_preprocessor.load(os.path.join(model_path, 'data_preprocessor')) + + threshold_selector = QuantileThresholdSelector() + threshold_selector.load(os.path.join(model_path, 'threshold_selector')) + + anomaly_score = RMSEScore() + anomaly_score.load(os.path.join(model_path, 'anomaly_score')) + + return config, data_preprocessor, threshold_selector, anomaly_score + + def _assert_non_keras_pipeline(self, model_path: str, data: pd.DataFrame, + expected_ae_name: str) -> None: + """Load non-Keras components, run data through the partial pipeline. + + Args: + model_path: Directory containing the saved model. + data: Synthetic data matching the fixture's training data. + expected_ae_name: Expected ``config.train.autoencoder.name`` value. + """ + config, data_preprocessor, threshold_selector, anomaly_score = \ + self._load_non_keras_components(model_path) + + self.assertEqual(config.train.autoencoder.name, expected_ae_name) + self.assertIsInstance(data_preprocessor, DataPreprocessor) + self.assertIsInstance(threshold_selector, QuantileThresholdSelector) + self.assertIsInstance(anomaly_score, RMSEScore) + + prepped = data_preprocessor.transform(data) + self.assertFalse(prepped.empty) + + rng = np.random.default_rng(0) + recon_error = pd.DataFrame( + rng.standard_normal(prepped.shape), + index=prepped.index, columns=prepped.columns, + ) + scores = anomaly_score.transform(recon_error) + self.assertFalse(scores.empty) + self.assertTrue(np.all(np.isfinite(scores.values))) + + predicted = threshold_selector.predict(scores) + self.assertEqual(len(predicted), len(scores)) + + def test_dense_py312_efd071(self) -> None: + """Dense MultilayerAutoencoder saved with EFD 0.7.1 / Python 3.12 / Keras 3.""" + model_path = os.path.join(OLD_MODELS_DIR, 'py312_efd071', 'dense') + detector = FaultDetector.load(model_path=model_path) + self._assert_loaded_components(detector) + self.assertIsInstance(detector.autoencoder, MultilayerAutoencoder) + self.assertEqual(detector.config.train.autoencoder.name, 'default') + + result = detector.predict(make_dense_data()) + self._assert_predict_results(result, expected_len=80) + + def test_sequence_py312_efd071(self) -> None: + """LSTM seq2one autoencoder saved with EFD 0.7.1 / Python 3.12 / Keras 3.""" + model_path = os.path.join(OLD_MODELS_DIR, 'py312_efd071', 'sequence') + detector = FaultDetector.load(model_path=model_path) + self._assert_loaded_components(detector) + self.assertIsInstance(detector.autoencoder, LSTMSeq2OneAutoencoder) + self.assertEqual(detector.config.train.autoencoder.name, 'lstm_seq2one') + + result = detector.predict(make_sequence_data()) + self._assert_predict_results(result, expected_len=113) + + def test_dense_py311_efd060(self) -> None: + """Non-Keras components from EFD 0.6.0 / Python 3.11 / Keras 2 fixture (dense). + + The Keras 2 autoencoder cannot be loaded by Keras 3, but the config, + data preprocessor, threshold selector, and anomaly score are plain + pickle/YAML and should load and run. + """ + model_path = os.path.join(OLD_MODELS_DIR, 'py311_efd060', 'dense') + self._assert_non_keras_pipeline(model_path, make_dense_data(), 'default') + + def test_sequence_py311_efd060(self) -> None: + """Non-Keras components from EFD 0.6.0 / Python 3.11 / Keras 2 fixture (sequence). + + The Keras 2 autoencoder cannot be loaded by Keras 3, but the config, + data preprocessor, threshold selector, and anomaly score are plain + pickle/YAML and should load and run. + """ + model_path = os.path.join(OLD_MODELS_DIR, 'py311_efd060', 'sequence') + self._assert_non_keras_pipeline(model_path, make_sequence_data(), 'lstm_seq2one') From 7a8844c0aaaed375f89d5f01c6a26de0ce3b60ec Mon Sep 17 00:00:00 2001 From: chr39552 Date: Fri, 6 Nov 2026 11:03:54 +0100 Subject: [PATCH 12/18] Implemented criticality based alarm event identification --- docs/configuration.rst | 23 +++ docs/criticality.rst | 155 ++++++++++-------- docs/usage_examples.rst | 17 +- .../core/fault_detection_result.py | 29 +++- energy_fault_detector/utils/analysis.py | 139 ++++++++++++++++ energy_fault_detector/utils/visualisation.py | 12 +- notebooks/PreDist/PreDist.ipynb | 6 +- tests/core/test_fault_detection_result.py | 40 +++++ tests/utils/test_analysis.py | 135 ++++++++++++++- tests/utils/test_visualisation.py | 19 ++- 10 files changed, 486 insertions(+), 89 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 4dd75733..acd0999d 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -208,6 +208,29 @@ returned by :meth:`FaultDetectionResult.criticality ` +(or :func:`calculate_alarms `) with the desired settings: + +.. code-block:: python + + results = fault_detector.predict(sensor_data=test_data) + + alarm_events, criticality = results.criticality( + normal_idx=test_status, # optional: True = normal operation + criticality_threshold=None, # None -> one hour of anomalous behaviour + alarm_reset_time_minutes=60, # reset window used to derive max_criticality + ) + +If ``criticality_threshold`` is omitted it defaults to ``int(1 hour / time_frequency)`` (or ``1`` if the time +frequency exceeds one hour). ``max_criticality`` is derived as +``criticality_threshold + int(alarm_reset_time_minutes / time_frequency)``. See :ref:`criticality` for the full +interpretation and guidance on choosing these values. + + Root cause analysis (ARCANA) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ If ``root_cause_analysis`` is provided, ARCANA will attempt to attribute anomalies to specific features using the diff --git a/docs/criticality.rst b/docs/criticality.rst index 57cb0371..14dc5663 100644 --- a/docs/criticality.rst +++ b/docs/criticality.rst @@ -1,20 +1,25 @@ .. _criticality: -Criticality -=========== +Criticality and alarms +====================== The criticality is a cumulative counter derived from the point-wise anomaly predictions of a model. It is used to convert raw per-timestamp anomaly decisions into a *persistence-aware* signal, so that alarms are raised only when -anomalous behaviour is sustained over time. This avoids raising alarms for isolated anomalies caused by noise or by -potential data-quality issues. +anomalous behaviour is sustained over time. This avoids raising unnecessary alarms for isolated anomalies caused by +noise or by potential data-quality issues. -The reference implementation is -:func:`calculate_criticality ` in -:mod:`energy_fault_detector.utils.analysis`. The same calculation is available directly on a prediction result via +The package provides two building blocks in :mod:`energy_fault_detector.utils.analysis`: + +- :func:`calculate_criticality ` computes the raw + criticality counter. +- :func:`calculate_alarms ` builds on it to derive + **alarm events** (start, end, duration) from the criticality. + +Both are exposed on a prediction result via :meth:`FaultDetectionResult.criticality `. -How it works ------------- +How the criticality works +------------------------- For every timestamp the counter is updated by one of three rules, depending on the predicted anomaly and on the operating status (``normal_idx``): @@ -40,41 +45,61 @@ The counter is bounded below by ``0`` and above by ``max_criticality``. If ``nor timestamps are treated as normal operation. .. note:: - The status information (``normal_idx``) can be used to ignore alarms which otherwise inflate the - counter during periods in which anomalous behavior is not meaningful (e.g. during maintenance) + The status information (normal_idx) can be used to ignore alarms which otherwise inflate the counter during periods in which anomalous + behavior is not meaningful (e.g. during maintenance). -Parameters ----------- +Deriving alarms with ``calculate_alarms`` +----------------------------------------- + +:func:`calculate_alarms ` computes the criticality and turns +every timestamp at which the criticality reaches the threshold into an alarm. Contiguous alarm timestamps are +aggregated into alarm events. .. code-block:: python - from energy_fault_detector.utils.analysis import calculate_criticality + from energy_fault_detector.utils.analysis import calculate_alarms - criticality = calculate_criticality( - anomalies, # pd.Series[bool] over time - normal_idx=None, # optional pd.Series[bool], True = normal operation - init_criticality=0, # starting value of the counter - max_criticality=1000, # upper bound of the counter + alarm_events, criticality = calculate_alarms( + anomalies, # pd.Series[bool] over time + normal_idx=None, # optional pd.Series[bool], True = normal operation + init_criticality=0, # starting value of the counter + criticality_threshold=None, # None -> derived from the time frequency (see below) + alarm_reset_time_minutes=60, # reset window used to derive max_criticality ) -- ``anomalies``: boolean :class:`pandas.Series` of predicted anomalies, indexed by timestamp or by a ``MultiIndex`` - such as ``(asset_id, timestamp)``. -- ``normal_idx``: optional boolean :class:`pandas.Series` with normal-operation status. It is reindexed to - ``anomalies``; missing values are treated as normal (``True``). -- ``init_criticality``: initial value of the counter. Used if persistence is desired across multiple calls to the function (e.g. when processing a long time series in separatechunks). -- ``max_criticality``: maximum value the counter can reach. +``alarm_events`` is a :class:`pandas.DataFrame` with the columns ``start``, ``end`` and ``duration`` (and an +additional ``group`` column for a ``MultiIndex``). ``criticality`` is the :class:`pandas.Series` of the counter over +time. + +If ``criticality_threshold`` is not given, it is derived from the time frequency of the data: + +- ``criticality_threshold = int(1 hour / time_frequency)`` — the number of timestamps needed to accumulate one hour + of anomalous behaviour. +- If the time frequency is larger than one hour (or cannot be inferred, e.g. for a ``RangeIndex``), the threshold + defaults to ``1``. + +``max_criticality`` is derived from the threshold and ``alarm_reset_time_minutes``, which has a default value of ``60``: + +- ``max_criticality = criticality_threshold + int(alarm_reset_time_minutes / time_frequency)`` +- If the time frequency is larger than ``alarm_reset_time_minutes`` (or cannot be inferred), + ``max_criticality = criticality_threshold + 1``. -The function returns a :class:`pandas.Series` with the criticality value per timestamp and the same index as the -input. For a ``MultiIndex``, the criticality is computed independently per group (e.g. per asset). +The time frequency is inferred as the median difference between consecutive timestamps, using the datetime level of a +``MultiIndex`` when present. For MultiIndex data the criticality and the alarm events are computed independently per +group (e.g. per asset). -On a prediction result you can call the method directly: +On a prediction result you can call the method directly. It returns the same ``(alarm_events, criticality)`` tuple: .. code-block:: python results = fault_detector.predict(sensor_data=test_sensor_data) - criticality = results.criticality() # all timestamps treated as normal - criticality = results.criticality(normal_idx=test_status, max_criticality=144) + alarm_events, criticality = results.criticality() # defaults derived from the data + alarm_events, criticality = results.criticality( + normal_idx=test_status, + criticality_threshold=6, + alarm_reset_time_minutes=60, + ) Interpreting criticality: raising alarms ---------------------------------------- @@ -84,9 +109,9 @@ Criticality is interpreted relative to an application-specific **criticality thr - as long as ``criticality < threshold``, no alarm is raised, - once ``criticality >= threshold``, an alarm is raised (the anomaly is treated as significant). -Because the counter rises by one per anomalous timestamp, the threshold can be read as the minimum number of consecutive -anomalous timestamps required to raise an alarm. With a fixed sampling frequency this corresponds directly to a time -window: +Because the counter rises by one per anomalous timestamp, the threshold can be read as the minimum number of +consecutive anomalous timestamps required to raise an alarm. With a fixed sampling frequency this corresponds directly +to a time window: .. code-block:: text @@ -114,10 +139,10 @@ Consider: - **Time frequency** of the data and the desired alarm latency. The same physical time window maps to different thresholds for different sampling rates. -- **Expected random anomalies** from noise or data-quality problems. These can be estimated from real anomalies used for validation - and or from validation data with normal status: run the model on validation data known to be normal, - observe how the criticality behaves, and choose a threshold that random fluctuations do not reach. - The more (expected) spurious anomalies per unit of time, the higher the threshold should be. +- **Expected random anomalies** from noise or data-quality problems. These can be estimated from real anomalies used + for validation and/or from validation data with normal status: run the model on validation data known to be normal, + observe how the criticality behaves, and choose a threshold that random fluctuations do not reach. The more + (expected) spurious anomalies per unit of time, the higher the threshold should be. - **Severity and cost** of a missed fault versus a false alarm. A simple procedure: @@ -126,29 +151,31 @@ A simple procedure: #. Observe the maximum criticality reached by random anomalies (noise / data quality). #. Set the threshold well above that level, and additionally require the desired minimum persistence time. -Choosing ``max_criticality`` -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Choosing ``alarm_reset_time_minutes`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -``max_criticality`` caps the counter and therefore controls how long it takes for an active alarm to be reset -after the system returns to normal behaviour. Once the counter has saturated at ``max_criticality``, it must be -decremented back towards the threshold before the alarm is closed. Because the counter decreases by one per normal +``alarm_reset_time_minutes`` controls how long it takes for an active alarm to be reset after the system returns to +normal behaviour, by determining ``max_criticality``. Once the counter has saturated at ``max_criticality``, it must be +decremented back below the threshold before the alarm is closed. Because the counter decreases by one per normal timestamp, the time to reset from saturation is at most: .. code-block:: text max_reset_time = (max_criticality - criticality_threshold) * time_frequency + = alarm_reset_time_minutes -Continuing the example above (``10 minutes`` resolution) with a threshold of ``6`` and ``max_criticality = 12``: +Continuing the example above (``10 minutes`` resolution) with a threshold of ``6`` and +``alarm_reset_time_minutes = 60``, ``max_criticality`` becomes ``6 + int(60 / 10) = 12``: .. math:: (12 - 6) \times 10\,\text{min} = 60\,\text{min} -so at most **one hour** of consecutive normal behaviour is needed for the counter to fall from saturation back below the -threshold and for the alarm to close. +so at most **one hour** of consecutive normal behaviour is needed for the counter to fall from saturation back below +the threshold and for the alarm to close. -Choose ``max_criticality`` relative to your threshold so that the time to reset matches what the application can -tolerate. Setting it so that the reset time is at most **1 hour** or **1 day** is often a good default. +Setting the reset time to at most **1 hour** or **1 day** is often a good default, depending on the application +context and user preferences. .. list-table:: :header-rows: 1 @@ -176,30 +203,27 @@ tolerate. Setting it so that the reset time is at most **1 hour** or **1 day** i - ~1 day normal (from saturation) .. note:: - Both the threshold and ``max_criticality`` are expressed in *number of timestamps*, not in physical time. When you + The threshold and ``max_criticality`` are expressed in *number of timestamps*, not in physical time. When you change the time frequency of your data, recompute them so that the intended physical time windows are preserved. + ``calculate_alarms`` does this automatically for the defaults. -Configuration -------------- - -When using the :class:`FaultDetector ` framework, the maximum -criticality can be set in the YAML configuration: - -.. code-block:: yaml +Alarm event output +^^^^^^^^^^^^^^^^^^ - predict: - criticality: - max_criticality: 144 # default: one day at 10 min resolution - -The criticality *threshold* is not part of this configuration: it is an application decision that you apply to the -returned criticality series, e.g.: +Each alarm event contains the first and last timestamp at which the criticality was at or above the threshold: .. code-block:: python - criticality = results.criticality(normal_idx=test_status, max_criticality=config.max_criticality) - alarms = criticality >= 6 + alarm_events, criticality = calculate_alarms( + anomalies, criticality_threshold=6, alarm_reset_time_minutes=60 + ) + print(alarm_events) + + # start end duration + # 0 2024-01-01 01:10:00 2024-01-01 03:10:00 0 days 02:00:00 -See :ref:`configuration_guide` for the full configuration reference. +The ``duration`` is the difference between ``end`` and ``start``. For a ``MultiIndex`` input an additional +``group`` column identifies the asset or device. Visualisation ------------- @@ -216,7 +240,8 @@ Criticality can be plotted together with the anomaly score using data=test_sensor_data, normal_index=test_status, show_criticality=True, - max_criticality=144, + criticality_threshold=6, + alarm_reset_time_minutes=60, ) Relation to evaluation (CARE score) diff --git a/docs/usage_examples.rst b/docs/usage_examples.rst index cd67454c..e9427752 100644 --- a/docs/usage_examples.rst +++ b/docs/usage_examples.rst @@ -147,14 +147,17 @@ with the following information: * arcana_losses: pandas DataFrame containing recorded values for all losses in ARCANA. None if ARCANA was not run. * tracked_bias: List of pandas DataFrames. None if ARCANA was not run. -On top of the raw predictions, you can derive the *criticality* counter, which accumulates sustained anomalies and is -used to raise alarms only after anomalous behaviour persists over time. See :ref:`criticality` for the interpretation -and how to choose a threshold: +On top of the raw predictions you can derive the *criticality* counter and alarm events, which raise alarms only after +anomalous behaviour persists over time. See :ref:`criticality` for the interpretation and how to choose the settings: .. code-block:: python - criticality = results.criticality(normal_idx=test_status, max_criticality=144) - alarms = criticality >= 6 # threshold chosen based on time frequency and application context + alarm_events, criticality = results.criticality( + normal_idx=test_status, # optional: True = normal operation + criticality_threshold=None, # None -> one hour of anomalous behaviour + alarm_reset_time_minutes=60, # reset window used to derive max_criticality + ) + # alarm_events: DataFrame with columns start, end, duration (and group for MultiIndex data) You can also create a :py:obj:`FaultDetector ` object and load trained models using the :py:obj:`FaultDetector.load ` class method. @@ -250,8 +253,8 @@ walkthrough of the evaluation workflow (event creation, criticality, CARE-Score on benchmark datasets such as CARE2Compare and PreDist). A higher-level evaluation helper/script may be added in a future version. -See :ref:`criticality` for how criticality is computed and interpreted for both alarm raising and event-level -evaluation. +See :ref:`criticality` for how criticality and alarm events are computed and interpreted for both alarm raising and +event-level evaluation. MultiIndex and sequence models ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/energy_fault_detector/core/fault_detection_result.py b/energy_fault_detector/core/fault_detection_result.py index f9984da1..7dfee6d9 100644 --- a/energy_fault_detector/core/fault_detection_result.py +++ b/energy_fault_detector/core/fault_detection_result.py @@ -1,5 +1,5 @@ -from typing import Optional, List +from typing import Optional, List, Tuple from dataclasses import dataclass from pathlib import Path import json @@ -7,7 +7,7 @@ import pandas as pd import numpy as np -from ..utils.analysis import calculate_criticality +from ..utils.analysis import calculate_alarms _INDEX_META_FILE = "_index_meta.json" @@ -39,18 +39,33 @@ class FaultDetectionResult: """List of DataFrames containing the ARCANA bias every 50th iteration. None if ARCANA was not run. Empty if bias was not tracked.""" - def criticality(self, normal_idx: pd.Series | None = None, init_criticality: int = 0, max_criticality: int = 1000 - ) -> pd.Series: - """Criticality based on the predicted anomalies. + def criticality(self, normal_idx: pd.Series | None = None, init_criticality: int = 0, + criticality_threshold: int | None = None, alarm_reset_time_minutes: float = 60 + ) -> Tuple[pd.DataFrame, pd.Series]: + """Derive alarm events and the criticality counter from the predicted anomalies. + + The criticality increases for sustained anomalies during normal operation and decreases again during normal + behaviour. Timestamps at which the criticality reaches ``criticality_threshold`` are treated as alarms and + aggregated into contiguous alarm events. Args: normal_idx (pd.Series, optional): A pandas Series with boolean values indicating normal operation, indexed by timestamp. Ignored if None. init_criticality (int, optional): The initial criticality value. Defaults to 0. - max_criticality (int, optional): The maximum criticality value. Defaults to 1000. + criticality_threshold (int, optional): Criticality value at which an alarm is raised. If None, it defaults + to one hour of anomalous behaviour (``int(1 hour / time_frequency)``); if the time frequency exceeds + one hour, it defaults to ``1``. + alarm_reset_time_minutes (float, optional): Time window in minutes after which an alarm is reset once the + system behaves normally again. Used to derive ``max_criticality``. Defaults to 60. + Returns: + Tuple[pd.DataFrame, pd.Series]: A tuple containing: + - alarm_events (pd.DataFrame): Columns ``start``, ``end`` and ``duration`` and, for a MultiIndex, + an additional ``group`` column. + - criticality (pd.Series): The criticality over time. """ - return calculate_criticality(self.predicted_anomalies, normal_idx, init_criticality, max_criticality) + return calculate_alarms(self.predicted_anomalies, normal_idx, init_criticality, criticality_threshold, + alarm_reset_time_minutes) def save(self, directory: str | Path, **kwargs) -> None: """Saves the results to CSV files in the specified directory. diff --git a/energy_fault_detector/utils/analysis.py b/energy_fault_detector/utils/analysis.py index a2970a0b..02440e78 100644 --- a/energy_fault_detector/utils/analysis.py +++ b/energy_fault_detector/utils/analysis.py @@ -5,6 +5,8 @@ import numpy as np import pandas as pd +_ALARM_EVENT_COLUMNS = ["start", "end", "duration"] + def create_events(sensor_data: pd.DataFrame, boolean_information: pd.Series, min_event_length: int = 10) -> Tuple[pd.DataFrame, List[pd.DataFrame]]: @@ -175,6 +177,143 @@ def calculate_criticality(anomalies: pd.Series, normal_idx: pd.Series = None, in return _compute_criticality_array(anomalies, normal_idx, init_criticality, max_criticality) +def calculate_alarms(anomalies: pd.Series, normal_idx: pd.Series = None, init_criticality: int = 0, + criticality_threshold: Optional[int] = None, alarm_reset_time_minutes: float = 60 + ) -> Tuple[pd.DataFrame, pd.Series]: + """Derive alarm events from predicted anomalies using a criticality counter. + + The function computes the :func:`criticality ` and marks every timestamp at which the + criticality reaches or exceeds ``criticality_threshold`` as an alarm. Contiguous alarm timestamps are aggregated + into alarm events with ``start``, ``end`` and ``duration``. + + If ``criticality_threshold`` is not provided, it defaults to ``int(1 hour / time_frequency)``, i.e. the number of + timestamps needed for one hour of anomalous behaviour. If the time frequency is larger than one hour, the default + threshold is ``1``. The time frequency is inferred from the datetime index of ``anomalies``. + + ``max_criticality`` is derived from the threshold and ``alarm_reset_time_minutes`` so that an alarm is reset after + at most ``alarm_reset_time_minutes`` of normal behaviour: + ``max_criticality = criticality_threshold + int(alarm_reset_time_minutes / time_frequency)``. If the time frequency + is larger than ``alarm_reset_time_minutes`` (or cannot be inferred), ``max_criticality`` is + ``criticality_threshold + 1``. + + Args: + anomalies (pd.Series): A pandas Series with boolean values indicating whether an anomaly was detected, + indexed by timestamp, or MultiIndex (device_id, timestamp). + normal_idx (pd.Series, optional): A pandas Series with boolean values indicating normal operation, same index + as ``anomalies``. If not provided, all timestamps are assumed to be normal operation. Defaults to None. + init_criticality (int, optional): The initial criticality value. Defaults to 0. + criticality_threshold (int, optional): Criticality value at which an alarm is raised. If None, it is derived + from the time frequency (one hour of anomalous behaviour). Defaults to None. + alarm_reset_time_minutes (float, optional): Time window in minutes after which an alarm is reset once the + system behaves normally again. Used to derive ``max_criticality``. Defaults to 60. + + Returns: + Tuple[pd.DataFrame, pd.Series]: A tuple containing: + - alarm_events (pd.DataFrame): Columns ``start``, ``end`` and ``duration`` and, for a MultiIndex, + an additional ``group`` column. + - criticality (pd.Series): The criticality over time, indexed like ``anomalies``. + """ + anomalies = anomalies.sort_index() + + index = anomalies.index + if isinstance(index, pd.MultiIndex): + dt_level = _detect_datetime_level(index) + time_index = index.get_level_values(dt_level) if dt_level is not None else None + else: + time_index = index + + time_frequency_nano_seconds = None + if isinstance(time_index, pd.DatetimeIndex): + # In a MultiIndex the datetime level repeats each timestamp per group, which prevents frequency inference. + time_index = pd.DatetimeIndex(time_index.drop_duplicates()) + freq = time_index.freqstr or time_index.inferred_freq + if freq is not None: + try: + time_frequency_nano_seconds = pd.tseries.frequencies.to_offset(freq).nanos + except ValueError: # non-fixed frequency + time_frequency_nano_seconds = None + + nano_seconds_in_an_hour = 60 * 60 * 1e9 + nano_seconds_alarm_reset_time = alarm_reset_time_minutes * 60 * 1e9 + + if criticality_threshold is None: + if time_frequency_nano_seconds is None or time_frequency_nano_seconds > nano_seconds_in_an_hour: + criticality_threshold = 1 + else: + criticality_threshold = max(1, int(nano_seconds_in_an_hour / time_frequency_nano_seconds)) + criticality_threshold = int(criticality_threshold) + + if time_frequency_nano_seconds is None or time_frequency_nano_seconds > nano_seconds_alarm_reset_time: + max_criticality = criticality_threshold + 1 + else: + reset_steps = max(1, int(nano_seconds_alarm_reset_time / time_frequency_nano_seconds)) + max_criticality = criticality_threshold + reset_steps + + criticality = calculate_criticality(anomalies, normal_idx, init_criticality, max_criticality) + alarm_events = _create_alarm_events(criticality, criticality_threshold) + return alarm_events, criticality + + +def _detect_datetime_level(index: pd.MultiIndex) -> Optional[int]: + """Return the datetime level index of a MultiIndex, or None.""" + for i, level in enumerate(index.levels): + if isinstance(level, pd.DatetimeIndex): + return i + return None + + +def _create_alarm_events(criticality: pd.Series, criticality_threshold: int) -> pd.DataFrame: + """Aggregate contiguous timestamps above the criticality threshold into alarm events.""" + alarm_mask = criticality >= criticality_threshold + index = alarm_mask.index + + if isinstance(index, pd.MultiIndex): + group_level = _detect_group_level(index) + datetime_level = _detect_datetime_level(index) + if group_level is not None and datetime_level is not None: + group_values = index.get_level_values(group_level) + events = [] + for group in pd.unique(group_values): + group_mask = alarm_mask[group_values == group].copy() + group_mask.index = index[group_values == group].get_level_values(datetime_level) + events.append(_single_alarm_events(group_mask, group_label=group)) + columns = _ALARM_EVENT_COLUMNS + ["group"] + non_empty = [event for event in events if not event.empty] + if not non_empty: + return pd.DataFrame(columns=columns) + return pd.concat(non_empty, ignore_index=True) + if datetime_level is not None: + alarm_mask = alarm_mask.copy() + alarm_mask.index = index.get_level_values(datetime_level) + else: + alarm_mask = alarm_mask.reset_index(drop=True) + + return _single_alarm_events(alarm_mask) + + +def _single_alarm_events(alarm_mask: pd.Series, group_label=None) -> pd.DataFrame: + """Create alarm events for a single contiguous boolean series.""" + mask = np.asarray(alarm_mask, dtype=bool) + if not mask.any(): + columns = _ALARM_EVENT_COLUMNS + (["group"] if group_label is not None else []) + return pd.DataFrame(columns=columns) + + padded = np.concatenate(([False], mask, [False])) + edges = np.diff(padded.astype(np.int8)) + start_positions = np.flatnonzero(edges == 1) + end_positions = np.flatnonzero(edges == -1) - 1 + + index = alarm_mask.index + events = pd.DataFrame({ + "start": index[start_positions], + "end": index[end_positions], + }) + events["duration"] = events["end"] - events["start"] + if group_label is not None: + events["group"] = group_label + return events + + def _detect_group_level(index: pd.Index) -> Optional[int]: """Return the non-datetime grouping level index, or None.""" if not isinstance(index, pd.MultiIndex): diff --git a/energy_fault_detector/utils/visualisation.py b/energy_fault_detector/utils/visualisation.py index b605d763..2afecc35 100644 --- a/energy_fault_detector/utils/visualisation.py +++ b/energy_fault_detector/utils/visualisation.py @@ -186,7 +186,8 @@ def plot_reconstruction_with_model(model: FaultDetector, data: pd.DataFrame, def plot_score_with_threshold(model: FaultDetector, data: pd.DataFrame, normal_index: pd.Series = None, ax: plt.Axes = None, figsize: Tuple[float, float] = (8, 3), show_predicted_anomaly: bool = False, show_threshold: bool = True, - show_criticality: bool = False, max_criticality: int = 144, + show_criticality: bool = False, criticality_threshold: Optional[int] = None, + alarm_reset_time_minutes: float = 60, score_color: Optional[str] = None, anomaly_color: Optional[str] = None, criticality_color: Optional[str] = "C2", @@ -208,8 +209,10 @@ def plot_score_with_threshold(model: FaultDetector, data: pd.DataFrame, normal_i show_predicted_anomaly (bool, optional): Whether to show the predicted anomaly scores. Defaults to False. show_threshold (bool, optional): Whether to show the threshold scores. Defaults to True. show_criticality (bool, optional): Whether to show the criticality counter. Defaults to False. - max_criticality (int optional): If show_criticality is True, the maximum value of the criticality counter can - be specified. Defaults to 144 (one day of 10 min timestamps). + criticality_threshold (Optional[int], optional): If show_criticality is True, the criticality value at which + an alarm is raised. If None, it is derived from the time frequency (one hour of anomalous behaviour). + alarm_reset_time_minutes (float, optional): If show_criticality is True, the time window in minutes after + which an alarm is reset once the system behaves normally again. Defaults to 60. score_color (Optional[str], optional): Color to use for the anomaly score. anomaly_color (Optional[str], optional): Color to use for the anomalous data points (using normal_index). criticality_color (Optional[str], optional): Color to use for the criticality counter if show_criticality is @@ -265,7 +268,8 @@ def plot_score_with_threshold(model: FaultDetector, data: pd.DataFrame, normal_i ax.plot(threshold, linestyle='-', linewidth=.7, label='threshold', c=threshold_color) if show_criticality: - crit = predictions.criticality(normal_idx=normal_index, max_criticality=max_criticality) + crit = predictions.criticality(normal_idx=normal_index, criticality_threshold=criticality_threshold, + alarm_reset_time_minutes=alarm_reset_time_minutes)[1] ax2 = ax.twinx() ax2.plot(crit, label='criticality counter', color=criticality_color) ax2.set_ylabel('criticality') diff --git a/notebooks/PreDist/PreDist.ipynb b/notebooks/PreDist/PreDist.ipynb index 3e51492f..53230a7c 100644 --- a/notebooks/PreDist/PreDist.ipynb +++ b/notebooks/PreDist/PreDist.ipynb @@ -615,7 +615,7 @@ " max_criticality_list = []\n", " for event_id, prediction in results_dict.items():\n", " event_row = dataset.events[manufacturer].loc[event_id]\n", - " max_criticality = prediction.criticality().loc[:event_row['Report date']].max()\n", + " max_criticality = prediction.criticality()[1].loc[:event_row['Report date']].max()\n", " max_criticality_list += [(event_id, max_criticality)]\n", "\n", " # Transform results to pandas series with max criticality with event id as index\n", @@ -717,7 +717,7 @@ " earliness_scores = []\n", " for event_id, predictions in results[manufacturer][model_name].items():\n", " if dataset.events[manufacturer].loc[event_id]['Event type'] == 'anomaly':\n", - " criticality = predictions.criticality()\n", + " criticality = predictions.criticality()[1]\n", " detection_time, earliness = calculate_earliness(\n", " criticality_threshold=criticality_thresholds[manufacturer][model_name],\n", " report_ts=dataset.events[manufacturer].loc[event_id]['Report date'],\n", @@ -846,7 +846,7 @@ "predictions = results[manufacturer][model_name][event_id]\n", "\n", "fig, ax = plt.subplots(1, 1, figsize=(8,3))\n", - "crit = predictions.criticality()\n", + "crit = predictions.criticality()[1]\n", "crit.plot(ax=ax, label=model_name)\n", "\n", "if pd.notna(report_date):\n", diff --git a/tests/core/test_fault_detection_result.py b/tests/core/test_fault_detection_result.py index f94994e6..8e318cef 100644 --- a/tests/core/test_fault_detection_result.py +++ b/tests/core/test_fault_detection_result.py @@ -204,5 +204,45 @@ def test_multiindex_without_optional_fields(self): self.assertIsNone(loaded.tracked_bias) +class TestFaultDetectionResultCriticality(unittest.TestCase): + """Test the alarm/criticality derivation on FaultDetectionResult.""" + + def _make_result(self, anomalies): + return FaultDetectionResult( + predicted_anomalies=anomalies, + reconstruction=pd.DataFrame(index=anomalies.index), + recon_error=pd.DataFrame(index=anomalies.index), + anomaly_score=pd.Series(0.0, index=anomalies.index), + ) + + def test_criticality_returns_events_and_series(self): + idx = pd.date_range("2024-01-01", periods=20, freq="10min") + anomalies = pd.Series(False, index=idx) + anomalies.iloc[2:10] = True + + result = self._make_result(anomalies) + alarm_events, criticality = result.criticality() + + self.assertIsInstance(alarm_events, pd.DataFrame) + self.assertIsInstance(criticality, pd.Series) + self.assertEqual(list(alarm_events.columns), ["start", "end", "duration"]) + self.assertEqual(criticality.index.equals(idx), True) + self.assertEqual(alarm_events.iloc[0]["start"], idx[7]) + + def test_criticality_uses_normal_idx_and_threshold(self): + idx = pd.date_range("2024-01-01", periods=10, freq="10min") + anomalies = pd.Series(True, index=idx) + normal_idx = pd.Series([True] * 5 + [False] * 5, index=idx) + + result = self._make_result(anomalies) + alarm_events, criticality = result.criticality( + normal_idx=normal_idx, criticality_threshold=3, alarm_reset_time_minutes=20 + ) + + # max criticality = 3 + int(20 / 10) = 5; non-normal timestamps keep the value frozen + self.assertEqual(list(criticality), [1, 2, 3, 4, 5, 5, 5, 5, 5, 5]) + self.assertEqual(alarm_events.iloc[0]["start"], idx[2]) + + if __name__ == "__main__": unittest.main() diff --git a/tests/utils/test_analysis.py b/tests/utils/test_analysis.py index f8be1520..9dd9a89f 100644 --- a/tests/utils/test_analysis.py +++ b/tests/utils/test_analysis.py @@ -5,7 +5,7 @@ import pandas as pd from energy_fault_detector.utils import analysis -from energy_fault_detector.utils.analysis import calculate_criticality, create_events +from energy_fault_detector.utils.analysis import calculate_alarms, calculate_criticality, create_events # ────────────────────────────────────────────────────────────────────────────── @@ -107,6 +107,139 @@ def test_preserves_multiindex(self): assert crit.index.equals(idx) +# ────────────────────────────────────────────────────────────────────────────── +# calculate_alarms +# ────────────────────────────────────────────────────────────────────────────── + +class TestCalculateAlarmsSingleIndex: + """Alarm derivation with a simple DatetimeIndex.""" + + def test_no_anomalies_returns_empty_events(self): + idx = pd.date_range("2024-01-01", periods=10, freq="10min") + anomalies = pd.Series(False, index=idx) + events, crit = calculate_alarms(anomalies) + assert list(events.columns) == ["start", "end", "duration"] + assert events.empty + assert (crit == 0).all() + + def test_default_threshold_from_time_frequency(self): + """10 minute data -> default threshold of 6 (one hour), max = threshold + 6.""" + idx = pd.date_range("2024-01-01", periods=40, freq="10min") + anomalies = pd.Series(False, index=idx) + anomalies.iloc[2:14] = True + events, crit = calculate_alarms(anomalies) + + # 12 anomalies raise the criticality to 12 (threshold 6 + 6 reset steps) + assert crit.max() == 12 + # The alarm window starts when criticality reaches 6, i.e. the 6th anomaly (iloc 7) + assert events.iloc[0]["start"] == idx[7] + # Alarm ends when the criticality drops below the threshold again (6 normal steps after iloc 13) + assert events.iloc[0]["end"] == idx[19] + assert events.iloc[0]["duration"] == idx[19] - idx[7] + + def test_default_threshold_one_for_high_frequency_gap(self): + """Time frequency > 1 hour -> default threshold 1.""" + idx = pd.date_range("2024-01-01", periods=6, freq="2h") + anomalies = pd.Series([False, True, True, False, False, False], index=idx) + events, crit = calculate_alarms(anomalies) + + # threshold 1 and time frequency > reset window -> max_criticality = 2 + assert list(crit) == [0, 1, 2, 1, 0, 0] + assert events.iloc[0]["start"] == idx[1] + assert events.iloc[0]["end"] == idx[3] + + def test_explicit_threshold_and_reset_time(self): + idx = pd.date_range("2024-01-01", periods=10, freq="10min") + anomalies = pd.Series(True, index=idx) + events, crit = calculate_alarms(anomalies, criticality_threshold=3, alarm_reset_time_minutes=20) + + # max criticality = 3 + int(20 / 10) = 5 + assert crit.max() == 5 + assert events.iloc[0]["start"] == idx[2] + + def test_normal_idx_ignored_periods(self): + idx = pd.date_range("2024-01-01", periods=8, freq="10min") + anomalies = pd.Series(True, index=idx) + normal_idx = pd.Series([True, True, False, False, True, True, True, True], index=idx) + events, crit = calculate_alarms(anomalies, normal_idx=normal_idx, + criticality_threshold=2, alarm_reset_time_minutes=10) + + # max criticality = 2 + int(10 / 10) = 3, so t4..t7 stay at 3 + # t0,t1 -> 1,2 ; t2,t3 ignored ; t4..t7 -> 3,3,3,3 + assert list(crit) == [1, 2, 2, 2, 3, 3, 3, 3] + assert events.iloc[0]["start"] == idx[1] + + def test_init_criticality(self): + idx = pd.date_range("2024-01-01", periods=5, freq="10min") + anomalies = pd.Series(True, index=idx) + events, crit = calculate_alarms(anomalies, init_criticality=4, + criticality_threshold=5, alarm_reset_time_minutes=10) + + assert list(crit) == [5, 6, 6, 6, 6] + # Already at/above the threshold on the first timestamp + assert events.iloc[0]["start"] == idx[0] + + def test_no_time_frequency_uses_fallback(self): + """Without a datetime index the threshold falls back to 1 and max to threshold + 1.""" + idx = pd.RangeIndex(8) + anomalies = pd.Series([False, True, True, True, False, False, False, False], index=idx) + events, crit = calculate_alarms(anomalies) + + assert list(crit) == [0, 1, 2, 2, 1, 0, 0, 0] + assert events.iloc[0]["start"] == idx[1] + assert events.iloc[0]["end"] == idx[4] + + def test_multiple_disjoint_alarms(self): + idx = pd.date_range("2024-01-01", periods=30, freq="10min") + anomalies = pd.Series(False, index=idx) + anomalies.iloc[0:8] = True # criticality reaches 8, drops to 0 by iloc 16 + anomalies.iloc[20:30] = True # second alarm + events, _ = calculate_alarms(anomalies, alarm_reset_time_minutes=20) + + assert len(events) == 2 + assert events.iloc[0]["start"] == idx[5] + assert events.iloc[1]["start"] == idx[25] + + +class TestCalculateAlarmsMultiIndex(unittest.TestCase): + """Alarm derivation with a MultiIndex (asset_id, timestamp).""" + + def setUp(self): + self.times = pd.date_range("2024-01-01", periods=20, freq="10min") + self.idx = pd.MultiIndex.from_product([["asset_A", "asset_B"], self.times], + names=["asset_id", "timestamp"]) + + def test_alarms_are_grouped_per_asset(self): + anomalies = pd.Series(False, index=self.idx) + anomalies.loc["asset_A"] = [False] * 2 + [True] * 10 + [False] * 8 + anomalies.loc["asset_B"] = [False] * 5 + [True] * 7 + [False] * 8 + + events, crit = calculate_alarms(anomalies) + + assert set(events["group"]) == {"asset_A", "asset_B"} + assert "group" in events.columns + assert crit.groupby(level="asset_id").max().to_dict() == {"asset_A": 10, "asset_B": 7} + + def test_time_frequency_from_datetime_level(self): + """Time frequency is inferred from the datetime level of the MultiIndex.""" + anomalies = pd.Series(False, index=self.idx) + anomalies.loc["asset_A"] = [False] * 2 + [True] * 12 + [False] * 6 + + events, crit = calculate_alarms(anomalies) + + # default threshold 6, max 12 as for a single DatetimeIndex with 10 min frequency + assert crit.loc["asset_A"].max() == 12 + assert events.loc[events["group"] == "asset_A"].iloc[0]["start"] == self.times[7] + + def test_empty_events_keep_group_column(self): + anomalies = pd.Series(False, index=self.idx) + events, crit = calculate_alarms(anomalies) + + assert events.empty + assert list(events.columns) == ["start", "end", "duration", "group"] + assert (crit == 0).all() + + # ────────────────────────────────────────────────────────────────────────────── # create_events # ────────────────────────────────────────────────────────────────────────────── diff --git a/tests/utils/test_visualisation.py b/tests/utils/test_visualisation.py index 162b1bfc..01a065c6 100644 --- a/tests/utils/test_visualisation.py +++ b/tests/utils/test_visualisation.py @@ -32,9 +32,12 @@ def __init__(self, reconstruction: pd.DataFrame): ) self.predicted_anomalies = pd.Series(False, index=idx) - def criticality(self, normal_idx=None, max_criticality=1000): + def criticality(self, normal_idx=None, init_criticality=0, criticality_threshold=None, + alarm_reset_time_minutes=60): # trivial constant criticality, same index as anomaly_score - return pd.Series(0, index=self.anomaly_score.index, name="criticality") + criticality = pd.Series(0, index=self.anomaly_score.index, name="criticality") + alarm_events = pd.DataFrame(columns=["start", "end", "duration"]) + return alarm_events, criticality class DummyFDWithDP: @@ -88,6 +91,18 @@ def test_plot_reconstruction_with_model(self): self.assertEqual(len(axes), 2) plt.close(fig) + def test_plot_score_with_threshold_show_criticality(self): + idx = pd.date_range("2025-01-01", periods=10, freq="h") + data = pd.DataFrame({"a": np.arange(10, dtype=float)}, index=idx) + fd = DummyFDWithDP(data) + + fig, ax = viz.plot_score_with_threshold( + model=fd, data=data, show_threshold=False, show_criticality=True, + criticality_threshold=3, alarm_reset_time_minutes=60, + ) + self.assertIsInstance(fig, plt.Figure) + plt.close(fig) + def test_plot_arcana_mean_importances(self): importances = pd.Series( { From abc5ccb816050f461ef69e1f88f1cf9cc3b1b5f9 Mon Sep 17 00:00:00 2001 From: chr39552 Date: Fri, 6 Nov 2026 11:08:41 +0100 Subject: [PATCH 13/18] Added checks for initial criticality --- energy_fault_detector/utils/analysis.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/energy_fault_detector/utils/analysis.py b/energy_fault_detector/utils/analysis.py index 02440e78..f3cfba04 100644 --- a/energy_fault_detector/utils/analysis.py +++ b/energy_fault_detector/utils/analysis.py @@ -4,6 +4,9 @@ import numpy as np import pandas as pd +import logging + +logger = logging.getLogger("energy_fault_detector") _ALARM_EVENT_COLUMNS = ["start", "end", "duration"] @@ -143,6 +146,12 @@ def calculate_criticality(anomalies: pd.Series, normal_idx: pd.Series = None, in Raises: ValueError: If the lengths of the given pandas Series for anomalies and normal_idx do not match. """ + if init_criticality < 0: + init_criticality = 0 + logger.warning(f'init_criticality < 0, was set to 0.') + elif init_criticality > max_criticality: + init_criticality = max_criticality + logger.warning(f'init_criticality > max_criticality, was set to max_criticality ({max_criticality}).') # Ensure aligned and sorted indices anomalies = anomalies.sort_index() From 270f735a78164f463ebe0bc4a5982ae48d4df6d5 Mon Sep 17 00:00:00 2001 From: chr39552 Date: Fri, 6 Nov 2026 11:51:04 +0100 Subject: [PATCH 14/18] Reintroduced raw criticality calculation and refactored criticality-based alarm function --- docs/configuration.rst | 12 ++++++-- docs/criticality.rst | 21 ++++++++++--- docs/usage_examples.rst | 5 +++- .../core/fault_detection_result.py | 21 ++++++++++--- energy_fault_detector/utils/visualisation.py | 12 +++----- notebooks/PreDist/PreDist.ipynb | 6 ++-- tests/core/test_fault_detection_result.py | 30 ++++++++++++++++--- tests/utils/test_visualisation.py | 10 ++----- 8 files changed, 84 insertions(+), 33 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index acd0999d..e71d2dee 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -212,14 +212,14 @@ Criticality and alarms ^^^^^^^^^^^^^^^^^^^^^^ The criticality counter and the derived alarm events are computed from the prediction result rather than configured in the YAML file. Call -:meth:`FaultDetectionResult.criticality ` +:meth:`FaultDetectionResult.criticality_alarms ` (or :func:`calculate_alarms `) with the desired settings: .. code-block:: python results = fault_detector.predict(sensor_data=test_data) - alarm_events, criticality = results.criticality( + alarm_events, criticality = results.criticality_alarms( normal_idx=test_status, # optional: True = normal operation criticality_threshold=None, # None -> one hour of anomalous behaviour alarm_reset_time_minutes=60, # reset window used to derive max_criticality @@ -230,6 +230,14 @@ frequency exceeds one hour). ``max_criticality`` is derived as ``criticality_threshold + int(alarm_reset_time_minutes / time_frequency)``. See :ref:`criticality` for the full interpretation and guidance on choosing these values. +For the plain criticality counter without alarm event detection, use the legacy +:meth:`FaultDetectionResult.criticality ` +method, which returns only the criticality series and accepts an explicit ``max_criticality``: + +.. code-block:: python + + criticality = results.criticality(normal_idx=test_status, max_criticality=144) + Root cause analysis (ARCANA) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/docs/criticality.rst b/docs/criticality.rst index 14dc5663..17825b00 100644 --- a/docs/criticality.rst +++ b/docs/criticality.rst @@ -15,8 +15,13 @@ The package provides two building blocks in :mod:`energy_fault_detector.utils.an - :func:`calculate_alarms ` builds on it to derive **alarm events** (start, end, duration) from the criticality. -Both are exposed on a prediction result via -:meth:`FaultDetectionResult.criticality `. +Both are exposed on a prediction result: + +- :meth:`FaultDetectionResult.criticality ` + returns only the criticality series (the basic counter, with an explicit ``max_criticality``). +- :meth:`FaultDetectionResult.criticality_alarms ` + returns both the alarm events and the criticality series, with the threshold and reset window derived from the + time frequency. How the criticality works ------------------------- @@ -94,13 +99,21 @@ On a prediction result you can call the method directly. It returns the same ``( results = fault_detector.predict(sensor_data=test_sensor_data) - alarm_events, criticality = results.criticality() # defaults derived from the data - alarm_events, criticality = results.criticality( + alarm_events, criticality = results.criticality_alarms() # defaults derived from the data + alarm_events, criticality = results.criticality_alarms( normal_idx=test_status, criticality_threshold=6, alarm_reset_time_minutes=60, ) +For the plain criticality counter (without alarm event detection) use the legacy +:meth:`FaultDetectionResult.criticality ` +method, which returns only the ``criticality`` series: + +.. code-block:: python + + criticality = results.criticality(normal_idx=test_status, max_criticality=144) + Interpreting criticality: raising alarms ---------------------------------------- diff --git a/docs/usage_examples.rst b/docs/usage_examples.rst index e9427752..13a91f78 100644 --- a/docs/usage_examples.rst +++ b/docs/usage_examples.rst @@ -152,13 +152,16 @@ anomalous behaviour persists over time. See :ref:`criticality` for the interpret .. code-block:: python - alarm_events, criticality = results.criticality( + alarm_events, criticality = results.criticality_alarms( normal_idx=test_status, # optional: True = normal operation criticality_threshold=None, # None -> one hour of anomalous behaviour alarm_reset_time_minutes=60, # reset window used to derive max_criticality ) # alarm_events: DataFrame with columns start, end, duration (and group for MultiIndex data) + # Legacy: only the criticality counter, with an explicit maximum + criticality = results.criticality(normal_idx=test_status, max_criticality=144) + You can also create a :py:obj:`FaultDetector ` object and load trained models using the :py:obj:`FaultDetector.load ` class method. diff --git a/energy_fault_detector/core/fault_detection_result.py b/energy_fault_detector/core/fault_detection_result.py index 7dfee6d9..16fd6a35 100644 --- a/energy_fault_detector/core/fault_detection_result.py +++ b/energy_fault_detector/core/fault_detection_result.py @@ -7,7 +7,7 @@ import pandas as pd import numpy as np -from ..utils.analysis import calculate_alarms +from ..utils.analysis import calculate_alarms, calculate_criticality _INDEX_META_FILE = "_index_meta.json" @@ -39,9 +39,22 @@ class FaultDetectionResult: """List of DataFrames containing the ARCANA bias every 50th iteration. None if ARCANA was not run. Empty if bias was not tracked.""" - def criticality(self, normal_idx: pd.Series | None = None, init_criticality: int = 0, - criticality_threshold: int | None = None, alarm_reset_time_minutes: float = 60 - ) -> Tuple[pd.DataFrame, pd.Series]: + def criticality(self, normal_idx: pd.Series | None = None, init_criticality: int = 0, max_criticality: int = 1000 + ) -> pd.Series: + """Criticality based on the predicted anomalies. + + Args: + normal_idx (pd.Series, optional): A pandas Series with boolean values indicating normal operation, indexed + by timestamp. Ignored if None. + init_criticality (int, optional): The initial criticality value. Defaults to 0. + max_criticality (int, optional): The maximum criticality value. Defaults to 1000. + + """ + return calculate_criticality(self.predicted_anomalies, normal_idx, init_criticality, max_criticality) + + def criticality_alarms(self, normal_idx: pd.Series | None = None, init_criticality: int = 0, + criticality_threshold: int | None = None, alarm_reset_time_minutes: float = 60 + ) -> Tuple[pd.DataFrame, pd.Series]: """Derive alarm events and the criticality counter from the predicted anomalies. The criticality increases for sustained anomalies during normal operation and decreases again during normal diff --git a/energy_fault_detector/utils/visualisation.py b/energy_fault_detector/utils/visualisation.py index 2afecc35..b605d763 100644 --- a/energy_fault_detector/utils/visualisation.py +++ b/energy_fault_detector/utils/visualisation.py @@ -186,8 +186,7 @@ def plot_reconstruction_with_model(model: FaultDetector, data: pd.DataFrame, def plot_score_with_threshold(model: FaultDetector, data: pd.DataFrame, normal_index: pd.Series = None, ax: plt.Axes = None, figsize: Tuple[float, float] = (8, 3), show_predicted_anomaly: bool = False, show_threshold: bool = True, - show_criticality: bool = False, criticality_threshold: Optional[int] = None, - alarm_reset_time_minutes: float = 60, + show_criticality: bool = False, max_criticality: int = 144, score_color: Optional[str] = None, anomaly_color: Optional[str] = None, criticality_color: Optional[str] = "C2", @@ -209,10 +208,8 @@ def plot_score_with_threshold(model: FaultDetector, data: pd.DataFrame, normal_i show_predicted_anomaly (bool, optional): Whether to show the predicted anomaly scores. Defaults to False. show_threshold (bool, optional): Whether to show the threshold scores. Defaults to True. show_criticality (bool, optional): Whether to show the criticality counter. Defaults to False. - criticality_threshold (Optional[int], optional): If show_criticality is True, the criticality value at which - an alarm is raised. If None, it is derived from the time frequency (one hour of anomalous behaviour). - alarm_reset_time_minutes (float, optional): If show_criticality is True, the time window in minutes after - which an alarm is reset once the system behaves normally again. Defaults to 60. + max_criticality (int optional): If show_criticality is True, the maximum value of the criticality counter can + be specified. Defaults to 144 (one day of 10 min timestamps). score_color (Optional[str], optional): Color to use for the anomaly score. anomaly_color (Optional[str], optional): Color to use for the anomalous data points (using normal_index). criticality_color (Optional[str], optional): Color to use for the criticality counter if show_criticality is @@ -268,8 +265,7 @@ def plot_score_with_threshold(model: FaultDetector, data: pd.DataFrame, normal_i ax.plot(threshold, linestyle='-', linewidth=.7, label='threshold', c=threshold_color) if show_criticality: - crit = predictions.criticality(normal_idx=normal_index, criticality_threshold=criticality_threshold, - alarm_reset_time_minutes=alarm_reset_time_minutes)[1] + crit = predictions.criticality(normal_idx=normal_index, max_criticality=max_criticality) ax2 = ax.twinx() ax2.plot(crit, label='criticality counter', color=criticality_color) ax2.set_ylabel('criticality') diff --git a/notebooks/PreDist/PreDist.ipynb b/notebooks/PreDist/PreDist.ipynb index 53230a7c..3e51492f 100644 --- a/notebooks/PreDist/PreDist.ipynb +++ b/notebooks/PreDist/PreDist.ipynb @@ -615,7 +615,7 @@ " max_criticality_list = []\n", " for event_id, prediction in results_dict.items():\n", " event_row = dataset.events[manufacturer].loc[event_id]\n", - " max_criticality = prediction.criticality()[1].loc[:event_row['Report date']].max()\n", + " max_criticality = prediction.criticality().loc[:event_row['Report date']].max()\n", " max_criticality_list += [(event_id, max_criticality)]\n", "\n", " # Transform results to pandas series with max criticality with event id as index\n", @@ -717,7 +717,7 @@ " earliness_scores = []\n", " for event_id, predictions in results[manufacturer][model_name].items():\n", " if dataset.events[manufacturer].loc[event_id]['Event type'] == 'anomaly':\n", - " criticality = predictions.criticality()[1]\n", + " criticality = predictions.criticality()\n", " detection_time, earliness = calculate_earliness(\n", " criticality_threshold=criticality_thresholds[manufacturer][model_name],\n", " report_ts=dataset.events[manufacturer].loc[event_id]['Report date'],\n", @@ -846,7 +846,7 @@ "predictions = results[manufacturer][model_name][event_id]\n", "\n", "fig, ax = plt.subplots(1, 1, figsize=(8,3))\n", - "crit = predictions.criticality()[1]\n", + "crit = predictions.criticality()\n", "crit.plot(ax=ax, label=model_name)\n", "\n", "if pd.notna(report_date):\n", diff --git a/tests/core/test_fault_detection_result.py b/tests/core/test_fault_detection_result.py index 8e318cef..f27a62b7 100644 --- a/tests/core/test_fault_detection_result.py +++ b/tests/core/test_fault_detection_result.py @@ -215,13 +215,35 @@ def _make_result(self, anomalies): anomaly_score=pd.Series(0.0, index=anomalies.index), ) - def test_criticality_returns_events_and_series(self): + def test_criticality_returns_series(self): + """The legacy criticality method returns only the criticality series.""" + idx = pd.date_range("2024-01-01", periods=6, freq="10min") + anomalies = pd.Series([True, True, True, False, False, False], index=idx) + + result = self._make_result(anomalies) + criticality = result.criticality() + + self.assertIsInstance(criticality, pd.Series) + self.assertEqual(criticality.index.equals(idx), True) + self.assertEqual(list(criticality), [1, 2, 3, 2, 1, 0]) + + def test_criticality_supports_max_criticality(self): + """The legacy criticality method caps the counter at max_criticality.""" + idx = pd.date_range("2024-01-01", periods=5, freq="10min") + anomalies = pd.Series([True] * 5, index=idx) + + result = self._make_result(anomalies) + criticality = result.criticality(max_criticality=3) + + self.assertEqual(list(criticality), [1, 2, 3, 3, 3]) + + def test_criticality_alarms_returns_events_and_series(self): idx = pd.date_range("2024-01-01", periods=20, freq="10min") anomalies = pd.Series(False, index=idx) anomalies.iloc[2:10] = True result = self._make_result(anomalies) - alarm_events, criticality = result.criticality() + alarm_events, criticality = result.criticality_alarms() self.assertIsInstance(alarm_events, pd.DataFrame) self.assertIsInstance(criticality, pd.Series) @@ -229,13 +251,13 @@ def test_criticality_returns_events_and_series(self): self.assertEqual(criticality.index.equals(idx), True) self.assertEqual(alarm_events.iloc[0]["start"], idx[7]) - def test_criticality_uses_normal_idx_and_threshold(self): + def test_criticality_alarms_uses_normal_idx_and_threshold(self): idx = pd.date_range("2024-01-01", periods=10, freq="10min") anomalies = pd.Series(True, index=idx) normal_idx = pd.Series([True] * 5 + [False] * 5, index=idx) result = self._make_result(anomalies) - alarm_events, criticality = result.criticality( + alarm_events, criticality = result.criticality_alarms( normal_idx=normal_idx, criticality_threshold=3, alarm_reset_time_minutes=20 ) diff --git a/tests/utils/test_visualisation.py b/tests/utils/test_visualisation.py index 01a065c6..43265ad4 100644 --- a/tests/utils/test_visualisation.py +++ b/tests/utils/test_visualisation.py @@ -32,12 +32,9 @@ def __init__(self, reconstruction: pd.DataFrame): ) self.predicted_anomalies = pd.Series(False, index=idx) - def criticality(self, normal_idx=None, init_criticality=0, criticality_threshold=None, - alarm_reset_time_minutes=60): + def criticality(self, normal_idx=None, max_criticality=1000): # trivial constant criticality, same index as anomaly_score - criticality = pd.Series(0, index=self.anomaly_score.index, name="criticality") - alarm_events = pd.DataFrame(columns=["start", "end", "duration"]) - return alarm_events, criticality + return pd.Series(0, index=self.anomaly_score.index, name="criticality") class DummyFDWithDP: @@ -97,8 +94,7 @@ def test_plot_score_with_threshold_show_criticality(self): fd = DummyFDWithDP(data) fig, ax = viz.plot_score_with_threshold( - model=fd, data=data, show_threshold=False, show_criticality=True, - criticality_threshold=3, alarm_reset_time_minutes=60, + model=fd, data=data, show_threshold=False, show_criticality=True, max_criticality=144, ) self.assertIsInstance(fig, plt.Figure) plt.close(fig) From 9047f7fb6d22f967ec51a657ec764b0e8b161569 Mon Sep 17 00:00:00 2001 From: croelofs <25582572+roelofsc@users.noreply.github.com> Date: Fri, 6 Nov 2026 11:39:19 +0100 Subject: [PATCH 15/18] Fix test for old RMSEScore object. --- energy_fault_detector/anomaly_scores/rmse_score.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/energy_fault_detector/anomaly_scores/rmse_score.py b/energy_fault_detector/anomaly_scores/rmse_score.py index 9cd7d0a1..927d951a 100644 --- a/energy_fault_detector/anomaly_scores/rmse_score.py +++ b/energy_fault_detector/anomaly_scores/rmse_score.py @@ -67,6 +67,11 @@ def standardize(self, x: DataType): """Standardization of the reconstruction error in x""" check_is_fitted(self) + + if not hasattr(self, 'std_x_'): + # backward compat. + self.std_x_ = np.zeros(x.shape[1]) + x_ = x.copy() std_mask = self.std_x_ > 0 if np.all(std_mask): From 94c29497c542e6f112fda1860975ed210d05b0ae Mon Sep 17 00:00:00 2001 From: chr39552 Date: Fri, 6 Nov 2026 11:53:28 +0100 Subject: [PATCH 16/18] fixed wording in documentation --- docs/criticality.rst | 2 +- docs/usage_examples.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/criticality.rst b/docs/criticality.rst index 17825b00..e606cb1a 100644 --- a/docs/criticality.rst +++ b/docs/criticality.rst @@ -106,7 +106,7 @@ On a prediction result you can call the method directly. It returns the same ``( alarm_reset_time_minutes=60, ) -For the plain criticality counter (without alarm event detection) use the legacy +For the plain criticality counter (without alarm event detection) use the :meth:`FaultDetectionResult.criticality ` method, which returns only the ``criticality`` series: diff --git a/docs/usage_examples.rst b/docs/usage_examples.rst index 13a91f78..924398ec 100644 --- a/docs/usage_examples.rst +++ b/docs/usage_examples.rst @@ -159,7 +159,7 @@ anomalous behaviour persists over time. See :ref:`criticality` for the interpret ) # alarm_events: DataFrame with columns start, end, duration (and group for MultiIndex data) - # Legacy: only the criticality counter, with an explicit maximum + # Alternatively, only the criticality counter, with an explicit maximum criticality = results.criticality(normal_idx=test_status, max_criticality=144) You can also create a :py:obj:`FaultDetector ` object and load From 49eeaace9d6336620042e91a22b6f2a3ca43deec Mon Sep 17 00:00:00 2001 From: chr39552 Date: Mon, 9 Nov 2026 08:30:17 +0100 Subject: [PATCH 17/18] Fixed unit tests (protect_conditional_features) --- energy_fault_detector/fault_detector.py | 2 +- tests/data_preprocessing/test_data_preprocessor.py | 2 +- tests/test_fault_detector.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/energy_fault_detector/fault_detector.py b/energy_fault_detector/fault_detector.py index b12f00f0..f235052e 100644 --- a/energy_fault_detector/fault_detector.py +++ b/energy_fault_detector/fault_detector.py @@ -493,7 +493,7 @@ def _resolve_conditional_features(self, prepped_sensor_data: pd.DataFrame) -> Li logger.warning(f"Declared conditions not found in sensor_data will be ignored: " f"{sorted(missing)}. Using: {available or 'none'}") - if not self.config.protect_conditional_features: + if not self.config.train.protect_conditional_features: # Uses nested for loop in case categorical cols have been encoded already and contain the original # conditional feature name as a substring. surviving = [declared_condition for declared_condition in available diff --git a/tests/data_preprocessing/test_data_preprocessor.py b/tests/data_preprocessing/test_data_preprocessor.py index 18375762..8cdd22ec 100644 --- a/tests/data_preprocessing/test_data_preprocessor.py +++ b/tests/data_preprocessing/test_data_preprocessor.py @@ -541,6 +541,7 @@ def _create_config_dict(self, protect_conditional_features: bool = True): """Create configuration matching updated advanced_config.yaml structure.""" return { 'train': { + 'protect_conditional_features': protect_conditional_features, 'data_clipping': { 'lower_percentile': 0.001, 'upper_percentile': 0.999, @@ -571,7 +572,6 @@ def _create_config_dict(self, protect_conditional_features: bool = True): 'verbose': 0 } }, - 'protect_conditional_features': protect_conditional_features, 'anomaly_score': {'name': 'rmse'}, 'threshold_selector': {'name': 'quantile'}, } diff --git a/tests/test_fault_detector.py b/tests/test_fault_detector.py index 2817ce61..da20bce7 100644 --- a/tests/test_fault_detector.py +++ b/tests/test_fault_detector.py @@ -713,8 +713,8 @@ def tearDown(self) -> None: def test_conditional_features_can_be_dropped_when_unprotected(self): """When protect=False, pipeline can drop constant conditional features.""" from energy_fault_detector.autoencoders import MultilayerAutoencoder - self.conf.config_dict['train']['protect_conditional_features'] = False - self.conf.config_dict['train']['data_preprocessor']['steps'].append({'name': 'low_unique_value_filter', 'params': {'min_unique_value_count': 2}}) + self.conf.train.protect_conditional_features = False + self.conf.train.data_preprocessor.steps.append({'name': 'low_unique_value_filter', 'params': {'min_unique_value_count': 2}}) fd = FaultDetector(config=self.conf, model_directory=self.test_dir) self.assertFalse(fd.config.train.protect_conditional_features) result = fd.fit(sensor_data=self.sensor_data, normal_index=self.normal_index, save_models=False) From bb08d2086a2a745324715645630ac1292f58031c Mon Sep 17 00:00:00 2001 From: croelofs <25582572+roelofsc@users.noreply.github.com> Date: Mon, 9 Nov 2026 10:05:50 +0100 Subject: [PATCH 18/18] Regenerate Keras 3 model fixtures with Keras 3.12.4 for py3.10 compatibility The py312_efd071 fixtures were saved with Keras 3.14.1, which adds a quantization_config key to Dense configs. Python 3.10 caps Keras at 3.12.4 (Keras 3.13+ requires >=3.11), so loading these fixtures failed with 'Unrecognized keyword arguments passed to Dense'. Regenerate the fixtures with EFD 0.7.1 on Python 3.10 (Keras 3.12.4), rename them to py310_efd071, and update the compatibility tests and the fixture generator docstring. Verified they load and predict on both Keras 3.12.4 and 3.14.1. --- .../create_legacy_model_fixtures.py | 3 +++ .../dense/anomaly_score/RMSEScore.pkl | Bin .../autoencoder/MultilayerAutoencoder.attrs | Bin 454 -> 454 bytes .../MultilayerAutoencoder.encoder.keras | Bin 23646 -> 23569 bytes .../MultilayerAutoencoder.model.keras | Bin 46717 -> 46582 bytes .../dense/config.yaml | 0 .../data_preprocessor/DataPreprocessor.pkl | Bin .../QuantileThresholdSelector.pkl | Bin 0 -> 57 bytes .../manifest.json | 14 +++++----- .../sequence/anomaly_score/RMSEScore.pkl | Bin .../autoencoder/LSTMSeq2OneAutoencoder.attrs | Bin 8141 -> 8141 bytes .../LSTMSeq2OneAutoencoder.decoder.keras | Bin 17405 -> 17328 bytes .../LSTMSeq2OneAutoencoder.encoder.keras | Bin 27565 -> 27546 bytes .../LSTMSeq2OneAutoencoder.model.keras | Bin 59896 -> 59781 bytes .../sequence/config.yaml | 4 ++- .../data_preprocessor/DataPreprocessor.pkl | Bin 0 -> 3037 bytes .../QuantileThresholdSelector.pkl | Bin 0 -> 57 bytes .../QuantileThresholdSelector.pkl | Bin 57 -> 0 bytes .../data_preprocessor/DataPreprocessor.pkl | Bin 3471 -> 0 bytes .../QuantileThresholdSelector.pkl | Bin 57 -> 0 bytes tests/test_model_compatibility.py | 25 ++++++++++-------- 21 files changed, 27 insertions(+), 19 deletions(-) rename tests/test_data/old_models/{py312_efd071 => py310_efd071}/dense/anomaly_score/RMSEScore.pkl (100%) rename tests/test_data/old_models/{py312_efd071 => py310_efd071}/dense/autoencoder/MultilayerAutoencoder.attrs (59%) rename tests/test_data/old_models/{py312_efd071 => py310_efd071}/dense/autoencoder/MultilayerAutoencoder.encoder.keras (75%) rename tests/test_data/old_models/{py312_efd071 => py310_efd071}/dense/autoencoder/MultilayerAutoencoder.model.keras (59%) rename tests/test_data/old_models/{py312_efd071 => py310_efd071}/dense/config.yaml (100%) rename tests/test_data/old_models/{py312_efd071 => py310_efd071}/dense/data_preprocessor/DataPreprocessor.pkl (100%) create mode 100644 tests/test_data/old_models/py310_efd071/dense/threshold_selector/QuantileThresholdSelector.pkl rename tests/test_data/old_models/{py312_efd071 => py310_efd071}/manifest.json (51%) rename tests/test_data/old_models/{py312_efd071 => py310_efd071}/sequence/anomaly_score/RMSEScore.pkl (100%) rename tests/test_data/old_models/{py312_efd071 => py310_efd071}/sequence/autoencoder/LSTMSeq2OneAutoencoder.attrs (98%) rename tests/test_data/old_models/{py312_efd071 => py310_efd071}/sequence/autoencoder/LSTMSeq2OneAutoencoder.decoder.keras (74%) rename tests/test_data/old_models/{py312_efd071 => py310_efd071}/sequence/autoencoder/LSTMSeq2OneAutoencoder.encoder.keras (61%) rename tests/test_data/old_models/{py312_efd071 => py310_efd071}/sequence/autoencoder/LSTMSeq2OneAutoencoder.model.keras (51%) rename tests/test_data/old_models/{py312_efd071 => py310_efd071}/sequence/config.yaml (92%) create mode 100644 tests/test_data/old_models/py310_efd071/sequence/data_preprocessor/DataPreprocessor.pkl create mode 100644 tests/test_data/old_models/py310_efd071/sequence/threshold_selector/QuantileThresholdSelector.pkl delete mode 100644 tests/test_data/old_models/py312_efd071/dense/threshold_selector/QuantileThresholdSelector.pkl delete mode 100644 tests/test_data/old_models/py312_efd071/sequence/data_preprocessor/DataPreprocessor.pkl delete mode 100644 tests/test_data/old_models/py312_efd071/sequence/threshold_selector/QuantileThresholdSelector.pkl diff --git a/tests/test_data/old_models/create_legacy_model_fixtures.py b/tests/test_data/old_models/create_legacy_model_fixtures.py index a0323705..b82ff1c9 100644 --- a/tests/test_data/old_models/create_legacy_model_fixtures.py +++ b/tests/test_data/old_models/create_legacy_model_fixtures.py @@ -1,6 +1,9 @@ """Create small saved-model fixtures for compatibility testing. 1. Create a python environment with a previous version of energy-fault-detector. + Use the minimum supported Python version (3.10) so Keras is capped at 3.12.4; + newer Keras versions add config keys (e.g. ``quantization_config``) that older + Keras cannot deserialize, so fixtures created with newer Keras fail on 3.10. 2. Run this script: python tests/test_data/old_models/create_legacy_model_fixtures.py \ --output tests/test_data/old_models/py_efd \ diff --git a/tests/test_data/old_models/py312_efd071/dense/anomaly_score/RMSEScore.pkl b/tests/test_data/old_models/py310_efd071/dense/anomaly_score/RMSEScore.pkl similarity index 100% rename from tests/test_data/old_models/py312_efd071/dense/anomaly_score/RMSEScore.pkl rename to tests/test_data/old_models/py310_efd071/dense/anomaly_score/RMSEScore.pkl diff --git a/tests/test_data/old_models/py312_efd071/dense/autoencoder/MultilayerAutoencoder.attrs b/tests/test_data/old_models/py310_efd071/dense/autoencoder/MultilayerAutoencoder.attrs similarity index 59% rename from tests/test_data/old_models/py312_efd071/dense/autoencoder/MultilayerAutoencoder.attrs rename to tests/test_data/old_models/py310_efd071/dense/autoencoder/MultilayerAutoencoder.attrs index d221693877fbe26f2034e158a3575ad6cf67f85f..7a07523dcc5f772780b8e1f1d594e9bba610bc0a 100644 GIT binary patch delta 63 zcmX@ce2jSm6Qh>>m!Ah0FfcGAW^lz$akqb${96IU>)|L%%!$v*FD{+}5`MW~>A++i PMkSV)UTqDNgBVKy`hgf3 delta 63 zcmX@ce2jSm6Qh=c^7>o{1_p-246fKI?hZ`q2M>UFJsf3;Iq^C9#l=%V!a@aB3nuF@ PDzW^0bWmY(5Mv1dY<3jj diff --git a/tests/test_data/old_models/py312_efd071/dense/autoencoder/MultilayerAutoencoder.encoder.keras b/tests/test_data/old_models/py310_efd071/dense/autoencoder/MultilayerAutoencoder.encoder.keras similarity index 75% rename from tests/test_data/old_models/py312_efd071/dense/autoencoder/MultilayerAutoencoder.encoder.keras rename to tests/test_data/old_models/py310_efd071/dense/autoencoder/MultilayerAutoencoder.encoder.keras index bd2f2de38a306ce991588b4aec4da596256064d0..97cec74a708d00abbc07becda6a5e5eb984aad02 100644 GIT binary patch delta 574 zcmcb&gK^>xMxg+2W)=|!2vB7346?s7QApp>NY6w`M?oniu_QIVII%1>MafD*$;iOS zOxMs**TB-jz|zVXh|HC0QS~$ZyvQ`2kAY$O#wKgV$qQLzH@{_^&NTT4r_|=%EY}!$ zjm*rA%*`wfOw0@n%{I?tTf>AV6wWz|5u|+bZWhhWf!wPxwJRrk18qK2Ji)ziSSsN>?H|N<}a41;c zNVn#*soK3JD|xr)pC;>hR*}1BXjkkGUtGHTjcwBI&Bt6DI1|d7ZSCcz`t8%VskeXV zU}7)D_o4?N1Y zpRsMfP5VtlJE^{}PBv0qUkW*>t{&c5BA_WL$3^N(QS2^1*by>+(vE~&2I z-IMjyB{nMsDRA)2zM{Q*`R)d5In|oooBg697+F9OKY3NOIVU^@C%=l;fd}$rxfn4< P?a8Jw%50v|pu_?I-Mi7k delta 636 zcmbQZgYn)DMxg+2W)=|!2vB6$z#$hgQApp>M9)x3M?oniu_QIVII%1>MafD*$;iOS zOxM6t*T~Yr(9Fu%#LC!6sTNiL)==e@Pxu%Zo@{KgW)udRkY7-enV*-K1Js|Em{XiO zxsXM6^DV~dOkzOE!qUXNlFX_^kdpZ1{JgZx^vQ+HikrJxt}*f&nj0INnH!p$n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`96kB^>AAMUIISh>=}3xvr#$M^v5-V2IKq7T9%fI_b!EUSntYVveoQ*ub{`&Jp{8 zN835MJM3)VjRrdLiq0dwSJfTa%W!UY8^O&DZ-hF0Q?X!X4`(P7=Z(j`;?6cKwd*=p z;AC@dqf?6u!I$2w<0&#qmwa!zQaS5G+RsQrM=X{id#n)tJr~)NiYv}^*`SMuRszw5 zV8vHrdYPPc-rYhFW;hO&-5BS)_J#7ry36_di!tFtP>VDaOy_^^w{kga7xOM~Df`G3 zBl(Jwi4^u_eQE+06#Kms)l@v)8-&Iel#D z<6Vs9@zRc;2=Ve%Wz13e{fvXV)bVHhXIR0L j>z1(o{V7N1sHlA1%zsTqUynpp0~5Th&Ro5&?(6lRA;|E) diff --git a/tests/test_data/old_models/py312_efd071/dense/config.yaml b/tests/test_data/old_models/py310_efd071/dense/config.yaml similarity index 100% rename from tests/test_data/old_models/py312_efd071/dense/config.yaml rename to tests/test_data/old_models/py310_efd071/dense/config.yaml diff --git a/tests/test_data/old_models/py312_efd071/dense/data_preprocessor/DataPreprocessor.pkl b/tests/test_data/old_models/py310_efd071/dense/data_preprocessor/DataPreprocessor.pkl similarity index 100% rename from tests/test_data/old_models/py312_efd071/dense/data_preprocessor/DataPreprocessor.pkl rename to tests/test_data/old_models/py310_efd071/dense/data_preprocessor/DataPreprocessor.pkl diff --git a/tests/test_data/old_models/py310_efd071/dense/threshold_selector/QuantileThresholdSelector.pkl b/tests/test_data/old_models/py310_efd071/dense/threshold_selector/QuantileThresholdSelector.pkl new file mode 100644 index 0000000000000000000000000000000000000000..76183c3293d1475432daa305babfc0fa25a94281 GIT binary patch literal 57 zcmZo*nX1PC0ku;!dN@lmic*U+@^ezAxZD3-_=o#d-{l^T!qUXNlFXb`pxC=KFeudn E05Aa+^8f$< literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py312_efd071/manifest.json b/tests/test_data/old_models/py310_efd071/manifest.json similarity index 51% rename from tests/test_data/old_models/py312_efd071/manifest.json rename to tests/test_data/old_models/py310_efd071/manifest.json index 493176bf..6f74d502 100644 --- a/tests/test_data/old_models/py312_efd071/manifest.json +++ b/tests/test_data/old_models/py310_efd071/manifest.json @@ -1,14 +1,14 @@ { "purpose": "Saved-model compatibility fixtures created before the Pydantic config migration.", - "python": "3.12.10 (tags/v3.12.10:0cc8128, Apr 8 2025, 12:21:36) [MSC v.1943 64 bit (AMD64)]", - "platform": "Windows-11-10.0.26100-SP0", + "python": "3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]", + "platform": "Windows-10-10.0.26100-SP0", "package_versions": { "energy-fault-detector": "0.7.1", "tensorflow": "2.18.1", - "keras": "3.14.1", - "pydantic": "2.13.4", + "keras": "3.12.4", + "pydantic": null, "scikit-learn": "1.7.0", - "pandas": "2.2.3", + "pandas": "2.3.3", "numpy": "1.26.4" }, "fixtures": { @@ -16,7 +16,7 @@ "sequence": "sequence" }, "data_generation": { - "dense": "make_dense_data(seed=42, rows=80)", - "sequence": "make_sequence_data(seed=123, rows=120)" + "dense": "make_dense_data(n_rows=80)", + "sequence": "make_sequence_data(n_rows=120)" } } \ No newline at end of file diff --git a/tests/test_data/old_models/py312_efd071/sequence/anomaly_score/RMSEScore.pkl b/tests/test_data/old_models/py310_efd071/sequence/anomaly_score/RMSEScore.pkl similarity index 100% rename from tests/test_data/old_models/py312_efd071/sequence/anomaly_score/RMSEScore.pkl rename to tests/test_data/old_models/py310_efd071/sequence/anomaly_score/RMSEScore.pkl diff --git a/tests/test_data/old_models/py312_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.attrs b/tests/test_data/old_models/py310_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.attrs similarity index 98% rename from tests/test_data/old_models/py312_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.attrs rename to tests/test_data/old_models/py310_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.attrs index 253ea8eaaa7c0a59f2b893556857c95e7e55af54..3aa7b8811c410f88d3d6e49d22c22e7a265367cd 100644 GIT binary patch delta 63 zcmX?Wf7X6OI-}<2^otD)3=D}Gg0WNF?ceGJ9{}-sILZ=p;&bwgi>H8uU*GL_m^^_| QiRJlOwga2DF^bCp02loj;Q#;t delta 63 zcmX?Wf7X6OI-};N6ZsDq7#I>W1Y@VT+rPPXWC4iR!%>!)6Q7e`Ts#FN{Bp7>!{iB! QN-WQMs~I+LV-%MI06;t##Q*>R diff --git a/tests/test_data/old_models/py312_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.decoder.keras b/tests/test_data/old_models/py310_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.decoder.keras similarity index 74% rename from tests/test_data/old_models/py312_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.decoder.keras rename to tests/test_data/old_models/py310_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.decoder.keras index 58d927f920437fefa7412535f5f817d48dcb6943..7db3d4bbec78619a9f136b75c92197bd86c99bc8 100644 GIT binary patch delta 528 zcmey{&bXnSQ7FKhnMH&F0u&iaYnHoA6w-Gz(lb%gQBX=rEJ=+oPAp4JQL<7{GBPkS z(={~IHL!Fru(UF^v@$VJszud5Z_<=FCr$Tu zd5z4>jm*s~4Gav8jVv~=W}DBrIi2GeBgYq?%-A&z{ZBTVa`9-_OX|z)pMH~V|E1I? zb`77I_WwH6YCCKFS36Z{5&N@=KkPPn@$HXhZr^7dcxK<{Kp8vN^B4B*Ta~wOn#eUf zHp^-Io@&)&8d9Yx?=7@ z>pb~`)>GE+-aUCEm&E2k3k8k@6)AoDvMJ1V9#J`aSi^MfPd(YUckZw4`z%|{_ZPpB zus=Tkwq5>DgZ&N>4*MQ{_+tD1#marmLQ?kIXS43(c&BS0``B(@JICaGQ+M+0zcTZw zo!OjQwo%Dyc8At8?4QAP!FKaS2cUbT`)^sDnqab9+%j!IxDfgZ~}1wH(|;? delta 572 zcmdnc&iJ>TQ7FKhnMH&F0u&icMC@7^QmZZiPCzhqAC|M~e85tOv z=^9w-8d*9Rnpqi}SQ(ot)uQS@dEo!Yeoh94{*6sGjKV+@@(W5b^YapOfcn!CbBa?Z ze`J>0e1mZwlNeC4urx8RB(o|Jq$EB$KQApaeRDp`e@0$Ib7NyOb0afT3o|2=&DCu4 z8F46|oX_I5IhLcDkt49hHdetVc<$yGoIKj~&Au#l>jioDFArt1cjoeft`-q%Zr^=*)edW;zJ1mnkGAhFPs_Hpu-dWtwYeon zf|$%KyU=9}`KldxxiVBNttVMhqDr! JsWT|4002!}(vbiF diff --git a/tests/test_data/old_models/py312_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.encoder.keras b/tests/test_data/old_models/py310_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.encoder.keras similarity index 61% rename from tests/test_data/old_models/py312_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.encoder.keras rename to tests/test_data/old_models/py310_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.encoder.keras index cfae7afc0697108b92af776ac72e8e7efc9dbe2b..64a74026ceec89f207e463eb5f9f4033b027418d 100644 GIT binary patch delta 2832 zcmZ9Oc{tVCAIIHmPs=SDDrG6kv|abQmV58{+%_gjsYFR5p+bupnKt=~$PEc2Ldf@v1UQw)v0JvaM!1bY7D<83T9G#2m$mQ&5mr}AxP@NL9G z8?go7c;~d;dvn1c^^ozxI3);)~1$#lNV%<^D(eq$c;js7x#T ztDTLxkZ&mz{lo4vF}D(a7XRDs3lUmdTmRqg^O3AO?X`0+ z6ptEVAz)glJ-Q1tP(D}yqAO=HB4Z)yJ_i&&SOiY7arC8WHHh`B2~pM~T7O7zB^d!; z&+}-%wk=q$C`6s<`#>x89Gbqr41Go^Xm@ck`rdS-X=m1g+Ug3NU|)@oVvk~5WDItt z0I6?`q`ahBlt!;b!=zITYHUI%8P4Ls^k({PCBgHfY9$#@6QO=jEv{W%q+oXpLq|cA zqRdo})Y&&G`oG@;J*5eFwWb8b%#S##vzk_UP-JF_Xy0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5*@w2w=qn=*fpZd)di9`b8pqSP9s2dh$;;;ss*y9-Nkg2F%JtoYFuyD|UErQ#W3 ib4>ml(yF}`6h4>sm;C#AOJJ$#ilf5Vst>n(KK>gAs1bkw diff --git a/tests/test_data/old_models/py312_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.model.keras b/tests/test_data/old_models/py310_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.model.keras similarity index 51% rename from tests/test_data/old_models/py312_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.model.keras rename to tests/test_data/old_models/py310_efd071/sequence/autoencoder/LSTMSeq2OneAutoencoder.model.keras index a591e78164a00e7c31e38746dc572e9002a1ab64..bc87ceaaa5c291bf752815c0ce03cdf4c9c07e73 100644 GIT binary patch delta 8710 zcmZ8{2UOHd+cv#}h$vMA6cihqw!29-0Tr>KC`F`LP_L4)fm;7+_6UTEhZZI0J%a2yjOMP9Qje3at12 z-~MZ6wYQO03JT=KXh%g^r1JQTaT>A_MWHS%6u}}KK{2rigJtPDV`a65^JT}C?)+&a z_z&v`#c8ss<7UW!&IB2(lJhUC5Elp_1Qu65P>ELj7la_F7!yITELg4Ne-Ic$QP~Nz z?HQxT{cjM5Wt{rIoBhKjz#zCXTw_S-Kj?RBEBz;wpd0gVMI1r|Lgdc?{#)@60*R16 z0L%I zO+Cbav~8vdV=+Z38&le^NwAVKpx3=G;eU*oOACF=fua3DTKiZnupPNh4_jpc=WElz zhPys|_N5?NZS55>X+bl1o_ZQQiBACoSv1ww9?$C^z5yi3LBR5Gu@q=*0d&=94*a(7 z&AxE-9nbdrw%rPMB` zY5W`mGYHna|JbE ze65)Ft}FtxudHRIt8?hm#%5sMn@_vnA?dhD$<*7taL~W=2Jq-;ryQ5n(rG(cx zy=HGUn5!Q_AC~N=7rHEUYj)_Mi?v~2r8i~y%Xruv?b`%%cUoFCen+`Ou%23 zhb1`{QYz(;9XQsRPFF!&c~yNO2oDPfs$10QEPgI+E={M0+|E$*kp$}6zQt1h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cP5GadAg!7^(t|!_dQYN$#in3^9|N3 z;tbifx1HW=Su8sJ(M9x&R5K+1kz(-PVVP&{Yh+kT6)(I;7l~*u!q#lMfbasW5XX`$ zybpRx>`9Upf7nAge`~WJ@fFYF|LR+Z-ZeuIg6D!nj+}?@-@5{-^@F?zFQ@VrA328n z96W@0rkf%s&U8D}?FmGlhwAa&gK#`peiUD~Jdqf$fuh3x5lHt`Id7l$2pLN3<`6~U zE1urbY=`up&b(~V3S{fV35e!rHwXQ}H9TXPlz**rB<5|OhZ%}YiB?BL^!@7@$T3=v z_wkD%(hx8WEjzD*6ouU2`IYX&e%g*i4Q5S3wmBE@)|h8tvmGW7CvNX1$O~BnBKu4{ z8PS1eXYWK_Jl8|ooz(2`e`omS$_F15PIua4s;qC(BfpvmnClD9k*mB^l>>hIq`Uc3 zdRJu%xnNv|vPxZ_DstgVf_5LI0+KMLq3=iWk%sxq+ZXT1|1##*RyaL@Z^}QtXaruT zS%_WuT}#-+JtwIC(RlBP(Km3;szr!$I01u-t?z%}H*H@}=+}7g{f=DZkNCcu zpFYD(Rq&6t+|%B1HQOqv=GB_qw9N_B%D9`H-jD@c%N-tNk+(%z@|Kb3b&i+!JnOZ5 zW)LURv^Nm0`#MQ9=PMLVI#Di+*jFaJIk->=3-*gDe{~F3^*>~clcO-DICkw3Qt#v^ zGHq`dz@iECs$*~0FY)b&TR$t`7MdDL!pM5?YtYHY?% z-lIZBKFN^;?3b|8NzX{He33G?rJdB6c9E@I|H50%zv=c4d{3qmuD#8lkfodP4R4+! z{9maN{ZZcpp5LSRDTxe!`8qrPtqc8xTl+{sdICzg@%9oujw6ZQDLVYPr~6(hl-|z5$SC{<#iBWa5 PlKZ~3(&D}S`}h9=o>#Q8 diff --git a/tests/test_data/old_models/py312_efd071/sequence/config.yaml b/tests/test_data/old_models/py310_efd071/sequence/config.yaml similarity index 92% rename from tests/test_data/old_models/py312_efd071/sequence/config.yaml rename to tests/test_data/old_models/py310_efd071/sequence/config.yaml index ef49d08a..066a1302 100644 --- a/tests/test_data/old_models/py312_efd071/sequence/config.yaml +++ b/tests/test_data/old_models/py310_efd071/sequence/config.yaml @@ -23,7 +23,9 @@ train: stride: 1 ts_freq: 600s verbose: 0 - data_preprocessor: null + data_preprocessor: + steps: + - name: standard_scaler data_splitter: shuffle: false type: sklearn diff --git a/tests/test_data/old_models/py310_efd071/sequence/data_preprocessor/DataPreprocessor.pkl b/tests/test_data/old_models/py310_efd071/sequence/data_preprocessor/DataPreprocessor.pkl new file mode 100644 index 0000000000000000000000000000000000000000..a84abcef4d5ec8a1f321a92e095049a58fbb20b6 GIT binary patch literal 3037 zcmbW3e{56N6~`Uy{7xK)@FPutIN?`-&Ui|O|p5Og-?mg$8^NpCsXG#tFXOK10QdJ|e%BeE(a%>+PWYi?_LBeQ-s_~MK zSA3l691AqkEl?A6#9qxpJAMhnpw*kz1$8irVV zo`)S~Pq4<$yiVf~6V}pvpEe*99I|B3HWnR8w;E~Qe&%#KAHM@1{ioBRF;5g-Sfmn3 z4JjPYvX7p7k6uQgBQ;CeP3o3+8fgjV7s12&a>B!OiGR^@t@kZwz*$PN2gt#}K+N%) zsA{5D<(SYQtj8S*8*}&55^b+GbRCcWdf4Mo|8TbP$nhbEG*{F8){3};;fxk8<6y3j zD5@BOP|5$gt=VR0VGpg!4Vt?lA*@UXnNX8;u235lR)Onic`&4EoL?bNhl!*yVYO3O zGa`IX*b(*!b#PWflkkY}4MLYLc4a86;ibtomx&VG28_@cnn8@{{$B;zyBTH4HI4^MyoQDaskn!+Vq%!saA2EJkZaDC0X=B z;B(H7?_#t(%6of>4})S=t}W?Nxu#@S)Q7=<$Lk8Nnw;nobn)(cE;b3Ri{r@v#Q@39sSAp*H-B*#*M+yh80o#7~yP{8l@rEEn zT0gF{E&xYQ&b)y%92{!?3@Gp1b{3he{K$D7=$d``J!Illm;VOPE*Y;OW6f_3-UM3m z#NvMgBU82G$kf;c>*qlCzC&*!r#C#Z?G~^tb@?nZe(Kns+d%8{yJnH2yYBe^12nAo z?KPx4?>q1XF!|cbk~=_`GBu7&v<%i8tgwE*eF7P~@cysFUbd5YX*LT9Q|NRLjlk*F*kvf`(FH3Au#FaIEQo< z-*6QH6Em;>4Qc=RlR_~tMk*GNmaXp`ECEJtYNe&X)R~P(k?t4XYbXOwcmMb|$hI|Y z+slFRe_T6K^| zDq!kLq(&6)+l2OxT|M zGtz$3{DX&qu`_3qNXrXa;A_@uObSq|^YtvtXzijjrm1>13;F#j(IA}_>=q@E6_AHI zOQOS&gw(^3QcTV;KIhhZZzvEBLhi{)!i$psy>?nJg(T1=-Tp#fofQ zf#i_M4P4BA9e{UIf&s}D@=Ock0tjbYC)yvfKUy7m7SLU%_LbfpzmRtA-( zTR6SMq9{r$F-B|jhW~B+h+x^ra;ufFJLgm^nUmmrN=TOB0N}`krGrfP5v{!|l@`l1 zE?sZTU76MIH?sH{Q4=^_rH#-c{g0~o*a%k6x(Cxgs+6s$J2JHtYXqDft&ljCM@#O-(G#GwEnegSzE<5)AzW&6AhADk` rMsN&)R}Kp!+0Y`iA{%+2Eg&dCLlp!`Fr*B?Qy~Z-PYA?qG;I4Xy61EH literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py310_efd071/sequence/threshold_selector/QuantileThresholdSelector.pkl b/tests/test_data/old_models/py310_efd071/sequence/threshold_selector/QuantileThresholdSelector.pkl new file mode 100644 index 0000000000000000000000000000000000000000..a252a318cb6af362e686cbc875ba9235e53b152d GIT binary patch literal 57 zcmZo*nX1PC0ku;!dN@lmic*U+@^ezAxZ8j6DOK-Vpwh!pSelqul9`hV6nmEj2Bmrc D14a}v literal 0 HcmV?d00001 diff --git a/tests/test_data/old_models/py312_efd071/dense/threshold_selector/QuantileThresholdSelector.pkl b/tests/test_data/old_models/py312_efd071/dense/threshold_selector/QuantileThresholdSelector.pkl deleted file mode 100644 index 0329b0dc63680c2ac76fe5801c61e47b6097b903..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 57 zcmZo*nX1PC0ku;!dN@lmic*U+@^ezAxI2g^D1Q6dUfIJ@Selqul9`h_#ohj08W@!7 F0RRYd6pH`= diff --git a/tests/test_data/old_models/py312_efd071/sequence/data_preprocessor/DataPreprocessor.pkl b/tests/test_data/old_models/py312_efd071/sequence/data_preprocessor/DataPreprocessor.pkl deleted file mode 100644 index ac67d3e67dd7ac96902bdce3a5a6d4f6fe4eabc4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3471 zcmbW4e{2)y8ONQ(`JFfp4oM)iaRQ|QHsdbak^!wCxMY-+n=XbP;bvgbKF zjzhW%)t3D6z31n-=Y5~&ecrEw`r+pbb=s?!)~NZiLPVL7MdD)UZmMQ#*YK@IEpqw2 z0iVFg#7kU?U!rO~5s1{$!+6+$S7F>l(Z(%qR$&=YBBJDX5n1Mi4$Bf#Lxbk5W!~2i zU3ZXT03|-Qn-N%n@kp$T5sAcrE!}22I)bm4Rg;IXNh1Y(Gcd_1NcCc6=-xBMS zu?&iZfRDs~k@Q`XC>l$A#KN?*GNEc=3tW52k_Q`nyjJD$WXW{ffgABvQ43kO8*0c6 z0pNxSsisasM27f81$IrMTxf`Ufcuu32TAtET|nXLU4F5L4sa%QIRq&7zz&j##RvP0 zXC;Y+ITkPyfog_H2V4prf~~6kkgC~G%GytcXp^pwHl(%FL-cW4)0Ebf(MP%OtC?=4 zMshg4H);^))KZHl)T?!jb&xQ9ZV4VGUm^!a54 zYMQ{FgKFpO4({Or&drfP`=W|YsbsZ)7qFwi%t$vw)qCPSB%Ua3kjU5yiNZrCfd<70 zWDnDr7}$YUkOI!97T!753k^q)O_Zvpgj2@Lx62kSt>9`E!-zfIuuVnY1?`P-G(L<8 z-^#i=i5v5}Dm9k4Rca{7Cu(M3@JMCW6}LO%7}j~17N4uWe)7i0?61aF1* zV>XuNup1KkwOoa^PGsQj`PZ&}A6J&^#PR%`e*>d?-yT9b8=tBC1UON+<_)Cv;)U;C z28P3-caX-Xw>Vb(Iprt!J|0R|^4 zhLN$MbLP*1ZMzS?iJV&d?fRQQd+gF_WaPxi&Ran9bIsGp!RFhZ{{nTTzqyJOXWje1 z07hRg%exJ9N|VFLiOs!LIx{>!(>jI>pL@SP4QPC6_)o|nyWN=%jIF;pjcl76>&O63 zooxFQX+LB-pa({rXY(?F=9N7^K@NVfp*jnw8=DzJid`>$FB=%OHJ(8_bFVvdfD`AB z{vB!k*;8CDFieW(kj9Pg9LNI(Zz%csz}Tt#k09G#c(1wuIMw>&UnA}J+BX#fBmca5 z25BB2earwH+`H=^NL^z-Uj!5j-=0H8FNi@S&>3D`Pz;>lFC0NyYeTD-0mHX8A43|? zezM5~3?6>++A@E8C-kr;3{D3a5#-dfm)6`1v^S4LkdfuhTPlI(*)QHj4!%C#Vg~9Y_bgJ}T-I3yjOr(^A)V*; zJzEW&II_{O8fazTA3=uK58t;2Xq?+Njtrjse9L{nSpV3ck!{Yl*0sQ?6{aZC{=u2f z`+<=+yRRe7T^pXO0S?+`4C{cp+!tR)isu{Ft_MbcdTku(Bu5|I0GzNq^%tb|hT(~C z0K=zFMUloA6z@09<=7P9aLv?ODpe~MwJ}B3x|!eOk%;-j_lrC_#Y4RjX z2EBlCYvWzZl6i})mbhtBl;p?nFxp`W+EGEFDY>b-QoHfxK@D)V5Lc>_N;!8lMfDv# zBXalf3dd+tXF$!-E@Z_`2LjxvS}`wS7VB^(eykW;5^>xSF8A93?so%t^qH2nbQBMd zeTf_>g1-bT3M2U2KnO@*ZmX&-AuHhl2d4nPaG+!?IZ&Wd8gjbhf=LI*31mAH=k&Fe zfxe5CzRLI^n`7O{pU>JNhT5u&)3dgU>pNY&RiklP5zqZsnQtn;m|wO3lI<7Ae|ht- zLzis3{!n%7L*1lio=^;TRuoZ-l7BWpFMw(Q5tQX4KEKoh-?Bl$wEIC}h60xV0YRT1 Ab^rhX diff --git a/tests/test_data/old_models/py312_efd071/sequence/threshold_selector/QuantileThresholdSelector.pkl b/tests/test_data/old_models/py312_efd071/sequence/threshold_selector/QuantileThresholdSelector.pkl deleted file mode 100644 index 83054a12277099593f0f01cba57d72ef9b6c8480..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 57 zcmZo*nX1PC0ku;!dN@lmic*U+@^ezAxZ8jJz3EtHu44~JVQFGsNoGzeQ0!eA7?kP( E04Ep~fB*mh diff --git a/tests/test_model_compatibility.py b/tests/test_model_compatibility.py index f47000a1..3123f737 100644 --- a/tests/test_model_compatibility.py +++ b/tests/test_model_compatibility.py @@ -4,11 +4,14 @@ versions of ``energy-fault-detector`` (before the Pydantic config migration) using the script ``tests/test_data/old_models/create_legacy_model_fixtures.py``. -For Keras 3 fixtures (``py312_efd071``) the full pipeline is exercised: -``FaultDetector.load`` + ``predict``. For Keras 2 fixtures (``py311_efd060``) -the autoencoder cannot be loaded by Keras 3 (``keras.src.engine.functional`` -was renamed), so only the non-Keras components (config, data preprocessor, -threshold selector, anomaly score) are loaded and applied individually. +For Keras 3 fixtures (``py310_efd071``) the full pipeline is exercised: +``FaultDetector.load`` + ``predict``. These fixtures are created with the +minimum supported Python version (3.10), which caps Keras at 3.12.4, so they +load on every supported Python/Keras combination. For Keras 2 fixtures +(``py311_efd060``) the autoencoder cannot be loaded by Keras 3 +(``keras.src.engine.functional`` was renamed), so only the non-Keras components +(config, data preprocessor, threshold selector, anomaly score) are loaded and +applied individually. """ import os @@ -156,9 +159,9 @@ def _assert_non_keras_pipeline(self, model_path: str, data: pd.DataFrame, predicted = threshold_selector.predict(scores) self.assertEqual(len(predicted), len(scores)) - def test_dense_py312_efd071(self) -> None: - """Dense MultilayerAutoencoder saved with EFD 0.7.1 / Python 3.12 / Keras 3.""" - model_path = os.path.join(OLD_MODELS_DIR, 'py312_efd071', 'dense') + def test_dense_py310_efd071(self) -> None: + """Dense MultilayerAutoencoder saved with EFD 0.7.1 / Python 3.10 / Keras 3.""" + model_path = os.path.join(OLD_MODELS_DIR, 'py310_efd071', 'dense') detector = FaultDetector.load(model_path=model_path) self._assert_loaded_components(detector) self.assertIsInstance(detector.autoencoder, MultilayerAutoencoder) @@ -167,9 +170,9 @@ def test_dense_py312_efd071(self) -> None: result = detector.predict(make_dense_data()) self._assert_predict_results(result, expected_len=80) - def test_sequence_py312_efd071(self) -> None: - """LSTM seq2one autoencoder saved with EFD 0.7.1 / Python 3.12 / Keras 3.""" - model_path = os.path.join(OLD_MODELS_DIR, 'py312_efd071', 'sequence') + def test_sequence_py310_efd071(self) -> None: + """LSTM seq2one autoencoder saved with EFD 0.7.1 / Python 3.10 / Keras 3.""" + model_path = os.path.join(OLD_MODELS_DIR, 'py310_efd071', 'sequence') detector = FaultDetector.load(model_path=model_path) self._assert_loaded_components(detector) self.assertIsInstance(detector.autoencoder, LSTMSeq2OneAutoencoder)