chaospy
chaospy copied to clipboard
modelling conditional distributions in chaospy
Hi,
Can conditional distributions be modelled in Chaospy, does it support them. Or the only way to model dependency is by using copulas.
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?
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.
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)
.
Hi,
Thanks for your quick response, I will try it out.