I'm trying to approximate Beta distribution using a library pomegranate. However, when I try to approximate parameters from the generated data, I got very different parameters. The code to reproduce such error is as follows
import numpy as np
from pomegranate import *
X = np.random.beta(1, 5, size=10000).reshape(-1, 1) # sample from beta distribution with alpha = 1, beta = 5
print(BetaDistribution.from_samples(X).parameters) # approximate beta parameters
>>> [0.0, 10000.0] # error here
I'm not sure where the error comes from. It seems like the test file test_distributions.py produces the right answer. If there is any suggestion on how to fix pomegranate
or creating custom model in pomegranate
would be highly appreciated.
Note I'm using Python 3.6.8
Answer according to this issue,
BetaDistribution
provided in the current library is beta-binomial distribution not beta distribution. That's why the model couldn't fit on the sample of beta distribution.Workaround solution
I got the workaround solution using
BayesianOptimization
library. Basically, I try to maximize log likelihood of the distribution from the given data using Bayesian Optimization library. The following code generalizes quite fine with mixture of distributions as well.Extra (for mixture of distributions)
Here, I just give an example of how to optimize parameters of mixture of Beta distribution and Gaussian distribution:
Using the optimized parameters to plot the distribution as follows: