evoc_rs/graph/mod.rs
1//! This module contains the needed graph-related functions: kNN graph
2//! generation, fuzzy graph generation, label propagation and the embedding
3//! optimisation.
4
5pub mod embedding;
6pub mod fuzzy_graph;
7pub mod label_prop;
8
9use crate::prelude::*;
10
11////////////
12// Params //
13////////////
14
15/// Default beta1 value for Adam optimisation (Umap-specific)
16pub const UMAP_BETA1: f64 = 0.5;
17/// Default beta2 value for Adam optimisation (Umap-specific)
18pub const UMAP_BETA2: f64 = 0.9;
19
20/// Parameters for the EVoC node embedding
21#[derive(Clone, Debug)]
22pub struct EvocEmbeddingParams<T> {
23 /// Number of iterations during the label propagation
24 pub n_label_prop_iter: usize,
25 /// Base initialisation threshold
26 pub base_init_threshold: usize,
27 /// Scaling parameter
28 pub scaling: T,
29 /// Number of training epochs. Higher values give more refined embeddings at
30 /// the cost of runtime. Default: 50.
31 pub n_epochs: usize,
32 /// Scaling factor in the attractive gradient kernel numerator (
33 /// `-2 * noise_level * d - 2`). Controls how aggressively connected nodes
34 /// attract. Default: 0.5.
35 pub noise_level: T,
36 /// Controls how many negative (repulsive) samples are drawn per positive
37 /// edge sample. Lower values reduce repulsion; setting to zero effectively
38 /// disables it. Default: 1.0.
39 pub negative_sample_rate: T,
40 /// Initial learning rate, linearly decayed to zero over training. Default:
41 /// 0.1.
42 pub initial_alpha: T,
43 /// Adam first moment decay rate. Default: 0.5.
44 pub beta1: T,
45 /// Adam second moment decay rate. Default: 0.9.
46 pub beta2: T,
47 /// Adam numerical stability constant. Default: 1e-7.
48 pub eps: T,
49}
50
51/// Defaults for the EvocEmbeddingParameters
52impl<T: EvocFloat> Default for EvocEmbeddingParams<T> {
53 fn default() -> Self {
54 Self {
55 n_label_prop_iter: 20,
56 base_init_threshold: 64,
57 scaling: T::from(0.1).unwrap(),
58 n_epochs: 50,
59 noise_level: T::from(0.5).unwrap(),
60 negative_sample_rate: T::one(),
61 initial_alpha: T::from(0.1).unwrap(),
62 beta1: T::from(UMAP_BETA1).unwrap(),
63 beta2: T::from(UMAP_BETA2).unwrap(),
64 eps: T::from(1e-7).unwrap(),
65 }
66 }
67}