MUQ  0.4.3
SamplingState.cpp
Go to the documentation of this file.
2 #include <Eigen/Core>
4 
5 using namespace muq::SamplingAlgorithms;
6 using namespace muq::Utilities;
7 
8 SamplingState::SamplingState(Eigen::VectorXd const& stateIn, double weight) : state({stateIn}), weight(weight) {}
9 SamplingState::SamplingState(std::vector<Eigen::VectorXd> const& stateIn, double const weight) : state(stateIn), weight(weight) {}
10 
11 bool SamplingState::HasMeta(std::string const& metaKey) {
12  auto iter = meta.find(metaKey);
13  return iter!=meta.end();
14 }
15 
17  int sum = 0;
18  for(auto& s : state){
19  sum += s.size();
20  }
21  return sum;
22 }
23 
24 Eigen::VectorXd SamplingState::ToVector(int blockInd) const
25 {
26  if(blockInd>=0){
27  return state.at(blockInd);
28  }else{
29  if(state.size()==1)
30  return state.at(0);
31 
32  Eigen::VectorXd output(TotalDim());
33  unsigned int currInd = 0;
34  for(auto& s : state){
35  output.segment(currInd, s.size()) = s;
36  currInd += s.size();
37  }
38  return output;
39  }
40 }
41 
42 
43 double SamplingState::StateValue(unsigned int totalInd) const
44 {
45  unsigned int sum = 0;
46  for(auto& s : state){
47 
48  if(totalInd < sum + s.size())
49  return s(totalInd - sum);
50 
51  sum += s.size();
52  }
53 
54  return std::numeric_limits<double>::quiet_NaN();
55 }
56 
57 
58 double& SamplingState::StateValue(unsigned int totalInd)
59 {
60  unsigned int sum = 0;
61  for(auto& s : state){
62 
63  if(totalInd < sum + s.size())
64  return s(totalInd - sum);
65 
66  sum += s.size();
67  }
68 
69  assert(false);
70  return state.at(0)(0);
71 }
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
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