def __init__(self, beta_coeff, idx_set, jpdf): self.beta_coeff = beta_coeff self.idx_set = idx_set self.jpdf = jpdf self.N = jpdf.getDimension() # get the distribution type of each random variable dist_types = [] for i in range(self.N): dist_type = self.jpdf.getMarginal(i).getName() dist_types.append(dist_type) # create orthogonal univariate bases poly_collection = ot.PolynomialFamilyCollection(self.N) for i in range(self.N): pdf = jpdf.getDistributionCollection()[i] algo = ot.AdaptiveStieltjesAlgorithm(pdf) poly_collection[i] = ot.StandardDistributionPolynomialFactory(algo) # create multivariate basis multivariate_basis = ot.OrthogonalProductPolynomialFactory( poly_collection, ot.EnumerateFunction(self.N)) # get enumerate function (multi-index handling) enum_func = multivariate_basis.getEnumerateFunction() # get epansion self.expansion = multivariate_basis.getSubBasis( transform_multi_index_set(idx_set, enum_func)) # create openturns surrogate model sur_model = ot.FunctionCollection() for i in range(len(self.expansion)): multi = str(beta_coeff[i]) + '*x' help_function = ot.SymbolicFunction(['x'], [multi]) sur_model.add(ot.ComposedFunction(help_function, self.expansion[i])) self.surrogate_model = np.sum(sur_model)
#! /usr/bin/env python from __future__ import print_function import openturns as ot basisSize = 3 sampleSize = 3 X = ot.Sample(sampleSize, 1) for i in range(sampleSize): X[i, 0] = i + 1.0 Y = ot.Sample(sampleSize, 1) phis = [] for j in range(basisSize): phis.append(ot.SymbolicFunction(['x'], ['x^' + str(j + 1)])) basis = ot.Basis(phis) for i in range(basisSize): print(ot.FunctionCollection(basis)[i](X)) proxy = ot.DesignProxy(X, basis) full = range(basisSize) design = proxy.computeDesign(full) print(design) proxy.setWeight([0.5] * sampleSize) design = proxy.computeDesign(full) print(design)