Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ categories = ["science"]
license = "MIT"

[dependencies]
ordered-float = "2"
rand = "0.8"
rand_distr = "0.4"
statrs = "0.15"
Expand Down
5 changes: 2 additions & 3 deletions src/density_estimation/parzen.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::density_estimation::{BuildDensityEstimator, DensityEstimator};
use crate::Range;
use ordered_float::OrderedFloat;
use rand::distributions::Distribution;
use rand::seq::SliceRandom;
use rand::Rng;
Expand Down Expand Up @@ -62,7 +61,7 @@ impl BuildDensityEstimator for ParzenEstimatorBuilder {
stddev: f64::NAN,
})
.collect::<Vec<_>>();
xs.sort_by_key(|x| OrderedFloat(x.mean));
xs.sort_by(|x, y| x.mean.total_cmp(&y.mean));

self.setup_stddev(&mut xs, range);

Expand Down Expand Up @@ -126,7 +125,7 @@ impl DensityEstimator for ParzenEstimator {
fn logsumexp(xs: &[f64]) -> f64 {
let max_x = xs
.iter()
.max_by_key(|&&x| OrderedFloat(x))
.max_by(|x, y| x.total_cmp(y))
.expect("unreachable");
xs.iter().map(|&x| (x - max_x).exp()).sum::<f64>().ln() + max_x
}
Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ use crate::density_estimation::{BuildDensityEstimator, DefaultEstimatorBuilder,
#[cfg(doc)]
use crate::density_estimation::{HistogramEstimator, ParzenEstimator};
use crate::range::{Range, RangeError};
use ordered_float::OrderedFloat;
use rand::distributions::Distribution;
use rand::Rng;
use std::num::NonZeroUsize;
Expand Down Expand Up @@ -171,7 +170,7 @@ impl<T: BuildDensityEstimator> TpeOptimizer<T> {
/// to reduce bias due to too few samples.
pub fn ask<R: Rng + ?Sized>(&mut self, rng: &mut R) -> Result<f64, T::Error> {
if !self.is_sorted {
self.trials.sort_by_key(|t| OrderedFloat(t.value));
self.trials.sort_by(|x, y| x.value.total_cmp(&y.value));
self.is_sorted = true;
}

Expand All @@ -196,7 +195,7 @@ impl<T: BuildDensityEstimator> TpeOptimizer<T> {
let ei = superior_log_likelihood - inferior_log_likelihood;
(ei, candidate)
})
.max_by_key(|(ei, _)| OrderedFloat(*ei))
.max_by(|(ei0, _), (ei1, _)| ei0.total_cmp(ei1))
.map(|(_, param)| param)
.expect("unreachable");
Ok(param)
Expand Down