-
Notifications
You must be signed in to change notification settings - Fork 17
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
Wanted: examples of constrained fitting #78
Comments
One example I have is from reaction kinetics. Suppose we have an equilibrium reaction between compound A and B with rate constants Therefore: Ea_r, Ea_f, A_r, A_f = parameters('Ea_r, Ea_f, A_r, A_f')
R, T = 8.3145, 298
k_f = A_f * exp(- Ea_f / R * T)
k_r = A_r * exp(- Ea_r / R * T)
model_dict = {
D(A, t): - k_f * A + k_r * B,
D(B, t): k_f * A - k_r * B
}
constraints = {
GreaterEq(Ea_r, Ea_f)
}
fit = Fit(model, ... , constraints=constraints) This can then be extended to multiple equilibria. |
I only have one example so far (and you're not going to like it) def boltzmann(T, V, *args, **kwargs):
kbT = kb * T
return exp(-V(*args, **kwargs)/kbT)
def periodic(x, x0, k, n):
return k*(1+cos(n*x - x0))
distribution = functools.partial(boltzmann, T=298, V=periodic)
x = Variable()
y = Variable()
x0 = Parameter()
k = Parameter()
n = Parameter()
constraints = {Integer(n)}
model = Model({y: distribution(x=x, x0=x0, k=k, n=n)})
fit = Fit(model, ..., constraints=constraints) |
Good one @Pitje06. You are right, I don't like it ;). Integer constraints in fitting are a pain. Do you have any ideas how to solve this? Any algorithms? Naively I would do a float fit and then check wether floor or ceiling results in a smaller chi^2 and return that, though I can see some problems with this. To adhere to standard nomenclature though, this is not a constraint but an assumption. And n = Symbol('n', integer=True)
k, m = symbols('k m', integer=True)
print(n.is_integer) # Prints True
print(n._assumptions) # Contains all assumptions In So I think that assumptions are a separate problem, unless they can be expressed as a constraining function, which in the case of integers is not obvious to me. I can create a separate milestone for (integer) assumptions. General assumptions are another step entirely ;). |
Nope, no clue how to do this :) |
I do a lot of double exponential fitting, in this case a use could be to constrain the decay constanstants to assure the first one is always the largest. However, its not a great example of pushing any boundaries. Also, in my experience 99/100 cases the first is always the largest. a1, t1, a2, t2 = parameters('a1 t1 a2 t2 c')
t = Variable()
m = a1*exp(-t/t1) + a2*exp(-t/t2) + c
}
constraints = {
Greater(t1, t2)
# or Greater(a1, a2)
}
fit = Fit(model, ... , constraints=constraints) |
Thanks @Jhsmit. @Pitje06: Currently only reals are supported, since typically your fit will be performed using I also saw the other day that |
Slightly off-topic: I'll make a separate issue concerning the parameter domains. |
Hi @Pitje06, @Jhsmit, @jbarnoud, and others,
I am looking for examples of fitting problems subject to constraints to write tests and examples with for the Constrained fitting milestone. If you know one from your daily experience or can think of one, can you post it here? As a simple example, I could imagine the following fit:
But I would like some more realistic and challenging examples to really push the boundaries of what
symfit
can handle.The text was updated successfully, but these errors were encountered: