You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This package provides a WebAssembly implementation of UMAP and approximate nearest neighbor search.
4
+
5
+
The UMAP implementation is [umappp](https://github.com/libscran/umappp/) by Aaron Lun.
6
+
7
+
The approximate nearest neighbor search is based on [knncolle](https://github.com/knncolle/knncolle), with two algorithms, including HNSW ([hnswlib](https://github.com/nmslib/hnswlib)) and [nndescent](https://github.com/brj0/nndescent) by Jon Brugger.
8
+
9
+
## Documentation
10
+
11
+
See `index.d.ts` for the full API.
12
+
13
+
To initialize the algorithm, use `createUMAP`:
14
+
15
+
```js
16
+
import { createUMAP } from"umap-wasm";
17
+
18
+
let count =2000;
19
+
let input_dim =100;
20
+
let output_dim =2;
21
+
22
+
// The data must be a Float32Array with count * input_dim elements.
23
+
let data =newFloat32Array(count * input_dim);
24
+
// ... fill in the data
25
+
26
+
let options = {
27
+
metric:"cosine",
28
+
};
29
+
30
+
// Use `createUMAP` to initialize the algorithm.
31
+
let umap =awaitcreateUMAP(count, input_dim, output_dim, data, options);
32
+
```
33
+
34
+
After initialization, use the `run` method to update the embedding coordinates:
35
+
36
+
```js
37
+
// Run the algorithm to completion.
38
+
umap.run();
39
+
40
+
// Alternatively, you can run up to a given number of epochs.
41
+
// This can be useful for animation effects.
42
+
for (let i =0; i <100; i++) {
43
+
// Run to the i-th epoch.
44
+
umap.run(i);
45
+
}
46
+
```
47
+
48
+
At any time, you can get the current embedding by calling the `embedding` method.
49
+
50
+
```js
51
+
// The result is a Float32Array with count * output_dim elements.
52
+
let embedding =umap.embedding();
53
+
```
54
+
55
+
After you are done with the instance, use the `destroy` method to release resources.
56
+
57
+
```js
58
+
umap.destroy();
59
+
```
60
+
61
+
## Development
62
+
63
+
A pre-compiled WASM file is included in the Git repository. If you'd like to build this package, proceed with the following instructions:
0 commit comments