1 //                                               -*- C++ -*-
2 /**
3  *  @brief Simulation algorithm to estimate Sobol indices
4  *
5  *  Copyright 2005-2021 Airbus-EDF-IMACS-ONERA-Phimeca
6  *
7  *  This library is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU Lesser General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This library is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU Lesser General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Lesser General Public License
18  *  along with this library.  If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 #ifndef OPENTURNS_SOBOLSIMULATIONALGORITHM_HXX
22 #define OPENTURNS_SOBOLSIMULATIONALGORITHM_HXX
23 
24 #include "openturns/SimulationAlgorithm.hxx"
25 #include "openturns/SobolSimulationResult.hxx"
26 #include "openturns/SobolIndicesAlgorithm.hxx"
27 
28 BEGIN_NAMESPACE_OPENTURNS
29 
30 /**
31  * @class SobolSimulationAlgorithm
32  */
33 
34 class OT_API SobolSimulationAlgorithm
35   : public SimulationAlgorithm
36 {
37 
38   CLASSNAME
39 public:
40   /** Default constructor */
41   SobolSimulationAlgorithm();
42 
43   /** Constructor with parameters */
44   SobolSimulationAlgorithm(const Distribution & distribution,
45                            const Function & model,
46                            const SobolIndicesAlgorithm & estimator);
47 
48   /** Virtual constructor */
49   SobolSimulationAlgorithm * clone() const override;
50 
51   /** RandomVector accessor */
52   Distribution getDistribution() const;
53 
54   /** Result accessor */
55   SobolSimulationResult getResult() const;
56 
57   /** Criterion type on standard deviation accessor */
58   void setIndexQuantileLevel(const Scalar indexQuantileLevel);
59   Scalar getIndexQuantileLevel() const;
60 
61   /** Maximum of standard deviation on each component */
62   void setIndexQuantileEpsilon(const Scalar indexQuantileEpsilon);
63   Scalar getIndexQuantileEpsilon() const;
64 
65   /** Estimator accessor */
66   void setEstimator(const SobolIndicesAlgorithm & estimator);
67   SobolIndicesAlgorithm getEstimator() const;
68 
69   /** Size of evaluation blocks */
70   void setBatchSize(const UnsignedInteger & replicationSize);
71   UnsignedInteger getBatchSize() const;
72 
73   /** String converter */
74   String __repr__() const override;
75 
76   /** Performs the actual computation. */
77   void run() override;
78 
79   /** Method save() stores the object through the StorageManager */
80   void save(Advocate & adv) const override;
81 
82   /** Method load() reloads the object from the StorageManager */
83   void load(Advocate & adv) override;
84 
85   /** Draw the probability convergence at the given level */
86   Graph drawFirstOrderIndexConvergence(const UnsignedInteger marginalIndex = 0,
87                                        const Scalar level = ResourceMap::GetAsScalar("ProbabilitySimulationResult-DefaultConfidenceLevel")) const;
88   Graph drawTotalOrderIndexConvergence(const UnsignedInteger marginalIndex = 0,
89                                        const Scalar level = ResourceMap::GetAsScalar("ProbabilitySimulationResult-DefaultConfidenceLevel")) const;
90 protected:
91   /** Draw the probability convergence at the given level */
92   Graph drawIndexConvergence(const UnsignedInteger marginalIndex,
93                              const Scalar level,
94                              const String & label) const;
95 
96   /** Result accessor */
97   void setResult(const SobolSimulationResult & result);
98 
99   // The vector to study
100   Distribution distribution_;
101   Function model_;
102 
103   // Estimator type
104   SobolIndicesAlgorithm estimator_;
105 
106   // Size of evaluation blocks
107   UnsignedInteger batchSize_;
108 
109   // Result of the simulation
110   SobolSimulationResult result_;
111 
112   // stopping criteria on the indices estimates
113   Scalar indexQuantileLevel_;
114   Scalar indexQuantileEpsilon_;
115 
116   // criterion to discriminate a small/controlled/large index
117   Scalar smallIndexThreshold_;
118 
119 } ; /* class SobolSimulationAlgorithm */
120 
121 
122 END_NAMESPACE_OPENTURNS
123 
124 #endif /* OPENTURNS_SOBOLSIMULATIONALGORITHM_HXX */
125