本文整理汇总了C++中Trajectory::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ Trajectory::resize方法的具体用法?C++ Trajectory::resize怎么用?C++ Trajectory::resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Trajectory
的用法示例。
在下文中一共展示了Trajectory::resize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pfilter
double pfilter(Model & sim_model, Parameter & model_params, MCMCoptions & options, Particle &particles, Trajectory & output_traj, TimeSeriesData &epi_data, TreeData &tree_data, MultiTreeData &multitree_data) {
int thread_max = omp_get_max_threads();
gsl_rng** rngs = new gsl_rng*[thread_max];
for (int thread = 0; thread < thread_max; thread++) {
rngs[thread] = gsl_rng_alloc(gsl_rng_mt19937);
gsl_rng_set(rngs[thread], omp_get_thread_num() + thread);
}
double loglik = 0.0;
int num_groups = options.num_groups;
int num_particles = options.particles;
int init_seed = options.seed;
int total_dt = options.total_dt;
double sim_dt = options.sim_dt;
int total_steps = ceil((double)total_dt/(double)options.pfilter_every);
int add_dt = 0;
double ESS_threshold = options.pfilter_threshold*(double)num_particles;
Likelihood likelihood_calc;
// std::vector <Parameter> values;// (options.num_threads, model_params);
// for (int i=0; i!=options.num_threads; ++i) values.push_back(model_params);
// for (int i=0; i!=model_params.get_total_params(); ++i) values.push_back(model_params.get(i));
std::vector <std::vector<double> > values(options.num_threads, std::vector<double>(model_params.get_total_params(), 0.0));
for (int i=0; i!=options.num_threads; ++i) {
for (int j=0; j!=model_params.get_total_params(); ++j) {
values[i][j] = model_params.get(j);
}
}
// printf("Size of values = %d\n",values.size());
double reporting_rate = 1.0;
if (model_params.param_exists("reporting")) {
reporting_rate = model_params.get("reporting");
}
std::vector <std::string> param_names = model_params.get_names_vector();
std::vector <std::vector<std::string> > param_names_threads (options.num_threads);
if (model_params.param_exists("time_before_data")) {
add_dt = model_params.get("time_before_data");
}
if (options.save_traj) {
if (add_dt > 0) {
particles.start_particle_tracing(add_dt+total_dt, num_groups);
}
else if (add_dt < 0) {
particles.start_particle_tracing(add_dt+total_dt, num_groups);
total_steps = ceil((double)(total_dt+add_dt)/(double)options.pfilter_every);
}
else {
particles.start_particle_tracing(total_dt, num_groups);
}
}
std::vector <Model> models;
for (int i=0; i<options.num_threads; ++i) {
models.push_back(sim_model);
}
std::vector <int> add_dt_threads (options.num_threads, add_dt);
std::vector <int> start_dt_threads (options.num_threads, 0);
std::vector <int> end_dt_threads (options.num_threads, add_dt);
std::vector <double> dt_threads (options.num_threads, sim_dt);
std::vector <int> total_dt_threads(options.num_threads, total_dt);
std::vector <double> reporting_rate_threads(options.num_threads, reporting_rate);
std::vector <int> num_groups_threads(options.num_threads, num_groups);
// Simulate model and calculate likelihood assuming no observed data
if (model_params.param_exists("time_before_data")) {
if (add_dt > 0) {
omp_set_num_threads(options.num_threads);
// std::vector <Trajectory *> curr_trajs;
// for (int i=0; i!=num_particles; ++i) {
// curr_trajs.push_back(particles.get_traj(i));
// }
#pragma omp parallel for shared(particles, values) schedule(static,1)
for (int tn = 0; tn < thread_max; tn++) {
for (int i = tn; i < num_particles; i += thread_max) {
// Adjust length of trajectory
particles.get_traj(i)->resize(add_dt, num_groups);
models[tn].simulate(values[tn], param_names_threads[tn], particles.get_traj(i), 0, add_dt_threads[tn], dt_threads[tn], total_dt_threads[tn], rngs[tn]);
if (options.which_likelihood < 2) {
double w = likelihood_calc.binomial_lik(reporting_rate_threads[tn], particles.get_traj(i)->get_total_traj(), add_dt_threads[tn] + total_dt_threads[tn], 0, add_dt_threads[tn], num_groups_threads[tn], false);
particles.set_weight(w, i, false);
}
if (options.save_traj) {
particles.save_traj_to_matrix(i, 0, add_dt);
particles.save_ancestry(i, 0, add_dt);
}
}
}
}
}
init_seed += num_particles;
int t=0;
int start_dt;
int end_dt;
for (t = 0; t != total_steps; ++t) {
// std::vector<double> we(options.particles, 0.0), wg(options.particles, 0.0);
start_dt = t*options.pfilter_every;
end_dt = std::min(total_dt, (t + 1)*options.pfilter_every);
std::fill(start_dt_threads.begin(), start_dt_threads.end(), start_dt);
std::fill(end_dt_threads.begin(), end_dt_threads.end(), end_dt);
omp_set_num_threads(options.num_threads);
#pragma omp parallel for shared (particles, values) schedule(static,1)
for (int tn = 0; tn < thread_max; tn++) {
for (int i = tn; i < num_particles; i+=thread_max) {
//.........这里部分代码省略.........