wasm-bhtsne 0.1.2
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/LICENSE +21 -0
- package/README.md +54 -0
- package/package.json +25 -0
- package/wasm_bhtsne.d.ts +103 -0
- package/wasm_bhtsne.js +4 -0
- package/wasm_bhtsne_bg.js +484 -0
- package/wasm_bhtsne_bg.wasm +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Francesco Iannelli
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<div align="center"> <h1 align="center"> wasm-bhtsne </h1> </div>
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
This is the wasm version of the [bhtsne](https://github.com/frjnn/bhtsne) crate.
|
|
10
|
+
|
|
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
|
+
Additional implementations of the algorithm, are listed at [this page](http://lvdmaaten.github.io/tsne/).
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
Add this line to your `Cargo.toml`:
|
|
17
|
+
```toml
|
|
18
|
+
[dependencies]
|
|
19
|
+
bhtsne = "0.5.2"
|
|
20
|
+
```
|
|
21
|
+
### Documentation
|
|
22
|
+
|
|
23
|
+
The API documentation is available [here](https://docs.rs/bhtsne).
|
|
24
|
+
|
|
25
|
+
### Example
|
|
26
|
+
|
|
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
|
+
```javascript
|
|
30
|
+
import {tSNE} from "wasm-bhtsne";
|
|
31
|
+
|
|
32
|
+
const data = [];
|
|
33
|
+
|
|
34
|
+
for (let i = 0; i < 300; i++) {
|
|
35
|
+
const randomNumber = Math.random();
|
|
36
|
+
data.push(randomNumber);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const tsne_encoder = new tSNE(data, 4);
|
|
40
|
+
tsne_encoder.exact();
|
|
41
|
+
const embedded_stuff = tsne_encoder.embedding();
|
|
42
|
+
|
|
43
|
+
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
|
+

|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wasm-bhtsne",
|
|
3
|
+
"collaborators": [
|
|
4
|
+
"lv291 <baiunco291@proton.me>"
|
|
5
|
+
],
|
|
6
|
+
"description": "Exact and Barnes-Hut implementations of t-SNE in wasm",
|
|
7
|
+
"version": "0.1.2",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/Lv-291/wasm-bhtsne"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"wasm_bhtsne_bg.wasm",
|
|
15
|
+
"wasm_bhtsne.js",
|
|
16
|
+
"wasm_bhtsne_bg.js",
|
|
17
|
+
"wasm_bhtsne.d.ts"
|
|
18
|
+
],
|
|
19
|
+
"module": "wasm_bhtsne.js",
|
|
20
|
+
"types": "wasm_bhtsne.d.ts",
|
|
21
|
+
"sideEffects": [
|
|
22
|
+
"./wasm_bhtsne.js",
|
|
23
|
+
"./snippets/*"
|
|
24
|
+
]
|
|
25
|
+
}
|
package/wasm_bhtsne.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* t-distributed stochastic neighbor embedding. Provides a parallel implementation of both the
|
|
5
|
+
* exact version of the algorithm and the tree accelerated one leveraging space partitioning trees.
|
|
6
|
+
*/
|
|
7
|
+
export class tSNE {
|
|
8
|
+
free(): void;
|
|
9
|
+
/**
|
|
10
|
+
* @param {Float32Array} data
|
|
11
|
+
* @param {number} d
|
|
12
|
+
*/
|
|
13
|
+
constructor(data: Float32Array, d: number);
|
|
14
|
+
/**
|
|
15
|
+
* Returns the computed embedding.
|
|
16
|
+
* @returns {Float32Array}
|
|
17
|
+
*/
|
|
18
|
+
embedding(): Float32Array;
|
|
19
|
+
/**
|
|
20
|
+
* Performs a parallel exact version of the t-SNE algorithm. Pairwise distances between samples
|
|
21
|
+
* in the input space will be computed accordingly to the supplied function `distance_f`.
|
|
22
|
+
*
|
|
23
|
+
* # Arguments
|
|
24
|
+
*
|
|
25
|
+
* `distance_f` - distance function.
|
|
26
|
+
*
|
|
27
|
+
* **Do note** that such a distance function needs not to be a metric distance, i.e. it is not
|
|
28
|
+
* necessary for it so satisfy the triangle inequality. Consequently, the squared euclidean
|
|
29
|
+
* distance, and many other, can be used.
|
|
30
|
+
*/
|
|
31
|
+
exact(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Sets a new value for the embedding dimension.
|
|
34
|
+
*
|
|
35
|
+
* # Arguments
|
|
36
|
+
*
|
|
37
|
+
* `embedding_dim` - new value for the embedding space dimensionality.
|
|
38
|
+
*/
|
|
39
|
+
embedding_dim: number;
|
|
40
|
+
/**
|
|
41
|
+
* Sets new epochs, i.e the maximum number of fitting iterations.
|
|
42
|
+
*
|
|
43
|
+
* # Arguments
|
|
44
|
+
*
|
|
45
|
+
* `epochs` - new value for the epochs.
|
|
46
|
+
*/
|
|
47
|
+
epochs: number;
|
|
48
|
+
/**
|
|
49
|
+
* Sets a new final momentum.
|
|
50
|
+
*
|
|
51
|
+
* # Arguments
|
|
52
|
+
*
|
|
53
|
+
* `final_momentum` - new value for the final momentum.
|
|
54
|
+
*/
|
|
55
|
+
final_momentum: number;
|
|
56
|
+
/**
|
|
57
|
+
* Sets a new learning rate.
|
|
58
|
+
*
|
|
59
|
+
* # Arguments
|
|
60
|
+
*
|
|
61
|
+
* `learning_rate` - new value for the learning rate.
|
|
62
|
+
*/
|
|
63
|
+
learning_rate: number;
|
|
64
|
+
/**
|
|
65
|
+
* Sets a new momentum.
|
|
66
|
+
*
|
|
67
|
+
* # Arguments
|
|
68
|
+
*
|
|
69
|
+
* `momentum` - new value for the momentum.
|
|
70
|
+
*/
|
|
71
|
+
momentum: number;
|
|
72
|
+
/**
|
|
73
|
+
* Sets a new momentum switch epoch, i.e. the epoch after which the algorithm switches to
|
|
74
|
+
* `final_momentum` for the map update.
|
|
75
|
+
*
|
|
76
|
+
* # Arguments
|
|
77
|
+
*
|
|
78
|
+
* `momentum_switch_epoch` - new value for the momentum switch epoch.
|
|
79
|
+
*/
|
|
80
|
+
momentum_switch_epoch: number;
|
|
81
|
+
/**
|
|
82
|
+
* Sets a new perplexity value.
|
|
83
|
+
*
|
|
84
|
+
* # Arguments
|
|
85
|
+
*
|
|
86
|
+
* `perplexity` - new value for the perplexity. It's used so that the bandwidth of the Gaussian
|
|
87
|
+
* kernels, is set in such a way that the perplexity of each the conditional distribution *Pi*
|
|
88
|
+
* equals a predefined perplexity *u*.
|
|
89
|
+
*
|
|
90
|
+
* A good value for perplexity lies between 5.0 and 50.0.
|
|
91
|
+
*/
|
|
92
|
+
perplexity: number;
|
|
93
|
+
/**
|
|
94
|
+
* Sets a new stop lying epoch, i.e. the epoch after which the P distribution values become
|
|
95
|
+
* true, as defined in the original implementation. For epochs < `stop_lying_epoch` the values
|
|
96
|
+
* of the P distribution are multiplied by a factor equal to `12.0`.
|
|
97
|
+
*
|
|
98
|
+
* # Arguments
|
|
99
|
+
*
|
|
100
|
+
* `stop_lying_epoch` - new value for the stop lying epoch.
|
|
101
|
+
*/
|
|
102
|
+
stop_lying_epoch: number;
|
|
103
|
+
}
|
package/wasm_bhtsne.js
ADDED
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
let wasm;
|
|
2
|
+
export function __wbg_set_wasm(val) {
|
|
3
|
+
wasm = val;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const heap = new Array(128).fill(undefined);
|
|
8
|
+
|
|
9
|
+
heap.push(undefined, null, true, false);
|
|
10
|
+
|
|
11
|
+
function getObject(idx) { return heap[idx]; }
|
|
12
|
+
|
|
13
|
+
let heap_next = heap.length;
|
|
14
|
+
|
|
15
|
+
function dropObject(idx) {
|
|
16
|
+
if (idx < 132) return;
|
|
17
|
+
heap[idx] = heap_next;
|
|
18
|
+
heap_next = idx;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function takeObject(idx) {
|
|
22
|
+
const ret = getObject(idx);
|
|
23
|
+
dropObject(idx);
|
|
24
|
+
return ret;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
|
|
28
|
+
|
|
29
|
+
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
30
|
+
|
|
31
|
+
cachedTextDecoder.decode();
|
|
32
|
+
|
|
33
|
+
let cachedUint8Memory0 = null;
|
|
34
|
+
|
|
35
|
+
function getUint8Memory0() {
|
|
36
|
+
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
|
|
37
|
+
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
|
38
|
+
}
|
|
39
|
+
return cachedUint8Memory0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getStringFromWasm0(ptr, len) {
|
|
43
|
+
ptr = ptr >>> 0;
|
|
44
|
+
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function addHeapObject(obj) {
|
|
48
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
49
|
+
const idx = heap_next;
|
|
50
|
+
heap_next = heap[idx];
|
|
51
|
+
|
|
52
|
+
heap[idx] = obj;
|
|
53
|
+
return idx;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let cachedFloat32Memory0 = null;
|
|
57
|
+
|
|
58
|
+
function getFloat32Memory0() {
|
|
59
|
+
if (cachedFloat32Memory0 === null || cachedFloat32Memory0.byteLength === 0) {
|
|
60
|
+
cachedFloat32Memory0 = new Float32Array(wasm.memory.buffer);
|
|
61
|
+
}
|
|
62
|
+
return cachedFloat32Memory0;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let WASM_VECTOR_LEN = 0;
|
|
66
|
+
|
|
67
|
+
function passArrayF32ToWasm0(arg, malloc) {
|
|
68
|
+
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
|
69
|
+
getFloat32Memory0().set(arg, ptr / 4);
|
|
70
|
+
WASM_VECTOR_LEN = arg.length;
|
|
71
|
+
return ptr;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let cachedInt32Memory0 = null;
|
|
75
|
+
|
|
76
|
+
function getInt32Memory0() {
|
|
77
|
+
if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
|
|
78
|
+
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
|
79
|
+
}
|
|
80
|
+
return cachedInt32Memory0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function getArrayF32FromWasm0(ptr, len) {
|
|
84
|
+
ptr = ptr >>> 0;
|
|
85
|
+
return getFloat32Memory0().subarray(ptr / 4, ptr / 4 + len);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
|
|
89
|
+
|
|
90
|
+
let cachedTextEncoder = new lTextEncoder('utf-8');
|
|
91
|
+
|
|
92
|
+
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
93
|
+
? function (arg, view) {
|
|
94
|
+
return cachedTextEncoder.encodeInto(arg, view);
|
|
95
|
+
}
|
|
96
|
+
: function (arg, view) {
|
|
97
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
98
|
+
view.set(buf);
|
|
99
|
+
return {
|
|
100
|
+
read: arg.length,
|
|
101
|
+
written: buf.length
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
106
|
+
|
|
107
|
+
if (realloc === undefined) {
|
|
108
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
109
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
110
|
+
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
111
|
+
WASM_VECTOR_LEN = buf.length;
|
|
112
|
+
return ptr;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let len = arg.length;
|
|
116
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
117
|
+
|
|
118
|
+
const mem = getUint8Memory0();
|
|
119
|
+
|
|
120
|
+
let offset = 0;
|
|
121
|
+
|
|
122
|
+
for (; offset < len; offset++) {
|
|
123
|
+
const code = arg.charCodeAt(offset);
|
|
124
|
+
if (code > 0x7F) break;
|
|
125
|
+
mem[ptr + offset] = code;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (offset !== len) {
|
|
129
|
+
if (offset !== 0) {
|
|
130
|
+
arg = arg.slice(offset);
|
|
131
|
+
}
|
|
132
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
133
|
+
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
|
|
134
|
+
const ret = encodeString(arg, view);
|
|
135
|
+
|
|
136
|
+
offset += ret.written;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
WASM_VECTOR_LEN = offset;
|
|
140
|
+
return ptr;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function handleError(f, args) {
|
|
144
|
+
try {
|
|
145
|
+
return f.apply(this, args);
|
|
146
|
+
} catch (e) {
|
|
147
|
+
wasm.__wbindgen_exn_store(addHeapObject(e));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* t-distributed stochastic neighbor embedding. Provides a parallel implementation of both the
|
|
152
|
+
* exact version of the algorithm and the tree accelerated one leveraging space partitioning trees.
|
|
153
|
+
*/
|
|
154
|
+
export class tSNE {
|
|
155
|
+
|
|
156
|
+
static __wrap(ptr) {
|
|
157
|
+
ptr = ptr >>> 0;
|
|
158
|
+
const obj = Object.create(tSNE.prototype);
|
|
159
|
+
obj.__wbg_ptr = ptr;
|
|
160
|
+
|
|
161
|
+
return obj;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
__destroy_into_raw() {
|
|
165
|
+
const ptr = this.__wbg_ptr;
|
|
166
|
+
this.__wbg_ptr = 0;
|
|
167
|
+
|
|
168
|
+
return ptr;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
free() {
|
|
172
|
+
const ptr = this.__destroy_into_raw();
|
|
173
|
+
wasm.__wbg_tsne_free(ptr);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* @param {Float32Array} data
|
|
177
|
+
* @param {number} d
|
|
178
|
+
*/
|
|
179
|
+
constructor(data, d) {
|
|
180
|
+
const ptr0 = passArrayF32ToWasm0(data, wasm.__wbindgen_malloc);
|
|
181
|
+
const len0 = WASM_VECTOR_LEN;
|
|
182
|
+
const ret = wasm.tsne_new(ptr0, len0, d);
|
|
183
|
+
return tSNE.__wrap(ret);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Sets a new learning rate.
|
|
187
|
+
*
|
|
188
|
+
* # Arguments
|
|
189
|
+
*
|
|
190
|
+
* `learning_rate` - new value for the learning rate.
|
|
191
|
+
* @param {number} learning_rate
|
|
192
|
+
*/
|
|
193
|
+
set learning_rate(learning_rate) {
|
|
194
|
+
wasm.tsne_set_learning_rate(this.__wbg_ptr, learning_rate);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Sets new epochs, i.e the maximum number of fitting iterations.
|
|
198
|
+
*
|
|
199
|
+
* # Arguments
|
|
200
|
+
*
|
|
201
|
+
* `epochs` - new value for the epochs.
|
|
202
|
+
* @param {number} epochs
|
|
203
|
+
*/
|
|
204
|
+
set epochs(epochs) {
|
|
205
|
+
wasm.tsne_set_epochs(this.__wbg_ptr, epochs);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Sets a new momentum.
|
|
209
|
+
*
|
|
210
|
+
* # Arguments
|
|
211
|
+
*
|
|
212
|
+
* `momentum` - new value for the momentum.
|
|
213
|
+
* @param {number} momentum
|
|
214
|
+
*/
|
|
215
|
+
set momentum(momentum) {
|
|
216
|
+
wasm.tsne_set_momentum(this.__wbg_ptr, momentum);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Sets a new final momentum.
|
|
220
|
+
*
|
|
221
|
+
* # Arguments
|
|
222
|
+
*
|
|
223
|
+
* `final_momentum` - new value for the final momentum.
|
|
224
|
+
* @param {number} final_momentum
|
|
225
|
+
*/
|
|
226
|
+
set final_momentum(final_momentum) {
|
|
227
|
+
wasm.tsne_set_final_momentum(this.__wbg_ptr, final_momentum);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Sets a new momentum switch epoch, i.e. the epoch after which the algorithm switches to
|
|
231
|
+
* `final_momentum` for the map update.
|
|
232
|
+
*
|
|
233
|
+
* # Arguments
|
|
234
|
+
*
|
|
235
|
+
* `momentum_switch_epoch` - new value for the momentum switch epoch.
|
|
236
|
+
* @param {number} momentum_switch_epoch
|
|
237
|
+
*/
|
|
238
|
+
set momentum_switch_epoch(momentum_switch_epoch) {
|
|
239
|
+
wasm.tsne_set_momentum_switch_epoch(this.__wbg_ptr, momentum_switch_epoch);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Sets a new stop lying epoch, i.e. the epoch after which the P distribution values become
|
|
243
|
+
* true, as defined in the original implementation. For epochs < `stop_lying_epoch` the values
|
|
244
|
+
* of the P distribution are multiplied by a factor equal to `12.0`.
|
|
245
|
+
*
|
|
246
|
+
* # Arguments
|
|
247
|
+
*
|
|
248
|
+
* `stop_lying_epoch` - new value for the stop lying epoch.
|
|
249
|
+
* @param {number} stop_lying_epoch
|
|
250
|
+
*/
|
|
251
|
+
set stop_lying_epoch(stop_lying_epoch) {
|
|
252
|
+
wasm.tsne_set_stop_lying_epoch(this.__wbg_ptr, stop_lying_epoch);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Sets a new value for the embedding dimension.
|
|
256
|
+
*
|
|
257
|
+
* # Arguments
|
|
258
|
+
*
|
|
259
|
+
* `embedding_dim` - new value for the embedding space dimensionality.
|
|
260
|
+
* @param {number} embedding_dim
|
|
261
|
+
*/
|
|
262
|
+
set embedding_dim(embedding_dim) {
|
|
263
|
+
wasm.tsne_set_embedding_dim(this.__wbg_ptr, embedding_dim);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Sets a new perplexity value.
|
|
267
|
+
*
|
|
268
|
+
* # Arguments
|
|
269
|
+
*
|
|
270
|
+
* `perplexity` - new value for the perplexity. It's used so that the bandwidth of the Gaussian
|
|
271
|
+
* kernels, is set in such a way that the perplexity of each the conditional distribution *Pi*
|
|
272
|
+
* equals a predefined perplexity *u*.
|
|
273
|
+
*
|
|
274
|
+
* A good value for perplexity lies between 5.0 and 50.0.
|
|
275
|
+
* @param {number} perplexity
|
|
276
|
+
*/
|
|
277
|
+
set perplexity(perplexity) {
|
|
278
|
+
wasm.tsne_set_perplexity(this.__wbg_ptr, perplexity);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Returns the computed embedding.
|
|
282
|
+
* @returns {Float32Array}
|
|
283
|
+
*/
|
|
284
|
+
embedding() {
|
|
285
|
+
try {
|
|
286
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
287
|
+
wasm.tsne_embedding(retptr, this.__wbg_ptr);
|
|
288
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
289
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
290
|
+
var v1 = getArrayF32FromWasm0(r0, r1).slice();
|
|
291
|
+
wasm.__wbindgen_free(r0, r1 * 4);
|
|
292
|
+
return v1;
|
|
293
|
+
} finally {
|
|
294
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Performs a parallel exact version of the t-SNE algorithm. Pairwise distances between samples
|
|
299
|
+
* in the input space will be computed accordingly to the supplied function `distance_f`.
|
|
300
|
+
*
|
|
301
|
+
* # Arguments
|
|
302
|
+
*
|
|
303
|
+
* `distance_f` - distance function.
|
|
304
|
+
*
|
|
305
|
+
* **Do note** that such a distance function needs not to be a metric distance, i.e. it is not
|
|
306
|
+
* necessary for it so satisfy the triangle inequality. Consequently, the squared euclidean
|
|
307
|
+
* distance, and many other, can be used.
|
|
308
|
+
*/
|
|
309
|
+
exact() {
|
|
310
|
+
wasm.tsne_exact(this.__wbg_ptr);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export function __wbg_new_abda76e883ba8a5f() {
|
|
315
|
+
const ret = new Error();
|
|
316
|
+
return addHeapObject(ret);
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
export function __wbg_stack_658279fe44541cf6(arg0, arg1) {
|
|
320
|
+
const ret = getObject(arg1).stack;
|
|
321
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
322
|
+
const len1 = WASM_VECTOR_LEN;
|
|
323
|
+
getInt32Memory0()[arg0 / 4 + 1] = len1;
|
|
324
|
+
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
export function __wbg_error_f851667af71bcfc6(arg0, arg1) {
|
|
328
|
+
let deferred0_0;
|
|
329
|
+
let deferred0_1;
|
|
330
|
+
try {
|
|
331
|
+
deferred0_0 = arg0;
|
|
332
|
+
deferred0_1 = arg1;
|
|
333
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
334
|
+
} finally {
|
|
335
|
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
export function __wbindgen_object_drop_ref(arg0) {
|
|
340
|
+
takeObject(arg0);
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
export function __wbg_randomFillSync_dc1e9a60c158336d() { return handleError(function (arg0, arg1) {
|
|
344
|
+
getObject(arg0).randomFillSync(takeObject(arg1));
|
|
345
|
+
}, arguments) };
|
|
346
|
+
|
|
347
|
+
export function __wbg_getRandomValues_37fa2ca9e4e07fab() { return handleError(function (arg0, arg1) {
|
|
348
|
+
getObject(arg0).getRandomValues(getObject(arg1));
|
|
349
|
+
}, arguments) };
|
|
350
|
+
|
|
351
|
+
export function __wbg_crypto_c48a774b022d20ac(arg0) {
|
|
352
|
+
const ret = getObject(arg0).crypto;
|
|
353
|
+
return addHeapObject(ret);
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
export function __wbindgen_is_object(arg0) {
|
|
357
|
+
const val = getObject(arg0);
|
|
358
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
359
|
+
return ret;
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
export function __wbg_process_298734cf255a885d(arg0) {
|
|
363
|
+
const ret = getObject(arg0).process;
|
|
364
|
+
return addHeapObject(ret);
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
export function __wbg_versions_e2e78e134e3e5d01(arg0) {
|
|
368
|
+
const ret = getObject(arg0).versions;
|
|
369
|
+
return addHeapObject(ret);
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
export function __wbg_node_1cd7a5d853dbea79(arg0) {
|
|
373
|
+
const ret = getObject(arg0).node;
|
|
374
|
+
return addHeapObject(ret);
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
export function __wbindgen_is_string(arg0) {
|
|
378
|
+
const ret = typeof(getObject(arg0)) === 'string';
|
|
379
|
+
return ret;
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
export function __wbg_require_8f08ceecec0f4fee() { return handleError(function () {
|
|
383
|
+
const ret = module.require;
|
|
384
|
+
return addHeapObject(ret);
|
|
385
|
+
}, arguments) };
|
|
386
|
+
|
|
387
|
+
export function __wbindgen_string_new(arg0, arg1) {
|
|
388
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
389
|
+
return addHeapObject(ret);
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
export function __wbg_msCrypto_bcb970640f50a1e8(arg0) {
|
|
393
|
+
const ret = getObject(arg0).msCrypto;
|
|
394
|
+
return addHeapObject(ret);
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
export function __wbindgen_is_function(arg0) {
|
|
398
|
+
const ret = typeof(getObject(arg0)) === 'function';
|
|
399
|
+
return ret;
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
export function __wbg_newnoargs_581967eacc0e2604(arg0, arg1) {
|
|
403
|
+
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
|
404
|
+
return addHeapObject(ret);
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
export function __wbg_call_cb65541d95d71282() { return handleError(function (arg0, arg1) {
|
|
408
|
+
const ret = getObject(arg0).call(getObject(arg1));
|
|
409
|
+
return addHeapObject(ret);
|
|
410
|
+
}, arguments) };
|
|
411
|
+
|
|
412
|
+
export function __wbg_self_1ff1d729e9aae938() { return handleError(function () {
|
|
413
|
+
const ret = self.self;
|
|
414
|
+
return addHeapObject(ret);
|
|
415
|
+
}, arguments) };
|
|
416
|
+
|
|
417
|
+
export function __wbg_window_5f4faef6c12b79ec() { return handleError(function () {
|
|
418
|
+
const ret = window.window;
|
|
419
|
+
return addHeapObject(ret);
|
|
420
|
+
}, arguments) };
|
|
421
|
+
|
|
422
|
+
export function __wbg_globalThis_1d39714405582d3c() { return handleError(function () {
|
|
423
|
+
const ret = globalThis.globalThis;
|
|
424
|
+
return addHeapObject(ret);
|
|
425
|
+
}, arguments) };
|
|
426
|
+
|
|
427
|
+
export function __wbg_global_651f05c6a0944d1c() { return handleError(function () {
|
|
428
|
+
const ret = global.global;
|
|
429
|
+
return addHeapObject(ret);
|
|
430
|
+
}, arguments) };
|
|
431
|
+
|
|
432
|
+
export function __wbindgen_is_undefined(arg0) {
|
|
433
|
+
const ret = getObject(arg0) === undefined;
|
|
434
|
+
return ret;
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
export function __wbg_call_01734de55d61e11d() { return handleError(function (arg0, arg1, arg2) {
|
|
438
|
+
const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
|
|
439
|
+
return addHeapObject(ret);
|
|
440
|
+
}, arguments) };
|
|
441
|
+
|
|
442
|
+
export function __wbg_buffer_085ec1f694018c4f(arg0) {
|
|
443
|
+
const ret = getObject(arg0).buffer;
|
|
444
|
+
return addHeapObject(ret);
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
export function __wbg_newwithbyteoffsetandlength_6da8e527659b86aa(arg0, arg1, arg2) {
|
|
448
|
+
const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
|
|
449
|
+
return addHeapObject(ret);
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
export function __wbg_new_8125e318e6245eed(arg0) {
|
|
453
|
+
const ret = new Uint8Array(getObject(arg0));
|
|
454
|
+
return addHeapObject(ret);
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
export function __wbg_set_5cf90238115182c3(arg0, arg1, arg2) {
|
|
458
|
+
getObject(arg0).set(getObject(arg1), arg2 >>> 0);
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
export function __wbg_newwithlength_e5d69174d6984cd7(arg0) {
|
|
462
|
+
const ret = new Uint8Array(arg0 >>> 0);
|
|
463
|
+
return addHeapObject(ret);
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
export function __wbg_subarray_13db269f57aa838d(arg0, arg1, arg2) {
|
|
467
|
+
const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
|
|
468
|
+
return addHeapObject(ret);
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
export function __wbindgen_object_clone_ref(arg0) {
|
|
472
|
+
const ret = getObject(arg0);
|
|
473
|
+
return addHeapObject(ret);
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
export function __wbindgen_throw(arg0, arg1) {
|
|
477
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
export function __wbindgen_memory() {
|
|
481
|
+
const ret = wasm.memory;
|
|
482
|
+
return addHeapObject(ret);
|
|
483
|
+
};
|
|
484
|
+
|
|
Binary file
|