Truncate NormalMixture between 1 and 12

Dear community,

Hope you are well!

I’m trying to create a bimodal distribution that represents peak sales during the year (blue line in the figure below).

I have used the following code to fit the distribution:

n_components = 2
data=df['c2']

with pm.Model() as gauss_mix:

    μ = pm.Normal("μ",data.mean(),10,shape=n_components)
    σ = pm.HalfNormal("σ", 10, shape=n_components)

    weights = pm.Dirichlet("w", np.ones(n_components))

    pm.NormalMixture("y", w=weights, mu=μ, sigma=σ, observed=data)

    trace = pm.sample(draws=1000, tune=2000, target_accept=0.95)

The results are :

Results

However, as you can see in the figure, the distributions is bounded between 1 and 12 (because it’s months). I’m trying to use pm.Bound(pm.NormalMixture, lower=1,upper=12) but it’s not working.

My question: how can I bound the NormalMixture bertween 1 and 12?

Thank you

1 Like

Can you say more about what exactly is not working?