OCDocker.OCScore.Utils.FeaturePolicy module¶
Feature-ablation policy discovery and application for OCScore training.
Policies constrain the candidate descriptor pool before train-only feature cleaning and reduction are fitted.
- class OCDocker.OCScore.Utils.FeaturePolicy.CandidateFeatureDiscovery(candidate_features, metadata_columns, target_columns, unmatched_columns, duplicate_assignments, blocks)[source]¶
Bases:
objectCandidate model features before policy filtering.
- Parameters:
candidate_features (list[str])
metadata_columns (list[str])
target_columns (list[str])
unmatched_columns (list[str])
duplicate_assignments (dict[str, list[str]])
blocks (DescriptorBlocks)
- candidate_features: list[str]¶
- metadata_columns: list[str]¶
- target_columns: list[str]¶
- unmatched_columns: list[str]¶
- duplicate_assignments: dict[str, list[str]]¶
- blocks: DescriptorBlocks¶
- class OCDocker.OCScore.Utils.FeaturePolicy.FeaturePolicy(name, description='', include_features=(), include_patterns=(), exclude_features=(), exclude_patterns=(), allow_missing_exclude_features=True, allow_empty_policy=False, source_path=PosixPath('.'), source_kind='bundled', source_hash='')[source]¶
Bases:
objectLoaded feature-ablation policy.
- Parameters:
name (str)
description (str)
include_features (tuple[str, ...])
include_patterns (tuple[str, ...])
exclude_features (tuple[str, ...])
exclude_patterns (tuple[str, ...])
allow_missing_exclude_features (bool)
allow_empty_policy (bool)
source_path (Path)
source_kind (str)
source_hash (str)
- name: str¶
- description: str = ''¶
- include_features: tuple[str, ...] = ()¶
- include_patterns: tuple[str, ...] = ()¶
- exclude_features: tuple[str, ...] = ()¶
- exclude_patterns: tuple[str, ...] = ()¶
- allow_missing_exclude_features: bool = True¶
- allow_empty_policy: bool = False¶
- source_path: Path = PosixPath('.')¶
- source_kind: str = 'bundled'¶
- source_hash: str = ''¶
- class OCDocker.OCScore.Utils.FeaturePolicy.FeaturePolicyApplication(policy, lookup_dirs, candidate_features_before_policy, included_features_found, excluded_features_found, missing_include_features, missing_exclude_features, patterns_with_no_matches, final_candidate_features_before_reduction)[source]¶
Bases:
objectResult of applying one policy to candidate model features.
- Parameters:
policy (FeaturePolicy)
lookup_dirs (tuple[Path, ...])
candidate_features_before_policy (list[str])
included_features_found (list[str])
excluded_features_found (list[str])
missing_include_features (list[str])
missing_exclude_features (list[str])
patterns_with_no_matches (list[str])
final_candidate_features_before_reduction (list[str])
- policy: FeaturePolicy¶
- lookup_dirs: tuple[Path, ...]¶
- candidate_features_before_policy: list[str]¶
- included_features_found: list[str]¶
- excluded_features_found: list[str]¶
- missing_include_features: list[str]¶
- missing_exclude_features: list[str]¶
- patterns_with_no_matches: list[str]¶
- final_candidate_features_before_reduction: list[str]¶
- class OCDocker.OCScore.Utils.FeaturePolicy.FeaturePolicyDiscovery(policies, lookup_dirs, explicit_ymls=())[source]¶
Bases:
objectResolved feature-policy lookup pool.
- Parameters:
policies (dict[str, FeaturePolicy])
lookup_dirs (tuple[Path, ...])
explicit_ymls (tuple[Path, ...])
- policies: dict[str, FeaturePolicy]¶
- lookup_dirs: tuple[Path, ...]¶
- explicit_ymls: tuple[Path, ...] = ()¶
- property available_names: tuple[str, ...]¶
Sorted policy names discovered in the lookup pool.
- Returns:
Policy names available for
--feature-policyresolution.- Return type:
tuple[str, …]
- OCDocker.OCScore.Utils.FeaturePolicy.apply_feature_policy(policy, candidate_features, *, lookup_dirs=())[source]¶
Apply one feature policy to ordered candidate model features.
- Parameters:
policy (FeaturePolicy)
candidate_features (Sequence[str])
lookup_dirs (Sequence[str | Path])
- Return type:
- OCDocker.OCScore.Utils.FeaturePolicy.discover_candidate_model_features(columns, *, config=None, non_feature_columns=None)[source]¶
Discover the current production candidate descriptor pool.
- Parameters:
columns (Sequence[str])
config (FeatureReductionConfig | None)
non_feature_columns (Sequence[str] | None)
- Return type:
- OCDocker.OCScore.Utils.FeaturePolicy.discover_feature_policies(*, policy_dirs=None, explicit_ymls=None)[source]¶
Discover bundled, user-directory, and explicit feature policies.
- Parameters:
policy_dirs (Sequence[str | Path] | None)
explicit_ymls (Sequence[str | Path] | None)
- Return type:
- OCDocker.OCScore.Utils.FeaturePolicy.feature_policy_from_mapping(data, *, source_kind='draft', source_path=None)[source]¶
Build a feature policy from an in-memory mapping.
- Parameters:
data (Mapping[str, Any]) – Feature-policy mapping with
name, optional description, and include/exclude fields.source_kind (str) – Provenance label stored on the returned policy.
source_path (str or pathlib.Path or None) – Optional source path recorded on the returned policy.
- Returns:
Validated in-memory feature policy.
- Return type:
- Raises:
ValueError – If required fields are missing or invalid.
- OCDocker.OCScore.Utils.FeaturePolicy.feature_policy_to_yaml_text(data)[source]¶
Serialize one feature-policy mapping to YAML text.
- Parameters:
data (Mapping[str, Any]) – Feature-policy mapping.
- Returns:
YAML text suitable for
--feature-policy-yml.- Return type:
str
- OCDocker.OCScore.Utils.FeaturePolicy.load_feature_policy(path, *, source_kind='bundled')[source]¶
Load one feature policy from a
.ymlfile.- Parameters:
path (str | Path)
source_kind (str)
- Return type:
- OCDocker.OCScore.Utils.FeaturePolicy.resolve_requested_feature_policies(*, requested_names=None, run_all=False, policy_dirs=None, explicit_ymls=None)[source]¶
Resolve CLI feature-policy requests to loaded policies.
- Parameters:
requested_names (Sequence[str] | None)
run_all (bool)
policy_dirs (Sequence[str | Path] | None)
explicit_ymls (Sequence[str | Path] | None)
- Return type:
tuple[list[FeaturePolicy], FeaturePolicyDiscovery]