yoavram / curveball

Predicting microbial growth in a mixed culture from growth curve data
http://curveball.yoavram.com
Other
14 stars 5 forks source link

Check if ModelResult.covar is None #56

Open yoavram opened 9 years ago

yoavram commented 9 years ago

Sometimes when the fit fails,ModelResult.covar is None. In this case, some things will fails (sample_params, who knows what else). One example - it happens when the bounds (min max) or params are too tight.

yoavram commented 9 years ago
def test_covar_is_none(self):
    df = randomize_data(logistic_ode, reps=5)
    params = curveball.models.logistic_model.make_params(r=0.1, y0=df.OD.min(), K=df.OD.max())
    params['r'].set(min=0.5, max=1.0)
    model_fit = curveball.models.logistic_model.fit(data=df.OD, t=df.Time, params=params)
    self.assertIsNotNone(model_fit.covar)
yoavram commented 9 years ago
t = np.linspace(0, 12)
y0=0.1; r=0.75; K=1.0
v = r
nu = 1.0
_lam = 2.0
q0 = 1.0 / (np.exp(_lam * v) - 1.0)
df = randomize_data(baranyi_roberts_ode, t=t, y0=y0, r=r, K=K, nu=nu, q0=q0, v=v, reps=1)
t = df.Time.as_matrix()
y = df.OD.as_matrix()
model = curveball.baranyi_roberts_model.BaranyiRobertsModel()
params = model.guess(data=y, t=t)
result = model.fit(data=y, t=t, params=params)
print('nu={}, lam={}'.format(nu, _lam))
print(result.fit_report())

v and q0 are ~1e12, doesn't happen when t goes to 24.

yoavram commented 8 years ago

This problem can be circumvent using bootstrap_params.