Skip to main content
Ctrl+K
mlquantify homepage mlquantify homepage
  • Install
  • User Guide
  • API
  • Getting Started
    • Examples
    • About Us
  • GitHub
  • Install
  • User Guide
  • API
  • Getting Started
  • Examples
  • About Us
  • GitHub

Section Navigation

  • mlquantify
    • get_config
    • set_config
    • config_context
  • mlquantify.base
    • BaseQuantifier
    • MetaquantifierMixin
    • ProtocolMixin
  • mlquantify.base_aggregative
    • AggregationMixin
    • SoftPredictionMixin
    • CrispPredictionMixin
  • mlquantify.calibration
    • Calibrator
    • ClassifierCalibrator
    • QuantifierCalibrator
  • mlquantify.compose
    • BaseComposeQuantifier
    • LinearComposeQuantifier
    • LikelihoodComposeQuantifier
    • ComposeQuantifier
  • mlquantify.confidence
    • BaseConfidenceRegion
    • ConfidenceInterval
    • ConfidenceEllipseSimplex
    • ConfidenceEllipseCLR
    • construct_confidence_region
  • mlquantify.counting
    • CC
    • PCC
    • ACC
    • ThresholdAdjustment
    • TAC
    • TX
    • TMAX
    • T50
    • MS
    • MS2
    • FM
    • GACC
    • GPACC
    • evaluate_thresholds
    • compute_tpr
    • compute_fpr
    • compute_table
  • mlquantify.datasets
    • make_quantification
    • fetch_mushroom
    • fetch_banknote_authentication
    • fetch_haberman_survival
    • fetch_miniboone
    • fetch_digits_optical_penbased
    • fetch_dry_bean
    • fetch_covertype
    • fetch_yeast
    • fetch_sensorless_drive
    • fetch_statlog_shuttle
    • fetch_wine_quality
    • fetch_online_news_popularity
    • fetch_pima_diabetes
    • fetch_electricity_elec2
    • fetch_airlines
    • fetch_newsgroups20
    • fetch_imdb
    • fetch_multidomain_sentiment
    • fetch_sentiment140
    • fetch_rcv1_v2
    • fetch_mnist_usps
    • fetch_cifar10
    • fetch_planetoid_cora_citeseer_pubmed
    • fetch_sea_concepts
    • fetch_lequa2024
    • Bunch
    • get_data_home
    • fetch_remote
  • mlquantify.likelihood
    • CDE
    • EMQ
    • MLPE
  • mlquantify.losses
    • BaseLoss
    • DistanceLoss
    • LeastSquaresLoss
    • HellingerSurrogateLoss
    • EnergyLoss
    • NegativeLogLikelihoodLoss
    • MixtureNegativeLogLikelihoodLoss
    • RegularizedMixtureNLLLoss
    • normalize_distribution
    • get_loss
  • mlquantify.matching
    • BaseMatchingQuantifier
    • MatchingHistogramQuantifier
    • DyS
    • HDy
    • HDx
    • SORD
    • MatchingKernelQuantifier
    • MMD_RKHS
    • KDEyQuantifier
    • KDEyML
    • KDEyHD
    • KDEyCS
    • GKDEyML
    • GHDx
    • GHDy
    • SMM
    • EDy
    • EDx
  • mlquantify.meta
    • EnsembleQ
    • QuaDapt
    • AggregativeBootstrap
  • mlquantify.metrics
    • AE
    • SE
    • MAE
    • MSE
    • KLD
    • RAE
    • NAE
    • NRAE
    • NKLD
    • NMD
    • RNOD
    • VSE
    • CvM_L1
  • mlquantify.model_selection
    • GridSearchQ
    • BaseProtocol
    • APP
    • NPP
    • UPP
    • PPP
    • apply_protocol
  • mlquantify.multiclass
    • binary_quantifier
    • BinaryQuantifier
    • MulticlassStrategy
    • register_strategy
    • get_strategy
    • available_strategies
  • mlquantify.neighbors
    • PWK
  • mlquantify.neural
    • QuaNet
  • mlquantify.representations
    • BaseRepresentation
    • HistogramRepresentation
    • KDERepresentation
    • DistanceRepresentation
    • KernelMeanRepresentation
    • PredictionRepresentation
    • HardPredictionRepresentation
    • SoftPredictionRepresentation
  • mlquantify.solvers
    • solve_binary
    • ternary_search
    • solve_simplex
    • minimize_prevalence
    • minimize_prevalence_blocks
  • mlquantify.utils
    • get_prev_from_labels
    • normalize_prevalence
    • load_quantifier
    • make_prevs
    • apply_cross_validation
    • simplex_uniform_kraemer
    • simplex_grid_sampling
    • simplex_uniform_sampling
    • get_indexes_with_prevalence
  • mlquantify.visualization
    • DiagonalDisplay
    • BiasDisplay
    • ErrorByShiftDisplay
    • PrevalenceDisplay
    • ConfidenceRegionDisplay
  • API Reference
  • mlquantify.solvers
  • ternary_search

ternary_search#

mlquantify.solvers.ternary_search(left, right, objective, tol=1e-06)[source]#

Find the minimum of a unimodal function via ternary search.

Iteratively narrows the interval [left, right] by comparing the objective at two interior probe points until the interval width falls below tol.

Parameters:
leftfloat

Left bound of the search interval.

rightfloat

Right bound of the search interval.

objectivecallable

Scalar function to minimize over [left, right]. Must be unimodal on the interval.

tolfloat, default=1e-6

Convergence criterion: the search stops when right - left <= tol.

Returns:
minimumfloat

Approximate location of the minimum.

See also

solve_binary

Binary prevalence solver that can call this search.

Examples

>>> from mlquantify.solvers._binary import ternary_search
>>> minimum = ternary_search(0.0, 1.0, lambda x: (x - 0.3) ** 2)
>>> round(minimum, 4)
0.3

previous

solve_binary

next

solve_simplex

On this page
  • ternary_search
Show Source