Closed MichaelDAlbrow closed 2 years ago
You can do this with a class, or with a function that builds and returns a function.
I have done this with a lambda
function and it worked. @JohannesBuchner is this what you were suggesting with your second part of the sentence above?
Yes, sorry for being terse. I'll close this now then.
To expand, you can do something like this:
def make_likelihood(data):
def mylikelihood(params):
return -0.5 * ((model(params) - data)**2).sum()
return mylikelihood
sampler = ReactiveNestedSampler(loglike=make_likelihood(mydata), ...)
or as a class:
class MyLikelihood():
def __init__(self, data):
self.data = data
def __call__(self, params):
return -0.5 * ((model(params) - self.data)**2).sum()
sampler = ReactiveNestedSampler(loglike=MyLikelihood(mydata), ...)
It would be very nice to have a way of passing extra (non-model-parameter) arguments through to the likelihood function, rather than relying on global variables. The emcee sampler has "args" and dynesty has "logl_args" to accomplish this.
regards, Michael Albrow