Skip to content

Provide both log posterior and log likelihood in optimisation output #28

@frankhezemans

Description

@frankhezemans

When performing optimisation with input argument prior=True, the results key "fun" will represent the participant-wise negative summed log posterior density at the optimised parameter values.

It might be useful to additionally save the summed log likelihood and summed log prior density at the optimised parameter values. For example, these separate quantities could be used for post-hoc model selection procedures / computing goodness-of-fit indices.

One approach to do this would be to calculate the log prior density as follows (solution by @lenarddome ):

## Fit.parameters are the parameters attribute of the cpm.optimisation object
## parameters is the Parameters object
prior_density = np.zeros(len(Fit.parameters))
for m, p in enumerate(Fit.parameters):
    parameters.update(p)
    prior_density[m] = parameters.PDF(log=True)

Then, the log likelihood is simply the log posterior density (i.e., "fun" * -1) minus the log prior density.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions