Set good defaults during builder construction
This commit is contained in:
parent
1f6f7b6c75
commit
afda7a0831
|
@ -20,11 +20,11 @@ use types::{Candidate, Layer, LayerId, UpperNode, Visited, ZeroNode, INVALID};
|
||||||
|
|
||||||
/// Parameters for building the `Hnsw`
|
/// Parameters for building the `Hnsw`
|
||||||
pub struct Builder {
|
pub struct Builder {
|
||||||
ef_search: Option<usize>,
|
ef_search: usize,
|
||||||
ef_construction: Option<usize>,
|
ef_construction: usize,
|
||||||
heuristic: Option<Heuristic>,
|
heuristic: Option<Heuristic>,
|
||||||
ml: Option<f32>,
|
ml: f32,
|
||||||
seed: Option<u64>,
|
seed: u64,
|
||||||
#[cfg(feature = "indicatif")]
|
#[cfg(feature = "indicatif")]
|
||||||
progress: Option<ProgressBar>,
|
progress: Option<ProgressBar>,
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ pub struct Builder {
|
||||||
impl Builder {
|
impl Builder {
|
||||||
/// Set the `efConstruction` parameter from the paper
|
/// Set the `efConstruction` parameter from the paper
|
||||||
pub fn ef_construction(mut self, ef_construction: usize) -> Self {
|
pub fn ef_construction(mut self, ef_construction: usize) -> Self {
|
||||||
self.ef_construction = Some(ef_construction);
|
self.ef_construction = ef_construction;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ impl Builder {
|
||||||
/// If the `efConstruction` parameter is not already set, it will be set
|
/// If the `efConstruction` parameter is not already set, it will be set
|
||||||
/// to the same value as `ef` by default.
|
/// to the same value as `ef` by default.
|
||||||
pub fn ef_search(mut self, ef: usize) -> Self {
|
pub fn ef_search(mut self, ef: usize) -> Self {
|
||||||
self.ef_search = Some(ef);
|
self.ef_search = ef;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ impl Builder {
|
||||||
///
|
///
|
||||||
/// If the `mL` parameter is not already set, it defaults to `1.0 / ln(M)`.
|
/// If the `mL` parameter is not already set, it defaults to `1.0 / ln(M)`.
|
||||||
pub fn ml(mut self, ml: f32) -> Self {
|
pub fn ml(mut self, ml: f32) -> Self {
|
||||||
self.ml = Some(ml);
|
self.ml = ml;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ impl Builder {
|
||||||
///
|
///
|
||||||
/// If this value is left unset, a seed is generated from entropy (via `getrandom()`).
|
/// If this value is left unset, a seed is generated from entropy (via `getrandom()`).
|
||||||
pub fn seed(mut self, seed: u64) -> Self {
|
pub fn seed(mut self, seed: u64) -> Self {
|
||||||
self.seed = Some(seed);
|
self.seed = seed;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,11 +82,11 @@ impl Builder {
|
||||||
impl Default for Builder {
|
impl Default for Builder {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
ef_search: None,
|
ef_search: 100,
|
||||||
ef_construction: None,
|
ef_construction: 100,
|
||||||
heuristic: Some(Heuristic::default()),
|
heuristic: Some(Heuristic::default()),
|
||||||
ml: None,
|
ml: 1.0 / (M as f32).ln(),
|
||||||
seed: None,
|
seed: rand::random(),
|
||||||
#[cfg(feature = "indicatif")]
|
#[cfg(feature = "indicatif")]
|
||||||
progress: None,
|
progress: None,
|
||||||
}
|
}
|
||||||
|
@ -125,14 +125,11 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new(points: &[P], builder: Builder) -> (Self, Vec<PointId>) {
|
fn new(points: &[P], builder: Builder) -> (Self, Vec<PointId>) {
|
||||||
let ef_search = builder.ef_search.unwrap_or(100);
|
let ef_search = builder.ef_search;
|
||||||
let ef_construction = builder.ef_construction.unwrap_or(100);
|
let ef_construction = builder.ef_construction;
|
||||||
let ml = builder.ml.unwrap_or_else(|| 1.0 / (M as f32).ln());
|
let ml = builder.ml;
|
||||||
let heuristic = builder.heuristic;
|
let heuristic = builder.heuristic;
|
||||||
let mut rng = match builder.seed {
|
let mut rng = SmallRng::seed_from_u64(builder.seed);
|
||||||
Some(seed) => SmallRng::seed_from_u64(seed),
|
|
||||||
None => SmallRng::from_entropy(),
|
|
||||||
};
|
|
||||||
|
|
||||||
#[cfg(feature = "indicatif")]
|
#[cfg(feature = "indicatif")]
|
||||||
let progress = builder.progress;
|
let progress = builder.progress;
|
||||||
|
|
Loading…
Reference in New Issue