-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update base library and build settings
- Loading branch information
Showing
241 changed files
with
4,857 additions
and
2,321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
*.vscode | ||
/src/bmlib/include/armadillo* | ||
.Rproj.user | ||
*.tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/*################################################################################ | ||
## | ||
## Copyright (C) 2011-2018 Keith O'Hara | ||
## | ||
## This file is part of the MCMC C++ library. | ||
## | ||
## MCMC is free software: you can redistribute it and/or modify | ||
## it under the terms of the GNU General Public License as published by | ||
## the Free Software Foundation, either version 2 of the License, or | ||
## (at your option) any later version. | ||
## | ||
## MCMC is distributed in the hope that it will be useful, | ||
## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
## GNU General Public License for more details. | ||
## | ||
################################################################################*/ | ||
|
||
/* | ||
* Adaptive Equi-Energy Sampler | ||
*/ | ||
|
||
#ifndef _mcmc_aees_HPP | ||
#define _mcmc_aees_HPP | ||
|
||
bool aees_int(const arma::vec& initial_vals, arma::mat& draws_out, std::function<double (const arma::vec& vals_inp, void* target_data)> target_log_kernel, void* target_data, algo_settings* settings_inp); | ||
|
||
bool aees(const arma::vec& initial_vals, arma::mat& draws_out, std::function<double (const arma::vec& vals_inp, void* target_data)> target_log_kernel, void* target_data); | ||
bool aees(const arma::vec& initial_vals, arma::mat& draws_out, std::function<double (const arma::vec& vals_inp, void* target_data)> target_log_kernel, void* target_data, algo_settings& settings); | ||
|
||
// single-step Metropolis-Hastings for tempered distributions | ||
inline | ||
arma::vec | ||
single_step_mh(const arma::vec& X_prev, const double temper_val, const arma::mat& sqrt_cov_mcmc, std::function<double (const arma::vec& vals_inp, void* target_data)> target_log_kernel, void* target_data, double* val_out) | ||
{ | ||
const int n_vals = X_prev.n_elem; | ||
|
||
arma::vec X_new = X_prev + std::sqrt(temper_val)*sqrt_cov_mcmc*arma::randn(n_vals,1); | ||
|
||
// | ||
|
||
double val_new = target_log_kernel(X_new, target_data); | ||
double val_prev = target_log_kernel(X_prev, target_data); | ||
|
||
double comp_val = std::min(0.0, (val_new - val_prev) / temper_val ); | ||
|
||
double z = arma::as_scalar(arma::randu(1,1)); | ||
|
||
if (z < std::exp(comp_val)){ | ||
if (val_out) { | ||
*val_out = val_new; | ||
} | ||
|
||
return X_new; | ||
} else { | ||
if (val_out) { | ||
*val_out = val_prev; | ||
} | ||
|
||
return X_prev; | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/*################################################################################ | ||
## | ||
## Copyright (C) 2011-2018 Keith O'Hara | ||
## | ||
## This file is part of the MCMC C++ library. | ||
## | ||
## MCMC is free software: you can redistribute it and/or modify | ||
## it under the terms of the GNU General Public License as published by | ||
## the Free Software Foundation, either version 2 of the License, or | ||
## (at your option) any later version. | ||
## | ||
## MCMC is distributed in the hope that it will be useful, | ||
## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
## GNU General Public License for more details. | ||
## | ||
################################################################################*/ | ||
|
||
/* | ||
* Hamiltonian Monte Carlo | ||
*/ | ||
|
||
#ifndef _mcmc_hmc_HPP | ||
#define _mcmc_hmc_HPP | ||
|
||
bool hmc_int(const arma::vec& initial_vals, arma::mat& draws_out, std::function<double (const arma::vec& vals_inp, arma::vec* grad_out, void* target_data)> target_log_kernel, void* target_data, algo_settings* settings_inp); | ||
|
||
bool hmc(const arma::vec& initial_vals, arma::mat& draws_out, std::function<double (const arma::vec& vals_inp, arma::vec* grad_out, void* target_data)> target_log_kernel, void* target_data); | ||
bool hmc(const arma::vec& initial_vals, arma::mat& draws_out, std::function<double (const arma::vec& vals_inp, arma::vec* grad_out, void* target_data)> target_log_kernel, void* target_data, algo_settings& settings); | ||
|
||
// | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/*################################################################################ | ||
## | ||
## Copyright (C) 2011-2018 Keith O'Hara | ||
## | ||
## This file is part of the MCMC C++ library. | ||
## | ||
## MCMC is free software: you can redistribute it and/or modify | ||
## it under the terms of the GNU General Public License as published by | ||
## the Free Software Foundation, either version 2 of the License, or | ||
## (at your option) any later version. | ||
## | ||
## MCMC is distributed in the hope that it will be useful, | ||
## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
## GNU General Public License for more details. | ||
## | ||
################################################################################*/ | ||
|
||
/* | ||
* inverse Jacobian adjustment | ||
*/ | ||
|
||
inline | ||
arma::mat | ||
inv_jacobian_adjust(const arma::vec& vals_trans_inp, const arma::uvec& bounds_type, const arma::vec& lower_bounds, const arma::vec& upper_bounds) | ||
{ | ||
const int n_vals = bounds_type.n_elem; | ||
|
||
arma::mat ret_mat = arma::eye(n_vals,n_vals); | ||
|
||
for (int i=0; i < n_vals; i++) { | ||
switch (bounds_type(i)) { | ||
case 2: // lower bound only | ||
ret_mat(i,i) = 1.0 / std::exp(vals_trans_inp(i)); | ||
break; | ||
case 3: // upper bound only | ||
ret_mat(i,i) = 1.0 / std::exp(-vals_trans_inp(i)); | ||
break; | ||
case 4: // upper and lower bounds | ||
ret_mat(i,i) = 1.0 / ( std::exp(vals_trans_inp(i))*(upper_bounds(i) - lower_bounds(i)) / std::pow(std::exp(vals_trans_inp(i)) + 1,2) ); | ||
break; | ||
} | ||
} | ||
|
||
// | ||
|
||
return ret_mat; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/*################################################################################ | ||
## | ||
## Copyright (C) 2011-2018 Keith O'Hara | ||
## | ||
## This file is part of the MCMC C++ library. | ||
## | ||
## MCMC is free software: you can redistribute it and/or modify | ||
## it under the terms of the GNU General Public License as published by | ||
## the Free Software Foundation, either version 2 of the License, or | ||
## (at your option) any later version. | ||
## | ||
## MCMC is distributed in the hope that it will be useful, | ||
## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
## GNU General Public License for more details. | ||
## | ||
################################################################################*/ | ||
|
||
/* | ||
* Metropolis-adjusted Langevin algorithm | ||
*/ | ||
|
||
#ifndef _mcmc_mala_HPP | ||
#define _mcmc_mala_HPP | ||
|
||
bool mala_int(const arma::vec& initial_vals, arma::mat& draws_out, std::function<double (const arma::vec& vals_inp, arma::vec* grad_out, void* target_data)> target_log_kernel, void* target_data, algo_settings* settings_inp); | ||
|
||
bool mala(const arma::vec& initial_vals, arma::mat& draws_out, std::function<double (const arma::vec& vals_inp, arma::vec* grad_out, void* target_data)> target_log_kernel, void* target_data); | ||
bool mala(const arma::vec& initial_vals, arma::mat& draws_out, std::function<double (const arma::vec& vals_inp, arma::vec* grad_out, void* target_data)> target_log_kernel, void* target_data, algo_settings& settings); | ||
|
||
// | ||
|
||
inline | ||
double | ||
mala_prop_adjustment(const arma::vec& prop_vals, const arma::vec& prev_vals, const double step_size, const bool vals_bound, const arma::mat& precond_mat, std::function<arma::vec (const arma::vec& vals_inp, void* target_data, const double step_size, arma::mat* jacob_matrix_out)> mala_mean_fn, void* target_data) | ||
{ | ||
|
||
double ret_val = 0; | ||
const double step_size_sq = step_size*step_size; | ||
|
||
// | ||
|
||
if (vals_bound) { | ||
|
||
arma::mat prop_inv_jacob, prev_inv_jacob; | ||
|
||
arma::vec prop_mean = mala_mean_fn(prop_vals, target_data, step_size, &prop_inv_jacob); | ||
arma::vec prev_mean = mala_mean_fn(prev_vals, target_data, step_size, &prev_inv_jacob); | ||
|
||
ret_val = stats_mcmc::dmvnorm(prev_vals, prop_mean, step_size_sq*prop_inv_jacob*precond_mat, true) - stats_mcmc::dmvnorm(prop_vals, prev_mean, step_size_sq*prop_inv_jacob*precond_mat, true); | ||
|
||
} else { | ||
arma::vec prop_mean = mala_mean_fn(prop_vals, target_data, step_size, nullptr); | ||
arma::vec prev_mean = mala_mean_fn(prev_vals, target_data, step_size, nullptr); | ||
|
||
ret_val = stats_mcmc::dmvnorm(prev_vals, prop_mean, step_size_sq*precond_mat, true) - stats_mcmc::dmvnorm(prop_vals, prev_mean, step_size_sq*precond_mat, true); | ||
} | ||
|
||
// | ||
|
||
return ret_val; | ||
} | ||
|
||
#endif |
Oops, something went wrong.