prior#
Class that represents a prior distribution.
The Prior
class is a wrapper around PyMC distributions that allows the user
to create outside of the PyMC model.
This is the alternative to using the dictionaries in PyMC-Marketing models.
Examples#
Create a normal prior.
from pymc_marketing.prior import Prior
normal = Prior("Normal")
Create a hierarchical normal prior by using distributions for the parameters and specifying the dims.
hierarchical_normal = Prior(
"Normal",
mu=Prior("Normal"),
sigma=Prior("HalfNormal"),
dims="channel",
)
Create a non-centered hierarchical normal prior with the centered
parameter.
non_centered_hierarchical_normal = Prior(
"Normal",
mu=Prior("Normal"),
sigma=Prior("HalfNormal"),
dims="channel",
# Only change needed to make it non-centered
centered=False,
)
Create a hierarchical beta prior by using Beta distribution, distributions for the parameters, and specifying the dims.
hierarchical_beta = Prior(
"Beta",
alpha=Prior("HalfNormal"),
beta=Prior("HalfNormal"),
dims="channel",
)
Create a transformed hierarchical normal prior by using the transform
parameter. Here the “sigmoid” transformation comes from pm.math
.
transformed_hierarchical_normal = Prior(
"Normal",
mu=Prior("Normal"),
sigma=Prior("HalfNormal"),
transform="sigmoid",
dims="channel",
)
Create a prior with a custom transform function by registering it with
register_tensor_transform
.
from pymc_marketing.prior import register_tensor_transform
def custom_transform(x):
return x ** 2
register_tensor_transform("square", custom_transform)
custom_distribution = Prior("Normal", transform="square")
Functions
|
Wrap the |
|
Take a tensor of dims |
|
Register a tensor transform function to be used in the |
|
Sample the prior for an arbitrary VariableFactory. |
Classes
|
Create censored random variable. |
|
A class to represent a prior distribution. |
|
Scaled distribution for numerical stability. |
|
Protocol for something that works like a Prior class. |
Exceptions
|
Error for when 'mu' is present in Prior. |
|
Error for when an unknown transform is used. |
|
Error for when an unsupported distribution is used. |
|
The follow parameterization is not supported. |
|
Error for when the shapes from variables are not compatible. |
|
Variable is not found. |