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

initialization of global parameter vector #21

Closed joergfunger closed 3 years ago

joergfunger commented 3 years ago

How would the init function for the parameter vector look like? Currently, I do

latent_length = sum(latent_par.N for latent_par in inference_problem.latent.values())
start_vector = np.empty(latent_length)
start_vector[inference_problem.latent['b'].global_index_range()] = 0.7

Should we have a set function?

inference_problem.latent['b'].set_value(0.7)
TTitscher commented 3 years ago

I mostly dealt with VB, so the VariationalBayesProblem, where the prior defines the start values, see e.g. here. The same should generally be true for Bayesian problems. So, technically, this start_vector is only present in a deterministic inference, right?

The LatentParameters is really just a mapping for multiple parameter lists to a global name, b in your example. So a latent['b'].set_value(...) would rather update all the individual parameter lists linked to that b (and not fill a start_vector).

So maybe you could first clarify, what you intend to do.

joergfunger commented 3 years ago

The start vector is (as you pointed out) for a deterministed problem. But it might also be relevant for testing, where you want to evaluate the model error for a specific set of parameters in the global problem. I agree that the set function would just set all values, we would probably have an extract function again. Or a function that somehow generates the global startvector

startvector = inference_problem.start_vector({'b':0, 'a':100})

The not defined variables will be extracted from the first parameter list that has this entry.

TTitscher commented 3 years ago

Except for VB (which is part of the lib itself), we decided to not have code to define an algorithm/tool specific prior. So if we interpret the start_vector as the prior of a deterministic inference, we should not have something like this. But this is really silly and, as you pointed out, also nice for testing.

And I like your code idea! As we strive for total clarity and unambiguousness, I would raise an exception like:

Global parameter "c" has value 42 in listA and value 6174 in listB [and I do not know which one to choose]. Please specify it in the argument dict.

joergfunger commented 3 years ago

The exception is even better in case there is some discrepancies.