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.

transformed_hierarchical_normal = Prior(
    "Normal",
    mu=Prior("Normal"),
    sigma=Prior("HalfNormal"),
    transform="sigmoid",
    dims="channel",
)

Functions

create_dim_handler(desired_dims)

Wrapper to act like the previous create_dim_handler function.

handle_dims(x, dims, desired_dims)

Take a tensor of dims dims and align it to desired_dims.

Classes

Prior(distribution, *[, dims, centered, ...])

A class to represent a prior distribution.

Exceptions

MuAlreadyExistsError(distribution)

Error for when 'mu' is present in Prior.

UnknownTransformError

Error for when an unknown transform is used.

UnsupportedDistributionError

Error for when an unsupported distribution is used.

UnsupportedParameterizationError

The follow parameterization is not supported.

UnsupportedShapeError

Error for when the shape of the hierarchical variable is not supported.