pints-team / pints

Probabilistic Inference on Noisy Time Series
http://pints.readthedocs.io
Other
224 stars 33 forks source link

Hierarchical modelling #1248

Closed DavAug closed 2 months ago

DavAug commented 3 years ago

There are some issues that have discussed hierarchical modelling before #1231 #1232 #1134 . Here is one more attempt that I've implemented in my repository https://erlotinib.readthedocs.io/en/latest/index.html.

New features that are going to be implemented with this issue:

DavAug commented 3 years ago

@MichaelClerx @martinjrobins @ben18785 @chonlei

I am happy to implement this solution. I am just wondering what your thoughts on identifying the parameters are, because it can get complicated.

Example: Imagine 10 log-likelihoods with 5 parameters. Each parameter is modelled by a population model with 2 parameters. The final HierarchicalLogLikelihood ends up being 60 dimensional, and the order is [parameter 1 loglikelihood 1, parameter 1 loglikelihood 2, ..., parameter 1 loglikelihood 10, parameter 1 poulation model 1, parameter 2 poulation model 1, parameter 2 loglikelihood 1, parameter 2 loglikelihood 2, ..., parameter 2 loglikelihood 10, parameter 1 poulation model 2, parameter 2 poulation model 2, ...]

I hope the pattern is somewhat clear, but you probably see my point of potential confusion. And when the popualtion models start to have different numbers of parameters it becomes more complicated. In my repository I circumvented this by giving each parameter meaningful names, but pints doesn't support names at the moment. Any thoughts?

MichaelClerx commented 3 years ago

What are the actions you want to do where the names are used?

DavAug commented 3 years ago

The names are not really used by anything. It's more for someone evaluating the hierarchical loglikelihood to understand which parameter index corresponds to which model parameter, if that makes sense?

MichaelClerx commented 3 years ago

hmmmm... you could have a dict mapping names to indices, I guess?

MichaelClerx commented 3 years ago

Can you point me towards the classes where you've solved this problem in Erlotinib ?

(I kept thinking it was a german pun. So glad to find out it's a drug :D )

DavAug commented 3 years ago

Yes a dict or just a list of names?

Hahah yes it's a drug 😂 So here is the population model classes that I've implemented https://erlotinib.readthedocs.io/en/latest/population_models.html. In the bottom you can find the base class (the compute_log_likelihood method would probably be the call method in pints).

And here is the HierarchicalLogLikelihood https://erlotinib.readthedocs.io/en/latest/log_pdfs.html#erlotinib.HierarchicalLogLikelihood

MichaelClerx commented 3 years ago

That looks quite similar to what we have for parameter names in plots!

See also #1171 :D and the tickets linked therein

DavAug commented 3 years ago

I've implemented this ProblemModellingController class to make my life a little easier, so I wouldn't have to keep track of it (here is a notebook, if you'd like to see it in action https://nbviewer.jupyter.org/github/DavAug/erlotinib/blob/main/analysis/treating_lung_cancer/control_group_analysis/tgi_koch_2009_reparametrised_model/population_inference.ipynb). But I guess that wouldn't necessarily be something for pints.