refactor: update random number generation to use rand::make_rng() and upgrade rand to version 0.10
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@ categories = ["algorithm", "science", "data-structures"]
|
||||
readme = "README.md"
|
||||
|
||||
[dependencies]
|
||||
rand = "0.9"
|
||||
rand = "0.10"
|
||||
thiserror = "2"
|
||||
parking_lot = "0.12"
|
||||
tokio = { version = "1", features = ["sync", "rt-multi-thread"], optional = true }
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
//! parameter independently, the multivariate KDE models the joint distribution
|
||||
//! to better capture correlations between parameters.
|
||||
|
||||
use rand::Rng;
|
||||
use rand::{Rng, RngExt};
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//! This module provides a Gaussian kernel density estimator used by the TPE
|
||||
//! sampler to model probability distributions over good and bad trial regions.
|
||||
|
||||
use rand::Rng;
|
||||
use rand::{Rng, RngExt};
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use parking_lot::Mutex;
|
||||
use rand::rngs::StdRng;
|
||||
use rand::{Rng, SeedableRng};
|
||||
use rand::{RngExt, SeedableRng};
|
||||
|
||||
use crate::distribution::Distribution;
|
||||
use crate::param::ParamValue;
|
||||
@@ -34,7 +34,7 @@ impl RandomSampler {
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
rng: Mutex::new(StdRng::from_os_rng()),
|
||||
rng: Mutex::new(rand::make_rng()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -116,8 +116,8 @@ use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use parking_lot::Mutex;
|
||||
use rand::SeedableRng;
|
||||
use rand::rngs::StdRng;
|
||||
use rand::{RngExt, SeedableRng};
|
||||
|
||||
use super::{FixedGamma, GammaStrategy};
|
||||
use crate::distribution::Distribution;
|
||||
@@ -219,7 +219,7 @@ impl MultivariateTpeSampler {
|
||||
n_ei_candidates: 24,
|
||||
group: false,
|
||||
constant_liar: ConstantLiarStrategy::None,
|
||||
rng: Mutex::new(StdRng::from_os_rng()),
|
||||
rng: Mutex::new(rand::make_rng()),
|
||||
joint_sample_cache: Mutex::new(None),
|
||||
}
|
||||
}
|
||||
@@ -782,8 +782,6 @@ impl MultivariateTpeSampler {
|
||||
distribution: &Distribution,
|
||||
rng: &mut rand::rngs::StdRng,
|
||||
) -> ParamValue {
|
||||
use rand::Rng;
|
||||
|
||||
match distribution {
|
||||
Distribution::Float(d) => {
|
||||
let value = if d.log_scale {
|
||||
@@ -1374,8 +1372,6 @@ impl MultivariateTpeSampler {
|
||||
bad_values: Vec<f64>,
|
||||
rng: &mut StdRng,
|
||||
) -> f64 {
|
||||
use rand::Rng;
|
||||
|
||||
use crate::kde::KernelDensityEstimator;
|
||||
|
||||
// Transform to internal space (log space if needed)
|
||||
@@ -1568,8 +1564,6 @@ impl MultivariateTpeSampler {
|
||||
bad_indices: &[usize],
|
||||
rng: &mut rand::rngs::StdRng,
|
||||
) -> usize {
|
||||
use rand::Rng;
|
||||
|
||||
// Count occurrences in good and bad groups
|
||||
let mut good_counts = vec![0usize; n_choices];
|
||||
let mut bad_counts = vec![0usize; n_choices];
|
||||
@@ -2076,7 +2070,7 @@ impl MultivariateTpeSamplerBuilder {
|
||||
|
||||
let rng = match self.seed {
|
||||
Some(s) => StdRng::seed_from_u64(s),
|
||||
None => StdRng::from_os_rng(),
|
||||
None => rand::make_rng(),
|
||||
};
|
||||
|
||||
Ok(MultivariateTpeSampler {
|
||||
|
||||
@@ -60,7 +60,7 @@ use std::sync::Arc;
|
||||
|
||||
use parking_lot::Mutex;
|
||||
use rand::rngs::StdRng;
|
||||
use rand::{Rng, SeedableRng};
|
||||
use rand::{RngExt, SeedableRng};
|
||||
|
||||
use crate::distribution::Distribution;
|
||||
use crate::error::{Error, Result};
|
||||
@@ -149,7 +149,7 @@ impl TpeSampler {
|
||||
n_startup_trials: 10,
|
||||
n_ei_candidates: 24,
|
||||
kde_bandwidth: None,
|
||||
rng: Mutex::new(StdRng::from_os_rng()),
|
||||
rng: Mutex::new(rand::make_rng()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ impl TpeSampler {
|
||||
|
||||
let rng = match seed {
|
||||
Some(s) => StdRng::seed_from_u64(s),
|
||||
None => StdRng::from_os_rng(),
|
||||
None => rand::make_rng(),
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
@@ -857,7 +857,7 @@ impl TpeSamplerBuilder {
|
||||
|
||||
let rng = match self.seed {
|
||||
Some(s) => StdRng::seed_from_u64(s),
|
||||
None => StdRng::from_os_rng(),
|
||||
None => rand::make_rng(),
|
||||
};
|
||||
|
||||
Ok(TpeSampler {
|
||||
|
||||
Reference in New Issue
Block a user