Skip to content

Commit 2aca488

Browse files
Volodymyr OrlovVolodymyr Orlov
authored andcommitted
feat: pre-release
1 parent 4067b20 commit 2aca488

File tree

4 files changed

+8
-33
lines changed

4 files changed

+8
-33
lines changed

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
[package]
22
name = "smartcore"
3+
description = "The most advanced machine learning library in rust."
4+
homepage = "https://smartcorelib.org"
35
version = "0.1.0"
46
authors = ["SmartCore Developers"]
57
edition = "2018"
8+
license = "Apache-2.0"
9+
documentation = "https://docs.rs/smartcore"
10+
repository = "https://github.com/smartcorelib/smartcore"
11+
readme = "README.md"
12+
keywords = ["machine learning", "statistical", "modeling", "machine", "learning", "ai", "optimization", "linear algebra"]
13+
categories = ["science"]
614

715
[features]
816
default = ["datasets"]

src/algorithm/neighbour/bbd_tree.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ impl<T: RealNumber> BBDTree<T> {
101101
) -> T {
102102
let d = centroids[0].len();
103103

104-
// Determine which mean the node mean is closest to
105104
let mut min_dist =
106105
Euclidian::squared_distance(&self.nodes[node].center, &centroids[candidates[0]]);
107106
let mut closest = candidates[0];
@@ -114,9 +113,7 @@ impl<T: RealNumber> BBDTree<T> {
114113
}
115114
}
116115

117-
// If this is a non-leaf node, recurse if necessary
118116
if !self.nodes[node].lower.is_none() {
119-
// Build the new list of candidates
120117
let mut new_candidates = vec![0; k];
121118
let mut newk = 0;
122119

@@ -133,7 +130,6 @@ impl<T: RealNumber> BBDTree<T> {
133130
}
134131
}
135132

