@ac-kit/math-linear 0.1.8 → 0.2.0
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/CHANGELOG.md +31 -0
- package/README.md +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/kl-activations.d.ts +87 -0
- package/dist/kl-activations.d.ts.map +1 -0
- package/dist/kl-activations.js +188 -0
- package/dist/kl-activations.js.map +1 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5152230: `KlActivations`: non-negative activations of a fixed sparse dictionary
|
|
8
|
+
(compressed sparse columns) under the Kullback–Leibler divergence, with
|
|
9
|
+
per-column L1 penalties and multiplicative updates whose iterations spread
|
|
10
|
+
across calls, allocation-free once built. The constructor throws `RangeError`
|
|
11
|
+
on a malformed dictionary, and `iterate` throws until `reset` has loaded a
|
|
12
|
+
problem.
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [2a0fe74]
|
|
17
|
+
- Updated dependencies [5152230]
|
|
18
|
+
- Updated dependencies [2a0fe74]
|
|
19
|
+
- Updated dependencies [5152230]
|
|
20
|
+
- Updated dependencies [5152230]
|
|
21
|
+
- Updated dependencies [2a0fe74]
|
|
22
|
+
- Updated dependencies [2a0fe74]
|
|
23
|
+
- Updated dependencies [5152230]
|
|
24
|
+
- Updated dependencies [5152230]
|
|
25
|
+
- Updated dependencies [5152230]
|
|
26
|
+
- Updated dependencies [5152230]
|
|
27
|
+
- Updated dependencies [5152230]
|
|
28
|
+
- Updated dependencies [5152230]
|
|
29
|
+
- Updated dependencies [5152230]
|
|
30
|
+
- @ac-kit/core@0.10.0
|
|
31
|
+
- @ac-kit/math-complex@0.1.9
|
|
32
|
+
- @ac-kit/math-scalar@0.2.2
|
|
33
|
+
|
|
3
34
|
## 0.1.8
|
|
4
35
|
|
|
5
36
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ operations inlineable and allocation-predictable, and it is why an arbitrary
|
|
|
19
19
|
| ---------------------------- | -------------------------------------------------------------------------------------------------- |
|
|
20
20
|
| `vec2`, `vec3`, `vec4` | Component-wise arithmetic, dot, cross, length, normalisation, interpolation, matrix application |
|
|
21
21
|
| `mat2x2`, `mat3x3`, `mat4x4` | Multiplication, determinant, inverse, transpose, transform construction |
|
|
22
|
+
| `kl-activations` | `KlActivations`: KL-divergence NMF activations of a sparse fixed dictionary, with per-column L1 penalties, iterated across calls |
|
|
22
23
|
| `quaternion` | Rotation composition, slerp, conversion to and from axis-angle, Euler angles and rotation matrices |
|
|
23
24
|
|
|
24
25
|
## Equality and tolerance
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A dictionary of non-negative columns in compressed sparse column form: column
|
|
3
|
+
* `c` holds the entries `columnOffsets[c]` to `columnOffsets[c + 1] - 1`, entry
|
|
4
|
+
* `e` being `values[e]` at row `rowIndices[e]`. Rows ascend within a column.
|
|
5
|
+
*/
|
|
6
|
+
export interface SparseColumns {
|
|
7
|
+
/** `columns + 1` offsets into `rowIndices` and `values`, from 0, ascending. */
|
|
8
|
+
readonly columnOffsets: Int32Array;
|
|
9
|
+
readonly rowIndices: Int32Array;
|
|
10
|
+
/** Non-negative, finite. */
|
|
11
|
+
readonly values: Float64Array;
|
|
12
|
+
}
|
|
13
|
+
export interface KlActivationsOptions {
|
|
14
|
+
/** The length of a target vector. */
|
|
15
|
+
readonly rows: number;
|
|
16
|
+
readonly dictionary: SparseColumns;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Non-negative activations `a` of a fixed dictionary `W` that best explain a
|
|
20
|
+
* target `v`, under the Kullback–Leibler divergence with a per-column L1
|
|
21
|
+
* penalty: it minimises `D(v ‖ W·a) + Σ λ_c·a_c`. Each iteration is the
|
|
22
|
+
* multiplicative update of Lee and Seung (2001) with the penalty added to the
|
|
23
|
+
* denominator (Virtanen 2007):
|
|
24
|
+
*
|
|
25
|
+
* a_c ← a_c · (Σ_r W[r,c]·v[r] / (W·a)[r]) / (Σ_r W[r,c] + λ_c)
|
|
26
|
+
*
|
|
27
|
+
* The iterations are spread across calls: {@link reset} loads a problem and
|
|
28
|
+
* {@link iterate} runs as many as the caller's time budget allows, so a
|
|
29
|
+
* real-time loop can split one decision over several audio blocks. A column
|
|
30
|
+
* whose activation falls below 1e-12 stays where it is, and a column whose
|
|
31
|
+
* denominator is zero (empty and unpenalised) is set to 0.
|
|
32
|
+
*
|
|
33
|
+
* Construction allocates; {@link reset} and {@link iterate} do not.
|
|
34
|
+
*
|
|
35
|
+
* Time complexity: O(nnz) per iteration. Memory: O(rows + columns + nnz).
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const nmf = new KlActivations({
|
|
39
|
+
* rows: 2,
|
|
40
|
+
* dictionary: {
|
|
41
|
+
* columnOffsets: Int32Array.of(0, 1, 2),
|
|
42
|
+
* rowIndices: Int32Array.of(0, 1),
|
|
43
|
+
* values: Float64Array.of(1, 1),
|
|
44
|
+
* },
|
|
45
|
+
* });
|
|
46
|
+
* nmf.reset(Float64Array.of(3, 1), new Float64Array(2));
|
|
47
|
+
* nmf.iterate(20);
|
|
48
|
+
* nmf.activations; // ≈ [3, 1]
|
|
49
|
+
*/
|
|
50
|
+
export declare class KlActivations {
|
|
51
|
+
/** The current activations, one per dictionary column. Read-only for callers. */
|
|
52
|
+
readonly activations: Float64Array;
|
|
53
|
+
private readonly rows_;
|
|
54
|
+
private readonly dictionary_;
|
|
55
|
+
private readonly columnSums_;
|
|
56
|
+
private readonly target_;
|
|
57
|
+
private readonly penalties_;
|
|
58
|
+
private readonly reconstruction_;
|
|
59
|
+
private readonly next_;
|
|
60
|
+
private loaded_;
|
|
61
|
+
/**
|
|
62
|
+
* @throws {RangeError} If `rows` is not a non-negative integer, or the
|
|
63
|
+
* dictionary is malformed: `columnOffsets` not starting at 0 or not
|
|
64
|
+
* ascending, `rowIndices` or `values` not as long as the last offset, a row
|
|
65
|
+
* index outside `[0, rows)`, or a negative or non-finite value.
|
|
66
|
+
*/
|
|
67
|
+
constructor(options: KlActivationsOptions);
|
|
68
|
+
/**
|
|
69
|
+
* Loads a problem and restarts from `initial`, or from the uniform
|
|
70
|
+
* activations `1 / columns`. Copies its arguments, so the caller may reuse
|
|
71
|
+
* them.
|
|
72
|
+
*
|
|
73
|
+
* @param target Non-negative, one per row.
|
|
74
|
+
* @param penalties Non-negative L1 weights, one per column.
|
|
75
|
+
* @param initial Non-negative, finite starting activations, one per column.
|
|
76
|
+
* @throws {RangeError} On a wrong length or a negative or non-finite entry.
|
|
77
|
+
*/
|
|
78
|
+
reset(target: Float64Array, penalties: Float64Array, initial?: Float64Array): void;
|
|
79
|
+
/**
|
|
80
|
+
* Runs `count` more iterations.
|
|
81
|
+
*
|
|
82
|
+
* @throws {RangeError} Unless `count` is a non-negative safe integer.
|
|
83
|
+
* @throws {Error} If no problem was loaded with {@link reset} yet.
|
|
84
|
+
*/
|
|
85
|
+
iterate(count: number): void;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=kl-activations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kl-activations.d.ts","sourceRoot":"","sources":["../src/kl-activations.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC7B,+EAA+E;IAC/E,QAAQ,CAAC,aAAa,EAAE,UAAU,CAAC;IACnC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,4BAA4B;IAC5B,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;CAC9B;AAED,MAAM,WAAW,oBAAoB;IACpC,qCAAqC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,aAAa,CAAC;CACnC;AAOD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAAa,aAAa;IACzB,iFAAiF;IACjF,SAAgB,WAAW,EAAE,YAAY,CAAC;IAE1C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAgB;IAC5C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAe;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IACvC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAe;IAC1C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAe;IAC/C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IACrC,OAAO,CAAC,OAAO,CAAS;IAExB;;;;;OAKG;IACH,YAAmB,OAAO,EAAE,oBAAoB,EAiD/C;IAED;;;;;;;;;OASG;IACI,KAAK,CACX,MAAM,EAAE,YAAY,EACpB,SAAS,EAAE,YAAY,EACvB,OAAO,CAAC,EAAE,YAAY,GACpB,IAAI,CA6CN;IAED;;;;;OAKG;IACI,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAuClC;CACD"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// The reconstruction's floor, keeping the division defined, and the activation
|
|
2
|
+
// below which a column is considered extinct and no longer updated.
|
|
3
|
+
const RECONSTRUCTION_FLOOR_ = 1e-12;
|
|
4
|
+
const EXTINCT_ACTIVATION_ = 1e-12;
|
|
5
|
+
/**
|
|
6
|
+
* Non-negative activations `a` of a fixed dictionary `W` that best explain a
|
|
7
|
+
* target `v`, under the Kullback–Leibler divergence with a per-column L1
|
|
8
|
+
* penalty: it minimises `D(v ‖ W·a) + Σ λ_c·a_c`. Each iteration is the
|
|
9
|
+
* multiplicative update of Lee and Seung (2001) with the penalty added to the
|
|
10
|
+
* denominator (Virtanen 2007):
|
|
11
|
+
*
|
|
12
|
+
* a_c ← a_c · (Σ_r W[r,c]·v[r] / (W·a)[r]) / (Σ_r W[r,c] + λ_c)
|
|
13
|
+
*
|
|
14
|
+
* The iterations are spread across calls: {@link reset} loads a problem and
|
|
15
|
+
* {@link iterate} runs as many as the caller's time budget allows, so a
|
|
16
|
+
* real-time loop can split one decision over several audio blocks. A column
|
|
17
|
+
* whose activation falls below 1e-12 stays where it is, and a column whose
|
|
18
|
+
* denominator is zero (empty and unpenalised) is set to 0.
|
|
19
|
+
*
|
|
20
|
+
* Construction allocates; {@link reset} and {@link iterate} do not.
|
|
21
|
+
*
|
|
22
|
+
* Time complexity: O(nnz) per iteration. Memory: O(rows + columns + nnz).
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const nmf = new KlActivations({
|
|
26
|
+
* rows: 2,
|
|
27
|
+
* dictionary: {
|
|
28
|
+
* columnOffsets: Int32Array.of(0, 1, 2),
|
|
29
|
+
* rowIndices: Int32Array.of(0, 1),
|
|
30
|
+
* values: Float64Array.of(1, 1),
|
|
31
|
+
* },
|
|
32
|
+
* });
|
|
33
|
+
* nmf.reset(Float64Array.of(3, 1), new Float64Array(2));
|
|
34
|
+
* nmf.iterate(20);
|
|
35
|
+
* nmf.activations; // ≈ [3, 1]
|
|
36
|
+
*/
|
|
37
|
+
export class KlActivations {
|
|
38
|
+
/** The current activations, one per dictionary column. Read-only for callers. */
|
|
39
|
+
activations;
|
|
40
|
+
rows_;
|
|
41
|
+
dictionary_;
|
|
42
|
+
columnSums_;
|
|
43
|
+
target_;
|
|
44
|
+
penalties_;
|
|
45
|
+
reconstruction_;
|
|
46
|
+
next_;
|
|
47
|
+
loaded_ = false;
|
|
48
|
+
/**
|
|
49
|
+
* @throws {RangeError} If `rows` is not a non-negative integer, or the
|
|
50
|
+
* dictionary is malformed: `columnOffsets` not starting at 0 or not
|
|
51
|
+
* ascending, `rowIndices` or `values` not as long as the last offset, a row
|
|
52
|
+
* index outside `[0, rows)`, or a negative or non-finite value.
|
|
53
|
+
*/
|
|
54
|
+
constructor(options) {
|
|
55
|
+
const { rows, dictionary } = options;
|
|
56
|
+
const { columnOffsets, rowIndices, values } = dictionary;
|
|
57
|
+
if (!Number.isInteger(rows) || rows < 0) {
|
|
58
|
+
throw new RangeError(`rows must be a non-negative integer, got ${rows}`);
|
|
59
|
+
}
|
|
60
|
+
if (columnOffsets.length < 1 || columnOffsets[0] !== 0) {
|
|
61
|
+
throw new RangeError("columnOffsets must start at 0");
|
|
62
|
+
}
|
|
63
|
+
const columns = columnOffsets.length - 1;
|
|
64
|
+
const entries = columnOffsets[columns];
|
|
65
|
+
if (rowIndices.length !== entries || values.length !== entries) {
|
|
66
|
+
throw new RangeError("rowIndices and values must have as many entries as the last column offset");
|
|
67
|
+
}
|
|
68
|
+
this.columnSums_ = new Float64Array(columns);
|
|
69
|
+
for (let c = 0; c < columns; c++) {
|
|
70
|
+
const start = columnOffsets[c];
|
|
71
|
+
const end = columnOffsets[c + 1];
|
|
72
|
+
if (end < start) {
|
|
73
|
+
throw new RangeError(`columnOffsets must ascend, at column ${c}`);
|
|
74
|
+
}
|
|
75
|
+
let sum = 0;
|
|
76
|
+
for (let e = start; e < end; e++) {
|
|
77
|
+
const row = rowIndices[e];
|
|
78
|
+
const value = values[e];
|
|
79
|
+
if (row < 0 || row >= rows) {
|
|
80
|
+
throw new RangeError(`row index ${row} out of range [0, ${rows}) at entry ${e}`);
|
|
81
|
+
}
|
|
82
|
+
if (!(value >= 0) || !Number.isFinite(value)) {
|
|
83
|
+
throw new RangeError(`values must be non-negative and finite, got ${value} at entry ${e}`);
|
|
84
|
+
}
|
|
85
|
+
sum += value;
|
|
86
|
+
}
|
|
87
|
+
this.columnSums_[c] = sum;
|
|
88
|
+
}
|
|
89
|
+
this.rows_ = rows;
|
|
90
|
+
this.dictionary_ = dictionary;
|
|
91
|
+
this.activations = new Float64Array(columns);
|
|
92
|
+
this.target_ = new Float64Array(rows);
|
|
93
|
+
this.penalties_ = new Float64Array(columns);
|
|
94
|
+
this.reconstruction_ = new Float64Array(rows);
|
|
95
|
+
this.next_ = new Float64Array(columns);
|
|
96
|
+
this.activations.fill(columns === 0 ? 0 : 1 / columns);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Loads a problem and restarts from `initial`, or from the uniform
|
|
100
|
+
* activations `1 / columns`. Copies its arguments, so the caller may reuse
|
|
101
|
+
* them.
|
|
102
|
+
*
|
|
103
|
+
* @param target Non-negative, one per row.
|
|
104
|
+
* @param penalties Non-negative L1 weights, one per column.
|
|
105
|
+
* @param initial Non-negative, finite starting activations, one per column.
|
|
106
|
+
* @throws {RangeError} On a wrong length or a negative or non-finite entry.
|
|
107
|
+
*/
|
|
108
|
+
reset(target, penalties, initial) {
|
|
109
|
+
const columns = this.activations.length;
|
|
110
|
+
if (target.length !== this.rows_) {
|
|
111
|
+
throw new RangeError(`target must have ${this.rows_} entries, got ${target.length}`);
|
|
112
|
+
}
|
|
113
|
+
if (penalties.length !== columns) {
|
|
114
|
+
throw new RangeError(`penalties must have ${columns} entries, got ${penalties.length}`);
|
|
115
|
+
}
|
|
116
|
+
if (initial !== undefined && initial.length !== columns) {
|
|
117
|
+
throw new RangeError(`initial must have ${columns} entries, got ${initial.length}`);
|
|
118
|
+
}
|
|
119
|
+
for (let r = 0; r < target.length; r++) {
|
|
120
|
+
if (!(target[r] >= 0) || !Number.isFinite(target[r])) {
|
|
121
|
+
throw new RangeError(`target must be non-negative and finite, at ${r}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
for (let c = 0; c < columns; c++) {
|
|
125
|
+
if (!(penalties[c] >= 0) || !Number.isFinite(penalties[c])) {
|
|
126
|
+
throw new RangeError(`penalties must be non-negative and finite, at ${c}`);
|
|
127
|
+
}
|
|
128
|
+
if (initial !== undefined &&
|
|
129
|
+
(!(initial[c] >= 0) || !Number.isFinite(initial[c]))) {
|
|
130
|
+
throw new RangeError(`initial must be non-negative and finite, at ${c}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
this.loaded_ = true;
|
|
134
|
+
this.target_.set(target);
|
|
135
|
+
this.penalties_.set(penalties);
|
|
136
|
+
if (initial === undefined) {
|
|
137
|
+
this.activations.fill(columns === 0 ? 0 : 1 / columns);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
this.activations.set(initial);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Runs `count` more iterations.
|
|
145
|
+
*
|
|
146
|
+
* @throws {RangeError} Unless `count` is a non-negative safe integer.
|
|
147
|
+
* @throws {Error} If no problem was loaded with {@link reset} yet.
|
|
148
|
+
*/
|
|
149
|
+
iterate(count) {
|
|
150
|
+
if (!Number.isSafeInteger(count) || count < 0) {
|
|
151
|
+
throw new RangeError(`count must be a non-negative safe integer, got ${count}`);
|
|
152
|
+
}
|
|
153
|
+
if (!this.loaded_) {
|
|
154
|
+
throw new Error("iterate called before reset loaded a problem");
|
|
155
|
+
}
|
|
156
|
+
const { columnOffsets, rowIndices, values } = this.dictionary_;
|
|
157
|
+
const { activations, reconstruction_, next_, target_, penalties_ } = this;
|
|
158
|
+
const columns = activations.length;
|
|
159
|
+
for (let n = 0; n < count; n++) {
|
|
160
|
+
reconstruction_.fill(RECONSTRUCTION_FLOOR_);
|
|
161
|
+
for (let c = 0; c < columns; c++) {
|
|
162
|
+
const a = activations[c];
|
|
163
|
+
if (a < EXTINCT_ACTIVATION_) {
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
for (let e = columnOffsets[c]; e < columnOffsets[c + 1]; e++) {
|
|
167
|
+
reconstruction_[rowIndices[e]] += a * values[e];
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
for (let c = 0; c < columns; c++) {
|
|
171
|
+
const a = activations[c];
|
|
172
|
+
if (a < EXTINCT_ACTIVATION_) {
|
|
173
|
+
next_[c] = a;
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
let s = 0;
|
|
177
|
+
for (let e = columnOffsets[c]; e < columnOffsets[c + 1]; e++) {
|
|
178
|
+
const row = rowIndices[e];
|
|
179
|
+
s += (values[e] * target_[row]) / reconstruction_[row];
|
|
180
|
+
}
|
|
181
|
+
const denominator = this.columnSums_[c] + penalties_[c];
|
|
182
|
+
next_[c] = denominator > 0 ? (a * s) / denominator : 0;
|
|
183
|
+
}
|
|
184
|
+
activations.set(next_);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=kl-activations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kl-activations.js","sourceRoot":"","sources":["../src/kl-activations.ts"],"names":[],"mappings":"AAmBA,+EAA+E;AAC/E,oEAAoE;AACpE,MAAM,qBAAqB,GAAG,KAAK,CAAC;AACpC,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,OAAO,aAAa;IACzB,iFAAiF;IACjE,WAAW,CAAe;IAEzB,KAAK,CAAS;IACd,WAAW,CAAgB;IAC3B,WAAW,CAAe;IAC1B,OAAO,CAAe;IACtB,UAAU,CAAe;IACzB,eAAe,CAAe;IAC9B,KAAK,CAAe;IAC7B,OAAO,GAAG,KAAK,CAAC;IAExB;;;;;OAKG;IACH,YAAmB,OAA6B;QAC/C,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;QACrC,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC;QACzD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;YACzC,MAAM,IAAI,UAAU,CAAC,4CAA4C,IAAI,EAAE,CAAC,CAAC;QAC1E,CAAC;QACD,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;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6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ac-kit/math-linear",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Linear algebra over IEEE 754 binary64: vectors, matrices and quaternions of fixed, small dimension.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"linear-algebra",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"prepack": "yarn build"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@ac-kit/core": "^0.
|
|
48
|
-
"@ac-kit/math-complex": "^0.1.
|
|
49
|
-
"@ac-kit/math-scalar": "^0.2.
|
|
47
|
+
"@ac-kit/core": "^0.10.0",
|
|
48
|
+
"@ac-kit/math-complex": "^0.1.9",
|
|
49
|
+
"@ac-kit/math-scalar": "^0.2.2",
|
|
50
50
|
"@types/web": "^0.0.367"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|