18 bool useGeneralisedMomentumPropose,
bool useGeneralisedMomentumKinetic,
bool normalizeMomentum,
bool 19 evaluateHamiltonianBeforeLeap) {
22 _model = std::move(in_model);
32 srand((
unsigned int) time(
nullptr));
115 std::ofstream samplesfile;
116 samplesfile.open(
"OUTPUT/samples.txt");
125 leap_frog(uturns, it == _iterations - 1);
135 double result_exponent;
136 result_exponent = exp(result);
139 if ((x_new < x) || (result_exponent >
randf(0.0, 1.0))) {
143 leap_frog(uturns, it == _iterations - 1);
153 samplesfile << accepted << std::endl;
156 std::cout <<
"Number of accepted models: " << accepted << std::endl;
157 std::cout <<
"Number of U-Turn terminations in propagation: " << uturns;
168 std::vector<double> misfitGrad;
169 double angle1, angle2;
171 std::ofstream trajectoryfile;
172 if (writeTrajectory) {
173 trajectoryfile.open(
"OUTPUT/trajectory.txt");
177 for (
int it = 0; it <
_nt; it++) {
196 if (angle1 > 0.0 && angle2 > 0.0) {
201 if (writeTrajectory) trajectoryfile.close();
209 outfile << std::endl;
215 return _A * std::move(parameters) -
_bT;
std::vector< std::vector< double > > InvertLowerTriangular(std::vector< std::vector< double >> L)
Invert a lower triangular matrix by use of solving the system per column of using SolveLowerTriang...
std::vector< double > _mean
std::vector< std::vector< double > > _inverseCovarianceMatrix
std::vector< std::vector< double > > _inverseMassMatrix
std::vector< double > MatrixTrace(std::vector< std::vector< double >> M)
Function to the trace of a square matrix .
std::vector< std::vector< double > > VectorToDiagonal(std::vector< double > A)
Function which takes a std::vector of double to make a diagonal matrix of it, such that ...
montecarlo(prior &in_prior, data &in_data, forwardModel in_model, int in_nt, double in_dt, int in_iterations, bool useGeneralisedMomentumPropose, bool useGeneralisedMomentumKinetic, bool normalizeMomentum, bool evaluateHamiltonianBeforeLeap)
std::vector< double > _std
std::vector< double > precomp_misfitGrad()
std::vector< std::vector< double > > _inverseMassMatrixDiagonal
std::vector< std::vector< double > > _inverseCD
double randf(double min, double max)
Draw uniformly distributed samples between two numbers.
bool _useGeneralisedMomentumPropose
void write_sample(std::ofstream &outfile, double misfit)
Set of functions to draw from (multivariate, correlated) normal distributions.
std::vector< std::vector< double > > TransposeMatrix(std::vector< std::vector< double > > M)
std::vector< double > _currentMomentum
void sample(bool hamilton)
std::vector< std::vector< double > > InvertMatrixElements(std::vector< std::vector< double >> M)
Function to take the inverse of the individual matrix elements.
std::vector< std::vector< double > > _CholeskyLowerMassMatrix
bool _evaluateHamiltonianBeforeLeap
std::vector< double > randn_Cholesky(std::vector< double > mean, std::vector< std::vector< double >> CholeskyLower_CovarianceMatrix)
Drawing non-zero mean samples from an dimensional correlated Gaussian. Invokes randn_Cholesky(std::v...
double randn(double mean, double stdv)
Draws from Gaussian (mean, standard deviation) using Box-Müller transform.
std::vector< double > _bT
std::vector< double > _currentModel
std::vector< double > _proposedMomentum
std::vector< double > NormalizeVector(std::vector< double > A)
Normalizes a vector to unit length.
std::vector< std::vector< double > > _massMatrix
std::vector< double > _proposedModel
Linear algebra functions operating on standard library containers.
void propose_metropolis()
bool _useGeneralisedMomentumKinetic
void leap_frog(int &uturns, bool writeTrajectory)
std::vector< double > _observedData
std::vector< std::vector< double > > _A
Prior information in parameter space.
unsigned long _numberParameters
std::vector< std::vector< double > > _designMatrix
std::vector< std::vector< double > > CholeskyDecompose(std::vector< std::vector< double >> A)
Cholesky-decomposition of a positive definite Hermitian matrix .
void propose_hamilton(int &uturns)