deeplc.calibration

Calibration utilities.

class deeplc.calibration.Calibration(*args, **kwargs)

Bases: ABC

Initialize the calibration model.

abstract property is_fitted: bool

Indicates whether the calibration model has been fitted.

abstractmethod fit(target, source)

Fit the calibration from source to target.

Parameters:
Return type:

None

abstractmethod transform(source)

Transform source values into the calibrated target space.

Parameters:

source (ndarray)

Return type:

ndarray

exception deeplc.calibration.CalibrationError

Bases: DeepLCError

Raised when calibration fails.

class deeplc.calibration.IdentityCalibration

Bases: Calibration

Initialize IdentityCalibration.

property is_fitted: bool

Always fitted; identity calibration requires no fitting.

fit(target, source)

No-op; identity calibration does not fit.

Parameters:
Return type:

None

transform(source)

Return source unchanged.

Parameters:

source (ndarray)

Return type:

ndarray

class deeplc.calibration.MultiHeadCalibration(*args, **kwargs)

Bases: ABC

Initialize the calibration model.

selected_model_head: int

The best-correlating head, set by fit. Meaningful for every implementer, including MultiHeadRidgeCalibration, which reports the single best head even though it fits on several.

abstract property is_fitted: bool

Indicates whether the calibration model has been fitted.

abstractmethod fit(target, source)

Fit the calibration from the source matrix to target.

Parameters:
Return type:

None

abstractmethod transform(source)

Transform the source matrix into the calibrated target space.

Parameters:

source (ndarray)

Return type:

ndarray

disagreement(source)

Per-input uncertainty score, or None when the calibration has none.

A calibration that combines several estimates of the same retention time can report how far they lie apart for each input, which deeplc.report.prediction_report() uses to scale its prediction intervals per peptide. One fitted on a single head has no spread to report and keeps this default.

Parameters:

source (ndarray)

Return type:

ndarray | None

class deeplc.calibration.MultiHeadPiecewiseLinearCalibration(number_of_splits=10, extrapolate=True, use_median=False, min_samples_per_segment=20)

Bases: _SingleHeadCalibration

Piece-wise linear calibration on whichever head correlates best with the reference.

Parameters:
  • number_of_splits (int) – Number of segments to split the source value range into. More segments allow more flexibility but may lead to overfitting.

  • extrapolate (bool) – If True, allows extrapolation outside the fitted source value range. If False, clips input values to the fitted range.

  • use_median (bool) – If True, uses the median of each segment to define anchors. If False, uses the mean.

  • min_samples_per_segment (int) – Minimum number of samples required for a segment to contribute an anchor. Segments with fewer samples are skipped, which helps avoid unstable anchors in sparse regions when using many splits.

class deeplc.calibration.MultiHeadRidgeCalibration(n_heads=80, alphas=None)

Bases: MultiHeadCalibration

Initialize MultiHeadRidgeCalibration.

Parameters:
  • n_heads (int)

  • alphas (np.ndarray | None)

property is_fitted: bool

True once the heads are selected, calibrated and weighted.

fit(target, source)

Select, calibrate and weight the heads.

Parameters:
  • target (ndarray) – Observed retention times of the reference, shape (n,).

  • source (ndarray) – Reference predictions for every head, shape (n, n_heads_total). A 1-D array is accepted and treated as a single head, so a single-task model still works.

Return type:

None

transform(source)

Calibrate predictions of the model this calibration was fitted with.

Parameters:

source (ndarray) – Predictions for every head, shape (n, n_heads_total), as returned by predict(..., return_matrix=True).

Return type:

ndarray

disagreement(source)

Report how far the combined setup heads lie apart for each input, in reference units.

Every selected head estimates the retention time of the same peptide, so the spread of those estimates, weighted by the ridge weight each head received, is an uncertainty that varies from peptide to peptide rather than only along the gradient. Returns None while the calibration is unfitted or combines a single head, which carries no spread.

Parameters:

source (ndarray)

Return type:

ndarray | None

class deeplc.calibration.MultiHeadSplineCalibration

Bases: _SingleHeadCalibration

Initialize MultiHeadSplineCalibration.

class deeplc.calibration.PiecewiseLinearCalibration(number_of_splits=10, extrapolate=True, use_median=False, min_samples_per_segment=20)

Bases: Calibration

Piece-wise linear calibration based on per-split anchors.

Parameters:
  • number_of_splits (int) – Number of segments to split the source value range into. More segments allow more flexibility but may lead to overfitting.

  • extrapolate (bool) – If True, allows extrapolation outside the fitted source value range. If False, clips input values to the fitted range.

  • use_median (bool) – If True, uses the median of each segment to define anchors. If False, uses the mean.

  • min_samples_per_segment (int) – Minimum number of samples required for a segment to contribute an anchor. Segments with fewer samples are skipped, which helps avoid unstable anchors in sparse regions when using many splits.

property is_fitted: bool

True if the calibration model has been fitted.

property calibrate_min: float | None

Minimum source value seen during fitting.

property calibrate_max: float | None

Maximum source value seen during fitting.

fit(target, source)

Fit a piece-wise linear model mapping source to target values.

Parameters:
Return type:

None

transform(source)

Transform source values using the fitted piece-wise linear model.

Parameters:

source (ndarray)

Return type:

ndarray

get_calibration_curve()

Return the calibration anchors as two arrays (x, y).

Return type:

tuple[ndarray, ndarray]

class deeplc.calibration.SplineTransformerCalibration

Bases: Calibration

Initialize SplineTransformerCalibration.

property is_fitted: bool

True if the calibration model has been fitted.

fit(target, source)

Fit a spline-based model mapping source to target values.

Parameters:
Return type:

None

transform(source)

Transform source values using the fitted spline model.

Parameters:

source (ndarray)

Return type:

ndarray

deeplc.calibration.upgrade_calibration(calibration)

Wrap a naive, single-series calibration in its matching MultiHeadCalibration.

A MultiHeadCalibration instance is returned unchanged. A naive Calibration must not be fitted yet: a fitted instance carries no record of which head it was fit on, so there is nothing to wrap it around.

Parameters:

calibration (Calibration | MultiHeadCalibration) – The calibration to wrap, naive or already multi-head.

Returns:

calibration itself if it already is one, otherwise a new wrapper around it.

Return type:

MultiHeadCalibration