def test_triangle_init(): """Assert that initialization checks lower and upper bounds.""" # Should just run u = cp.Uniform(0., 1.) t = cp.Triangle(u - 1., u, u + 1.) cp.J(u, t) # Overlapping lb and ub with pytest.raises(ValueError): cp.Triangle(u - 0.5, u, u + 1.) with pytest.raises(ValueError): cp.Triangle(u - 1., u, u + 0.5) # Should initialize fine cp.Triangle(u - 1., 0., u + 0.5)
#!/usr/bin/env python from __future__ import print_function import openturns as ot import chaospy as cp import numpy as np # A chaospy Triangle distribution d0 = cp.Triangle(2.0, 3.5, 4.0) d1 = cp.Kumaraswamy(2.0, 3.0, -1.0, 4.0) d2 = cp.J(d0, d1) for chaospy_dist in [d0, d1, d2]: np.random.seed(42) # create an openturns distribution py_dist = ot.ChaospyDistribution(chaospy_dist) distribution = ot.Distribution(py_dist) print('distribution=', distribution) print('realization=', distribution.getRealization()) sample = distribution.getSample(10) print('sample=', sample[0:5]) point = [2.6]*distribution.getDimension() print('pdf= %.6g' % distribution.computePDF(point)) cdf = distribution.computeCDF(point) print('cdf= %.6g' % cdf) print('mean=', distribution.getMean()) print('mean(sampling)=', sample.computeMean()) print('std=', distribution.getStandardDeviation()) print('std(sampling)=', sample.computeStandardDeviationPerComponent()) print('skewness=', distribution.getSkewness())
delimiter='$', target_filename='input.json') decoder = uq.decoders.JSONDecoder(target_filename='output.json', output_columns=['g1']) execute = ExecuteLocal('{}/beam input.json'.format(os.getcwd())) actions = Actions(CreateRunDirectory('/tmp'), Encode(encoder), execute, Decode(decoder)) campaign = uq.Campaign(name='beam', params=params, actions=actions) vary = { "F": cp.Normal(1, 0.1), "L": cp.Normal(1.5, 0.01), "a": cp.Uniform(0.7, 1.2), "D": cp.Triangle(0.75, 0.8, 0.85) } campaign.set_sampler(uq.sampling.PCESampler(vary=vary, polynomial_order=1)) with QCGPJPool( template_params={'venv': '/home/bartek/.virtualenv/qcgpj7'}) as qcgpj: #with QCGPJPool() as qcgpj: campaign.execute(pool=qcgpj).collate() campaign.get_collation_result() campaign.campaign_db.dump() results = campaign.analyse(qoi_cols=['g1']) results.plot_sobols_treemap('g1', figsize=(10, 10))