136-
// Recurse if there's at least two
137133
if newk > 1 {
138134
return self.filter(
139135
self.nodes[node].lower.unwrap(),
@@ -155,7 +151,6 @@ impl<T: RealNumber> BBDTree<T> {
155151
}
156152
}
157153

158-
// Assigns all data within this node to a single mean
159154
for i in 0..d {
160155
sums[closest][i] = sums[closest][i] + self.nodes[node].sum[i];
161156
}
@@ -203,14 +198,11 @@ impl<T: RealNumber> BBDTree<T> {
203198
fn build_node<M: Matrix<T>>(&mut self, data: &M, begin: usize, end: usize) -> usize {
204199
let (_, d) = data.shape();
205200

206-
// Allocate the node
207201
let mut node = BBDTreeNode::new(d);
208202

209-
// Fill in basic info
210203
node.count = end - begin;
211204
node.index = begin;
212205

213-
// Calculate the bounding box
214206
let mut lower_bound = vec![T::zero(); d];
215207
let mut upper_bound = vec![T::zero(); d];
216208

@@ -231,7 +223,6 @@ impl<T: RealNumber> BBDTree<T> {
231223
}
232224
}
233225

234-
// Calculate bounding box stats
235226
let mut max_radius = T::from(-1.).unwrap();
236227
let mut split_index = 0;
237228
for i in 0..d {
@@ -243,7 +234,6 @@ impl<T: RealNumber> BBDTree<T> {
243234
}
244235
}
245236

246-
// If the max spread is 0, make this a leaf node
247237
if max_radius < T::from(1E-10).unwrap() {
248238
node.lower = Option::None;
249239
node.upper = Option::None;
@@ -262,9 +252,6 @@ impl<T: RealNumber> BBDTree<T> {
262252
return self.add_node(node);
263253
}
264254

265-
// Partition the data around the midpoint in this dimension. The
266-
// partitioning is done in-place by iterating from left-to-right and
267-
// right-to-left in the same way that partioning is done in quicksort.
268255
let split_cutoff = node.center[split_index];
269256
let mut i1 = begin;
270257
let mut i2 = end - 1;
@@ -291,11 +278,9 @@ impl<T: RealNumber> BBDTree<T> {
291278
}
292279
}
293280

294-
// Create the child nodes
295281
node.lower = Option::Some(self.build_node(data, begin, begin + size));
296282
node.upper = Option::Some(self.build_node(data, begin + size, end));
297283

298-
// Calculate the new sum and opt cost
299284
for i in 0..d {
300285
node.sum[i] =
301286
self.nodes[node.lower.unwrap()].sum[i] + self.nodes[node.upper.unwrap()].sum[i];

src/cluster/kmeans.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,8 @@ impl<T: RealNumber + Sum> KMeans<T> {
222222

223223
let mut row = vec![T::zero(); m];
224224

225-
// pick the next center
226225
for j in 1..k {
227-
// Loop over the samples and compare them to the most recent center. Store
228-
// the distance from each sample to its closest center in scores.
229226
for i in 0..n {
230-
// compute the distance between this sample and the current center
231227
data.copy_row_as_vec(i, &mut row);
232228
let dist = Euclidian::squared_distance(&row, &centroid);
233229

@@ -257,7 +253,6 @@ impl<T: RealNumber + Sum> KMeans<T> {
257253

258254
for i in 0..n {
259255
data.copy_row_as_vec(i, &mut row);
260-
// compute the distance between this sample and the current center
261256
let dist = Euclidian::squared_distance(&row, &centroid);
262257

263258
if dist < d[i] {

src/linalg/evd.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ fn tred2<T: RealNumber, M: BaseMatrix<T>>(V: &mut M, d: &mut Vec<T>, e: &mut Vec
103103
d[i] = V.get(n - 1, i);
104104
}
105105

106-
// Householder reduction to tridiagonal form.
107106
for i in (1..n).rev() {
108-
// Scale to avoid under/overflow.
109107
let mut scale = T::zero();
110108
let mut h = T::zero();
111109
for k in 0..i {
@@ -119,7 +117,6 @@ fn tred2<T: RealNumber, M: BaseMatrix<T>>(V: &mut M, d: &mut Vec<T>, e: &mut Vec
119117
V.set(j, i, T::zero());
120118
}
121119
} else {
122-
// Generate Householder vector.
123120
for k in 0..i {
124121
d[k] = d[k] / scale;
125122
h = h + d[k] * d[k];
@@ -136,7 +133,6 @@ fn tred2<T: RealNumber, M: BaseMatrix<T>>(V: &mut M, d: &mut Vec<T>, e: &mut Vec
136133
e[j] = T::zero();
137134
}
138135

139-
// Apply similarity transformation to remaining columns.
140136
for j in 0..i {
141137
f = d[j];
142138
V.set(j, i, f);
@@ -169,7 +165,6 @@ fn tred2<T: RealNumber, M: BaseMatrix<T>>(V: &mut M, d: &mut Vec<T>, e: &mut Vec
169165
d[i] = h;
170166
}
171167

172-
// Accumulate transformations.
173168
for i in 0..n - 1 {
174169
V.set(n - 1, i, V.get(i, i));
175170
V.set(i, i, T::one());
@@ -210,7 +205,6 @@ fn tql2<T: RealNumber, M: BaseMatrix<T>>(V: &mut M, d: &mut Vec<T>, e: &mut Vec<
210205
let mut f = T::zero();
211206
let mut tst1 = T::zero();
212207
for l in 0..n {
213-
// Find small subdiagonal element
214208
tst1 = T::max(tst1, d[l].abs() + e[l].abs());
215209

216210
let mut m = l;
@@ -226,8 +220,6 @@ fn tql2<T: RealNumber, M: BaseMatrix<T>>(V: &mut M, d: &mut Vec<T>, e: &mut Vec<
226220
}
227221
}
228222

229-
// If m == l, d[l] is an eigenvalue,
230-
// otherwise, iterate.
231223
if m > l {
232224
let mut iter = 0;
233225
loop {
@@ -236,7 +228,6 @@ fn tql2<T: RealNumber, M: BaseMatrix<T>>(V: &mut M, d: &mut Vec<T>, e: &mut Vec<
236228
panic!("Too many iterations");
237229
}
238230

239-
// Compute implicit shift
240231
let mut g = d[l];
241232
let mut p = (d[l + 1] - g) / (T::two() * e[l]);
242233
let mut r = p.hypot(T::one());
@@ -252,7 +243,6 @@ fn tql2<T: RealNumber, M: BaseMatrix<T>>(V: &mut M, d: &mut Vec<T>, e: &mut Vec<
252243
}
253244
f = f + h;
254245

255-
// Implicit QL transformation.
256246
p = d[m];
257247
let mut c = T::one();
258248
let mut c2 = c;
@@ -273,7 +263,6 @@ fn tql2<T: RealNumber, M: BaseMatrix<T>>(V: &mut M, d: &mut Vec<T>, e: &mut Vec<
273263
p = c * d[i] - s * g;
274264
d[i + 1] = h + s * (c * g + s * d[i]);
275265

276-
// Accumulate transformation.
277266
for k in 0..n {
278267
h = V.get(k, i + 1);
279268
V.set(k, i + 1, s * V.get(k, i) + c * h);
@@ -284,7 +273,6 @@ fn tql2<T: RealNumber, M: BaseMatrix<T>>(V: &mut M, d: &mut Vec<T>, e: &mut Vec<
284273
e[l] = s * p;
285274
d[l] = c * p;
286275

287-
// Check for convergence.
288276
if e[l].abs() <= tst1 * T::epsilon() {
289277
break;
290278
}
@@ -294,7 +282,6 @@ fn tql2<T: RealNumber, M: BaseMatrix<T>>(V: &mut M, d: &mut Vec<T>, e: &mut Vec<
294282
e[l] = T::zero();
295283
}
296284

297-
// Sort eigenvalues and corresponding vectors.
298285
for i in 0..n - 1 {
299286
let mut k = i;
300287
let mut p = d[i];

0 commit comments

Comments
 (0)