def getWindRose(): """Gets a chaospy distribution, which is initialized with a distribution class I created and extended by it. """ amalia_wind_rose = amaliaWindRose() # amalia_wind_rose = amaliaWindRoseRaw() # Using this option needs updating # amalia_wind_rose = amaliaWindRoseRaw01() # Set the necessary functions to construct a chaospy distribution windRose = cp.construct( cdf=lambda self, x: amalia_wind_rose.cdf(x), bnd=lambda self: amalia_wind_rose.bnd(), pdf=lambda self, x: amalia_wind_rose.pdf(x), str=lambda self: amalia_wind_rose.str() ) windrose_dist = windRose() # print windrose_dist # print windrose_dist.pdf(180) # print windrose_dist.pdf(365) # print windrose_dist.range() # Dynamically add method if amalia_wind_rose.str() == 'Amalia windrose': windrose_dist.get_zero_probability_region = amalia_wind_rose.get_zero_probability_region return windrose_dist
def getWeibull(): my_weibull = myWeibull() # Set the necessary functions to construct a chaospy distribution Weibull = cp.construct( cdf=lambda self, x: my_weibull.cdf(x), bnd=lambda self: my_weibull.bnd(), pdf=lambda self, x: my_weibull.pdf(x), mom=lambda self, k: my_weibull.mom(k), str=lambda self: my_weibull.str() ) weibull_dist = Weibull() return weibull_dist
def getWeibull(): # my_weibull = myWeibull() my_weibull = TruncatedWeibull() # my_weibull = TruncatedWeibull01() # Set the necessary functions to construct a chaospy distribution Weibull = cp.construct( cdf=lambda self, x: my_weibull.cdf(x), bnd=lambda self: my_weibull.bnd(), pdf=lambda self, x: my_weibull.pdf(x), # mom=lambda self, k: my_weibull.mom(k), str=lambda self: my_weibull.str() ) weibull_dist = Weibull() # Dynamically add method weibull_dist.get_truncation_value = my_weibull.get_truncation_value return weibull_dist
def getWindRose(): amalia_wind_rose = amaliaWindRose() # amalia_wind_rose = amaliaWindRoseRaw() # Using this option needs updating # Set the necessary functions to construct a chaospy distribution windRose = cp.construct( cdf=lambda self, x: amalia_wind_rose.cdf(x), bnd=lambda self: amalia_wind_rose.bnd(), pdf=lambda self, x: amalia_wind_rose.pdf(x), str=lambda self: amalia_wind_rose.str() ) windrose_dist = windRose() # print windrose_dist # print windrose_dist.pdf(180) # print windrose_dist.pdf(365) # print windrose_dist.range() return windrose_dist
integral = sum(f(nodes[0])*weights) return integral def pdf(self, x): return kernel.pdf(x) def cdf(self, x): return kernel.integrate_box1d(min(samples), x) def bnd(self): return min(samples), max(samples) if __name__ == '__main__': quad_deg = 4 # standard approach dist_real = cp.Normal() nodes_std, weights_std = cp.generate_quadrature(quad_deg, dist_real, rule = "G") integral_std = eval_integral(test_function, nodes_std, weights_std) # convoluted approach samples = random.normal(0, 1, size=100000) kernel = gaussian_kde(samples) Dist = cp.construct(pdf=pdf, cdf=cdf, bnd=bnd) dist_approx = Dist() nodes_approx, weights_approx = cp.generate_quadrature(2*quad_deg, dist_approx, rule="G") integral_approx = eval_integral(test_function, nodes_approx, weights_approx) print integral_std print integral_approx