def __init__(self, p1, p2, size): self.size = size self.KF1 = openturns.KrawtchoukFactory(size[0] - 1, p1) self.KF2 = openturns.KrawtchoukFactory(size[1] - 1, p2) steps = [] for i in xrange(5): for j in xrange(5): steps.append((i, j)) self.Q = [(self.KF1.build(n), self.KF2.build(m)) for n, m in steps]
def __init__(self, p1, p2, size): self.size = size self.KF1 = openturns.KrawtchoukFactory(size[0] - 1, p1) self.KF2 = openturns.KrawtchoukFactory(size[1] - 1, p2) steps = [] for i in xrange(5): for j in xrange(5): steps.append((i, j)) self.Qf = [(self.KF1.build(n), self.KF2.build(m)) for n, m in steps] self.q = [] N, M = self.size for qf in self.Qf: K1, K2 = qf arr = numpy.zeros(self.size) for x in xrange(N): for y in xrange(M): arr[x, y] = K1(x) * K2(y) self.q.append(arr)
# %% # STEP 1: Construction of the multivariate orthonormal basis # ---------------------------------------------------------- # %% # Create the univariate polynomial family collection which regroups the polynomial families for each direction. # %% polyColl = ot.PolynomialFamilyCollection(inputDimension) # %% # We could use the Krawtchouk and Charlier families (for discrete distributions). # %% polyColl[0] = ot.KrawtchoukFactory() polyColl[1] = ot.CharlierFactory() # %% # We could also use the automatic selection of the polynomial which corresponds to the distribution: this is done with the `StandardDistributionPolynomialFactory` class. # %% for i in range(inputDimension): marginal = distribution.getMarginal(i) polyColl[i] = ot.StandardDistributionPolynomialFactory(marginal) # %% # In our specific case, we use specific polynomial factories. # %% polyColl[0] = ot.HermiteFactory()
import openturns as ot import numpy as np from matplotlib import pyplot as plt n_functions = 8 function_factory = ot.KrawtchoukFactory() if function_factory.getClassName() == 'KrawtchoukFactory': function_factory = ot.KrawtchoukFactory(n_functions, .5) functions = [function_factory.build(i) for i in range(n_functions)] measure = function_factory.getMeasure() if hasattr(measure, 'getA') and hasattr(measure, 'getB'): x_min = measure.getA() x_max = measure.getB() else: x_min = measure.computeQuantile(1e-3)[0] x_max = measure.computeQuantile(1. - 1e-3)[0] n_points = 200 meshed_support = np.linspace(x_min, x_max, n_points) fig = plt.figure() ax = fig.add_subplot(111) for i in range(n_functions): plt.plot(meshed_support, [functions[i](x) for x in meshed_support], lw=1.5, label='$\phi_{' + str(i) + '}(x)$') plt.xlabel('$x$') plt.ylabel('$\phi_i(x)$') plt.xlim(x_min, x_max) plt.grid() box = ax.get_position() ax.set_position([box.x0, box.y0, box.width, box.height * 0.9]) plt.legend(loc='upper center', bbox_to_anchor=(.5, 1.25), ncol=4)