本文整理汇总了C++中arma::cube::set_size方法的典型用法代码示例。如果您正苦于以下问题:C++ cube::set_size方法的具体用法?C++ cube::set_size怎么用?C++ cube::set_size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arma::cube
的用法示例。
在下文中一共展示了cube::set_size方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: target_log_kernel
bool
mcmc::de_int(const arma::vec& initial_vals, arma::cube& draws_out, std::function<double (const arma::vec& vals_inp, void* target_data)> target_log_kernel, void* target_data, algo_settings_t* settings_inp)
{
bool success = false;
const size_t n_vals = initial_vals.n_elem;
//
// DE settings
algo_settings_t settings;
if (settings_inp) {
settings = *settings_inp;
}
const size_t n_pop = settings.de_n_pop;
const size_t n_gen = settings.de_n_gen;
const size_t n_burnin = settings.de_n_burnin;
const bool jumps = settings.de_jumps;
const double par_b = settings.de_par_b;
// const double par_gamma = settings.de_par_gamma;
const double par_gamma = 2.38 / std::sqrt(2.0*n_vals);
const double par_gamma_jump = settings.de_par_gamma_jump;
const arma::vec par_initial_lb = (settings.de_initial_lb.n_elem == n_vals) ? settings.de_initial_lb : initial_vals - 0.5;
const arma::vec par_initial_ub = (settings.de_initial_ub.n_elem == n_vals) ? settings.de_initial_ub : initial_vals + 0.5;
const bool vals_bound = settings.vals_bound;
const arma::vec lower_bounds = settings.lower_bounds;
const arma::vec upper_bounds = settings.upper_bounds;
const arma::uvec bounds_type = determine_bounds_type(vals_bound, n_vals, lower_bounds, upper_bounds);
// lambda function for box constraints
std::function<double (const arma::vec& vals_inp, void* box_data)> box_log_kernel \
= [target_log_kernel, vals_bound, bounds_type, lower_bounds, upper_bounds] (const arma::vec& vals_inp, void* target_data) \
-> double
{
if (vals_bound)
{
arma::vec vals_inv_trans = inv_transform(vals_inp, bounds_type, lower_bounds, upper_bounds);
return target_log_kernel(vals_inv_trans, target_data) + log_jacobian(vals_inp, bounds_type, lower_bounds, upper_bounds);
}
else
{
return target_log_kernel(vals_inp, target_data);
}
};
//
arma::vec target_vals(n_pop);
arma::mat X(n_pop,n_vals);
#ifdef MCMC_USE_OPENMP
#pragma omp parallel for
#endif
for (size_t i=0; i < n_pop; i++)
{
X.row(i) = par_initial_lb.t() + (par_initial_ub.t() - par_initial_lb.t())%arma::randu(1,n_vals);
double prop_kernel_val = box_log_kernel(X.row(i).t(),target_data);
if (!std::isfinite(prop_kernel_val)) {
prop_kernel_val = neginf;
}
target_vals(i) = prop_kernel_val;
}
//
// begin MCMC run
draws_out.set_size(n_pop,n_vals,n_gen);
int n_accept = 0;
double par_gamma_run = par_gamma;
for (size_t j=0; j < n_gen + n_burnin; j++)
{
double temperature_j = de_cooling_schedule(j,n_gen);
if (jumps && ((j+1) % 10 == 0)) {
par_gamma_run = par_gamma_jump;
}
#ifdef MCMC_USE_OPENMP
#pragma omp parallel for
#endif
for (size_t i=0; i < n_pop; i++) {
uint_t R_1, R_2;
do {
R_1 = arma::as_scalar(arma::randi(1, arma::distr_param(0, n_pop-1)));
} while(R_1==i);
//.........这里部分代码省略.........