wasm-bhtsne 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -22
- package/package.json +1 -1
- package/wasm_bhtsne.d.ts +19 -0
- package/wasm_bhtsne_bg.js +21 -0
- package/wasm_bhtsne_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -11,21 +11,13 @@ This is the wasm version of the [bhtsne](https://github.com/frjnn/bhtsne) crate.
|
|
|
11
11
|
Parallel implementations of Barnes-Hut and exact implementations of the t-SNE algorithm written in Rust to run in wasm. The tree-accelerated version of the algorithm is described with fine detail in [this paper](http://lvdmaaten.github.io/publications/papers/JMLR_2014.pdf) by [Laurens van der Maaten](https://github.com/lvdmaaten). The exact, original, version of the algorithm is described in [this other paper](https://www.jmlr.org/papers/volume9/vandermaaten08a/vandermaaten08a.pdf) by [G. Hinton](https://www.cs.toronto.edu/~hinton/) and Laurens van der Maaten.
|
|
12
12
|
Additional implementations of the algorithm, are listed at [this page](http://lvdmaaten.github.io/tsne/).
|
|
13
13
|
|
|
14
|
-
## Installation
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
```toml
|
|
18
|
-
[dependencies]
|
|
19
|
-
bhtsne = "0.5.2"
|
|
14
|
+
## Installation
|
|
15
|
+
```shell
|
|
16
|
+
npm i wasm-bhtsne
|
|
20
17
|
```
|
|
21
|
-
### Documentation
|
|
22
|
-
|
|
23
|
-
The API documentation is available [here](https://docs.rs/bhtsne).
|
|
24
18
|
|
|
25
19
|
### Example
|
|
26
20
|
|
|
27
|
-
The implementation supports custom data types and custom defined metrics. For instance, general vector data can be handled in the following way.
|
|
28
|
-
|
|
29
21
|
```javascript
|
|
30
22
|
import {tSNE} from "wasm-bhtsne";
|
|
31
23
|
|
|
@@ -41,14 +33,4 @@ tsne_encoder.exact();
|
|
|
41
33
|
const embedded_stuff = tsne_encoder.embedding();
|
|
42
34
|
|
|
43
35
|
console.log(embedded_stuff);
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
In the example euclidean distance is used, but any other distance metric on data types of choice, such as strings, can be defined and plugged in.
|
|
47
|
-
|
|
48
|
-
## Parallelism
|
|
49
|
-
Being built on [rayon](https://github.com/rayon-rs/rayon), the algorithm uses the same number of threads as the number of CPUs available. Do note that on systems with hyperthreading enabled this equals the number of logical cores and not the physical ones. See [rayon's FAQs](https://github.com/rayon-rs/rayon/blob/master/FAQ.md) for additional informations.
|
|
50
|
-
|
|
51
|
-
## MNIST embedding
|
|
52
|
-
The following embedding has been obtained by preprocessing the [MNIST](https://git-disl.github.io/GTDLBench/datasets/mnist_datasets/) train set using PCA to reduce its
|
|
53
|
-
dimensionality to 50. It took approximately **3 minutes and 6 seconds** on a 2.0GHz quad-core 10th-generation i5 MacBook Pro.
|
|
54
|
-

|
|
36
|
+
```
|
package/package.json
CHANGED
package/wasm_bhtsne.d.ts
CHANGED
|
@@ -30,6 +30,25 @@ export class tSNE {
|
|
|
30
30
|
*/
|
|
31
31
|
exact(): void;
|
|
32
32
|
/**
|
|
33
|
+
* Performs a parallel Barnes-Hut approximation of the t-SNE algorithm.
|
|
34
|
+
*
|
|
35
|
+
* # Arguments
|
|
36
|
+
*
|
|
37
|
+
* * `theta` - determines the accuracy of the approximation. Must be **strictly greater than
|
|
38
|
+
* 0.0**. Large values for θ increase the speed of the algorithm but decrease its accuracy.
|
|
39
|
+
* For small values of θ it is less probable that a cell in the space partitioning tree will
|
|
40
|
+
* be treated as a single point. For θ equal to 0.0 the method degenerates in the exact
|
|
41
|
+
* version.
|
|
42
|
+
*
|
|
43
|
+
* * `metric_f` - metric function.
|
|
44
|
+
*
|
|
45
|
+
*
|
|
46
|
+
* **Do note that** `metric_f` **must be a metric distance**, i.e. it must
|
|
47
|
+
* satisfy the [triangle inequality](https://en.wikipedia.org/wiki/Triangle_inequality).
|
|
48
|
+
* @param {number} theta
|
|
49
|
+
*/
|
|
50
|
+
barnes_hut(theta: number): void;
|
|
51
|
+
/**
|
|
33
52
|
* Sets a new value for the embedding dimension.
|
|
34
53
|
*
|
|
35
54
|
* # Arguments
|
package/wasm_bhtsne_bg.js
CHANGED
|
@@ -309,6 +309,27 @@ export class tSNE {
|
|
|
309
309
|
exact() {
|
|
310
310
|
wasm.tsne_exact(this.__wbg_ptr);
|
|
311
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Performs a parallel Barnes-Hut approximation of the t-SNE algorithm.
|
|
314
|
+
*
|
|
315
|
+
* # Arguments
|
|
316
|
+
*
|
|
317
|
+
* * `theta` - determines the accuracy of the approximation. Must be **strictly greater than
|
|
318
|
+
* 0.0**. Large values for θ increase the speed of the algorithm but decrease its accuracy.
|
|
319
|
+
* For small values of θ it is less probable that a cell in the space partitioning tree will
|
|
320
|
+
* be treated as a single point. For θ equal to 0.0 the method degenerates in the exact
|
|
321
|
+
* version.
|
|
322
|
+
*
|
|
323
|
+
* * `metric_f` - metric function.
|
|
324
|
+
*
|
|
325
|
+
*
|
|
326
|
+
* **Do note that** `metric_f` **must be a metric distance**, i.e. it must
|
|
327
|
+
* satisfy the [triangle inequality](https://en.wikipedia.org/wiki/Triangle_inequality).
|
|
328
|
+
* @param {number} theta
|
|
329
|
+
*/
|
|
330
|
+
barnes_hut(theta) {
|
|
331
|
+
wasm.tsne_barnes_hut(this.__wbg_ptr, theta);
|
|
332
|
+
}
|
|
312
333
|
}
|
|
313
334
|
|
|
314
335
|
export function __wbg_new_abda76e883ba8a5f() {
|
package/wasm_bhtsne_bg.wasm
CHANGED
|
Binary file
|