def test_validate_similarity_hellinger(): validator = uq.comparison.validate.ValidateSimilarityHellinger() assert(validator.element_name() == 'validate_similarity_hellinger') assert(validator.element_version() == '0.1') d1 = cp.Exponential(1) d2 = cp.Exponential(2) xmin = min(d1.lower[0], d2.lower[0]) xmax = max(d1.upper[0], d2.upper[0]) x = np.linspace(xmin, xmax, 100) p1 = d1.pdf(x) p2 = d2.pdf(x) distance = validator.compare(p1, p2) err = abs(distance - np.sqrt(1 - 2 * np.sqrt(2) / 3)) assert err < 1.e-2
def test_dependent_density(): """Assert that manually create dependency structure holds.""" distribution1 = chaospy.Exponential(1) distribution2 = chaospy.Uniform(lower=0, upper=distribution1) distribution = chaospy.J(distribution1, distribution2) assert distribution.pdf([0.5, 0.6]) == 0 assert distribution.pdf([0.5, 0.4]) > 0
def make_descriptive(): numpy.random.seed(1234) dist1 = chaospy.Normal(0, 1) samples1 = dist1.sample(40) dist2 = chaospy.Exponential() samples2 = dist2.sample(20) x = y = numpy.linspace(0, 2*numpy.pi, 200) x, y = numpy.cos(x), numpy.sin(y) pyplot.pie([0.5], colors=[COLOR1], radius=1, normalize=False, center=(-0.3, 0.3), startangle=45, wedgeprops={"width": 0.5, "alpha": 0.5, "lw": 4}) pyplot.plot(x-0.3, y+0.3, COLOR1, lw=4) pyplot.plot(x/2-0.3, y/2+0.3, COLOR1, lw=4) pyplot.bar([0, 0.6], [0.5, 1], bottom=[-0.6, -0.6], width=0.5, yerr=[0.2, 0.3], color=COLOR2) save("descriptive")
def test_dependent_pdf(): distribution1 = chaospy.Exponential(1) distribution2 = chaospy.Uniform(lower=0, upper=distribution1) distribution = chaospy.J(distribution1, distribution2) assert distribution.pdf([0.5, 0.6]) == 0 assert distribution.pdf([0.5, 0.4]) > 0
import pytest import chaospy from chaospy.recurrence import RECURRENCE_ALGORITHMS ANALYTICAL_DISTRIBUTIONS = { "beta": chaospy.Beta(4, 2), "expon": chaospy.Exponential(1), "gamma": chaospy.Gamma(2, 2), "lognorm": chaospy.LogNormal(-10, 0.1), "normal": chaospy.Normal(2, 3), "student": chaospy.StudentT(df=25, mu=0.5), "uniform": chaospy.Uniform(-1, 2), } @pytest.fixture(params=RECURRENCE_ALGORITHMS) def recurrence_algorithm(request): """Parameterization of name of recurrence algorithms.""" yield request.param @pytest.fixture(params=ANALYTICAL_DISTRIBUTIONS.keys()) def analytical_distribution(request): """Parameterization of distribution with analytical TTR methods.""" return ANALYTICAL_DISTRIBUTIONS[request.param]
import pylab as pp import numpy as np import chaospy as cp import os Directory = 'Projects/WDSA_Models/' FileName = '5Pipes.inp' maxTime = 30 dt =0.01 Transient_Times = np.arange(0,maxTime,dt) distribution = cp.J(cp.Normal(1,0.4))#,cp.Normal(1,0.4),cp.Normal(1,0.4),cp.Normal(1,0.4),cp.Normal(1,0.4)) demand_distribution = cp.Exponential(1.) Iterations = 1000 #samples = np.load(Directory + '5_pipes_varying_demand_samples.npy') #output = np.load(Directory + '5_pipes_varying_demand.npy') samples = np.load(Directory + '5_pipes_varying_friction_all_same_samples.npy') output = np.load(Directory + '5_pipes_varying_friction_all_same.npy') #### # Plotting input distributions #pp.figure() #pp.hist(samples[0,:],density=True,color='k',bins=40,alpha=0.50,label='Samples') #d = np.linspace(min(samples[0,:]),max(samples[0,:]),1000) #pp.plot(d,cp.Normal(1,0.4).pdf(d),'k',label='Roughness PDF') #pp.xlabel('Roughness (mm)') #pp.ylabel('Frequency')
axes[1, 2].set_xlabel("N = " + str(c)) axes[1, 2].xaxis.set_label_position('top') # 2nd row 4th plot axes[1, 3].hist(samples2c, bins = f) axes[1, 3].set_xlabel("N = " + str(c)) axes[1, 3].xaxis.set_label_position('top') # 2nd row 5th plot axes[1, 4].hist(samples2e, bins = f) axes[1, 4].set_xlabel("N = " + str(e)) axes[1, 4].xaxis.set_label_position('top') # Creating Exponential Distribution and samplesizes db3 = cp.Exponential(1, 0) samples3a = db3.sample(a, rule = 'S') samples3b = db3.sample(b, rule = 'S') samples3c = db3.sample(c, rule = 'S') samples3d = db3.sample(d, rule = 'S') samples3e = db3.sample(e, rule = 'S') # 3rd row 1st plot axes[2, 0].hist(samples3a, bins = f) axes[2, 0].set_xlabel("N = " + str(a)) axes[2, 0].xaxis.set_label_position('top') axes[2, 0].set_ylabel("Uniform") # 3rd row 2nd plot axes[2, 1].hist(samples3b, bins = f) axes[2, 1].set_xlabel("N = " + str(b))
@author: anecaise """ import numpy as np from matplotlib import pyplot as plt import chaospy # Create Fig fig = plt.figure(figsize=[5,3], num=100) """exponential""" dist = chaospy.Exponential() x = dist.sample(10, 'S') axes = fig.add_subplot(3,5, 1) # axes.set_ylabel('Y Values') axes.hist(x,bins=7,edgecolor='black') axes.set_ylabel("Exponential") axes.set_title('N=10') axes.set_xticks([]) axes.set_yticks([]) x = dist.sample(50, 'S') axes = fig.add_subplot(3,5, 2) # axes.set_ylabel('Y Values') axes.hist(x,bins=7,edgecolor='black')
plt.title("N=2000") plt.yticks([]) plt.xticks([]) plt.subplot(3, 5, 5) uniform = cp.J(cp.Uniform(0, 1)) x5k = uniform.sample(5000, rule="S") plt.hist(x5k, density=True, bins=100) plt.title("N=5000") plt.yticks([]) plt.xticks([]) #Exponential Distribution plt.subplot(3, 5, 6) uniform = cp.J(cp.Exponential()) x100 = uniform.sample(100, rule="S") plt.hist(x100, density=True, bins=100) plt.ylabel("Q_Exponential") plt.yticks([]) plt.xticks([]) plt.subplot(3, 5, 7) uniform = cp.J(cp.Exponential()) x500 = uniform.sample(500, rule="S") plt.hist(x500, density=True, bins=100) plt.yticks([]) plt.xticks([]) plt.subplot(3, 5, 8) uniform = cp.J(cp.Exponential())