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

VB_postprocess_per_iteration #86

Open ajafarihub opened 2 years ago

ajafarihub commented 2 years ago

For studying purposes in particular, it is nice to have the possibility of doing kind of post-processing of intermediate iterations in the VB via some callable(s) given by the user. For example, one might like to monitor:

One idea would be to consider a list of callable(s) each being called after any iterative update. This can be possibly done after update of parameters and noises in a separate way.

ajafarihub commented 2 years ago

@TTitscher , As far as I see the current implementation, it is to me unclear how to do it in a flexible way. Let say, I wish to monitor the condition-number of the Lambda matrix. How could I do it? The issue that I see is that, the vba routine is all in one command. It would however be better to have for example:

vba = VBA(dict_f, x0, options)
my_desired_pp = some_class(vba.m, vba.noise, vba.Lm, ... ).__call__
vba.add_pp(my_desired_pp)
vba.run()

Or do you see an alternative way to do that in the current setup ?

TTitscher commented 2 years ago

We can certainly discuss the need of a function that is called somewhere inside VB. These functions are usually called callback functions that are passed as an argument.

def print_L(m, L, s, c, ...):
    print(L)

result = bayem.vba(model_error, prior, callback=print_L)

However, Lambda, the parameter values, noises and many more are stored for all iterations in VBResult, e.g.

result = bayem.vba(model_error, prior, ...)
condition_number_of_iteration_5 = np.linalg.cond(result.precisions[5])
model_params_of_iteration_42 = result.means[42]

So does the information in VBResult already solve your issue?

ajafarihub commented 2 years ago

I think, the point would be to be able to monitor some quantities of interest as the iterations go on, especially in case of a possibility for divergence of the VB for any reason. So, maybe if we resolve the other issue (#87 ) , then this one is quite not needed any longer.

TTitscher commented 2 years ago

With #88 merged, please double-check if this issue is needed anymore. If not, close. If so, what is missing?