Getting started¶
Design¶
From \(N\) points of data \(X=(\vec x_1, \ldots, \vec x_N)\), mix’EM will let you fit a probability distribution \(P(x|\phi)\) from a mixture of \(D\) probability distributions with parameters \(\phi_d\) and mixing weights \(w_d\):
To fit the data to your user-defined model, you pass both the data \(X\) and a list
of mixem.distribution.Distribution
objects with initial parameters to the mixem.em()
function. Mix’EM will optimize the model parameters to best fit the provided data and return the mixing weights \(w_d\) and distributions with parameters \(\phi_d\) plus the final log-likelihood:
weights, distributions, log_likelihood = mixem.em(my_data, [
mixem.distribution.NormalDistribution(mu=1, sigma=1),
mixem.distribution.ExponentialDistribution(lmbda=1),
], initial_weights=[0.5, 0.5])
print(("Final model: {w0} * Norm[mu={mu}, sigma={sigma}] +"
" {w1} * Exp[lambda={lmbda}]").format(
w0=weights[0], w1=weights[1],
mu=distributions[0].mu, sigma=distributions[0].sigma,
lmbda=distributions[1].lmbda
))
Examples¶
A good walkthrough of all major functions of mix’EM is given in the Old Faithful example.
If you have a particular set of distributions that you’d like to fit, you can check out the examples in the examples subdirectory of the mixem project.