View source on GitHub
|
Serializes and deserializes a ModelSpec into a Hyperparameters proto.
Inherits From: Serde
Note that this Serde only handles the Hyperparameters part of ModelSpec. The 'prior' attribute of ModelSpec is serialized/deserialized separately using DistributionSerde.
Several ModelSpec attributes come in pairs: a declarative attribute and the
deprecated array it supersedes. This Serde is a faithful mirror of whichever
of them are set, and implements no precedence between them: it writes the
declarative proto field if and only if the declarative attribute is set, and
the deprecated proto field if and only if the deprecated attribute is set.
Deserialization is the exact inverse, so every ModelSpec state round-trips
unchanged -- including the state where both are set, which ModelSpec allows
with a warning.
Resolving which of a pair governs is ModelContext's job, not this one. Were
this Serde to make that decision too, the two could drift apart, and a model
could silently fit differently after a save and reload.
Methods
deserialize
deserialize(
serialized: meridian_pb.Hyperparameters,
serialized_version: str = '',
*,
input_data: (meridian.data.input_data.InputData | None) = None
) -> meridian.model.spec.ModelSpec
Deserializes the given Hyperparameters proto into a ModelSpec.
Note that this only deserializes the Hyperparameters part of ModelSpec. The 'prior' attribute of ModelSpec is deserialized separately using DistributionSerde and should be combined in the MeridianSerde.
| Args | |
|---|---|
serialized
|
The serialized Hyperparameters proto.
|
serialized_version
|
The version of the serialized model. This is used to handle changes in deserialization logic across different versions. |
input_data
|
The input data deserialized from the same payload. Required
only if serialized carries a declarative date-range configuration,
whose half-open date intervals are interpreted against the input data's
time coordinates.
|
| Returns | |
|---|---|
A Meridian model spec container. It is a
spec._ModelSpecWithChangepoints if serialized has changepoints or
sets one of their settings. An unspecified prior type counts as unset.
|
| Raises | |
|---|---|
ValueError
|
If serialized carries a declarative date-range
configuration but input_data is None.
|
serialize
serialize(
obj: meridian.model.spec.ModelSpec,
*,
model_context: (meridian.model.context.ModelContext | None) = None
) -> meridian_pb.Hyperparameters
Serializes the given ModelSpec into a Hyperparameters proto.
| Args | |
|---|---|
obj
|
The model spec to serialize. |
model_context
|
The context of the model being serialized. Required only if
obj carries a declarative date-range specification, whose bounds are
expressed against the input data's time coordinates, and which for a
random holdout also supplies the draw to record.
|
| Returns | |
|---|---|
A Hyperparameters proto.
|
| Raises | |
|---|---|
ValueError
|
If obj carries a declarative date-range specification but
model_context is None, or if a date range bound is not one of the
input data's time coordinates.
|
View source on GitHub