31 #ifndef __TASMANIAN_DREAM_STATE_HPP
32 #define __TASMANIAN_DREAM_STATE_HPP
34 #include "tsgDreamEnumerates.hpp"
82 static const char*
getVersion(){
return TASMANIAN_VERSION_STRING; }
84 static const char*
getLicense(){
return TASMANIAN_LICENSE; }
107 void setState(
const std::vector<double> &new_state);
115 void setState(std::function<
void(
double *)> update_state);
131 void setPDFvalues(std::function<
void(
const std::vector<double> &state, std::vector<double> &values)> probability_distribution);
142 void getIJKdelta(
size_t i,
size_t j,
size_t k,
double w, std::vector<double> &x)
const;
147 void getChainState(
size_t i,
double *x)
const{ std::copy_n(state.begin() + i * num_dimensions, num_dimensions, x); }
168 const std::vector<double>&
getHistory()
const{
return history; }
181 std::vector<double> mode;
190 double getAcceptanceRate()
const{
return ((pdf_history.empty()) ? 0 : ((
double) accepted) / ((
double) pdf_history.size())); }
194 size_t num_chains, num_dimensions;
195 bool init_state, init_values;
199 std::vector<double> state, history;
200 std::vector<double> pdf_values, pdf_history;
Contains the current state and the history of the DREAM chains.
Definition: tsgDreamState.hpp:70
~TasmanianDREAM()
Default destructor, release all used memory.
double getPDFvalue(size_t i) const
Return the value of the probability_distribution of the i-th chain.
Definition: tsgDreamState.hpp:155
void setState(std::function< void(double *)> update_state)
Set the current DREAM state by calling update_state on each vector.
static int getVersionMinor()
Return the minor version of the library.
Definition: tsgDreamState.hpp:88
const std::vector< double > & getHistory() const
Return a const reference to the internal state vector.
Definition: tsgDreamState.hpp:168
static int getVersionMajor()
Return the major version of the library.
Definition: tsgDreamState.hpp:86
void saveStateHistory(size_t num_accepted)
Appends the current state to the history.
int getNumDimensions() const
Return the number of dimensions.
Definition: tsgDreamState.hpp:91
void getHistoryMeanVariance(std::vector< double > &mean, std::vector< double > &var) const
Compute the means and variance of the saved history.
void setPDFvalues(const std::vector< double > &new_values)
Set the current set of pdf values to the new_values.
std::vector< double > getApproximateMode() const
Overload that returns the vector.
Definition: tsgDreamState.hpp:180
bool isStateReady() const
Return true if the state has already been initialized with setState().
Definition: tsgDreamState.hpp:98
void getApproximateMode(std::vector< double > &mode) const
Return the sample with highest probability, searchers within the history.
static const char * getVersion()
Return human readable string with the version.
Definition: tsgDreamState.hpp:82
TasmanianDREAM()
Constructor for a null DREAM state, no chains and no dimensions (used for MPI purposes).
void getChainState(size_t i, double *x) const
Return the state of the i-th chain, store an array x of size at least num_dimensions.
Definition: tsgDreamState.hpp:147
TasmanianDREAM(int cnum_chains, int cnum_dimensions)
Constructor for a DREAM state with the number of chains and dimensions.
void clearPDFvalues()
Erase the currently stored pdf values, useful when switching between log and non-log form sampling.
void expandHistory(int num_snapshots)
Allocate (expand) internal storage for the history snapshots, avoids reallocating data when saving a ...
double getAcceptanceRate() const
Returns the acceptance rate of the current history.
Definition: tsgDreamState.hpp:190
size_t getNumHistory() const
Return the number of saved vectors in the history.
Definition: tsgDreamState.hpp:95
void getIJKdelta(size_t i, size_t j, size_t k, double w, std::vector< double > &x) const
Used by the DREAM sampler, , where s indicates the current i, j, and k-th state vectors.
int getNumChains() const
Return the number of chains.
Definition: tsgDreamState.hpp:93
void setPDFvalues(std::function< void(const std::vector< double > &state, std::vector< double > &values)> probability_distribution)
Set the current set of pdf values using the given probability_distribution.
const std::vector< double > & getHistoryPDF() const
Return a const reference to the internal state vector.
Definition: tsgDreamState.hpp:171
bool isPDFReady() const
Return true if the pdf values have already been initialized with setPDF().
Definition: tsgDreamState.hpp:100
const std::vector< double > & getChainState() const
Return a const reference to the internal state vector.
Definition: tsgDreamState.hpp:150
static const char * getLicense()
Return human readable sting with the license, refer to the LICENSE file for details.
Definition: tsgDreamState.hpp:84
TasmanianDREAM(int cnum_chains, const TasGrid::TasmanianSparseGrid &grid)
Constructor for a DREAM state with the number of chains and the dimension of the sparse grid.
void setState(const std::vector< double > &new_state)
Set the current DREAM state to the new_state.
void clearHistory()
Clear the stored history (does not touch the state).
The master-class that represents an instance of a Tasmanian sparse grid.
Definition: TasmanianSparseGrid.hpp:293
Encapsulates the Tasmanian DREAM module.
Definition: TasmanianDREAM.hpp:80