94 template <
typename DataType>
99 const IndexType* processed_samples_indices,
101 const DataType confidence_level,
102 const DataType error_atol,
103 const DataType error_rtol,
114 if (num_processed_samples < min_num_samples)
117 for (j=0; j < num_inquiries; j++)
121 num_samples_used[j] = num_processed_samples;
124 return all_converged;
134 DataType standard_z_score = sqrt(2) * \
135 static_cast<DataType>(
erf_inv(
static_cast<double>(confidence_level)));
138 for (j=0; j < num_inquiries; ++j)
141 if (converged[j] == 0)
145 for (i=0; i < num_processed_samples; ++i)
147 summand += samples[processed_samples_indices[i]][j];
149 mean = summand / num_processed_samples;
152 if (num_processed_samples > 1)
155 for (i=0; i < num_processed_samples; ++i)
157 data = samples[processed_samples_indices[i]][j];
158 summand += (data - mean) * (data - mean);
160 std = sqrt(summand / (num_processed_samples - 1.0));
168 error[j] = standard_z_score * std / sqrt(num_processed_samples);
171 if (error[j] < std::max(error_atol, error_rtol*mean))
177 num_samples_used[j] = num_processed_samples;
183 for (j=0; j < num_inquiries; ++j)
185 if (converged[j] == 0)
193 return all_converged;
255 template <
typename DataType>
257 const DataType confidence_level,
258 const DataType outlier_significance_level,
262 const IndexType* processed_samples_indices,
273 DataType mean_discrepancy;
274 DataType outlier_half_interval;
280 DataType error_z_score = sqrt(2) *
erf_inv(confidence_level);
283 DataType outlier_confidence_level = 1.0 - outlier_significance_level;
286 DataType outlier_z_score = sqrt(2.0) *
erf_inv(outlier_confidence_level);
288 for (j=0; j < num_inquiries; ++j)
291 for (i=0; i < max_num_samples; ++i)
293 outlier_indices[i] = 0;
299 for (i=0; i < num_samples_used[j]; ++i)
301 summand += samples[processed_samples_indices[i]][j];
303 mean = summand / num_samples_used[j];
307 if (num_samples_used[j] > 1)
310 for (i=0; i < num_samples_used[j]; ++i)
313 samples[processed_samples_indices[i]][j] - mean;
314 summand += mean_discrepancy * mean_discrepancy;
316 std = sqrt(summand / (num_samples_used[j] - 1.0));
324 outlier_half_interval = outlier_z_score * std;
327 for (i=0; i < num_samples_used[j]; ++i)
329 mean_discrepancy = samples[processed_samples_indices[i]][j] - mean;
330 if (std::abs(mean_discrepancy) > outlier_half_interval)
333 outlier_indices[i] = 1;
334 num_outliers[j] += 1;
340 for (i=0; i < num_samples_used[j]; ++i)
342 if (outlier_indices[i] == 0)
344 summand += samples[processed_samples_indices[i]][j];
347 mean = summand / (num_samples_used[j] - num_outliers[j]);
350 if (num_samples_used[j] > 1 + num_outliers[j])
353 for (i=0; i < num_samples_used[j]; ++i)
355 if (outlier_indices[i] == 0)
358 samples[processed_samples_indices[i]][j] - mean;
359 summand += mean_discrepancy * mean_discrepancy;
362 std = sqrt(summand/(num_samples_used[j] - num_outliers[j] - 1.0));
371 error[j] = error_z_score * std / \
372 sqrt(num_samples_used[j] - num_outliers[j]);
375 delete[] outlier_indices;
double erf_inv(const double x)
Inverse error function.