this is the code in the Chaospy.
the first, I run the code to consider what is the value of three coefficients
import chaospy as cp
import numpy as np
import matplotlib.pyplot as plt
distribution = cp.J(cp.Uniform(0.054, 0.066), cp.Uniform(0.9, 1.1), cp.Uniform( 45, 55))
cp.seed (20)
samples = distribution.sample(20,"L")
print (samples)
this is the output:
nodes1 = np.array([0.05675, 0.05934, 0.05633, 0.0557 , 0.05702, 0.06401, 0.06322, 0.06571, 0.06099, 0.05832, 0.06196, 0.06463, 0.05507, 0.06351, 0.06287, 0.06122, 0.05407, 0.05985, 0.05774,0.06015])
nodes2 = np.array([0.9486, 0.9095, 0.9856, 0.9318, 1.0477, 1.0489,1.0663, 0.9184, 0.9646, 1.0345, 1.0168, 1.0565, 0.9727, 0.9907, 0.9277, 0.9548, 1.0933, 1.0751,1.0026, 1.0231])
nodes3 = np.array([51.813, 54.279, 52.659, 51.197 , 46.629, 49.791, 48.581, 54.799, 46.413, 47.078, 52.367, 48.204, 50.389, 45.402, 47.893, 50.796 , 49.332, 53.323, 53.713, 45.757])
and then.
I use then these values to simulation I have the correspond to result. I called “evals”
example: with the node1 = 0.05675, node2 = 0.9486, node3 = 51.813 after I run simulation I have the evals = 0.0204232.
I have to simulate all case.
when I have the result all case. I will run the code
import chaospy as cp
import numpy as np
import matplotlib.pyplot as plt
nodes1 = np.array([0.05675, 0.05934, 0.05633, 0.0557 , 0.05702, 0.06401, 0.06322, 0.06571, 0.06099, 0.05832, 0.06196, 0.06463, 0.05507, 0.06351, 0.06287, 0.06122, 0.05407, 0.05985, 0.05774,0.06015])
nodes2 = np.array([0.9486, 0.9095, 0.9856, 0.9318, 1.0477, 1.0489,1.0663, 0.9184, 0.9646, 1.0345, 1.0168, 1.0565, 0.9727, 0.9907, 0.9277, 0.9548, 1.0933, 1.0751,1.0026, 1.0231])
nodes3 = np.array([51.813, 54.279, 52.659, 51.197 , 46.629, 49.791, 48.581, 54.799, 46.413, 47.078, 52.367, 48.204, 50.389, 45.402, 47.893, 50.796 , 49.332, 53.323, 53.713, 45.757])
distribution = cp.J(cp.Uniform(0.054, 0.066), cp.Uniform(0.9, 1.1), cp.Uniform( 45, 55))
nodes = np.vstack([nodes1, nodes2, nodes3])
evals = np.array([0.0204232,0.0205054,0.0204971,0.0204463,0.0206686,0.0206678,0.0206883,0.0204627,0.020426,0.0206532,0.0206322,0.020677,0.0204431,0.0205319,0.0204508,0.0204115,0.020721,0.0206988,0.0206179,0.0206418])
polynomial_expansion = cp.orth_ttr(2, distribution)
approx = cp.fit_regression(polynomial_expansion, nodes, evals)
expected = cp.E( approx, distribution)
variance = cp.Var(approx, distribution)
deviation = cp.Std( approx, distribution)
sobol_t = cp.Sens_t(approx,distribution)
print (sobol_t)
print (expected)
print(deviation)
samples = distribution.sample(10000,"L")
evaluations = approx(*samples)
plt.hist(evaluations,bins = 80, rwidth =1, color = 'b',edgecolor='K')
plt.xlabel ('Cd')
plt.ylabel ('numbers')
plt.grid(True,linestyle ='dotted' )
plt.show()
the result that I need is the mean and variance value of "evals " and the last step I sample 10000 sampling to plot the histogram of the 10000 sampling.
thank you