1 //                                               -*- C++ -*-
2 /**
3  *  @brief A class which implements the Gaussian process
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_GAUSSIANPROCESS_HXX
22 #define OPENTURNS_GAUSSIANPROCESS_HXX
23 
24 #include "openturns/ProcessImplementation.hxx"
25 #include "openturns/SquareMatrix.hxx"
26 #include "openturns/CovarianceModel.hxx"
27 #include "openturns/TrendTransform.hxx"
28 #include "openturns/HMatrix.hxx"
29 #include "openturns/Process.hxx"
30 
31 BEGIN_NAMESPACE_OPENTURNS
32 
33 /**
34  * @class GaussianProcess
35  *
36  * The implementation of the Gaussian process class
37  */
38 class OT_API GaussianProcess
39   : public ProcessImplementation
40 {
41   CLASSNAME
42 
43 public:
44 
45   /** Default constructor */
46   GaussianProcess();
47 
48   /** Standard constructor  */
49   GaussianProcess(const TrendTransform & trend,
50                   const CovarianceModel & covarianceModel,
51                   const Mesh & mesh);
52 
53   /** Standard constructor  */
54   GaussianProcess(const CovarianceModel & covarianceModel,
55                   const Mesh & mesh);
56 
57   /** Virtual constructor */
58   GaussianProcess * clone() const override;
59 
60   /** String converter */
61   String __repr__() const override;
62 
63   /** String converter  - pretty print */
64   String __str__(const String & offset = "") const override;
65 
66   /** Mesh accessor */
67   void setMesh(const Mesh & mesh) override;
68   void setTimeGrid(const RegularGrid & timeGrid) override;
69 
70   /** Set sampling method accessor */
71   enum SamplingMethod { CHOLESKY, HMAT, GIBBS };
72   void setSamplingMethod(const SamplingMethod samplingMethod);
73 
74   /** Realization accessor */
75   Field getRealization() const override;
76 private:
77   Sample getRealizationCholesky() const;
78   Sample getRealizationGibbs() const;
79   Sample getRealizationHMatrix() const;
80 public:
81 
82   /** Covariance model accessor */
83   CovarianceModel getCovarianceModel() const override;
84 
85   /** Trend accessor */
86   TrendTransform getTrend() const override;
87 
88   /** Check if the process is stationary */
89   Bool isStationary() const override;
90 
91   /** Check if the process trend is stationary */
92   Bool isTrendStationary() const;
93 
94   /** Check if the process is Normal */
95   Bool isNormal() const override;
96 
97   /** Get the process corresponding to indices components */
98   Process getMarginal(const Indices & indices) const override;
99 
100   /** Method save() stores the object through the StorageManager */
101   void save(Advocate & adv) const override;
102 
103   /** Method load() reloads the object from the StorageManager */
104   void load(Advocate & adv) override;
105 
106 protected:
107 
108   /** Initialization of the process */
109   void initialize() const;
110 
111   /** Check if the trend function is stationary */
112   void checkStationaryTrend() const;
113 
114 
115   /** Covariance model */
116   CovarianceModel covarianceModel_;
117 
118   /** Cholesky factor  */
119   mutable TriangularMatrix covarianceCholeskyFactor_;
120 
121   /** Cholesky factor  */
122   mutable HMatrix covarianceHMatrix_;
123 
124   /** Flag to manage process initialization */
125   mutable Bool isInitialized_ = false;
126 
127   /** Flag to tell if the process has a stationary trend */
128   mutable Bool hasStationaryTrend_;
129   mutable Bool checkedStationaryTrend_;
130 
131   /** Trend function */
132   TrendTransform trend_;
133 
134   mutable Point stationaryTrendValue_;
135 
136   /** Sampling method */
137   UnsignedInteger samplingMethod_ = SamplingMethod::CHOLESKY;
138 
139 }; /* class GaussianProcess */
140 
141 END_NAMESPACE_OPENTURNS
142 
143 #endif /* OPENTURNS_NORMALPROCESS_HXX */
144