chaospy icon indicating copy to clipboard operation
chaospy copied to clipboard

modelling conditional distributions in chaospy

Open gaoutham92 opened this issue 4 years ago • 4 comments

Hi,

Can conditional distributions be modelled in Chaospy, does it support them. Or the only way to model dependency is by using copulas.

gaoutham92 avatar Dec 10 '20 12:12 gaoutham92

You definetly can model conditional distributions in chaospy, but it is a big topic that deserves a lot more attention in the documentation than what is actually there. I really should get around to fixing that one of these days...

In the short term though, maybe I can help. What do you want to do?

jonathf avatar Dec 10 '20 13:12 jonathf

Hi,

Thanks for the reply. I want to model conditional lognormal distribution, conditioned upon Weibull marginal distribution. To be more precise, I have data for ocean waves - wave height and wave period. I want to fit a Weibull distribution based on wave height data and conditional lognormal distribution - conditioned upon Weibull based on wave period data and make a joint distribution.

So if you can make an example code snippet for generating conditional lognormal using any synthetic and less data samples(like 20 samples), it would be fine and helpful.

gaoutham92 avatar Dec 10 '20 13:12 gaoutham92

In chaospy dependencies are declared through parameters. So when you say "conditional lognormal" that can either be declared as:

chaospy.LogNormal(mu=chaospy.Weibull())

or

chaospy.LogNormal(sigma=chaospy.Weibull())

The latter is illigal as the Weibull distribution overlaps with 0 which causes a pole in the distribution which the software can not handle. This can not be easily fixed.

If you mean the former, that should be possible, but I discovered a bug trying it out. Log-normal's mu parameter lacks a handler for dealing with dependencies properly. I will look into fixing that soon.

Short term, you can make a workaround like this:

dist1 = numpy.e**chaospy.Weibull(2)
dist2 = chaospy.LogNormal(mu=0)*dist1
joint = chaospy.J(chaospy.Log(dist1), dist2)
samples = joint.sample(20)

This should be equivalent declaring dependencies through the mu parameter because Log(e**dist) == dist and LogNormal(mu=0)*e^dist == LogNormal(mu=dist).

jonathf avatar Dec 10 '20 20:12 jonathf

Hi,

Thanks for your quick response, I will try it out.

gaoutham92 avatar Dec 10 '20 21:12 gaoutham92