summaryrefslogtreecommitdiffstats
path: root/vendor/criterion/src/kde.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:42 +0000
commit837b550238aa671a591ccf282dddeab29cadb206 (patch)
tree914b6b8862bace72bd3245ca184d374b08d8a672 /vendor/criterion/src/kde.rs
parentAdding debian version 1.70.0+dfsg2-1. (diff)
downloadrustc-837b550238aa671a591ccf282dddeab29cadb206.tar.xz
rustc-837b550238aa671a591ccf282dddeab29cadb206.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/criterion/src/kde.rs')
-rwxr-xr-xvendor/criterion/src/kde.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/vendor/criterion/src/kde.rs b/vendor/criterion/src/kde.rs
new file mode 100755
index 000000000..8812142eb
--- /dev/null
+++ b/vendor/criterion/src/kde.rs
@@ -0,0 +1,41 @@
+use crate::stats::univariate::kde::kernel::Gaussian;
+use crate::stats::univariate::kde::{Bandwidth, Kde};
+use crate::stats::univariate::Sample;
+
+pub fn sweep(
+ sample: &Sample<f64>,
+ npoints: usize,
+ range: Option<(f64, f64)>,
+) -> (Box<[f64]>, Box<[f64]>) {
+ let (xs, ys, _) = sweep_and_estimate(sample, npoints, range, sample[0]);
+ (xs, ys)
+}
+
+pub fn sweep_and_estimate(
+ sample: &Sample<f64>,
+ npoints: usize,
+ range: Option<(f64, f64)>,
+ point_to_estimate: f64,
+) -> (Box<[f64]>, Box<[f64]>, f64) {
+ let x_min = sample.min();
+ let x_max = sample.max();
+
+ let kde = Kde::new(sample, Gaussian, Bandwidth::Silverman);
+ let h = kde.bandwidth();
+
+ let (start, end) = match range {
+ Some((start, end)) => (start, end),
+ None => (x_min - 3. * h, x_max + 3. * h),
+ };
+
+ let mut xs: Vec<f64> = Vec::with_capacity(npoints);
+ let step_size = (end - start) / (npoints - 1) as f64;
+ for n in 0..npoints {
+ xs.push(start + (step_size * n as f64));
+ }
+
+ let ys = kde.map(&xs);
+ let point_estimate = kde.estimate(point_to_estimate);
+
+ (xs.into_boxed_slice(), ys, point_estimate)
+}