Model fitting
Model fitting in DIVE
- Design class for model fitting.
- needs to have access to model
- needs to have access to data
- optionally fitting algorithm?
Something like:
from scipy.optimize import optimize
import numpy as np
class Optimise():
def __init__(self,model,acq):
self.model = model
self.acq = acq
def initialise(self):
x = [m.parameters.default() for m in model]
return x
def x2p(self,x):
p = []
i = 0
for c in self.model.compartments:
n = len(c.parameters)
p.extend(x[i:i+n])
i += n
return p
def get_signal(self,x):
p = self.x2p(x)
signal = 0
for i in range(len(p)):
signal += self.model.compartments(p[i],**self.acq)
return signal
def fit(data):
x0 = self.initialise()
def err(x):
return np.mean( (data - self.get_signal(x))**2 )
res = optimize(err,s0)
return res.x
BUT:
- what to do if model has convolution? @ndcn0236 this is where we need something more complex than the convolve functions?
How it can be used:
Edited by Amy Howard