JohannesBuchner / UltraNest

Fit and compare complex models reliably and rapidly. Advanced nested sampling.
https://johannesbuchner.github.io/UltraNest/
Other
142 stars 30 forks source link

Docs update: Transformation of a dependent uniform prior #62

Closed Nicholaswogan closed 2 years ago

Nicholaswogan commented 2 years ago

Description

I am trying to specify a prior transformation from the uniform cube to the prior distribution for the following prior:

parameter_1_lower < parameter_1 < parameter_1_upper
parameter_2_lower < parameter_2 < parameter_2_upper
parameter_1 + parameter_2 < constant

What I Did

I saw your example for dependent priors: https://johannesbuchner.github.io/UltraNest/priors.html#Dependent-priors . But this example doesn't make it clear to me how to do the transformation. Part of this is my fault. I'm an atmospheric chemist, and only dabble in statistics.

So a question: How do I specify the transformation corresponding to the prior given above?

and a recommendation: The example for dependent priors is hard to follow. I recommend explaining the example more thoroughly, and also giving a simpler example for dependent priors (e.g. my prior above is simpler than your example).

JohannesBuchner commented 2 years ago

The constraints look non-trivial to me.

I am also not sure what distribution you want over the parameters. If you want it uniform in parameter_1 and parameter_2 within their lower and upper bounds, their sum will not be uniform between 0 and constant.

Maybe you can explain a bit where these constraints come from. Are they really hard constraints, or knowledge from previous experiments?

I would move either the first two or the last constraint into the likelihood function, whichever option is more relaxed (i.e., causes fewer rejections). This is achieved by returning a very low likelihood (e.g., -1e100), when the constraint is not met.

It is beneficial for the sampler if you can add a slight slope towards the good region of the constraint. e.g., -1e100 * (1 + parameter_1 + parameter_2) or similar. This is because if you use the exact same constant, this is a likelihood plateau, and the live points have to be reduced until it is traversed.

It can be beneficial to assume something with slightly softer boundaries than a hard limit. For example, if a normal distribution is assumed, the data could, if informative enough, update to something different.

Nicholaswogan commented 2 years ago

Ya sorry, I should explain more. I aim to infer posteriors for 3 parameters describing the structure of an atmosphere:

I want to specify log-uniform prior distributions for all parameters. But also, I want the prior to satisfy the fact that the cloud must be located at a pressure lower than the surface pressure (it must be in the sky!)

P_cloud_top + P_cloud_thickness < P_surface

Nicholaswogan commented 2 years ago

Maybe it makes sense to infer the following 3 parameters

With the priors

The transformation from the uniform cube to the prior distribution is then possible by doing the transformation, one step at a time.

Just so you know. I have very little prior knowledge of the value of these parameters. They could be anything between some pretty massive bounds. This is why I aim to use a wide uniform prior.

JohannesBuchner commented 2 years ago

OK, then I would recommend three independent log-uniform priors, and implement the last constraint in the likelihood as I mentioned above.

JohannesBuchner commented 2 years ago

The transformation from the uniform cube to the prior distribution is then possible by doing the transformation, one step at a time.

Ah, yes, with a shifted bound based on the previous priors, that also works.

That is what the dependent prior section "A similar effect can be achieved by defining transforms in sequence:" tries to demonstrate.

Nicholaswogan commented 2 years ago

Ok great thanks!

One related question. I also have parameters which are gas concentrations. These concentrations need to have uniform priors in log space, and also sum to <= 1 (in non-log space). I see your section in the docs about Fractional priors: https://johannesbuchner.github.io/UltraNest/priors.html#Fraction-parameters . Would it be straightforward to use a Dirichlet distribution in this case?

JohannesBuchner commented 2 years ago

Yes

Nicholaswogan commented 2 years ago

For alpha = 1, the dirichlet distribution samples the simplex uniformly. But I don't want to sample the simplex uniformly. I want to sample the simplex in such a way so that each parameter is log-uniformly distributed between, for example, (1e-10, 1).

Do you know a way to do this?

JohannesBuchner commented 2 years ago

Yeah, have a look at https://en.wikipedia.org/wiki/Dirichlet_distribution#Random_number_generation Assume you already have n "random" uniform numbers (the prior proposal in the cube variable), and follow the formula.

JohannesBuchner commented 2 years ago

You may also need https://en.wikipedia.org/wiki/Gamma_distribution#Generating_gamma-distributed_random_variables

JohannesBuchner commented 2 years ago

I have updated the docs which hopefully clarifies the dependent prior section. Let me know if you have further suggestions to the docs.