[BUG] - Proportions sum to 1 Mixture_model
Closed this issue · 1 comments
The Mixture_Model raises ValueError("the sum of the proportions must be 1") even when the proportions sum is equal to 1.
For exemple :
ls =[]
for i in range(0, 10):
ls.append(Distributions.Lognormal_Distribution(mu=2, sigma=0.8))
mixture_model = Distributions.Mixture_Model(distributions=ls, proportions=np.full(10, 0.1))
Thanks for identifying this. It is caused by a floating point precision error which is inherent in Python. Numpy manages to resolve this somehow but python's sum function (which I was using) does not.
import numpy as np
p = np.full(10, 0.1)
print(np.sum(p))
print(p.sum())
print(sum(p)) # this has a floating point error
Output:
1.0
1.0
0.9999999999999999
I have fixed this, but I won't be doing a new release just for this since I believe it's a very rare bug to encounter. It will be part of the next release, which will be when I fix another more significant bug.
As for your use of the Mixture Model, please try to limit the number of components in the mixture to no more than 5. A lower number like 2 or 3 is better. This isn't for any mathematical or programmatic reasons, but it is for practical reasons. It's unlikely that a Distribution with 10 components will have all 10 components identified correctly from data, especially if they are similar distributions. In the Fit_Weibull_Mixture it only searches for 2 Weibull distributions. Also, in your example, all of the components are the same so it's not really a mixture.