-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make constraints as Model instead of the same as their parent model #287
Conversation
…Add initial parameters to connectivity_mapping Fixes tBuLi#282
|
||
constraints = [Ge(a0, c0)] | ||
|
||
fit = Fit(ode_model, t=tdata, a=AA, c=AAB, d=BAAB) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constraints are not passed to Fit
. It is probably better to use an equatilty or make the constraint the other way around, since initially the constraint is already true so we don't know if it was enforced properly.
Nice one. But I think the original reason for using the same class is that when adding constraints to a E.g. model = CallableNumericalModel({y: lambda x: a * x**2}, connectivity_mapping={y: {x, a}})
constraint = CallableNumericalModel.as_constraint(
{z: lambda y: np.sum(y)},
connectivity_mapping={z: {y}},
model=model, constraint_type=Eq
) I'm actually surprised the tests didn't fail for this, I guess that means I never added proper testing for the above functionality. Perhaps whoever of us has time first can check if this indeed works, because this is very nice functionality to have: it means that also for these kinds of models the constraints can depend on the output of the model, not just the parameters. I personally already used this type of construction to fix the integral of my solution to be 1. So I think I'm more in favor of adding a simple check for ODEModels and only do your new fix there but keep the standard behavior otherwise. |
I also think that ultimately the solution would be to rework |
I forgot about this TODO. I'll fix both in one go. |
Btw, a potential unified syntax could be as follows: ODEModel({
D(y, t): - k * y,
y: 1,
t: 0
}) This would move everything to the model_dict and makes the ambition of having expressions as initial conditions much easier. It would also streamline internal code regarding ODEModels, though at the expense of some readability for the user I think, since it is not immediately obvious that these are to be read as initial conditions. What do you think? |
It could also be a good idea an improved version of the current ODEModel but call it RawODEModel instead, and then make a new ODEModel which allows for mixing of ODE and normal expressions, but which then seperates the ODE components into a RawODEModel and then adds this as a numerical component to a CallableNumericalModel. This would essentially automate the process here: https://symfit.readthedocs.io/en/stable/examples/ex_CallableNumericalModel_ode.html |
ODEModels make for poor constraints, since they require an
initial
argument, which is not passed byBaseModel.as_constraint
. This does mean that if you want to use an ODEModel as constraint, you need to initialize your constraint model yourself, and pass it.On top of that, this PR adds initial ODE parameters to the
connectivity_mapping
.Fixes #282