32#ifndef UQTKMCMC_H_SEEN
33#define UQTKMCMC_H_SEEN
56 virtual double fun(
double* x,
int n){
return 0.0;}
107 void setOutputInfo(
string outtype,
string file,
int freq_file,
int freq_screen);
Header file for array read/write utilities.
Stores data of any type T in a 1D array.
Definition Array1D.h:61
Stores data of any type T in a 2D array.
Definition Array2D.h:60
virtual ~LogPosteriorBase()
Definition mcmc.h:51
virtual double eval(Array1D< double > &)
Definition mcmc.h:48
Markov Chain Monte Carlo base class. Implemented the basic and most general MCMC algorithms.
Definition mcmc.h:72
void setCurrentStateStep(int i)
Function to set the step of the current state.
Definition mcmc.cpp:425
Array2D< double > chcov
Definition mcmc.h:272
int getUpperFlag(int i)
Definition mcmc.cpp:571
double getLower(int i)
Get the lower bounds based on an index i.
Definition mcmc.cpp:271
void setFcnAccept(void(*fcnAccept)(void *))
Set the accept and reject functions.
Definition mcmc.cpp:111
void writeFullChainTxt(string filename, Array1D< chainstate > fullchain)
Write an array of chain-states to a file.
Definition mcmc.cpp:368
LogPosteriorBase * L_
Definition mcmc.h:260
bool fcnAcceptFlag_
Definition mcmc.h:297
chainstate currState_
Definition mcmc.h:278
bool inDomain(Array1D< double > &m)
Check if a point is in the domain.
Definition mcmc.cpp:526
Array1D< int > lower_flag_
Lower bound existence flags.
Definition mcmc.h:306
void setLower(double lower, int i)
Set lower bound at the index of i.
Definition mcmc.cpp:185
int GetChainDim() const
Get the MCMC chain dimensionality.
Definition mcmc.cpp:513
Array1D< int > upper_flag_
Upper bound existence flags.
Definition mcmc.h:308
bool fcnRejectFlag_
Definition mcmc.h:298
int chainDim_
Definition mcmc.h:267
dsfmt_t RandomState
Definition mcmc.h:254
void setFcnReject(void(*fcnReject)(void *))
Definition mcmc.cpp:119
string getFilename()
Get the name of the chain file.
Definition mcmc.cpp:217
MCMC()
Dummy Constructor, used for TMCMC.
Definition mcmc.cpp:88
void getFullChain(Array1D< chainstate > &readchain)
Get full chain as an array of chain-states.
Definition mcmc.cpp:402
void setChainDim(int chdim)
Set the dimensions of the chain given an integer.
Definition mcmc.cpp:127
bool getFcnAcceptInit()
Get if the accept and reject functions are initialized.
Definition mcmc.cpp:559
void initChainPropCovDiag(Array1D< double > &sig)
Initialize proposal covariance matrix given its 1d-array diagonal For aMCMC, this matrix is used only...
Definition mcmc.cpp:145
virtual void runChain(int ncalls)=0
Start an MCMC chain with trivial initial condition.
struct MCMC::outputInfo outputinfo_
void writeChainTxt(string filename)
Write the full chain as a text.
Definition mcmc.cpp:575
void runAcceptFcn()
Function to run the accept function.
Definition mcmc.cpp:315
void setCurrentStateState(Array1D< double > &newState)
Function to set the current state's state.
Definition mcmc.cpp:435
void getCurrentStateState(Array1D< double > &state)
Function to get the state of the current state.
Definition mcmc.cpp:430
double getUpper(int i)
Get the upper bounds based on an index i.
Definition mcmc.cpp:275
virtual void runChain(int ncalls, Array1D< double > &chstart)=0
The actual function that generates MCMC.
bool getDimInit()
Get if the Chain Dimensions are initialized.
Definition mcmc.cpp:279
bool propcovInit_
Definition mcmc.h:293
int seed_
Definition mcmc.h:273
int FLAG
Definition mcmc.h:259
int getFullChainSize()
Get the full chain size.
Definition mcmc.cpp:417
void(* fcnAccept_)(void *)
Definition mcmc.h:269
double getModeStatePost()
Function to get the mode state's post.
Definition mcmc.cpp:449
bool getOutputInit()
Get if the output info has been initialized.
Definition mcmc.cpp:292
void addCurrentState()
Function to add the current chain state to the full chain.
Definition mcmc.cpp:421
void initChainPropCov(Array2D< double > &propcov)
Initialize proposal covariance matrix given as a 2d-array For aMCMC, this matrix is used only before ...
Definition mcmc.cpp:135
void getChainPropCov(Array2D< double > &propcov)
Returns proposal covariance matrix.
Definition mcmc.cpp:211
void getFcnAccept(void(*fcnAccept)(void *))
Get the accept and reject functions given a pointer.
Definition mcmc.cpp:241
void setSeed(int seed)
Set random generation seed.
Definition mcmc.cpp:178
double evalLogPosterior(Array1D< double > &m)
Function to evaluate the log-posterior.
Definition mcmc.cpp:517
void setAcceptRatio(double d)
Set the acceptance ratio.
Definition mcmc.cpp:305
string getOutputType()
Get the output file type as a string.
Definition mcmc.cpp:251
int getLowerFlag(int i)
Get function for the lower and upper Flag at index i.
Definition mcmc.cpp:567
bool newModeFound()
Check to see if a new mode was found during last call to runChain.
Definition mcmc.cpp:499
void * postInfo_
Definition mcmc.h:271
Array1D< double > Lower_
Lower bounds.
Definition mcmc.h:301
void getModeStateState(Array1D< double > &state)
Function to get the mode state's state.
Definition mcmc.cpp:458
void getPostInfo(void *post)
Get post info pointer.
Definition mcmc.cpp:283
virtual int getNSubSteps()
Get function for number of sub steps.
Definition mcmc.h:164
void setCurrentStatePost(double newPost)
Function to set the current state's post.
Definition mcmc.cpp:444
virtual double probOldNew(Array1D< double > &a, Array1D< double > &b)
Definition mcmc.h:275
void setPostInfo(void *postinfo)
Set the Posterior Info pointer.
Definition mcmc.cpp:310
Array1D< double > Upper_
Upper bounds.
Definition mcmc.h:303
bool newMode_
Definition mcmc.h:287
void writeChainBin(string filename)
Write the full chain as a binary file.
Definition mcmc.cpp:609
void setNewMode(bool value)
Function to set a new mode value.
Definition mcmc.cpp:554
int WRITE_FLAG
Definition mcmc.h:258
int getFileFreq()
Get the frequency of output to file.
Definition mcmc.cpp:255
void namesPrepended()
Set the indicator to confirm that the names of parameters are prepended in the output file.
Definition mcmc.cpp:171
void setOutputInfo(string outtype, string file, int freq_file, int freq_screen)
Set output specification struct, type('txt' or 'bin'), filename, frequency of outputs to the file and...
Definition mcmc.cpp:159
bool methodInit_
Definition mcmc.h:294
void setCurrentStateAlfa(double newAlfa)
Function to set the current state's alfa.
Definition mcmc.cpp:453
int getWriteFlag()
Get the value of the write flag as an integer.
Definition mcmc.cpp:221
bool outputInit_
Definition mcmc.h:295
bool chaindimInit_
Definition mcmc.h:292
double getMode(Array1D< double > &MAPparams)
Get MAP parameters.
Definition mcmc.cpp:412
void appendMAP()
Append MAP state to the end.
Definition mcmc.cpp:407
virtual void runOptim(Array1D< double > &start)
The optimization routine.
Definition mcmc.cpp:463
double getAcceptRatio()
Get the chain's acceptance ratio as a double.
Definition mcmc.cpp:509
double(* logPosterior_)(Array1D< double > &, void *)
Definition mcmc.h:268
void runRejectFcn()
Function to run the reject function.
Definition mcmc.cpp:320
int getLastWrite()
Get last write.
Definition mcmc.cpp:296
void parseBinChain(string filename, Array1D< chainstate > &readchain)
An auxiliary function to parse the binary file and produce an array of chain-states.
Definition mcmc.cpp:339
void setLastWrite(int i)
Set last write.
Definition mcmc.cpp:300
void getSamples(int burnin, int every, Array2D< double > &samples)
Get samples of the chain with burnin and thining.
Definition mcmc.cpp:225
void getFcnReject(void(*fcnReject)(void *))
Definition mcmc.cpp:246
double accRatio_
Definition mcmc.h:289
int getScreenFreq()
Get the frequency of output to the screen.
Definition mcmc.cpp:259
bool getFcnRejectInit()
Definition mcmc.cpp:563
bool getPropCovInit()
Get if the Prop Cov has been initialized.
Definition mcmc.cpp:288
void(* fcnReject_)(void *)
Definition mcmc.h:270
void resetChainState()
Reset the chain state.
Definition mcmc.cpp:325
double getCurrentStatePost()
Function to get the post of the current state.
Definition mcmc.cpp:440
void setUpper(double upper, int i)
Set upper bound at the index of i.
Definition mcmc.cpp:193
void setDefaultDomain()
Set default unbounded domain.
Definition mcmc.cpp:201
int getSeed()
Get the seed used for random generation.
Definition mcmc.cpp:267
void updateMode()
Function to update the Chain mode.
Definition mcmc.cpp:544
bool namesPrepend
Definition mcmc.h:285
int lastwrite_
Definition mcmc.h:284
void setWriteFlag(int I)
Set the write flag function given an integer.
Definition mcmc.cpp:106
Array1D< chainstate > fullChain_
Definition mcmc.h:280
bool getNamesPrepended()
Get if the names are prepended.
Definition mcmc.cpp:263
void resetChainFilename(string filename)
Reset to a new chain file.
Definition mcmc.cpp:331
chainstate modeState_
Definition mcmc.h:279
virtual double fun(double *x, int n)
Definition mcmc.h:56
base * b_
Definition mcmc.h:61
main(base &b)
Definition mcmc.h:63
double alfa
Definition mcmc.h:78
Array1D< double > state
Definition mcmc.h:77
double post
Definition mcmc.h:79
int step
Definition mcmc.h:76
string filename
Definition mcmc.h:263
int freq_file
Definition mcmc.h:264
string outtype
Definition mcmc.h:262
int freq_screen
Definition mcmc.h:265