Skip to content

Commit 309753d

Browse files
committed
added convergence criteria for lc_extrap/pop_size: converge when difference between iterations < 1.0
1 parent d201df8 commit 309753d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/preseq.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ using std::unordered_map;
5454
using std::runtime_error;
5555
using std::to_string;
5656
using std::mt19937;
57+
using std::max;
5758

5859
static const string preseq_version = "3.0.2";
5960

@@ -126,6 +127,7 @@ vector_median_and_ci(const vector<vector<double> > &bootstrap_estimates,
126127

127128
const size_t n_est = bootstrap_estimates.size();
128129
vector<double> estimates_row(n_est, 0.0);
130+
double prev_estimate = 0;
129131
for (size_t i = 0; i < bootstrap_estimates[0].size(); i++) {
130132

131133
// estimates is in wrong order, work locally on const val
@@ -137,9 +139,14 @@ vector_median_and_ci(const vector<vector<double> > &bootstrap_estimates,
137139
lower_ci_estimate, upper_ci_estimate);
138140
sort(begin(estimates_row), end(estimates_row));
139141

142+
if(median_estimate - prev_estimate < 1.0)
143+
break;
144+
140145
yield_estimates.push_back(median_estimate);
141146
lower_ci_lognorm.push_back(lower_ci_estimate);
142147
upper_ci_lognorm.push_back(upper_ci_estimate);
148+
149+
prev_estimate = median_estimate;
143150
}
144151
}
145152

@@ -350,7 +357,6 @@ extrap_bootstrap(const bool VERBOSE, const bool allow_defects,
350357
extrapolate_curve(defect_cf, initial_distinct, sample_vals_sum,
351358
curr_sample_sz, bin_step_size,
352359
max_extrap, yield_vector);
353-
354360
// no checking of curve in defect mode
355361
bootstrap_estimates.push_back(yield_vector);
356362
successful_bootstrap = true;

0 commit comments

Comments
 (0)