Treat near-zero intercept values as zero when calculating weights (#12573)

* Treat near-zero intercept values as zero when calculating weights

* Simplify comparison

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update contract weights

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
Koute
2022-10-28 22:39:59 +02:00
committed by GitHub
parent a1f8a74a37
commit 3faa0bd20d
2 changed files with 987 additions and 741 deletions
+19 -1
View File
@@ -170,7 +170,8 @@ fn linear_regression(
x_vars: usize,
) -> Option<(f64, Vec<f64>, Vec<f64>)> {
let (intercept, params, errors) = raw_linear_regression(&xs, &ys, x_vars, true)?;
if intercept > 0.0 {
if intercept >= -0.0001 {
// The intercept is positive, or is effectively zero.
return Some((intercept, params, errors[1..].to_vec()))
}
@@ -748,4 +749,21 @@ mod tests {
assert_eq!(extrinsic_time.base, 3_000_000_000);
assert_eq!(extrinsic_time.slopes, vec![3_000_000_000]);
}
#[test]
fn intercept_of_a_little_under_zero_is_rounded_up_to_zero() {
// Analytically this should result in an intercept of 0, but
// due to numerical imprecision this will generate an intercept
// equal to roughly -0.0000000000000004440892098500626
let data = vec![
benchmark_result(vec![(BenchmarkParameter::n, 1)], 2, 0, 0, 0),
benchmark_result(vec![(BenchmarkParameter::n, 2)], 4, 0, 0, 0),
benchmark_result(vec![(BenchmarkParameter::n, 3)], 6, 0, 0, 0),
];
let extrinsic_time =
Analysis::min_squares_iqr(&data, BenchmarkSelector::ExtrinsicTime).unwrap();
assert_eq!(extrinsic_time.base, 0);
assert_eq!(extrinsic_time.slopes, vec![2000]);
}
}