elbow_helper.types module
Result and intermediate data types for the robust knee detector.
The public contract is a tagged union: elbow_helper.robust_knee() always
returns either a ClearKnee or a NoClearKnee, both subclasses
of KneeResult, so callers must handle abstention explicitly. Every
NoClearKnee carries a machine-readable Reason code plus a
diagnostics dict; every ClearKnee carries the full evidence chain.
- class elbow_helper.types.BootstrapEvidence(passes, detection_rate, ci90, ci90_width, primary_cluster_rate, secondary_cluster_rate, median_shift, knees, reason=None)[source]
Bases:
objectStability of the detected knee across residual-bootstrap replicates.
- Parameters:
- class elbow_helper.types.CandidateCluster(median_knee, mad, members, n_windows, consecutive_scales, sensitivity_support, neighbor_shift, support, support_frac, median_prominence, median_noise_prominence_ratio, persistent=False, stable_window=None)[source]
Bases:
objectA group of candidates at nearby knee locations across the scale space.
- Parameters:
- members
The candidates in this cluster.
- Type:
- stable_window
Smallest smoothing window meeting the sensitivity-support threshold, set only when
persistentisTrue.- Type:
int, optional
- members: List[KneeCandidate]
- class elbow_helper.types.ClearKnee(reason, diagnostics=<factory>, knee_x=0.0, knee_x_norm=0.0, knee_index=0, ci90=(0.0, 0.0), detection_rate=0.0, smoothing_window=1, sensitivity=1.0, prominence=0.0, slope_contrast=0.0, bic_improvement=0.0, null_p_value=1.0)[source]
Bases:
KneeResultA knee accepted by every stage of the pipeline, with uncertainty.
- Parameters:
- smoothing_window, sensitivity
The scale-space setting that produced the winning candidate.
- class elbow_helper.types.InvalidKnees(reason, diagnostics=<factory>)[source]
Bases:
MultiKneeResultPreprocessing failed: the input could not be searched at all.
- class elbow_helper.types.KneeCandidate(knee_x_norm, knee_index, window, sensitivity, prominence=0.0, local_noise=0.0, noise_prominence_ratio=0.0, boundary_distance=0.0, rejected=None)[source]
Bases:
objectA single knee-candidate hit at one (smoothing window, sensitivity) setting.
- Parameters:
- prominence
Topographic prominence of the peak (see
peak_prominence()).- Type:
- class elbow_helper.types.KneeEstimate(x, x_norm, index, slope_left, slope_right, fwer_p_value=None)[source]
Bases:
objectOne accepted breakpoint from
elbow_helper.robust_knees().Segments are independent (discontinuous) OLS lines, not the continuous broken-line model
ClearKneeuses;slope_left/slope_rightare each segment’s own fitted slope, in data units and need not agree at the breakpoint.- Parameters:
- slope_left, slope_right
Each neighbouring segment’s own fitted slope, data units.
- Type:
- class elbow_helper.types.KneeResult(reason, diagnostics=<factory>)[source]
Bases:
objectBase class for the tagged union returned by
robust_knee().- property is_clear: bool
TrueforClearKnee,FalseforNoClearKnee.
- class elbow_helper.types.Knees(reason, diagnostics=<factory>, knees=<factory>)[source]
Bases:
MultiKneeResultA valid multi-knee result: zero or more accepted breakpoints.
Unlike
NoClearKnee, an emptykneeslist here is not an abstention: it is the pipeline’s confident conclusion that the data has no real breakpoint, having survived the same search and false-positive gates a nonempty result would have to survive.- Parameters:
reason (str)
diagnostics (Dict)
knees (List[KneeEstimate])
- knees: List[KneeEstimate]
- class elbow_helper.types.MultiKneeResult(reason, diagnostics=<factory>)[source]
Bases:
objectBase class for the tagged union returned by
elbow_helper.robust_knees().- property is_valid: bool
TrueforKnees,FalseforInvalidKnees.
- class elbow_helper.types.NoClearKnee(reason, diagnostics=<factory>)[source]
Bases:
KneeResultAn explicit abstention: no knee is strong enough to report.
- class elbow_helper.types.NullEvidence(passes, p_value, observed_statistic, null_replicates, reason=None)[source]
Bases:
objectSearch-adjusted Monte-Carlo test against a no-knee null model.
- Parameters:
- class elbow_helper.types.PreparedCurve(x_norm, y_scaled, n, x_lo, x_hi, y_lo, y_hi, curve, direction, spearman, violation_rate)[source]
Bases:
objectA cleaned, sorted, normalized curve plus inverse-transform metadata.
- Parameters:
- x_norm, y_scaled
The curve on the unit square:
xlinearly scaled to[0, 1]andyrobustly scaled (5th/95th percentile) and clipped to[0, 1].- Type:
numpy.ndarray
- x_lo, x_hi
Original x-range, used to map a normalized knee back to data units.
- Type:
- y_lo, y_hi
Robust y-limits used for scaling (inverse transform for y).
- Type:
- curve, direction
The caller-supplied curve orientation.
- Type:
- violation_rate
Fraction of lightly-smoothed first differences that move against
direction.- Type:
- x_norm: ndarray
- y_scaled: ndarray
- class elbow_helper.types.Reason[source]
Bases:
objectStable, machine-readable abstention (and status) reason codes.
- ALL_CANDIDATES_WEAK = 'ALL_CANDIDATES_WEAK'
- BOOTSTRAP_MULTIMODAL = 'BOOTSTRAP_MULTIMODAL'
- BOOTSTRAP_UNSTABLE = 'BOOTSTRAP_UNSTABLE'
- BOUNDARY_KNEE = 'BOUNDARY_KNEE'
- CLEAR_KNEE = 'CLEAR_KNEE'
- INCOMPATIBLE_GLOBAL_SHAPE = 'INCOMPATIBLE_GLOBAL_SHAPE'
- INSUFFICIENT_DATA = 'INSUFFICIENT_DATA'
- INTERNAL_NUMERICAL_FAILURE = 'INTERNAL_NUMERICAL_FAILURE'
- INVALID_INPUT = 'INVALID_INPUT'
- KNEES_FOUND = 'KNEES_FOUND'
- MULTIPLE_PLAUSIBLE_KNEES = 'MULTIPLE_PLAUSIBLE_KNEES'
- NO_KNEE_CANDIDATES = 'NO_KNEE_CANDIDATES'
- NO_PERSISTENT_CLUSTER = 'NO_PERSISTENT_CLUSTER'
- NULL_NOT_REJECTED = 'NULL_NOT_REJECTED'
- SEGMENTED_MODEL_NOT_BETTER = 'SEGMENTED_MODEL_NOT_BETTER'
- WEAK_SLOPE_CHANGE = 'WEAK_SLOPE_CHANGE'
- ZERO_RANGE = 'ZERO_RANGE'
- class elbow_helper.types.SegmentEvidence(passes, slope_contrast, m_left, m_right, bic_improvement, cv_improvement, reason=None)[source]
Bases:
objectSlope-contrast and broken-line vs single-line model comparison.
- Parameters:
- m_left, m_right
The robust slopes on either side of the candidate knee.
- Type:
- bic_improvement
BIC of the single line minus BIC of the broken line (higher favors the broken line).
- Type:
- cv_improvement
Fractional reduction in blocked cross-validated SSE from using the broken line instead of the single line.
- Type: