14 #ifndef VMCMC_SAMPLE_H_ 15 #define VMCMC_SAMPLE_H_ 20 #include <initializer_list> 34 Sample(
const Vector& pValues);
35 Sample(std::initializer_list<double> pValues);
36 Sample(
size_t nParams = 0);
39 void SetGeneration(
size_t value) { fGeneration = value; }
40 size_t GetGeneration()
const {
return fGeneration; }
41 size_t IncrementGeneration() {
return ++fGeneration; }
43 Vector& Values() {
return fParameterValues; }
44 const Vector& Values()
const {
return fParameterValues; }
46 double& operator[](
size_t index) {
return fParameterValues[index]; }
47 const double& operator[](
size_t index)
const {
return fParameterValues[index]; }
48 size_t size()
const {
return fParameterValues.size(); }
50 Sample& operator= (std::initializer_list<double> pValues);
58 void SetLikelihood(
double value) { fLikelihood = value; }
59 double GetLikelihood()
const {
return fLikelihood; }
61 void SetNegLogLikelihood(
double value) { fNegLogLikelihood = value; }
62 double GetNegLogLikelihood()
const {
return fNegLogLikelihood; }
64 void SetPrior(
double value) { fPrior = value; }
65 double GetPrior()
const {
return fPrior; }
67 void SetAccepted(
bool value) { fAccepted = value; }
68 double IsAccepted()
const {
return fAccepted; }
70 void operator+= (
const Sample& other);
71 void operator-= (
const Sample& other);
72 void operator*= (
double factor);
73 void operator/= (
double factor);
75 bool operator== (
const Sample& other)
const {
return !(*
this != other); }
76 bool operator!= (
const Sample& other)
const;
84 size_t fGeneration = 0;
85 Vector fParameterValues;
86 double fLikelihood = 0.0;
87 double fNegLogLikelihood = -numeric::inf();
89 bool fAccepted =
false;
92 inline Sample::Sample(
const Vector& pValues) :
93 fParameterValues( pValues )
96 inline Sample::Sample(std::initializer_list<double> pValues) :
97 fParameterValues( pValues )
100 inline Sample::Sample(
size_t nParams) :
101 fParameterValues( nParams, 0.0 )
104 inline Sample& Sample::operator= (std::initializer_list<double> pValues)
106 fParameterValues = Vector(pValues);
112 fPrior = fLikelihood = 0.0;
113 fNegLogLikelihood = -numeric::inf();
119 inline void Sample::operator+= (
const Sample& other)
121 fParameterValues += other.fParameterValues;
125 inline void Sample::operator-= (
const Sample& other)
127 fParameterValues -= other.fParameterValues;
131 inline void Sample::operator*= (
double factor)
133 fParameterValues *= factor;
137 inline void Sample::operator/= (
double factor)
139 fParameterValues /= factor;
143 inline bool Sample::operator!= (
const Sample& other)
const 145 return fParameterValues != other.fParameterValues;
152 return Sample( s1.fParameterValues + s2.fParameterValues );
157 return Sample( s1.fParameterValues - s2.fParameterValues );
162 return Sample( s1.fParameterValues * f );
167 return Sample( s1.fParameterValues / f );
void Reset()
Reset ::fLikelihood, ::fNegLogLikelihood and ::fPrior to their default values.
Definition: sample.hpp:110
Definition: algorithm.cpp:28
BLAS (Basic Linear Algebra Subprograms) utility functions.
A 'sample' represents a node or data point in a Markov Chain.
Definition: sample.hpp:31
Numeric utility functions.