tBuLi / symfit

Symbolic Fitting; fitting as it should be.
http://symfit.readthedocs.org
MIT License
233 stars 17 forks source link

TrustConstr cannot handle LogLikelihood with constraints #305

Closed antonykamp closed 3 years ago

antonykamp commented 4 years ago

An error was pointed out when translating test_fit_result in #289 : In the case, that you want to fit a model with constraints and the minimizer TrustConstr with the objective LogLikelihood, you get an error message regarding a missing Hessian.

The corresponding code was approximately the following:

def ge_constraint(a): 
    return a - 1

model=Model({y: a * x ** b})
constraints = [
    Eq(a, b),
    CallableNumericalModel.as_constraint(
        {z: ge_constraint}, connectivity_mapping={z: {a}},
        constraint_type=Ge, model=model
    )
]
fit = Fit(model, x=np.linspace(1, 10, 10), minimizer=TrustConstr, objective=LogLikelihood, constraints=constraints)
result = fit.execute()
tBuLi commented 4 years ago

What is ge_constraint here? I have the feeling it is not so much because it doesn't support a constraint, but constraints of the type CallableNumericalModel since they don't have a Jacobian/hessian and TrustConstr requires this.

antonykamp commented 4 years ago

ge_constraint is a method I forgot to mention.

tBuLi commented 4 years ago

Yeah I think it is most probably because of CallableNumericalModel not having jacobians or hessians, which is actually expected behavior.