9.4. Solvers#

Solver utilities minimize objective functions under prevalence constraints. They are used by compose and matching quantifiers to enforce simplex constraints.

9.4.1. Available solvers#

9.4.2. Example#

import numpy as np
from mlquantify.solvers import minimize_prevalence

def objective(p):
    target = np.array([0.4, 0.6])
    return np.sum((p - target) ** 2)

prevalences, value = minimize_prevalence(
    objective=objective,
    n_classes=2,
    solver="slsqp",
    random_state=0,
)