Skip to content

Commit 3791cd0

Browse files
authored
Merge pull request #33 from osorensen/doubling-issue-32
added doubling threshold option
2 parents 7a0189f + 40ca53a commit 3791cd0

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

R/set_smc_options.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#' particle
66
#' @param max_particle_filters Maximum number of particle filters.
77
#' @param resampling_threshold Effective sample size threshold for resampling
8+
#' @param doubling_threshold Threshold for particle filter doubling. If the
9+
#' acceptance rate of the rejuvenation step falls below this threshold, the
10+
#' number of particle filters is doubled. Defaults to 0.2.
811
#' @param max_rejuvenation_steps Maximum number of rejuvenation steps. If the
912
#' number of unique particles has not exceeded half the number of particles
1013
#' after this many steps, the rejuvenation is still stopped.
@@ -22,7 +25,8 @@
2225
#'
2326
set_smc_options <- function(
2427
n_particles = 1000, n_particle_filters = 50, max_particle_filters = 10000,
25-
resampling_threshold = n_particles / 2, max_rejuvenation_steps = 20,
28+
resampling_threshold = n_particles / 2, doubling_threshold = .2,
29+
max_rejuvenation_steps = 20,
2630
metric = "footrule", resampler = "multinomial",
2731
latent_rank_proposal = "uniform", verbose = FALSE,
2832
trace = FALSE, trace_latent = FALSE) {

man/set_smc_options.Rd

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/options.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Options::Options(const Rcpp::List& input_options) :
99
max_particle_filters {input_options["max_particle_filters"]},
1010
resampling_threshold{input_options["resampling_threshold"]},
1111
max_rejuvenation_steps{input_options["max_rejuvenation_steps"]},
12+
doubling_threshold{input_options["doubling_threshold"]},
1213
verbose{input_options["verbose"]},
1314
trace{input_options["trace"]},
1415
trace_latent{input_options["trace_latent"]}{}

src/options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct Options{
1414
unsigned int max_particle_filters;
1515
unsigned int resampling_threshold;
1616
unsigned int max_rejuvenation_steps;
17+
const double doubling_threshold;
1718
const bool verbose;
1819
const bool trace;
1920
const bool trace_latent;

src/run_smc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Rcpp::List run_smc(
9191
double acceptance_rate = accepted / particle_vector.size() / iter;
9292
reporter.report_acceptance_rate(acceptance_rate);
9393

94-
if(acceptance_rate < 0.2 && options.n_particle_filters < options.max_particle_filters) {
94+
if(acceptance_rate < options.doubling_threshold && options.n_particle_filters < options.max_particle_filters) {
9595
for(auto& p : particle_vector) {
9696
double log_Z_old = compute_log_Z(p.particle_filters, t);
9797

0 commit comments

Comments
 (0)