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

Noise model #13

Closed TTitscher closed 3 years ago

TTitscher commented 3 years ago

In recent discussions and even implementations the idea of a noise model came up. Maybe even with separate parameters similar to the model_error.

Main purpose:

The multiple model errors of an inference problem currently return the individual model error contributions as a nested dictionary like {experiment_key : {sensor : vector_of_numbers}}. We now need a way to further adapt this output:

The main interface would be like

class NoiseModel:
    def define_parameters(self):
        pass

    def vector_contribution(self, raw_model_error_output, prm):
        pass

    def loglike_contribution(self, raw_model_error_output, prm):
        pass

Benefits:

User experience:

problem = InferenceProblem()
key_me1 = problem.add_model_error(me1, me1.define_parameters())
key_me2 = problem.add_model_error(me2, me2.define_parameters())

# similar pattern for noise!
noise_model = SingleNoiseForEverything()
key_noise = problem.add_noise_model(noise_model, noise_model.define_parameters())

# assign the shared parameter "A" to the latent parameter "latentA"
problem.latent("latentA", "A", key_me1)
problem.latent("latentA", "A", key_me2)

# similar API for the noise
problem.latent("latentSigma", "sigma", key_noise)

# the following is yet to be discussed and (please) not part of this issue/discussion:
vb_prior = VBPrior(problem.latent)
vb_prior.set("latentA", Normal(...))
vb_prior.set("latentSigma", Gamma(...)) # well actually it should be "precision" for VB...

with pm.Model:
    pm_priors[problem.latent["latentA"].idx] = pm.Normal("latentA", ...)
    ...
joergfunger commented 3 years ago

As for the very simple case with a single model, I would say there is no need to define a multimodel error, but maybe have a specific inference problem that has the same functions (e.g. noise models), but just works with vectors (no keys, just pure np.arrays). But maybe that's something we can decide later on. Similar with the definitions of the priors (decide later). But I think on the other hand we should also allow the user to define the loglike individually (just as an alternative) by providing the option of easily defining user-specific noise models (I see no reason why this whould not work) or directly the complete loglike. So thumbs up from my point of view.