hops
NegativeLogLikelihoodRecorder.hpp
Go to the documentation of this file.
1 #ifndef HOPS_NEGATIVELOGLIKELIHOODRECORDER_HPP
2 #define HOPS_NEGATIVELOGLIKELIHOODRECORDER_HPP
3 
4 #include "../../FileWriter/FileWriter.hpp"
9 #include "../../Utility/ChainData.hpp"
10 
11 #include <memory>
12 #include <vector>
13 
14 namespace hops {
15  template<typename MarkovChainImpl>
16  class NegativeLogLikelihoodRecorder : public MarkovChainImpl {
17  public:
18  explicit NegativeLogLikelihoodRecorder(const MarkovChainImpl &markovChainImpl) : MarkovChainImpl(markovChainImpl) {
19  records = std::make_shared<std::vector<double>>();
20  }
21 
22  void installDataObject(ChainData& chainData) {
23  chainData.setNegativeLogLikelihood(records);
25  MarkovChainImpl::installDataObject(chainData);
26  }
27  }
28 
29  void writeRecordsToFile(const FileWriter *const fileWriter) const {
30  fileWriter->write("negativeLogLikelihood", *records);
32  MarkovChainImpl::writeRecordsToFile(fileWriter);
33  }
34  }
35 
36  void storeRecord() {
37  records->emplace_back(MarkovChainImpl::getNegativeLogLikelihoodOfCurrentState());
39  MarkovChainImpl::storeRecord();
40  }
41  }
42 
43  void clearRecords() {
44  records->clear();
46  MarkovChainImpl::clearRecords();
47  }
48  }
49 
50  private:
51  std::shared_ptr<std::vector<double>> records;
52  };
53 }
54 
55 #endif //HOPS_NEGATIVELOGLIKELIHOODRECORDER_HPP
hops::IsClearRecordsAvailable
Definition: IsClearRecordsAvailable.hpp:8
hops::NegativeLogLikelihoodRecorder::clearRecords
void clearRecords()
Definition: NegativeLogLikelihoodRecorder.hpp:43
IsInstallDataObjectAvailable.hpp
IsClearRecordsAvailable.hpp
IsStoreRecordAvailable.hpp
hops::NegativeLogLikelihoodRecorder::NegativeLogLikelihoodRecorder
NegativeLogLikelihoodRecorder(const MarkovChainImpl &markovChainImpl)
Definition: NegativeLogLikelihoodRecorder.hpp:18
hops::IsInstallDataObjectAvailable
Definition: IsInstallDataObjectAvailable.hpp:9
hops::IsWriteRecordsToFileAvailable
Definition: IsWriteRecordsToFileAvailable.hpp:9
hops::NegativeLogLikelihoodRecorder
Definition: NegativeLogLikelihoodRecorder.hpp:16
hops::ChainData::setNegativeLogLikelihood
void setNegativeLogLikelihood(const std::shared_ptr< std::vector< double >> &negativeLogLikelihood)
Definition: ChainData.hpp:37
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::NegativeLogLikelihoodRecorder::writeRecordsToFile
void writeRecordsToFile(const FileWriter *const fileWriter) const
Definition: NegativeLogLikelihoodRecorder.hpp:29
hops::FileWriter
Definition: FileWriter.hpp:9
hops::NegativeLogLikelihoodRecorder::installDataObject
void installDataObject(ChainData &chainData)
Definition: NegativeLogLikelihoodRecorder.hpp:22
hops
Definition: CsvReader.hpp:8
hops::NegativeLogLikelihoodRecorder::storeRecord
void storeRecord()
Definition: NegativeLogLikelihoodRecorder.hpp:36
IsWriteRecordsToFileAvailable.hpp