Skip to content

Commit dae557e

Browse files
committed
chore: lift some restrictions on confidence interval function
- if a value is computed it will be correct - if the value is not finite (NaN or infinity) we panic with a message to the user indicating what course of action they can take - ideally we would want to use a scientific crate written in rust, xsf-rust seemed promising but the dependency on clang + libclang is proving more annoying than not, given we would need a single function from xsf (and it's hard to translate all the required pieces) we keep a sort of status quo - statrs issue : statrs-dev/statrs#361
1 parent a33c12d commit dae557e

File tree

1 file changed

+12
-7
lines changed
  • tfhe/src/core_crypto/commons

1 file changed

+12
-7
lines changed

tfhe/src/core_crypto/commons/mod.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ pub mod test_tools {
164164

165165
/// Samples must come from a gaussian distribution, returns the estimated confidence interval
166166
/// for a variance measurement of a gaussian distribution.
167+
#[track_caller]
167168
pub fn gaussian_variance_confidence_interval(
168169
sample_count: f64,
169170
measured_variance: Variance,
@@ -172,19 +173,23 @@ pub mod test_tools {
172173
assert!(probability_to_be_in_the_interval >= 0.0);
173174
assert!(probability_to_be_in_the_interval <= 1.0);
174175

175-
// We have f64 arithmetic errors sightly farther away, so to protect ourselves, limit to
176-
// 125000
177-
assert!(
178-
sample_count <= 125000.,
179-
"variance_confidence_interval cannot handle sample count > 125000",
180-
);
181-
182176
let alpha = 1.0 - probability_to_be_in_the_interval;
183177
let degrees_of_freedom = sample_count - 1.0;
184178
let chi2 = ChiSquared::new(degrees_of_freedom).unwrap();
185179
let chi2_lower = chi2.inverse_cdf(alpha / 2.0);
186180
let chi2_upper = chi2.inverse_cdf(1.0 - alpha / 2.0);
187181

182+
let result_ok = chi2_lower.is_finite() && chi2_upper.is_finite();
183+
184+
assert!(
185+
result_ok,
186+
"Got an invalid value as a result of Chi2 inverse CDF with: \n\
187+
sample_count={sample_count} \n\
188+
probability_to_be_in_the_interval={probability_to_be_in_the_interval} \n\
189+
this is a known issue with statrs, \
190+
try to change your number of samples to get a computable value."
191+
);
192+
188193
// Lower bound is divided by Chi_right^2 so by chi2_upper, upper bound divided by Chi_left^2
189194
// so chi2_lower
190195
let lower_bound = Variance(degrees_of_freedom * measured_variance.0 / chi2_upper);

0 commit comments

Comments
 (0)