pyzag.stochastic
Tools for converting deterministc models implemented in pytorch to stochastic models
- class pyzag.stochastic.MapNormal(cov: float, loc_suffix: str = '_loc', scale_suffix: str = '_scale')
Bases:
objectA map between a deterministic torch parameter and a two-scale normal distribution
- Parameters:
cov – coefficient of variation used to define the scale priors
- Keyword Arguments:
sep (str) – seperator character in names
loc_suffix – suffix to add to parameter name to give the upper-level distribution for the scale
scale_suffix – suffix to add to the parameter name to give the lower-level distribution for the scale
- class pyzag.stochastic.HierarchicalStatisticalModel(base: Module, parameter_mapper: MapNormal, noise_prior: Tensor, update_mask: bool = False)
Bases:
PyroModuleConverts a torch model over to being a Pyro-based hierarchical statistical model
- Parameters:
base (torch.nn.Module) – base torch module
parameter_mapper (MapParameter) – mapper class describing how to convert from Parameter to Distribution
noise_prior (float) – scale prior for white noise
- Keyword Arguments:
update_mask (bool) – if True, update the mask to remove samples that are not valid
- training: bool
- forward(*args: Tensor, results: Tensor | None = None, weights: Tensor | None = None, **kwargs) Tensor
Call the base forward with the appropriate args.
- Parameters:
*args – arguments forwarded to the underlying model. At least one must be a tensor so the batch shape can be inferred.
- Keyword Arguments:
results (torch.tensor or None) – results to condition on.
weights (torch.tensor or None) – weights on the results; defaults to ones.