Bound Plate

class alan.BoundPlate(plate: Plate, all_platesizes: dict[str, int], inputs=None, extra_opt_params=None)[source]

Binds a Plate representing P or Q to platesizes, and initializes parameters specified by OptParam or QEMParam.

Parameters:
  • plate (Plate) – The plate specifying P or Q.

  • all_platesizes (dict[str, int]) – Dictionary mapping string platename to integer platesize.

Keyword Arguments:
  • inputs (dict[str, (named) torch.Tensor]) – Dictionary mapping string input name to input value, as a named torch.Tensor. This is used to represent e.g. features that the model is conditioned on, but that aren’t sampled from the model. Note that

  • extra_opt_params (dict[str, (named) torch.Tensor]) – Dictionary mapping string parameter name to initial parameter value, as a named torch.Tensor. Usually you’d specify parameters to be optimized using OptParam. But the OptParam approach is slightly restictive, as an OptParam can only be used as a direct argument to a distribution (e.g. `` a = Normal(OptParam(0.), 1.)``, whereas an parameter given here can be used anywhere in the program.

Inputs or extra_opt_params are specified as named tensors, where the names corresond to the plates (as with data).

sample()[source]

Returns a single sample from the model, as a flat dictionary of named tensors, where the names correspond to plate dimensions.

inputs()[source]

Returns a dictionary of the inputs.

opt_params()[source]

Returns a dictionary of the parameters learned by optimization.

qem_params()[source]

Returns a dictionary of the parameters learned using QEM.

qem_means()[source]

Returns a dictionary of the exponential moving average moments used for QEM.