hops
AcceptanceRateRecorder.hpp
Go to the documentation of this file.
1 #ifndef HOPS_ACCEPTANCERATERECORDER_HPP
2 #define HOPS_ACCEPTANCERATERECORDER_HPP
3 
4 #include <memory>
5 #include <vector>
6 
13 
14 namespace hops {
15  template<typename MarkovChainImpl>
16  class AcceptanceRateRecorder : public MarkovChainImpl {
17  public:
18  explicit AcceptanceRateRecorder(const MarkovChainImpl &markovChainImpl) : MarkovChainImpl(markovChainImpl) {
19  records = std::make_shared<std::vector<double>>();
20  }
21 
22  void installDataObject(ChainData& chainData) {
23  chainData.setAcceptanceRates(records);
25  MarkovChainImpl::installDataObject(chainData);
26  }
27  }
28 
29  void writeRecordsToFile(const FileWriter *const fileWriter) const {
30  fileWriter->write("acceptance rates", *records);
32  MarkovChainImpl::writeRecordsToFile(fileWriter);
33  }
34  };
35 
36  [[nodiscard]] std::vector<double> getAcceptanceRateRecords() const {
37  return *records;
38  }
39 
40  void storeRecord() {
41  records->emplace_back(MarkovChainImpl::getAcceptanceRate());
43  MarkovChainImpl::storeRecord();
44  }
45  }
46 
47  void clearRecords() {
48  records->clear();
50  MarkovChainImpl::clearRecords();
51  }
52  }
53 
54  private:
55  std::shared_ptr<std::vector<double>> records;
56  };
57 }
58 
59 #endif //HOPS_ACCEPTANCERATERECORDER_HPP
hops::AcceptanceRateRecorder::clearRecords
void clearRecords()
Definition: AcceptanceRateRecorder.hpp:47
hops::AcceptanceRateRecorder
Definition: AcceptanceRateRecorder.hpp:16
hops::AcceptanceRateRecorder::installDataObject
void installDataObject(ChainData &chainData)
Definition: AcceptanceRateRecorder.hpp:22
hops::IsClearRecordsAvailable
Definition: IsClearRecordsAvailable.hpp:8
hops::AcceptanceRateRecorder::getAcceptanceRateRecords
std::vector< double > getAcceptanceRateRecords() const
Definition: AcceptanceRateRecorder.hpp:36
hops::AcceptanceRateRecorder::storeRecord
void storeRecord()
Definition: AcceptanceRateRecorder.hpp:40
IsInstallDataObjectAvailable.hpp
IsClearRecordsAvailable.hpp
IsStoreRecordAvailable.hpp
hops::AcceptanceRateRecorder::writeRecordsToFile
void writeRecordsToFile(const FileWriter *const fileWriter) const
Definition: AcceptanceRateRecorder.hpp:29
hops::IsInstallDataObjectAvailable
Definition: IsInstallDataObjectAvailable.hpp:9
hops::IsWriteRecordsToFileAvailable
Definition: IsWriteRecordsToFileAvailable.hpp:9
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::IsStoreRecordAvailable
Definition: IsStoreRecordAvailable.hpp:8
hops::AcceptanceRateRecorder::AcceptanceRateRecorder
AcceptanceRateRecorder(const MarkovChainImpl &markovChainImpl)
Definition: AcceptanceRateRecorder.hpp:18
hops::FileWriter
Definition: FileWriter.hpp:9
hops
Definition: CsvReader.hpp:8
ChainData.hpp
hops::ChainData::setAcceptanceRates
void setAcceptanceRates(const std::shared_ptr< std::vector< double >> &acceptanceRates)
Definition: ChainData.hpp:27
IsWriteRecordsToFileAvailable.hpp
FileWriter.hpp