@elarsaks/umap-wasm 0.3.13 → 0.3.15

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/dist/heap.d.ts CHANGED
@@ -1,111 +1,12 @@
1
- /**
2
- * @license
3
- *
4
- * Copyright 2019 Google LLC. All Rights Reserved.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- * ==============================================================================
18
- */
19
- /**
20
- * This is a JavaScript reimplementation of UMAP (original license below), from
21
- * the python implementation found at https://github.com/lmcinnes/umap.
22
- *
23
- * @author andycoenen@google.com (Andy Coenen)
24
- */
25
- /**
26
- * @license
27
- * BSD 3-Clause License
28
- *
29
- * Copyright (c) 2017, Leland McInnes
30
- * All rights reserved.
31
- *
32
- * Redistribution and use in source and binary forms, with or without
33
- * modification, are permitted provided that the following conditions are met:
34
- *
35
- * * Redistributions of source code must retain the above copyright notice, this
36
- * list of conditions and the following disclaimer.
37
- *
38
- * * Redistributions in binary form must reproduce the above copyright notice,
39
- * this list of conditions and the following disclaimer in the documentation
40
- * and/or other materials provided with the distribution.
41
- *
42
- * * Neither the name of the copyright holder nor the names of its
43
- * contributors may be used to endorse or promote products derived from
44
- * this software without specific prior written permission.
45
- *
46
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
47
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
49
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
50
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
52
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
53
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
55
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56
- */
57
1
  import { RandomFn } from './umap.js';
58
2
  export type Heap = number[][][];
59
- /**
60
- * Constructor for the heap objects. The heaps are used
61
- * for approximate nearest neighbor search, maintaining a list of potential
62
- * neighbors sorted by their distance. We also flag if potential neighbors
63
- * are newly added to the list or not. Internally this is stored as
64
- * a single array; the first axis determines whether we are looking at the
65
- * array of candidate indices, the array of distances, or the flag array for
66
- * whether elements are new or not. Each of these arrays are of shape
67
- * (``nPoints``, ``size``)
68
- */
69
3
  export declare function makeHeap(nPoints: number, size: number): Heap;
70
- /**
71
- * Generate n_samples many integers from 0 to pool_size such that no
72
- * integer is selected twice. The duplication constraint is achieved via
73
- * rejection sampling.
74
- */
75
4
  export declare function rejectionSample(nSamples: number, poolSize: number, random: RandomFn): number[];
76
- /**
77
- * Push a new element onto the heap. The heap stores potential neighbors
78
- * for each data point. The ``row`` parameter determines which data point we
79
- * are addressing, the ``weight`` determines the distance (for heap sorting),
80
- * the ``index`` is the element to add, and the flag determines whether this
81
- * is to be considered a new addition.
82
- */
83
5
  export declare function heapPush(heap: Heap, row: number, weight: number, index: number, flag: number): number;
84
- /**
85
- * Push a new element onto the heap. The heap stores potential neighbors
86
- * for each data point. The ``row`` parameter determines which data point we
87
- * are addressing, the ``weight`` determines the distance (for heap sorting),
88
- * the ``index`` is the element to add, and the flag determines whether this
89
- * is to be considered a new addition.
90
- */
91
6
  export declare function uncheckedHeapPush(heap: Heap, row: number, weight: number, index: number, flag: number): number;
92
- /**
93
- * Build a heap of candidate neighbors for nearest neighbor descent. For
94
- * each vertex the candidate neighbors are any current neighbors, and any
95
- * vertices that have the vertex as one of their nearest neighbors.
96
- */
97
7
  export declare function buildCandidates(currentGraph: Heap, nVertices: number, nNeighbors: number, maxCandidates: number, random: RandomFn): Heap;
98
- /**
99
- * Given an array of heaps (of indices and weights), unpack the heap
100
- * out to give and array of sorted lists of indices and weights by increasing
101
- * weight. This is effectively just the second half of heap sort (the first
102
- * half not being required since we already have the data in a heap).
103
- */
104
8
  export declare function deheapSort(heap: Heap): {
105
9
  indices: number[][];
106
10
  weights: number[][];
107
11
  };
