meridian.schema.serde.distribution.DistributionSerde

Serializes and deserializes a Meridian prior distributions container into a Distribution proto.

Inherits From: Serde

function_registry A lookup table containing custom functions used by various backend.tfd classes. It's recommended to explicitly define the custom functions instead of using lambdas, as lambda functions may not be registered successfully.

function_registry

Methods

deserialize

View source

Deserializes the PriorTfpDistributions proto.

WARNING: If any custom functions in the function registry are modified after serialization, the deserialized model can differ from the original model, as the original function's behavior is no longer guaranteed. This will result in an error during deserialization.

For users who are intentionally changing functions and are confident that the changes will not affect the deserialized model, you can bypass safety mechanisms to force deserialization. See example:

Args
serialized A serialized PriorDistributions object.
serialized_version The version of the serialized Meridian model. This is used to handle changes in deserialization logic across different versions.
force_deserialization If True, bypasses the safety check that validates whether functions within function_registry have changed after serialization. Use with caution. This should only be used if you have intentionally modified a custom function and are confident that the changes will not affect the deserialized model. A safer alternative is to first deserialize the model with the original functions and then serialize it with the new ones.

Returns
A deserialized PriorDistribution object. It is a prior_distribution._PriorDistributionWithChangepoints if serialized has priors for time-varying media effects.

serialize

View source

Serializes Meridian priors into a PriorTfpDistributions proto.

The priors of time-varying media effects, zeta_m and zeta_rf, are written only for a prior_distribution._PriorDistributionWithChangepoints.

Args
obj The Meridian priors container.

Returns
A PriorTfpDistributions proto.