Source code for elbow_helper.search

"""The shared inner search: candidates -> filter -> cluster -> confirm.

Factored out so the main pipeline, the bootstrap replicates, and the null-test
replicates all run *the same* detection logic. The search-adjusted test
statistic (used by the null test) is a lexicographic tuple, in decreasing
priority: passed model confirmation, cluster dominance, prominence-to-noise.

Author
------
Warith Harchaoui, <warith.harchaoui@deraison.ai>
"""

from __future__ import annotations

from dataclasses import dataclass
from typing import Optional, Tuple

from .candidates import generate_candidates
from .clustering import cluster_candidates, select_unique_cluster
from .config import RobustKneeConfig
from .metrics import passes_basic_filters
from .segmented import confirm_segmented_model
from .types import CandidateCluster, PreparedCurve, Reason, SegmentEvidence


[docs] @dataclass class SearchResult: """Outcome of one inner detection pass over a (prepared) curve.""" detected: bool reason: Optional[str] = None knee_x_norm: Optional[float] = None window: Optional[int] = None cluster: Optional[CandidateCluster] = None segment: Optional[SegmentEvidence] = None statistic: Tuple[int, float, float] = (0, 0.0, 0.0) n_candidates: int = 0 n_filtered: int = 0