# Mixture Model Implementation

Cordial greeting.

For some context: I have some experimental data that I collected, and an equation that’s supposed to fit that data. So what I need to do is get the parameters for that equation. That’s why I’m trying to use PYMC.

This is my model in a simple way:

def modelo(Ro, Ml, tau, c,F):
base=(1j * 2np.piF * tau)
aux = Ml * (1 - 1 / (1 + np.power(base,c)))
R = Ro / (1 + aux)
return R

with pm.Model() as ModelOne:
R_modelo = modelo(Ro, Ml, tau, c,F_val)
R_imag_obs = pm.ExGaussian(‘R_imag_obs’, mu=R_modelo.imag, sigma=sigma ,nu=1, observed=data.imag)
R_real_obs = pm.ExGaussian(‘R_real_obs’, mu=R_modelo.real, sigma=sigma2,nu=1, observed=data.real)

The thing is, my data has kind of two peaks, so I’m having bad results with that likelihood. I was reading about the mixture models, but I don’t need to infer the peak and the sd, I need to get the parameters for the equation. So is there a way I could use mixture models for the parameters of my equation?

Hi,

It is very hard to understand without a fully working code. For instance you say you want to fit parameters but in the model you posted

``````with pm.Model() as ModelOne:
R_modelo = modelo(Ro, Ml, tau, c,F_val)
R_imag_obs = pm.ExGaussian(‘R_imag_obs’, mu=R_modelo.imag, sigma=sigma ,nu=1, observed=data.imag)
R_real_obs = pm.ExGaussian(‘R_real_obs’, mu=R_modelo.real, sigma=sigma2,nu=1, observed=data.real)
``````

there are not priors and so no parameters. What are sigma, Ro, Ml, tau, c, F_val? Are they parameters coming from priors or constants or both? The function you have posted also has some expressions that probably won’t work such as

`````` base=(1j * 2np.piF * tau)
``````

In any case, if you want to model a mixture for either or both of the imaginary and real parts of the observed, the way to go would be the mixture class in pymc which can take other distributions as argument:

https://www.pymc.io/projects/docs/en/stable/api/distributions/generated/pymc.Mixture.html

ps: Here is a guide on how to structure your question so people can help you more easily: