Loading...
Searching...
No Matches
Fang2017filter.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ██╗████████╗██╗ ██╗ █████╗ ██████╗ █████╗ ███████╗██╗ ██╗
3 ██║╚══██╔══╝██║ ██║██╔══██╗██╔════╝██╔══██╗ ██╔════╝██║ ██║
4 ██║ ██║ ███████║███████║██║ ███████║█████╗█████╗ ██║ ██║
5 ██║ ██║ ██╔══██║██╔══██║██║ ██╔══██║╚════╝██╔══╝ ╚██╗ ██╔╝
6 ██║ ██║ ██║ ██║██║ ██║╚██████╗██║ ██║ ██║ ╚████╔╝
7 ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═══╝
8
9 * In real Time Highly Advanced Computational Applications for Finite Volumes
10 * Copyright (C) 2017 by the ITHACA-FV authors
11-------------------------------------------------------------------------------
12License
13 This file is part of ITHACA-FV
14 ITHACA-FV is free software: you can redistribute it and/or modify
15 it under the terms of the GNU Lesser General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18 ITHACA-FV is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU Lesser General Public License for more details.
22 You should have received a copy of the GNU Lesser General Public License
23 along with ITHACA-FV. If not, see <http://www.gnu.org/licenses/>.
24Class
25 Fang2017filter
26Description
27 A class that implements the Ensamble Kalman Filter in the version by Fang et al. 2017
28SourceFiles
29 Fang2017filter.C
30\*---------------------------------------------------------------------------*/
31
36
37#ifndef fang2017filter_H
38#define fang2017filter_H
39
40#include "ITHACAutilities.H"
41#include "muq2ithaca.H"
42#include "ensembleClass.H"
43
44
45
46namespace ITHACAmuq
47{
48//--------------------------------------------------------------------------
51class Fang2017filter
52{
53 int Nsamples = 0;
54
55 int stateSize = 0;
56 int parameterSize = 0;
57 int observationSize = 0;
58
59 int timeStepI = 0;
60 double startTime;
61 double deltaTime;
62 double endTime;
63 int Ntimes;
64
65 bool initialStateFlag = 0;
66 bool parameterPriorFlag = 0;
67 bool modelErrorFlag = 0;
68 bool measurementNoiseFlag = 0;
69
71 Eigen::VectorXd initialStateMean;
72
74 Eigen::MatrixXd initialStateCov;
75
77 Eigen::VectorXd parameterPriorMean;
78
80 Eigen::MatrixXd parameterPriorCov;
81
83 Eigen::MatrixXd parameterMean;
84
86 Eigen::MatrixXd stateMean;
87
89 Eigen::VectorXd timeVector;
90
92 int observationStart;
93
95 int observationDelta;
96
98 Eigen::VectorXi observationBoolVec;
99
101 Eigen::MatrixXd observations;
102
104 std::shared_ptr<muq::Modeling::Gaussian> initialStateDensity;
105
107 std::shared_ptr<muq::Modeling::Gaussian> parameterPriorDensity;
108
109
110 int innerLoopI = 0;
111
112
113 public:
114 // Constructors
115 Fang2017filter();
116
117 Fang2017filter(int _Nsamples);
118
119 virtual ~Fang2017filter() = default;
120
122 std::shared_ptr<muq::Modeling::Gaussian> modelErrorDensity;
123
125 std::shared_ptr<muq::Modeling::Gaussian> measNoiseDensity;
126
129
132
135
138
141
143 Eigen::MatrixXd state_maxConf;
144
146 Eigen::MatrixXd state_minConf;
147
149 Eigen::MatrixXd parameter_maxConf;
150
152 Eigen::MatrixXd parameter_minConf;
153
154 // Functions
155
156 //--------------------------------------------------------------------------
158 int getNumberOfSamples();
159
160 //--------------------------------------------------------------------------
162 double getTime();
163
164 //--------------------------------------------------------------------------
166 double getTime(int _timeStepI);
167
168 //--------------------------------------------------------------------------
170 int getTimeStep();
171
172 //--------------------------------------------------------------------------
174 Eigen::VectorXd getTimeVector();
175
176 //--------------------------------------------------------------------------
178 Eigen::MatrixXd getStateMean();
179
180 //--------------------------------------------------------------------------
182 void setObservations(Eigen::MatrixXd _observations);
183
184 //--------------------------------------------------------------------------
186 void setTime(double _startTime, double _deltaTime, double _endTime);
187
188 //--------------------------------------------------------------------------
190 void setObservationTime(int _observationStart, int _observationDelta);
191
192 //--------------------------------------------------------------------------
194 void setModelError(double cov, bool univariate = 0);
195
196 //--------------------------------------------------------------------------
198 void setMeasNoise(double cov);
199
200 //--------------------------------------------------------------------------
202 void setInitialStateDensity(Eigen::VectorXd _mean, Eigen::MatrixXd _cov);
203
204 //--------------------------------------------------------------------------
206 void sampleInitialState();
207
208 //--------------------------------------------------------------------------
210 void setParameterPriorDensity(Eigen::VectorXd _mean, Eigen::MatrixXd _cov);
211
212 //--------------------------------------------------------------------------
214 void sampleParameterDist();
215
216 //--------------------------------------------------------------------------
218 Eigen::MatrixXd ensembleFromDensity(
219 std::shared_ptr<muq::Modeling::Gaussian> _density);
220
221 //--------------------------------------------------------------------------
223 void buildJointEns();
224
225 //--------------------------------------------------------------------------
227 virtual void stateProjection() = 0;
228
229 //--------------------------------------------------------------------------
231 virtual void observeState() = 0;
232
233 //--------------------------------------------------------------------------
235 void setObservationSize(int _size);
236
237 //--------------------------------------------------------------------------
239 void setStateSize(int _size);
240
241 //--------------------------------------------------------------------------
243 int getStateSize();
244
245 //--------------------------------------------------------------------------
247 void setParameterSize(int _size);
248
249 //--------------------------------------------------------------------------
251 int getParameterSize();
252
253 //--------------------------------------------------------------------------
255 void updateJointEns(Eigen::VectorXd _observation);
256
257 //--------------------------------------------------------------------------
259 void run(int innerLoopMax, word outputFolder);
260};
261}
262#endif
Header file of the ITHACAutilities namespace.
std::shared_ptr< muq::Modeling::Gaussian > modelErrorDensity
Model noise density.
int getNumberOfSamples()
Return number of samples per ensamble.
void sampleParameterDist()
Create parameter ensemble.
ensemble observationEns
Observation ensemble.
void setMeasNoise(double cov)
Setup of the measurement noise distribution.
void sampleInitialState()
Create initial state ensemble.
Eigen::MatrixXd state_maxConf
State maximum confidence level.
Eigen::MatrixXd getStateMean()
Return state mean.
void setInitialStateDensity(Eigen::VectorXd _mean, Eigen::MatrixXd _cov)
Create initial state ensemble.
Eigen::MatrixXd state_minConf
State minimum confidence level.
void setParameterPriorDensity(Eigen::VectorXd _mean, Eigen::MatrixXd _cov)
Create parameter ensemble.
void buildJointEns()
Concatenate state and parameter ensambles to create the joint ensamble.
int getTimeStep()
Return timestep.
void setModelError(double cov, bool univariate=0)
Setup of the model error distribution.
double getTime()
Return time.
void setTime(double _startTime, double _deltaTime, double _endTime)
Setup the time vector.
Eigen::MatrixXd parameter_minConf
parameter minimum confidence level
ensemble oldStateEns
Old state ensemble.
Eigen::MatrixXd ensembleFromDensity(std::shared_ptr< muq::Modeling::Gaussian > _density)
General class to sample from an input density.
Eigen::MatrixXd parameter_maxConf
parameter maximum confidence level
ensemble jointEns
Joint state and parameter ensemble.
Eigen::VectorXd getTimeVector()
Return time vector.
void setObservationTime(int _observationStart, int _observationDelta)
Setup the observation vector.
ensemble parameterEns
Parameter ensemble.
void setObservations(Eigen::MatrixXd _observations)
Set the observations matrix.
std::shared_ptr< muq::Modeling::Gaussian > measNoiseDensity
Measurement noise density.
ensemble stateEns
State ensemble.
void run(int innerLoopMax, word outputFolder)
Run the filtering.
Class for ensembles, each column is a sample.
Header file of the muq2ithaca namespace.