hops
ChainData.hpp
Go to the documentation of this file.
1 #ifndef HOPS_CHAINDATA_HPP
2 #define HOPS_CHAINDATA_HPP
3 
5 #include "Exceptions.hpp"
6 #include <Eigen/Core>
7 
8 #include <vector>
9 #include <memory>
10 
11 namespace hops {
12  class ChainData {
13  public:
14  ChainData () : acceptanceRates(nullptr),
15  negativeLogLikelihood(nullptr),
16  states(nullptr),
17  timestamps(nullptr) {
18  //
19  }
20 
21 
22  const std::vector<double>& getAcceptanceRates() const {
23  if (!acceptanceRates) throw UninitializedDataFieldException("acceptanceRates");
24  return *acceptanceRates;
25  }
26 
27  void setAcceptanceRates(const std::shared_ptr<std::vector<double>>& acceptanceRates) {
28  this->acceptanceRates = std::shared_ptr<std::vector<double>>(acceptanceRates);
29  }
30 
31 
32  const std::vector<double>& getNegativeLogLikelihood() const {
33  if (!negativeLogLikelihood) throw UninitializedDataFieldException("negativeLogLikelihood");
34  return *negativeLogLikelihood;
35  }
36 
37  void setNegativeLogLikelihood(const std::shared_ptr<std::vector<double>>& negativeLogLikelihood) {
38  this->negativeLogLikelihood = std::shared_ptr<std::vector<double>>(negativeLogLikelihood);
39  }
40 
41 
42  const std::vector<Eigen::VectorXd>& getStates() const {
43  if (!states) throw UninitializedDataFieldException("states");
44  return *states;
45  }
46 
47  void setStates(const std::shared_ptr<std::vector<Eigen::VectorXd>>& states) {
48  this->states = std::shared_ptr<std::vector<Eigen::VectorXd>>(states);
49  }
50 
51 
52  const std::vector<long>& getTimestamps() const {
53  if (!timestamps) throw UninitializedDataFieldException("timestamps");
54  return *timestamps;
55  }
56 
57  void setTimestamps(const std::shared_ptr<std::vector<long>> timestamps) {
58  this->timestamps = std::shared_ptr<std::vector<long>>(timestamps);
59  }
60 
61 
62  void write(FileWriter *const fileWriter) const {
63  if (acceptanceRates) {
64  fileWriter->write("acceptanceRates", *acceptanceRates);
65  }
66 
67  if (negativeLogLikelihood) {
68  fileWriter->write("negativeLogLikelihood", *negativeLogLikelihood);
69  }
70 
71  if (states) {
72  fileWriter->write("states", *states);
73  }
74 
75  if (timestamps) {
76  fileWriter->write("timestamps", *timestamps);
77  }
78  }
79 
80  void reset() {
81  if (acceptanceRates) {
82  (*acceptanceRates.get()).clear();
83  }
84 
85  if (negativeLogLikelihood) {
86  negativeLogLikelihood->clear();
87  }
88 
89  if (states) {
90  states->clear();
91  }
92 
93  if (timestamps) {
94  timestamps->clear();
95  }
96  }
97 
98  private:
99  std::shared_ptr<std::vector<double>> acceptanceRates;
100  std::shared_ptr<std::vector<double>> negativeLogLikelihood;
101  std::shared_ptr<std::vector<Eigen::VectorXd>> states;
102  std::shared_ptr<std::vector<long>> timestamps;
103 
104  friend class Data;
105  };
106 }
107 
108 #endif // HOPS_CHAINDATA_HPP
109 
hops::ChainData::setStates
void setStates(const std::shared_ptr< std::vector< Eigen::VectorXd >> &states)
Definition: ChainData.hpp:47
hops::Data
Definition: Data.hpp:19
hops::ChainData::write
void write(FileWriter *const fileWriter) const
Definition: ChainData.hpp:62
Exceptions.hpp
hops::ChainData::getAcceptanceRates
const std::vector< double > & getAcceptanceRates() const
Definition: ChainData.hpp:22
hops::ChainData::ChainData
ChainData()
Definition: ChainData.hpp:14
hops::ChainData::getTimestamps
const std::vector< long > & getTimestamps() const
Definition: ChainData.hpp:52
hops::ChainData::setNegativeLogLikelihood
void setNegativeLogLikelihood(const std::shared_ptr< std::vector< double >> &negativeLogLikelihood)
Definition: ChainData.hpp:37
hops::ChainData::reset
void reset()
Definition: ChainData.hpp:80
hops::UninitializedDataFieldException
Definition: Exceptions.hpp:39
hops::FileWriter::write
virtual void write(const std::string &description, const std::vector< float > &records) const =0
Writes records.
hops::ChainData
Definition: ChainData.hpp:12
hops::ChainData::setTimestamps
void setTimestamps(const std::shared_ptr< std::vector< long >> timestamps)
Definition: ChainData.hpp:57
hops::FileWriter
Definition: FileWriter.hpp:9
hops
Definition: CsvReader.hpp:8
hops::ChainData::setAcceptanceRates
void setAcceptanceRates(const std::shared_ptr< std::vector< double >> &acceptanceRates)
Definition: ChainData.hpp:27
hops::ChainData::getNegativeLogLikelihood
const std::vector< double > & getNegativeLogLikelihood() const
Definition: ChainData.hpp:32
hops::ChainData::getStates
const std::vector< Eigen::VectorXd > & getStates() const
Definition: ChainData.hpp:42
FileWriter.hpp