Conditional Sampling with Distinct Distributions Based on Sampled Values

Hello :slight_smile:

I am currently working on a problem where the distribution applied to a variable depends on the value sampled from another variable. Specifically, I need to sample from one distribution and then, based on that sampled value, choose from among several other distributions for the next sampling step.

For example:

  • If X falls within a specific range, say [a, b], then Y should be sampled from distribution D_Y1.
  • If X is outside the range [a, b], then Y should be sampled from a completely different distribution D_Y2.

Is there a feature in OpenTURNS that allows this?

Thank you!

You may be looking for the Mixture distribution, the probability of each range will have to be normalized into relative weights for each pdf:
https://openturns.github.io/openturns/latest/user_manual/_generated/openturns.Mixture.html

Thank you! That looks interesting!

Do you know if it is possible to define the weights based on a distribution without implementing a custom distribution?

I was thinking about a using a JointByConditioningDistribution (BayesDistribution in v1.23) something like this:

uniform_distribution = ot.Uniform(0, 1.0)

collDist = [ot.Triangular(1.0, 2.0, 4.0), ot.Normal(-1.0, 1.0)]
myMixture = ot.Mixture()

parameter_weights = ot.SymbolicFunction(["uniform_sample"], ["[ot.Triangular(1.0, 2.0, 4.0), ot.Normal(-1.0, 1.0)]","[uniform_sample, 1-uniform_sample]"])
combined_2d_velocity_distribution = ot.BayesDistribution(
    myMixture, uniform_distribution, parameter_weights
)

However, I am getting an error saying

expected a link function with output dimension equal to the number of parameters of the conditioned distribution.

I guess this is not what the two distribution were made for, I am also not sure if it is allowed to use ot expressions in SymbolicFuntions.

Is there a way to link the output of the uniform distribution to the weights of the mixture?

Thank you!