MUQ  0.4.3
SamplingState.h
Go to the documentation of this file.
1 #ifndef SAMPLINGSTATE_H_
2 #define SAMPLINGSTATE_H_
3 
4 #include <iostream>
5 #include <unordered_map>
6 #include <vector>
7 #include <memory>
8 
9 #include <Eigen/Core>
10 #include <boost/any.hpp>
11 
12 #include "MUQ/config.h"
13 
14 #if MUQ_HAS_PARCER
16 #include <cereal/types/string.hpp>
17 #include <cereal/types/unordered_map.hpp>
18 #include <cereal/types/vector.hpp>
19 #endif
20 
21 namespace muq {
22  namespace SamplingAlgorithms {
23 
31  class SamplingState {
32  public:
33 
34 
35  SamplingState() = default;
36 
37  /*SamplingState(SamplingState const& in) {
38  state = in.state;
39  weight = in.weight;
40  meta = in.meta;
41  };*/
42  SamplingState(Eigen::VectorXd const& stateIn, double weight = 1.0);
43  SamplingState(std::vector<Eigen::VectorXd> const& stateIn, double weight = 1.0);
44 
45  virtual ~SamplingState() = default;
46 
48  std::vector<Eigen::VectorXd> state;
49 
51  double weight;
52 
54  bool HasMeta(std::string const& metaKey);
55 
57  int TotalDim() const;
58 
63  Eigen::VectorXd ToVector(int blockInd=-1) const;
64 
68  double StateValue(unsigned int totalInd) const;
69  double& StateValue(unsigned int totalInd);
70 
72  std::unordered_map<std::string, boost::any> meta;
73 
74 
75 #if MUQ_HAS_PARCER
81  template<class Archive>
82  void serialize(Archive & archive) {
83  archive(state, weight, meta); // serialize things by passing them to the archive
84  }
85 
86 #endif
87  };
88  } // namespace SamplingAlgoritms
89 } // namespace muq
90 
91 #endif
Each state is one sample generated by a sampling algorithm.
Definition: SamplingState.h:31
int TotalDim() const
The total number of parameters in the state, i.e., the sum of state[i].size()
std::unordered_map< std::string, boost::any > meta
A map containing extra information like the target density, run time, forward model output,...
Definition: SamplingState.h:72
double weight
The weight of this state.
Definition: SamplingState.h:51
void serialize(Archive &archive)
Serialization function for use with Cereal.
Definition: SamplingState.h:82
std::vector< Eigen::VectorXd > state
The state variables.
Definition: SamplingState.h:48
double StateValue(unsigned int totalInd) const
bool HasMeta(std::string const &metaKey)
Checks to see if the meta map contains a particular key.
Eigen::VectorXd ToVector(int blockInd=-1) const