MeteoIODoc 2.11.0
FilterParticle.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2019 Avalanche Warning Service Tyrol LWD-TIROL */
4/***********************************************************************************/
5/* This file is part of MeteoIO.
6 MeteoIO is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 MeteoIO is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef FILTERPARTICLE_H
21#define FILTERPARTICLE_H
22
26
27#include <meteoio/thirdParty/tinyexpr.h>
28
29#include <inttypes.h> //for RNG int types
30#include <string>
31#include <vector>
32
33namespace mio {
34
413 public:
414 FilterParticle(const std::vector< std::pair<std::string, std::string> >& vecArgs, const std::string& name, const Config& cfg);
415 virtual void process(const unsigned int& param, const std::vector<MeteoData>& ivec,
416 std::vector<MeteoData>& ovec);
417
418 private:
419 void resamplePaths(Matrix& xx, Matrix& ww, const size_t& kk, RandomNumberGenerator& RNU) const;
420 bool checkInitialState(const std::vector<MeteoData>& ivec, const size_t& param);
421 void initFunctionVars(te_variable* vars, const std::vector<std::string>& names, const std::vector<double>& meteo) const;
422 te_expr* compileExpression(const std::string& expression, const te_variable* te_vars, const size_t& sz) const;
423 void parseSubstitutionStrings(std::string& line_m, std::string& line_o, std::vector<std::string>& sub_expr,
424 std::vector<std::string>& sub_params) const;
425 void parseBracketExpression(std::string& line, std::vector<std::string>& sub_expr,
426 std::vector<std::string>& sub_params) const;
427 void dumpInternalStates(Matrix& particles, Matrix& weights) const;
428 bool readInternalStates(Matrix& particles, Matrix& weights) const;
429 void dumpParticlePaths(Matrix& particles) const;
430 std::vector<double> buildTimeVector(const std::vector<MeteoData>& ivec) const;
431 void parse_args(const std::vector< std::pair<std::string, std::string> >& vecArgs);
432 void seedGeneratorsFromIni(RandomNumberGenerator& RNGU, RandomNumberGenerator& RNGV, RandomNumberGenerator& RNG0,
433 RandomNumberGenerator& RNU) const;
434 void vecMeteoToMatrix(const std::vector<MeteoData>& vec, Matrix& mat, const unsigned int& param) const;
435 void readLineToVec(const std::string& line_in, std::vector<uint64_t>& vec_out) const;
436 bool isNan(const double& xx) const;
437
438 typedef enum PF_FILTER_ALGORITHM {
439 PF_SIR, //only SIR is implemented so far
440 PF_SIS
441 } pf_filter_algorithm;
442 typedef enum PF_RESAMPLE_ALGORITHM {
443 PF_SYSTEMATIC, //only SYSTEMATIC implemented so far
444 PF_EPANECHNIKOV
445 } pf_resample_algorithm;
446 typedef enum PF_ESTIMATION_MEASURE {
447 PF_MEAN,
448 PF_MAX_WEIGHT
449 } pf_estimation_measure;
450
451 pf_filter_algorithm filter_alg;
452 pf_resample_algorithm resample_alg; //resampling of particle paths
453
454 unsigned int NN; //number of particles
455 bool path_resampling; //has nothing to do with temporal or spatial meteo resampling
456
457 std::string model_expression; //model formula
458 std::string obs_model_expression;
459 std::string fit_expression; //fit data points to get a model function
460 std::string fit_param; //meteo parameter that will be fitted for model
461 unsigned int fit_degree; //degree of interpolation
462 double model_x0; //initial state at T=0
463
464 double resample_percentile; //simple resampling heuristic
465 pf_estimation_measure estim_measure; //how to choose most likely particle path
466
467 struct rng_settings {
470 std::vector<double> parameters;
471 std::vector<uint64_t> seed;
472 rng_settings() : algorithm(RandomNumberGenerator::RNG_XOR),
474 parameters(),
475 seed() {}
476 };
477 struct rng_settings rng_model; //noise generator for model function
478 struct rng_settings rng_obs; //observation noise pdf
479 struct rng_settings rng_prior; //generator to sample from prior pdf
480 std::vector<uint64_t> resample_seed;
481
482 bool be_verbose; //output warnings/info?
483 std::string unrecognized_keys; //to warn about unknown ini keys
484 std::string dump_particles_file;
485 std::string dump_states_file;
486 std::string input_states_file;
487};
488
489} //namespace
490
491#endif //FILTERPARTICLE_H
A class that reads a key/value file. These files (typically named *.ini) follow the INI file format s...
Definition: Config.h:79
A Monte Carlo sampling method: the particle filter.
Definition: FilterParticle.h:412
FilterParticle(const std::vector< std::pair< std::string, std::string > > &vecArgs, const std::string &name, const Config &cfg)
Definition: FilterParticle.cc:32
virtual void process(const unsigned int &param, const std::vector< MeteoData > &ivec, std::vector< MeteoData > &ovec)
The filtering routine as called by the processing toolchain.
Definition: FilterParticle.cc:48
This class implements the basic operations on matrices. Elements are access in matrix notation: that ...
Definition: Matrix.h:42
The base class for all filters that provides the interface and a few helper methods.
Definition: ProcessingBlock.h:67
Definition: RandomNumberGenerator.h:1231
RNG_TYPE
Definition: RandomNumberGenerator.h:1234
@ RNG_XOR
Combined generator.
Definition: RandomNumberGenerator.h:1235
RNG_DISTR
Definition: RandomNumberGenerator.h:1242
@ RNG_GAUSS
Gaussian deviates.
Definition: RandomNumberGenerator.h:1244
Definition: Config.cc:31