Distributions
These are the supported distributions based on the conjugate models.
Many have the dist
attribute which is a scipy.stats distribution object. From there,
you can use the methods from scipy.stats to get the pdf, cdf, etc.
Distributions can be plotted using the plot_pmf
or plot_pdf
methods of the distribution.
from conjugate.distribution import Beta
beta = Beta(1, 1)
scipy_dist = beta.dist
print(scipy_dist.mean())
# 0.5
print(scipy_dist.ppf([0.025, 0.975]))
# [0.025 0.975]
samples = scipy_dist.rvs(100)
beta.plot_pmf(label="beta distribution")
Distributions like Poisson can be added with other Poissons or multiplied by numerical values in order to scale rate. For instance,
daily_rate = 0.25
daily_pois = Poisson(lam=daily_rate)
two_day_pois = daily_pois + daily_pois
weekly_pois = 7 * daily_pois
Below are the currently supported distributions
Beta
dataclass
Bases: ContinuousPlotDistMixin
, SliceMixin
Beta distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha |
NUMERIC
|
shape parameter |
required |
beta |
NUMERIC
|
shape parameter |
required |
Source code in conjugate/distributions.py
from_mean(mean, alpha)
classmethod
Alternative constructor from mean and alpha.
from_successes_and_failures(successes, failures)
classmethod
Alternative constructor based on hyperparameter interpretation.
Source code in conjugate/distributions.py
BetaBinomial
dataclass
Bases: DiscretePlotMixin
, SliceMixin
Beta binomial distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
NUMERIC
|
number of trials |
required |
alpha |
NUMERIC
|
shape parameter |
required |
beta |
NUMERIC
|
shape parameter |
required |
Source code in conjugate/distributions.py
BetaNegativeBinomial
dataclass
Bases: DiscretePlotMixin
, SliceMixin
Beta negative binomial distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
NUMERIC
|
number of successes |
required |
alpha |
NUMERIC
|
shape parameter |
required |
beta |
NUMERIC
|
shape parameter |
required |
Source code in conjugate/distributions.py
BetaProportional
dataclass
Beta proportional distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
p |
NUMERIC
|
product of observations |
required |
q |
NUMERIC
|
product of complements |
required |
k |
NUMERIC
|
number of observations |
required |
Source code in conjugate/distributions.py
approx_log_likelihood(alpha, beta, ln=np.log, gammaln=gammaln)
Approximate log likelihood.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha |
NUMERIC
|
shape parameter |
required |
beta |
NUMERIC
|
shape parameter |
required |
ln |
log function |
log
|
|
gammaln |
log gamma function |
gammaln
|
Returns:
Type | Description |
---|---|
NUMERIC
|
log likelihood up to a constant |
Source code in conjugate/distributions.py
Binomial
dataclass
Bases: DiscretePlotMixin
, SliceMixin
Binomial distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
NUMERIC
|
number of trials |
required |
p |
NUMERIC
|
probability of success |
required |
Source code in conjugate/distributions.py
CompoundGamma
dataclass
Bases: ContinuousPlotDistMixin
, SliceMixin
Compound gamma distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha |
NUMERIC
|
shape |
required |
beta |
NUMERIC
|
scale |
required |
lam |
NUMERIC
|
rate |
required |
Source code in conjugate/distributions.py
Dirichlet
dataclass
Bases: DirichletPlotDistMixin
Dirichlet distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha |
NUMERIC
|
shape parameter |
required |
Source code in conjugate/distributions.py
DirichletMultinomial
dataclass
Bases: SliceMixin
Dirichlet multinomial distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha |
NUMERIC
|
shape parameter |
required |
n |
NUMERIC
|
number of trials |
required |
Source code in conjugate/distributions.py
Exponential
dataclass
Bases: ContinuousPlotDistMixin
, SliceMixin
Exponential distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lam |
NUMERIC
|
rate parameter |
required |
Source code in conjugate/distributions.py
Gamma
dataclass
Bases: ContinuousPlotDistMixin
, SliceMixin
Gamma distribution.
Gamma Distribution Scipy Docmentation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha |
NUMERIC
|
shape parameter |
required |
beta |
NUMERIC
|
rate parameter |
required |
Source code in conjugate/distributions.py
GammaKnownRateProportional
dataclass
Gamma known rate proportional distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a |
NUMERIC
|
prod of observations |
required |
b |
NUMERIC
|
number of observations |
required |
c |
NUMERIC
|
number of observations |
required |
Source code in conjugate/distributions.py
approx_log_likelihood(alpha, beta, ln=np.log, gammaln=gammaln)
Approximate log likelihood.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha |
NUMERIC
|
shape parameter |
required |
beta |
NUMERIC
|
known rate parameter |
required |
ln |
log function |
log
|
|
gammaln |
log gamma function |
gammaln
|
Returns:
Type | Description |
---|---|
NUMERIC
|
log likelihood up to a constant |
Source code in conjugate/distributions.py
GammaProportional
dataclass
Gamma proportional distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
p |
NUMERIC
|
product of r observations |
required |
q |
NUMERIC
|
sum of s observations |
required |
r |
NUMERIC
|
number of observations for p |
required |
s |
NUMERIC
|
number of observations for q |
required |
Source code in conjugate/distributions.py
approx_log_likelihood(alpha, beta, ln=np.log, gammaln=gammaln)
Approximate log likelihood.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha |
NUMERIC
|
shape parameter |
required |
beta |
NUMERIC
|
rate parameter |
required |
ln |
log function |
log
|
|
gammaln |
log gamma function |
gammaln
|
Returns:
Type | Description |
---|---|
NUMERIC
|
log likelihood up to a constant |
Source code in conjugate/distributions.py
Geometric
dataclass
Bases: DiscretePlotMixin
, SliceMixin
Geometric distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
p |
NUMERIC
|
probability of success |
required |
Source code in conjugate/distributions.py
Hypergeometric
dataclass
Bases: DiscretePlotMixin
, SliceMixin
Hypergeometric distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
N |
NUMERIC
|
population size |
required |
k |
NUMERIC
|
number of successes in the population |
required |
n |
NUMERIC
|
number of draws |
required |
Source code in conjugate/distributions.py
InverseGamma
dataclass
Bases: ContinuousPlotDistMixin
, SliceMixin
InverseGamma distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha |
NUMERIC
|
shape |
required |
beta |
NUMERIC
|
scale |
required |
Source code in conjugate/distributions.py
InverseWishart
dataclass
Inverse wishart distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nu |
NUMERIC
|
degrees of freedom |
required |
psi |
NUMERIC
|
scale matrix |
required |
Source code in conjugate/distributions.py
LogNormal
dataclass
Bases: ContinuousPlotDistMixin
, SliceMixin
Log normal distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mu |
NUMERIC
|
mean |
required |
sigma |
NUMERIC
|
standard deviation |
required |
Source code in conjugate/distributions.py
Lomax
dataclass
Bases: ContinuousPlotDistMixin
, SliceMixin
Lomax distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha |
NUMERIC
|
shape |
required |
lam |
NUMERIC
|
scale |
required |
Source code in conjugate/distributions.py
Multinomial
dataclass
Bases: SliceMixin
Multinomial distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
NUMERIC
|
number of trials |
required |
p |
NUMERIC
|
probability of success |
required |
Source code in conjugate/distributions.py
MultivariateNormal
dataclass
Multivariate normal distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mu |
NUMERIC
|
mean |
required |
sigma |
NUMERIC
|
covariance matrix |
required |
Source code in conjugate/distributions.py
MultivariateStudentT
dataclass
MultivariateStudentT distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mu |
NUMERIC
|
mean |
required |
sigma |
NUMERIC
|
covariance matrix |
required |
nu |
NUMERIC
|
degrees of freedom |
required |
Source code in conjugate/distributions.py
NegativeBinomial
dataclass
Bases: DiscretePlotMixin
, SliceMixin
Negative binomial distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
NUMERIC
|
number of successes |
required |
p |
NUMERIC
|
probability of success |
required |
Source code in conjugate/distributions.py
Normal
dataclass
Bases: ContinuousPlotDistMixin
, SliceMixin
Normal distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mu |
NUMERIC
|
mean |
required |
sigma |
NUMERIC
|
standard deviation |
required |
Source code in conjugate/distributions.py
from_mean_and_precision(mean, precision)
classmethod
from_mean_and_variance(mean, variance)
classmethod
NormalGamma
dataclass
Normal gamma distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mu |
NUMERIC
|
mean |
required |
lam |
NUMERIC
|
precision |
required |
alpha |
NUMERIC
|
shape |
required |
beta |
NUMERIC
|
scale |
required |
Source code in conjugate/distributions.py
sample_beta(size, return_variance=False, random_state=None)
Sample beta from the normal distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size |
int
|
number of samples |
required |
return_variance |
bool
|
whether to return variance as well |
False
|
random_state |
random state |
None
|
Returns:
Type | Description |
---|---|
Union[NUMERIC, Tuple[NUMERIC, NUMERIC]]
|
samples from the normal distribution |
Source code in conjugate/distributions.py
sample_variance(size, random_state=None)
Sample precision from gamma distribution and invert.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size |
int
|
number of samples |
required |
random_state |
random state |
None
|
Returns:
Type | Description |
---|---|
NUMERIC
|
samples from the inverse gamma distribution |
Source code in conjugate/distributions.py
NormalInverseGamma
dataclass
Normal inverse gamma distribution.
Supports both 1 dimensional and multivariate cases.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mu |
NUMERIC
|
mean |
required |
alpha |
NUMERIC
|
shape |
required |
beta |
NUMERIC
|
scale |
required |
delta_inverse |
NUMERIC
|
covariance matrix, 2d array for multivariate case |
None
|
nu |
NUMERIC
|
alternative precision parameter for 1 dimensional case |
None
|
Source code in conjugate/distributions.py
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 |
|
sample_beta(size, return_variance=False, random_state=None)
Sample beta from the normal distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size |
int
|
number of samples |
required |
return_variance |
bool
|
whether to return variance as well |
False
|
random_state |
random state |
None
|
Returns:
Type | Description |
---|---|
Union[NUMERIC, Tuple[NUMERIC, NUMERIC]]
|
samples from the normal distribution and optionally variance |
Source code in conjugate/distributions.py
sample_mean(size, return_variance=False, random_state=None)
Sample the mean from the normal distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size |
int
|
number of samples |
required |
return_variance |
bool
|
whether to return variance as well |
False
|
random_state |
random state |
None
|
Returns:
Type | Description |
---|---|
Union[NUMERIC, Tuple[NUMERIC, NUMERIC]]
|
samples from the normal distribution and optionally variance |
Source code in conjugate/distributions.py
sample_variance(size, random_state=None)
Sample variance from the inverse gamma distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size |
int
|
number of samples |
required |
random_state |
random state |
None
|
Returns:
Type | Description |
---|---|
NUMERIC
|
samples from the inverse gamma distribution |
Source code in conjugate/distributions.py
NormalInverseWishart
dataclass
Normal inverse wishart distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mu |
NUMERIC
|
mean |
required |
kappa |
NUMERIC
|
precision |
required |
nu |
NUMERIC
|
degrees of freedom |
required |
psi |
NUMERIC
|
scale matrix |
required |
Source code in conjugate/distributions.py
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 |
|
sample_mean(size, return_variance=False, random_state=None)
Sample the mean from the normal distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size |
int
|
number of samples |
required |
return_variance |
bool
|
whether to return variance as well |
False
|
random_state |
random state |
None
|
Returns:
Type | Description |
---|---|
NUMERIC
|
samples from the normal distribution and optionally variance |
Source code in conjugate/distributions.py
sample_variance(size, random_state=None)
Sample precision from gamma distribution and invert.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size |
int
|
number of samples |
required |
random_state |
random state |
None
|
Returns:
Type | Description |
---|---|
NUMERIC
|
samples from the inverse wishart distribution |
Source code in conjugate/distributions.py
Pareto
dataclass
Bases: ContinuousPlotDistMixin
, SliceMixin
Pareto distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_m |
NUMERIC
|
minimum value |
required |
alpha |
NUMERIC
|
scale parameter |
required |
Source code in conjugate/distributions.py
Poisson
dataclass
Bases: DiscretePlotMixin
, SliceMixin
Poisson distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lam |
NUMERIC
|
rate parameter |
required |
Source code in conjugate/distributions.py
ScaledInverseChiSquared
dataclass
Bases: ContinuousPlotDistMixin
, SliceMixin
Scaled inverse chi squared distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nu |
NUMERIC
|
degrees of freedom |
required |
sigma2 |
NUMERIC
|
scale parameter |
required |
Source code in conjugate/distributions.py
from_inverse_gamma(inverse_gamma)
classmethod
Alternative constructor from inverse gamma distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inverse_gamma |
InverseGamma
|
inverse gamma distribution |
required |
Returns:
Type | Description |
---|---|
ScaledInverseChiSquared
|
scaled inverse chi squared distribution |
Source code in conjugate/distributions.py
to_inverse_gamma()
Convert to inverse gamma distribution.
Returns:
Type | Description |
---|---|
InverseGamma
|
inverse gamma distribution |
StudentT
dataclass
Bases: ContinuousPlotDistMixin
, SliceMixin
StudentT distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mu |
NUMERIC
|
mean |
required |
sigma |
NUMERIC
|
standard deviation |
required |
nu |
NUMERIC
|
degrees of freedom |
required |
Source code in conjugate/distributions.py
Uniform
dataclass
Bases: ContinuousPlotDistMixin
, SliceMixin
Uniform distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
low |
NUMERIC
|
lower bound |
required |
high |
NUMERIC
|
upper bound |
required |
Source code in conjugate/distributions.py
VectorizedDist
Vectorized distribution to handle scipy distributions that don't support vectorization.
Source code in conjugate/distributions.py
VonMises
dataclass
Bases: ContinuousPlotDistMixin
, SliceMixin
Von Mises distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mu |
NUMERIC
|
mean |
required |
kappa |
NUMERIC
|
concentration |
required |
Source code in conjugate/distributions.py
VonMisesKnownConcentration
dataclass
Von Mises known concentration distribution.
Taken from Section 2.13.1.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a |
NUMERIC
|
positive value |
required |
b |
NUMERIC
|
value between 0 and 2 pi |
required |
Source code in conjugate/distributions.py
log_likelihood(mu, cos=np.cos, ln=np.log, i0=i0)
Approximate log likelihood.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mu |
NUMERIC
|
mean |
required |
cos |
cosine function |
cos
|
|
ln |
log function |
log
|
|
i0 |
modified bessel function of order 0 |
i0
|
Returns:
Type | Description |
---|---|
NUMERIC
|
log likelihood |
Source code in conjugate/distributions.py
VonMisesKnownDirectionProportional
dataclass
Von Mises known direction proportional distribution.
Taken from Section 2.13.2.
Args: c: NUMERIC r: NUMERIC
Source code in conjugate/distributions.py
approx_log_likelihood(kappa, ln=np.log, i0=i0)
Approximate log likelihood.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kappa |
NUMERIC
|
concentration |
required |
ln |
log function |
log
|
|
i0 |
modified bessel function of order 0 |
i0
|
Returns:
Type | Description |
---|---|
NUMERIC
|
log likelihood up to a constant |
Source code in conjugate/distributions.py
Wishart
dataclass
Wishart distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nu |
NUMERIC
|
degrees of freedom |
required |
V |
NUMERIC
|
scale matrix |
required |