OpenMS
Math

Math functions and classes. More...

Collaboration diagram for Math:

Modules

 Statistics functions
 Various statistical functions.
 
 Misc functions
 Math functions.
 

Classes

class  BasicStatistics< RealT >
 Calculates some basic statistical parameters of a distribution: sum, mean, variance, and provides the normal approximation. More...
 
class  GammaDistributionFitter
 Implements a fitter for the Gamma distribution. More...
 
class  GaussFitter
 Implements a fitter for Gaussian functions. More...
 
class  GumbelMaxLikelihoodFitter
 Implements a fitter for the Gumbel distribution. More...
 
class  Histogram< ValueType, BinSizeType >
 Representation of a histogram. More...
 
class  PosteriorErrorProbabilityModel
 Implements a mixture model of the inverse gumbel and the gauss distribution or a gaussian mixture. More...
 
class  CrossValidation
 Lightweight K-fold / LOO cross-validation utilities and 1-D grid search. More...
 
class  BilinearInterpolation< Key, Value >
 Provides access to bilinearly interpolated values (and derivatives) from discrete data points. Values beyond the given range of data points are implicitly taken as zero. More...
 
class  LinearInterpolation< Key, Value >
 Provides access to linearly interpolated values (and derivatives) from discrete data points. Values beyond the given range of data points are implicitly taken as zero. More...
 
class  LinearRegression
 This class offers functions to perform least-squares fits to a straight line model, \( Y(c,x) = c_0 + c_1 x \). More...
 
class  LinearRegressionWithoutIntercept
 This class offers functions to perform least-squares fits to a straight line model, \( Y(c,x) = c_0 + c_1 x \). More...
 
class  ROCCurve
 ROCCurves show the trade-off in sensitivity and specificity for binary classifiers using different cutoff values. More...
 

Enumerations

enum class  CandidateTieBreak { PreferLarger , PreferSmaller , PreferAny }
 Tie-breaking preference for equal (within tolerance) CV scores. More...
 

Functions

static std::vector< std::vector< Size > > makeKFolds (Size n, Size K)
 Build K folds for indices [0, n). More...
 
template<typename CandIter , typename TrainEval , typename ScoreFn >
static std::pair< typename std::iterator_traits< CandIter >::value_type, double > gridSearch1D (CandIter cbegin, CandIter cend, const std::vector< std::vector< Size >> &folds, TrainEval train_eval, ScoreFn score, double tie_tol=1e-12, CandidateTieBreak tie_break=CandidateTieBreak::PreferLarger)
 One-dimensional grid search with external cross-validation evaluation. More...
 

Detailed Description

Math functions and classes.

Enumeration Type Documentation

◆ CandidateTieBreak

enum CandidateTieBreak
strong

Tie-breaking preference for equal (within tolerance) CV scores.

  • PreferLarger : choose the larger candidate value on ties
  • PreferSmaller : choose the smaller candidate value on ties
  • PreferAny : keep the first encountered (stable, no size preference)
Enumerator
PreferLarger 
PreferSmaller 
PreferAny 

Function Documentation

◆ gridSearch1D()

static std::pair<typename std::iterator_traits<CandIter>::value_type, double> gridSearch1D ( CandIter  cbegin,
CandIter  cend,
const std::vector< std::vector< Size >> &  folds,
TrainEval  train_eval,
ScoreFn  score,
double  tie_tol = 1e-12,
CandidateTieBreak  tie_break = CandidateTieBreak::PreferLarger 
)
inlinestatic

One-dimensional grid search with external cross-validation evaluation.

Iterates candidates [cbegin, cend), calls train_eval(candidate, folds, abs_errs) to append absolute errors from all validation points, then scores them via score(abs_errs) (lower is better). Returns the best (candidate, score).

Tie-breaking:

  • If |score - best_score| <= tie_tol, choose by prefer_larger (true → larger wins).
Template Parameters
CandIterRandom-access or forward iterator over candidate values
TrainEvalCallable of signature void(const Cand&, const std::vector<std::vector<Size>>&, std::vector<double>&)
ScoreFnCallable of signature double(const std::vector<double>&)
Parameters
cbeginBegin iterator of candidate grid
cendEnd iterator of candidate grid
foldsFold index sets (e.g., from makeKFolds)
train_evalCallback: fit on train folds and append |error| for all held-out points
scoreCallback: convert accumulated errors to a scalar loss (lower is better)
tie_tolAbsolute tolerance for tie detection (default: 1e-12)
tie_breakPreference for ties (default: PreferLarger)
Returns
(best_candidate, best_score)
Exceptions
Exception::InvalidRangeif candidate range is empty

References CrossValidation::PreferAny, CrossValidation::PreferLarger, and CrossValidation::PreferSmaller.

◆ makeKFolds()

static std::vector<std::vector<Size> > makeKFolds ( Size  n,
Size  K 
)
inlinestatic

Build K folds for indices [0, n).

Deterministic round-robin assignment: fold(i) = i % K. For leave-one-out (LOO), use K = n.

Parameters
nNumber of samples
KRequested number of folds (clamped to [1, n])
Exceptions
Exception::InvalidValueif n == 0 or K == 0