Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Models as components for CallableNumericalModel #251

@tBuLi

Description

@tBuLi

Taking the example from #248, we realized that the syntax for CallableNumericalModel's could be improved a bit from

ode_model = ODEModel({D(y, x): a * y}, initial={x: 0.0, y: 1.0})
model_dict = {
    z: 2 * y + b,
    y: lambda x, a: ode_model(x=x, a=a).y,
}

to

ode_model = ODEModel({D(y, x): a * y}, initial={x: 0.0, y: 1.0})
model_dict = {
    z: 2 * y + b,
    y: ode_model
}

if we make CallableNumericalModel's aware of Ans objects to automate the unpacking. (ODEModel is used here for no particular reason, could be any model.) I think this looks a lot cleaner. However, this could potentially open a pandora's box I haven't thought about, but for now I think it's save.
An interesting extension would be tuple unpacking for multicomponent models:

ode_model = ODEModel({D(y1, x): a * y1, D(y2, x): a * y2}, initial={x: 0.0, y1: 1.0, y2: 0.0})
model_dict = {
    z: 2 * y1 + b,
    (y1, y2): ode_model
}
model = CallableNumericalModel(model_dict, connectivity_mapping={z: {y2, b}})

fit = Fit(model, x=xdata, z=zdata, y2=None)

where y2 is set to None so it is ignored in the optimization as usual. The general invariant here would be {ode_model.dependent_vars: ode_model}.

For general models this might not be a good idea because of the extra work involved for calculating jacobians etc, but for CallableNumericalModel this might in fact be a powerful addition.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions