1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//! This module defines parameters for ann embedding.
//!
/// It is necessary to describe briefly the model used in the embedding:
///
/// ## Definition of the weight of an edge of the graph to embed
///
/// First we define the local scale $\rho$ around a point.
/// It is defined as the mean of distances of points to their nearest neighbour.
/// The points taken into account to define $\rho$ are the node we consider and
/// all its knbn neighbours. So we compute the mean of distances to nearest neighbours
/// on knbn + 1 points around current point.
///
/// let ($d_{i}$) be the sorted distances in increasing order of neighbours for i=0..k of a node n,
/// $$w_{i} = \exp\left(- \left(\frac{d_{i} - d_{0}}{S * \rho}\right)^{\beta} \right)$$
///
/// S is a scale factor modulating $\rho$.
/// After that weights are normalized to a probability distribution.
///
/// So before normalization $w_{0}$ is always equal to 1. Augmenting β to 2. makes the weight $w_{i}$ decrease faster.
/// *The least weight of an edge must not go under $10^{-5}$ to limit the range of weight and avoid Svd numeric difficulties*.
/// The code stops with an error in this case.
/// So after normalization the range of weights from $w_{0}$ to $w_{k}$ is larger.
/// Reducing S as similar effect but playing with both $\beta$ and the scale adjustment must not violate the range constraint on weights.
///
/// It must be noted that setting the scale as described before and renormalizing to get a probability distribution
/// gives a perplexity nearly equal to the number of neighbours.
/// This can be verified by using the logging (implemented using the crates **env_logger** and **log**) and setting
/// RUST_LOG=annembed=INFO in your environment.
/// Then quantile summaries are given for the distributions of edge distances, edge weights, and perplexity
/// of nodes. This helps adjusting parameters β, Scale and show their impact on these quantiles.
///
///
/// Default value :
///
/// $\beta = 1$ so that we have exponential weights similar to Umap.
///
/// $S = 0.5$
///
/// But it is possible to set β to 2. to get more gaussian weight or reduce to 0.5 and adjust S to respect the constraints on edge weights.
///
/// ## Definition of the weight of an edge of the embedded graph
///
/// The embedded edge has the usual expression :
/// $$ w(x,y) = \frac{1}{1+ || \left((x - y)/a_{x} \right)||^{2*b} } $$
///
/// by default b = 1.
/// The coefficient $a_{x}$ is deduced from the scale coefficient in the original space with some
/// restriction to avoid too large fluctuations.
///
///
///
/// - Initial step of the gradient and number of batches
///
/// A number of batch for the Mnist digits data around 10-20 seems sufficient.
/// The initial gradient step $\gamma_{0}$ can be chosen around 1. (in the range 1/5 ... 5.).
/// Reasonably it should satisfy nb_batch $ * \gamma_{0} < 1 $
///
/// - asked_dimension : default is set to 2.
///
/// ## The optimization of the embedding
///
/// The embedding is optimized by minimizing the (Shannon at present time) cross entropy
/// between distribution of original and embedded weight of edges. This minimization is done
/// by a standard (multithreaded) stochastic gradient with negative sampling for the unobserved edges
/// (see [Mnih-Teh](https://arxiv.org/abs/1206.6426) or
/// [Mikolov](https://proceedings.neurips.cc/paper/2013/file/9aa42b31882ec039965f3c4923ce901b-Paper.pdf))
///
/// The number of negative edge sampling is set to a fixed value 5.
///
/// - expression of the gradient
///
/// main parameters driving Embeding
// end of EmbedderParams
// end of impl EmbedderParams