Adventures with PreliZ
Adventures with PreliZ.
import preliz as pz
WARNING (pytensor.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
I'll start looking at continuous variables, specifically the beta. This one is great to start with because when the parameters for the distribution and both equal 1, then we get a uniform distribution over the support. The beta distribution has the mathematical form
where is the Gamma function, and and are parameters we can adjust. Below I have set , which gives us a uniform distribution over the support (x-axis) of the distribution.
pz.Beta(alpha=1, beta=1).plot_pdf(pointinterval=True)
<Axes: >
<Figure size 640x480 with 1 Axes>
Another choice of the beta distribution is shown below. The "box plot" shows the 50% highest density interval (thicker line) and the 95% highest density interval (thinner line). Another cool thing about the beta distribution is that as and , we get the Bernoulli distribution.
pz.Beta(alpha=2, beta=5).plot_pdf(pointinterval=True)
<Axes: >
<Figure size 640x480 with 1 Axes>
One of the coolest things about PreliZ is that you can determine parameters for a distribution, by defining the maximum entropy interval.
pz.maxent(distribution=pz.Beta(), lower=0.3, upper=0.8, mass=0.8)
([1mBeta[0m(alpha=3.3, beta=2.8), <Axes: >)
<Figure size 640x480 with 1 Axes>
So what does this mean exactly? Well, if I had data between 0.3 and 0.8, I could choose a well informed prior that encompassed the data, but still had probabilities beyond those values. To compare, look at what happens when the mass is set to 0.6.
pz.maxent(distribution=pz.Beta(), lower=0.3, upper=0.8, mass=0.8)
pz.maxent(distribution=pz.Beta(), lower=0.3, upper=0.8, mass=0.6)
([1mBeta[0m(alpha=1.49, beta=1.4), <Axes: >)
<Figure size 640x480 with 1 Axes>
Comparing the two distributions shows that the one with the mass set to 0.6 between the interval has higher probabilities for sampling values between than the distribution with mass 0.8.
pz.maxent(distribution=pz.Normal(), lower=0.3, upper=0.8, mass=0.6)
([1mNormal[0m(mu=0.55, sigma=0.297), <Axes: >)
<Figure size 640x480 with 1 Axes>
pz.BetaScaled(
alpha=2,
beta=5,
lower=300,
upper=500,
).plot_pdf(pointinterval=True)
<Axes: >
<Figure size 640x480 with 1 Axes>