BAMresearch / bayem

Implementation and derivation of "Variational Bayesian inference for a nonlinear forward model." [Chappell et al. 2008] for arbitrary, user-defined model errors.
MIT License
2 stars 1 forks source link

Length of vector valued parameters #37

Closed TTitscher closed 3 years ago

TTitscher commented 3 years ago

For simplicity, we want to support vector valued parameters to have, for example, a whole displacement field u as a latent variable. That would simply work as

p = bayes.parameters.ParameterList()
p.define("u", [0,0,0,0,0])

If you define this parameter as latent, the LatentParameters must know its length -- 5 in this case -- to assign it to a region in the global latent parameter vector.

There is, however, no check if the length of the parameter keeps constant. So no error on

p["u"] = 42.
p["u"] = [0,0,0]

Also, we support to initialize empty parameters like

p.define("u2")

This is convenient if you want to indicate that this parameter must be latent.In this case, however, LatentParameters has no chance to know its length and (currently) assumes length 1. So this behavior must be clearly documented or the length must be provided explicitly:

p.define("u2") # raises "No length given!"
# or
p.define("u2") # logs: "Parmameter 'u2' defined as scalar."
p.define("u2", length=6) # logs: "Parmameter 'u2' defined as vector of length 6."