108
- /**
109
- * Search the heap for the smallest element that is still flagged.
110
- */
111
12
  export declare function smallestFlagged(heap: Heap, row: number): number;
package/dist/index.d.ts CHANGED
@@ -1,20 +1,2 @@
1
- /**
2
- * @license
3
- *
4
- * Copyright 2019 Google LLC. All Rights Reserved.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- * ==============================================================================
18
- */
19
1
  export { UMAP, UMAPParameters } from './umap.js';
20
2
  export { initWasm, isWasmAvailable } from './wasmBridge.js';
package/dist/lib.d.ts CHANGED
@@ -1,20 +1,2 @@
1
- /**
2
- * @license
3
- *
4
- * Copyright 2019 Google LLC. All Rights Reserved.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- * ==============================================================================
18
- */
19
1
  export { UMAP } from './umap.js';
20
2
  export { initWasm, isWasmAvailable } from './wasmBridge.js';
package/dist/matrix.d.ts CHANGED
@@ -1,24 +1,3 @@
1
- /**
2
- * @license
3
- *
4
- * Copyright 2019 Google LLC. All Rights Reserved.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- * ==============================================================================
18
- */
19
- /**
20
- * Internal 2-dimensional sparse matrix class
21
- */
22
1
  export declare class SparseMatrix {
23
2
  private entries;
24
3
  readonly nRows: number;
@@ -41,53 +20,20 @@ export declare class SparseMatrix {
41
20
  map(fn: (value: number, row: number, col: number) => number): SparseMatrix;
42
21
  toArray(): number[][];
43
22
  }
44
- /**
45
- * Transpose a sparse matrix
46
- */
47
23
  export declare function transpose(matrix: SparseMatrix): SparseMatrix;
48
- /**
49
- * Construct a sparse identity matrix
50
- */
51
24
  export declare function identity(size: number[]): SparseMatrix;
52
- /**
53
- * Element-wise multiplication of two matrices
54
- */
55
25
  export declare function pairwiseMultiply(a: SparseMatrix, b: SparseMatrix): SparseMatrix;
56
- /**
57
- * Element-wise addition of two matrices
58
- */
59
26
  export declare function add(a: SparseMatrix, b: SparseMatrix): SparseMatrix;
60
- /**
61
- * Element-wise subtraction of two matrices
62
- */
63
27
  export declare function subtract(a: SparseMatrix, b: SparseMatrix): SparseMatrix;
64
- /**
65
- * Element-wise maximum of two matrices
66
- */
67
28
  export declare function maximum(a: SparseMatrix, b: SparseMatrix): SparseMatrix;
68
- /**
69
- * Scalar multiplication of two matrices
70
- */
71
29
  export declare function multiplyScalar(a: SparseMatrix, scalar: number): SparseMatrix;
72
- /**
73
- * Returns a new matrix with zero entries removed.
74
- */
75
30
  export declare function eliminateZeros(m: SparseMatrix): SparseMatrix;
76
- /**
77
- * Normalization of a sparse matrix.
78
- */
79
31
  export declare function normalize(m: SparseMatrix, normType?: NormType): SparseMatrix;
80
32
  export declare const enum NormType {
81
33
  max = "max",
82
34
  l1 = "l1",
83
35
  l2 = "l2"
84
36
  }
85
- /**
86
- * Helper function for getting data, indices, and inptr arrays from a sparse
87
- * matrix to follow csr matrix conventions. Super inefficient (and kind of
88
- * defeats the purpose of this convention) but a lot of the ported python tree
89
- * search logic depends on this data format.
90
- */
91
37
  export declare function getCSR(x: SparseMatrix): {
92
38
  indices: number[];
93
39
  values: number[];
@@ -1,71 +1,7 @@
1
- /**
2
- * @license
3
- *
4
- * Copyright 2019 Google LLC. All Rights Reserved.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- * ==============================================================================
18
- */
19
- /**
20
- * This is a JavaScript reimplementation of UMAP (original license below), from
21
- * the python implementation found at https://github.com/lmcinnes/umap.
22
- *
23
- * @author andycoenen@google.com (Andy Coenen)
24
- */
25
- /**
26
- * @license
27
- * BSD 3-Clause License
28
- *
29
- * Copyright (c) 2017, Leland McInnes
30
- * All rights reserved.
31
- *
32
- * Redistribution and use in source and binary forms, with or without
33
- * modification, are permitted provided that the following conditions are met:
34
- *
35
- * * Redistributions of source code must retain the above copyright notice, this
36
- * list of conditions and the following disclaimer.
37
- *
38
- * * Redistributions in binary form must reproduce the above copyright notice,
39
- * this list of conditions and the following disclaimer in the documentation
40
- * and/or other materials provided with the distribution.
41
- *
42
- * * Neither the name of the copyright holder nor the names of its
43
- * contributors may be used to endorse or promote products derived from
44
- * this software without specific prior written permission.
45
- *
46
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
47
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
49
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
50
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
52
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
53
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
55
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56
- */
57
1
  import * as heap from './heap.js';
58
2
  import * as matrix from './matrix.js';
59
3
  import * as tree from './tree.js';
60
4
  import { RandomFn, Vectors, DistanceFn } from './umap.js';
61
- /**
62
- * Create a version of nearest neighbor descent with optional WASM acceleration.
63
- *
64
- * @param distanceFn - Distance function for comparing vectors
65
- * @param random - Random number generator
66
- * @param useWasm - Whether to use WASM implementation when available
67
- * @returns The NN-Descent function
68
- */
69
5
  export declare function makeNNDescent(distanceFn: DistanceFn, random: RandomFn, useWasm?: boolean): (data: Vectors, leafArray: Vectors, nNeighbors: number, nIters?: number, maxCandidates?: number, delta?: number, rho?: number, rpTreeInit?: boolean) => {
70
6
  indices: number[][];
71
7
  weights: number[][];
package/dist/tree.d.ts CHANGED
@@ -1,21 +1,3 @@
1
- /**
2
- * @license
3
- *
4
- * Copyright 2019 Google LLC. All Rights Reserved.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- * ==============================================================================
18
- */
19
1
  import { RandomFn, Vector, Vectors } from './umap.js';
20
2
  import { WasmFlatTree } from './wasmBridge.js';
21
3
  export declare class FlatTree {
@@ -25,34 +7,10 @@ export declare class FlatTree {
25
7
  indices: number[][];
26
8
  private wasmTree?;
27
9
  constructor(hyperplanes: number[][], offsets: number[], children: number[][], indices: number[][]);
28
- /**
29
- * Create a FlatTree from a WASM tree object
30
- */
31
10
  static fromWasm(wasmTree: WasmFlatTree): FlatTree;
32
- /**
33
- * Get the underlying WASM tree if available
34
- */
35
11
  getWasmTree(): WasmFlatTree | undefined;
36
- /**
37
- * Clean up WASM resources
38
- */
39
12
  dispose(): void;
40
13
  }
41
- /**
42
- * Build a random projection forest with ``nTrees``.
43
- */
44
14
  export declare function makeForest(data: Vectors, nNeighbors: number, nTrees: number, random: RandomFn, useWasm?: boolean): FlatTree[];
45
- /**
46
- * Generate an array of sets of candidate nearest neighbors by
47
- * constructing a random projection forest and taking the leaves of all the
48
- * trees. Any given tree has leaves that are a set of potential nearest
49
- * neighbors. Given enough trees the set of all such leaves gives a good
50
- * likelihood of getting a good set of nearest neighbors in composite. Since
51
- * such a random projection forest is inexpensive to compute, this can be a
52
- * useful means of seeding other nearest neighbor algorithms.
53
- */
54
15
  export declare function makeLeafArray(rpForest: FlatTree[]): number[][];
55
- /**
56
- * Searches a flattened rp-tree for a point.
57
- */
58
16
  export declare function searchFlatTree(point: Vector, tree: FlatTree, random: RandomFn): number[];