Likelihood maximization

In this notebook, we are going to look over likelihood maximisation and how it is implemented in folie

[ ]:

[ ]:

The next step is to choose a discretisation of the likelihood

[ ]:

[ ]:
for trj in data:
    transition.preprocess_traj(trj)
[1]:
def log_likelihood_negative(coefficients, data):
    weightsum = data.weights.sum()
    return np.sum([transition(weight, coefficients)[0] * weight / weightsum for weight, trj in zip(data.weights, data)])
[ ]:

KramersMoyalEstimator(self.model).fit(data) coefficients0 = self.model.coefficients transition.use_jac = False res = minimize(log_likelihood_negative, coefficients0, args=(data,), callback=callback, **minimize_kwargs) self.model.coefficients = res.x

We can also use the jacobian

[ ]:
def log_likelihood_negative_w_jac(transition, weights, data, coefficients):
    weightsum = weights.sum()
    array_res = [transition(weight, trj, coefficients, jac=True) * weight / weightsum for weight, trj in zip(data.weights, data)]
    likelihood = np.sum([val[0] for val in array_res])
    likelihood_jac = np.sum([val[1] for val in array_res], axis=0)
    return likelihood,likelihood_jac
[ ]:

res = minimize(log_likelihood_negative_w_jac, coefficients0, args=(data,), jac=True, **minimize_kwargs) self.model.coefficients = res.x