31#ifndef __TASMANIAN_DREAM_STATE_HPP
32#define __TASMANIAN_DREAM_STATE_HPP
34#include "tsgDreamEnumerates.hpp"
90 :
TasmanianDREAM(static_cast<int>(chains), static_cast<int>(dims)) {}
97 static const char*
getVersion(){
return TASMANIAN_VERSION_STRING; }
99 static const char*
getLicense(){
return TASMANIAN_LICENSE; }
122 void setState(
const std::vector<double> &new_state);
130 void setState(std::function<
void(
double *)> update_state);
146 void setPDFvalues(std::function<
void(
const std::vector<double> &state, std::vector<double> &values)> probability_distribution);
157 void getIJKdelta(
size_t i,
size_t j,
size_t k,
double w, std::vector<double> &x)
const;
162 void getChainState(
size_t i,
double *x)
const{ std::copy_n(state.begin() + i * num_dimensions, num_dimensions, x); }
183 const std::vector<double>&
getHistory()
const{
return history; }
196 std::vector<double> mode;
205 double getAcceptanceRate()
const{
return ((pdf_history.empty()) ? 0 : ((
double) accepted) / ((
double) pdf_history.size())); }
209 size_t num_chains, num_dimensions;
210 bool init_state, init_values;
214 std::vector<double> state, history;
215 std::vector<double> pdf_values, pdf_history;
~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:170
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:103
static int getVersionMajor()
Return the major version of the library.
Definition tsgDreamState.hpp:101
void saveStateHistory(size_t num_accepted)
Appends the current state to the history.
const std::vector< double > & getChainState() const
Return a const reference to the internal state vector.
Definition tsgDreamState.hpp:165
std::vector< double > getApproximateMode() const
Overload that returns the vector.
Definition tsgDreamState.hpp:195
int getNumDimensions() const
Return the number of dimensions.
Definition tsgDreamState.hpp:106
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.
const std::vector< double > & getHistory() const
Return a const reference to the internal state vector.
Definition tsgDreamState.hpp:183
bool isStateReady() const
Return true if the state has already been initialized with setState().
Definition tsgDreamState.hpp:113
void getApproximateMode(std::vector< double > &mode) const
Return the sample with highest probability, searchers within the history.
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:162
TasmanianDREAM(int cnum_chains, int cnum_dimensions)
Constructor for a DREAM state with the number of chains and dimensions.
static const char * getLicense()
Return human readable sting with the license, refer to the LICENSE file for details.
Definition tsgDreamState.hpp:99
const std::vector< double > & getHistoryPDF() const
Return a const reference to the internal state vector.
Definition tsgDreamState.hpp:186
void clearPDFvalues()
Erase the currently stored pdf values, useful when switching between log and non-log form sampling.
static const char * getVersion()
Return human readable string with the version.
Definition tsgDreamState.hpp:97
TasmanianDREAM(NumChains chains, NumDimensions dims)
Constructor for a DREAM state with the number of chains and dimensions.
Definition tsgDreamState.hpp:89
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:205
size_t getNumHistory() const
Return the number of saved vectors in the history.
Definition tsgDreamState.hpp:110
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:108
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.
bool isPDFReady() const
Return true if the pdf values have already been initialized with setPDF().
Definition tsgDreamState.hpp:115
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
NumChains
Strong type for number of chains in TasDREAM::TasmanianDREAM.
Definition tsgDreamState.hpp:58
NumDimensions
Strong type for the number of dimensions.
Definition TasmanianSparseGrid.hpp:2450
Encapsulates the Tasmanian DREAM module.
Definition TasmanianDREAM.hpp:80