Hi Regis,

Thank you for this detailed answer.

- I am using the latest release from conda (OT 1.9, python 3.6.2, latest numpy, 
etc.) ,
- For the sample, I need it to generate externally the output (cost code that 
cannot be integrated into OT as model),
- I have to convert ot.Sample into np.array because it is then used by other 
functions to create the simulations, etc.

If I understood correctly, I can create the projection strategy using this 
snippet:

basis = ot.AdaptiveStieltjesAlgorithm(dist)
measure = basis.getMeasure()
quad = ot.Indices(in_dim)
for i in range(in_dim):
    quad[i] = degree + 1

comp_dist = ot.GaussProductExperiment(measure, quad)
proj_strategy = ot.IntegrationStrategy(comp_dist)

inv_trans = 
ot.Function(ot.MarginalTransformationEvaluation([measure.getMarginal(i) for i 
in range(in_dim)], distributions))
sample = np.array(inv_trans(comp_dist.generate()))


It seems to work. Except that the basis does not work with 
ot.FixedStrategy(basis, dim_basis). I get a non implemented method error.

After I get the sample and the corresponding output, what is the way to go? 
Which arguments do I need to use for the
ot.FunctionalChaosAlgorithm? 

I am comparing the Q2 and on Ishigami and I was only able to get correct 
results using:

pc_algo = ot.FunctionalChaosAlgorithm(sample, output, dist, trunc_strategy)

But for least square strategy I had to use this:

pc_algo = ot.FunctionalChaosAlgorithm(sample, output)


Is it normal?


Pamphile ROY
Chercheur doctorant en Quantification d’Incertitudes
CERFACS - Toulouse (31) - France
+33 (0) 5 61 19 31 57
+33 (0) 7 86 43 24 22



> Le 5 oct. 2017 à 15:40, regis lebrun <[email protected]> a 
> écrit :
> 
> Hi Pamphile,
> 
> 
> 1) The problem:
> The problem you get is due to the fact that in your version of OpenTURNS (1.7 
> I suppose), the GaussProductExperiment class has a different way to handle 
> the input distribution than the other WeightedExperiment classes: it 
> generates the quadrature rule of the *standard representatives* of the 
> marginal distributions instead of the marginal distributions. It does not 
> change the rate of convergence of the PCE algorithm and allows to use 
> specific algorithms for distributions with known orthonormal polynomials. It 
> is not explained in the documentation and if you ask the doe for its 
> distribution it will give you the initial distribution instead of the 
> standardized one.
> 
> 2) The mathematical background:
> The generation of quadrature rules for arbitrary 1D distributions is a badly 
> conditioned problem. Even if the quadrature rule is well-defined (existence 
> of moments of any order, distribution characterized by these moments), the 
> application that maps the recurrence coefficients of the orthogonal 
> polynomials to their value can have a very large condition number. As a 
> result, the adaptive integration used to compute the recurrence coefficients 
> of order n, based on the values of the polynomials of degree n-1 and n-2, can 
> lead to wrong values and all the process falls down.
> 
> 3) The current state of the software:
> Since version 1.8, OpenTURNS no more generates the quadrature rule of the 
> standard representatives, but the quadrature rule of the actual marginal 
> distributions. The AdaptiveStieltjesAlgorithm class, introduced in release 
> 1.8, is much more robust than the previous orthonormalization algorithms and 
> is able to handle even stiff problems. There are still difficult situations 
> (distributions with discontinuous PDF inside of the range, fixed in OT 1.9, 
> or really badly conditioned distributions, hopefully fixed when ticket#885 
> will be solved) but most usual situations are under control even with 
> marginal degrees of order 20.
> 
> 4) The (probable) bug in your code and the way to solve it
> You must be aware of the fact that the distribution you put into your 
> WeightedExperiment object will be superseded by the distribution 
> corresponding to your OrthogonalBasisFactory inside of the 
> FunctionalChaosAlgorithm. If you need to have the input sample before to run 
> the functional chaos algorithm, then you have to build your transformation by 
> hand. Assuming that you already defined your projection basis called 
> 'myBasis', your marginal integration degrees 'myDegrees' and your marginal 
> distributions 'myMarginals', you have to write (in OT 1.7):
> 
> # Here the explicit cast into a NumericalMathFunction is to be able to 
> evaluate the transformation over a sample
> myTransformation = 
> ot.NumericalMathFunction(ot.MarginalTransformationEvaluation([myBasis.getDistribution().getMarginal(i)
>  for i in range(dimension), myMarginals))
> sample = 
> myTransformation(ot.GaussProductExperiment(myBasis.getDistribution(), 
> myDegrees).generate())
> 
> 
> You should avoid to cast OT objects into np objects as much as possible, and 
> if you cannot avoid these casts you should do them only in the sections where 
> they are needed. They can be expansive for large objects, and if the sample 
> you get from generate() is used only as an argument of a 
> NumericalMathFunction, then it will be converted back into a NumericalSample!
> 
> Best regards
> 
> Régis
> ________________________________
> De : roy <[email protected]>
> À : users <[email protected]> 
> Envoyé le : Jeudi 5 octobre 2017 11h13
> Objet : [ot-users] Sample transformation
> 
> 
> 
> Hi,
> 
> I am facing consistency concerns in the API regarding distributions and 
> sampling.
> 
> The initial goal was to get the sampling for Polynomial Chaos as I must not 
> use the model variable.
> So for least square strategy I do something like this:
> 
> proj_strategy = ot.LeastSquaresStrategy(montecarlo_design)
> sample = np.array(proj_strategy.getExperiment().generate())
> 
> sample is correct as the bounds of each feature lie in the corresponding 
> ranges.
> 
> But now if I want to use IntegrationStrategy:
> 
> ot.IntegrationStrategy(ot.GaussProductExperiment(dists, list))
> sample = np.array(proj_strategy.getExperiment().generate())
> 
> sample’s outputs lie between [-1, 1] which does not corresponds to the 
> distribution I have initially.
> 
> So I used the conversion class but it does not work well with 
> GaussProductExperiment as it requires [0, 1] instead of [-1, 1].
> 
> Thus I use this hack:
> 
> # Convert from [-1, 1] -> input distributions
> marg_inv_transf = ot.MarginalTransformationEvaluation(distributions, 1)
> sample = (proj_strategy.getExperiment().generate() + 1) / 2.
> 
> 
> Is it normal that the distribution classes are not returning in the same 
> intervals?
> 
> 
> Thanks for your support!
> 
> 
> Pamphile ROY
> Chercheur doctorant en Quantification d’Incertitudes
> CERFACS - Toulouse (31) - France
> +33 (0) 5 61 19 31 57
> +33 (0) 7 86 43 24 22
> 
> 
> _______________________________________________
> OpenTURNS users mailing list
> [email protected]
> http://openturns.org/mailman/listinfo/users

_______________________________________________
OpenTURNS users mailing list
[email protected]
http://openturns.org/mailman/listinfo/users

Reply via email to