Skip to content

Commit

Permalink
Treat near-zero intercept values as zero when calculating weights (pa…
Browse files Browse the repository at this point in the history
…ritytech#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>
  • Loading branch information
2 people authored and ark0f committed Feb 27, 2023
1 parent dd9d39e commit 13e65d9
Show file tree
Hide file tree
Showing 2 changed files with 987 additions and 741 deletions.
20 changes: 19 additions & 1 deletion frame/benchmarking/src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}

Expand Down Expand Up @@ -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]);
}
}
Loading

0 comments on commit 13e65d9

Please sign in to comment.