Hi Everyone,
I am new to OpenTURNS and I am wondering if it is possible to optimize this code ?
The objective is to generate a sample over multiple variables.
Thanks in advance
import numpy as np
import pandas as pd
import openturns as ot
distance_dist = ot.Uniform(300, 6000)
verticaldist = ot.Uniform(1.6, 4)
epsilon = 0.01
nsamples=1000
fbottomFunction = ot.SymbolicFunction(
["x0", "x1"], ["y0", "y1"],
f"y0 := max(min(((305+x0)*tan(x1*pi_/180)) + 152, 1990), 200) - {epsilon}; \
y1 := 1990")
bottomDistribution = ot.BayesDistribution(
ot.Uniform(),
ot.ComposedDistribution([distance_dist, verticaldist]),
fbottomFunction)
ftopFunction = ot.SymbolicFunction(["x0", "x1", "x2"], [f"x0+10", f"2000"])
cDistribution= ot.BayesDistribution(ot.Uniform(), bottomDistribution, ftopFunction)
cDistribution.setDescription(['top', 'base', 'dst', 'vdeg'])
fr = ot.SymbolicFunction(["xTop", "xBase", "xDst", "xvdeg"], ["y0", "y1"], "y0 := (-10*(xDst<=2500)) + (-15*(2500<xDst)*(xDst<=4500)) + (-30*(4500<xDst)); \
y1 := (10*(xDst<=2500)) + (15*(2500<xDst)*(xDst<=4500)) + (30*(4500<xDst));")
rDistribution = ot.BayesDistribution(ot.Uniform(), cDistribution, fr)
rDistribution.setDescription(['rdeg', 'top', 'base', 'dst', 'vdeg'])
fy = ot.SymbolicFunction(
["xR", "xTop", "xBase", "xDst", "xvdeg"],
["y0", "y1"], "y0 := (-18.5*(xDst<=2500)) + (-24*(2500<xDst)); \
y1 := (18.5*(xDst<=2500)) + (24*(2500<xDst));")
yDistribution = ot.BayesDistribution(ot.Uniform(), rDistribution, fy)
yDistribution.setDescription(['ydeg', 'rdeg', 'top', 'base', 'dst', 'vdeg'])
sample = yDistribution.getSample(10*nsamples)
yDistributionFinal = ot.UserDefined(
sample, [1./w[0] for w in np.array(yDistribution.computePDF(sample))])
yDistributionFinal.setDescription(yDistribution.getDescription())