Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hierarchical distributions for all parameters in model config #708

Closed
wd60622 opened this issue May 31, 2024 · 4 comments · Fixed by #743
Closed

Hierarchical distributions for all parameters in model config #708

wd60622 opened this issue May 31, 2024 · 4 comments · Fixed by #743
Labels
enhancement New feature or request model config
Milestone

Comments

@wd60622
Copy link
Contributor

wd60622 commented May 31, 2024

The _create_likelihood_distribution accepts a nested dictionary. i.e.

"likelihood": {
"dist": "Normal",
"kwargs": {
"sigma": {"dist": "HalfNormal", "kwargs": {"sigma": 2}},
},
},

That is based on the single recursive section of that method

It might be beneficial to allow this nesting for other parameters in the model. For example, a spin on the current gamma_control can be viewed as hierarchical parameters for the control coefficients. Where the "gamma_control_mu" and "gamma_control_sigma" are then scaler population parameters for "gamma_control"

model_config = {
    ..., 
    "gamma_control": {
        "dist": "Normal", 
        "kwargs": {
            # "mu": 0,
            "mu": {"dist": "Normal", "kwargs": {"mu": 0, "sigma": 1}}, 
            # "sigma": 2, 
            "sigma": {"dist": "HalfNormal", "kwargs": {"sigma": 1}}, 
        }, 
        # Implicit in the model to have dims=control but could be explicit as well
        # "dims": "control"
    }, 
    ..., 
}

Overall, think it would be easy to add and would consolidate the model_config logic in the process.
Open to other's thoughts

@wd60622 wd60622 added enhancement New feature or request model config labels May 31, 2024
@ColtAllen
Copy link
Collaborator

I've been wanting to nest distributions on the CLV side because Beta priors benefit from a pooled approach:

https://discourse.pymc.io/t/prior-distribution-for-certainty-parameter-of-beta-distribution/1071

However, as-written _create_likelihood_distribution doesn't support Beta distributions.

@wd60622
Copy link
Contributor Author

wd60622 commented May 31, 2024

I've been wanting to nest distributions on the CLV side because Beta priors benefit from a pooled approach:

https://discourse.pymc.io/t/prior-distribution-for-certainty-parameter-of-beta-distribution/1071

However, as-written _create_likelihood_distribution doesn't support Beta distributions.

Good to know. Thanks for the link

Can you point out where you had this in mind in clv module for reference.

Will Beta be the only likelihood you use? Or do they overlap with the mmm likelihood stored in that method?

In my mind, there will be some overlap in functionality so itd make sense to at least pull out the method into function. Then maybe have two separate main functions if needed

@ColtAllen
Copy link
Collaborator

ColtAllen commented May 31, 2024

Can you point out where you had this in mind in clv module for reference.

BetaGeoModel, ShiftedBetaGeoModelIndividual, and the upcoming BetaGeoBetaBinomModel all require Beta distributions.

Will Beta be the only likelihood you use? Or do they overlap with the mmm likelihood stored in that method?

Pooling distributions like Pareto and Uniform would also be needed. I used both in my fork of lifetimes:

https://github.com/ColtAllen/btyd/blob/main/btyd/models/beta_geo_model.py#L110

This was the only way I could get the MCMC posterior means to match the MLE results from research during testing. Right now BetaGeoModel will return very different parameter estimates for MAP/MCMC.

In my mind, there will be some overlap in functionality so itd make sense to at least pull out the method into function. Then maybe have two separate main functions if needed.

Could also move create_likelihood_distribution into the base ModelBuilder class so it's supported across the library.

@juanitorduz
Copy link
Collaborator

Yes! This would be great indeed!

@wd60622 wd60622 changed the title Nested distributions for all parameters in model config Hierarchical distributions for all parameters in model config Jun 12, 2024
@juanitorduz juanitorduz added this to the 0.7.0 milestone Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request model config
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants