1

When creating a Model of type CallableNumericalModel with dependencies in Symfit the Fit method asks for data even for interdependent variables. Put differently, even if I create a model with dependencies such that no independent variables are left (only parameters), the Fit method requires me to pass some data to that variable. Can someone help me understand that behaviour?

I have checked that the connectivity_mapping of mixed_model indeed maps the variable q in func1 to func2 - which only contains parameters a and b - by looking at the attributes of mixed_model.

See the example below:

from symfit import parameters, variables, Eq, Ge, Fit, CallableNumericalModel, Model
import numpy as np

x, y, a, b = parameters('x, y, a, b')
z, q = variables('z, q')

def func1(x, y, b, q):
    return x+y*b + q

def func2(a, b):
    return b**2 + a

model_dict = {z: func1}
dependency_model = CallableNumericalModel({q: func2}, connectivity_mapping={q: {a,b}})

mixed_model = CallableNumericalModel.with_dependencies(
    model_dict,
    dependency_model,
    connectivity_mapping={z: {x, y, b, q}}
)

zdata = np.linspace(21,41)

constraints = [
    Eq(x**3 - y, 0),
    Ge(y - 3, 0),
]

fit = Fit(mixed_model, constraints=constraints, z=zdata)
#fit = Fit(mixed_model, constraints=constraints) <-- This line doesn't work, even though z isn't independent...
fit_result = fit.execute()

print(fit_result)
TAH
  • 11
  • 3

0 Answers0