Skip to content

Commit 405c558

Browse files
committed
Change return value to Array
1 parent 5440343 commit 405c558

27 files changed

+42
-39
lines changed

js/view/ica.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ var dispICA = function (elm, platform) {
99
const dim = platform.dimension
1010
const model = new ICA()
1111
model.fit(tx)
12-
let y = model.predict(tx, dim)
13-
pred_cb(y.toArray())
12+
const y = model.predict(tx, dim)
13+
pred_cb(y)
1414
})
1515
})
1616
}

js/view/isomap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ var dispIsomap = function (elm, platform) {
55
const neighbors = +elm.select('[name=neighbors]').property('value')
66
platform.fit((tx, ty, pred_cb) => {
77
const dim = platform.dimension
8-
let y = Isomap(tx, dim, neighbors)
9-
pred_cb(y.toArray())
8+
const y = Isomap(tx, dim, neighbors)
9+
pred_cb(y)
1010
})
1111
}
1212

js/view/laplacian_eigenmaps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var dispLE = function (elm, platform) {
4343
const dim = platform.dimension
4444
const model = new LaplacianEigenmaps(method, k, sigma)
4545
const pred = model.predict(tx, dim)
46-
pred_cb(pred.toArray())
46+
pred_cb(pred)
4747
})
4848
})
4949
}

js/view/lda.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var dispLDA = function (elm, platform) {
3030
} else {
3131
const dim = platform.dimension
3232
let y = LinearDiscriminantAnalysis(tx, ty, dim)
33-
pred_cb(y.toArray())
33+
pred_cb(y)
3434
}
3535
cb && cb()
3636
})

js/view/lle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ var dispLLE = function (elm, platform) {
55
platform.fit((tx, ty, pred_cb) => {
66
const neighbor = +elm.select('[name=neighbor_size]').property('value')
77
const dim = platform.dimension
8-
let y = LLE(tx, neighbor, dim)
9-
pred_cb(y.toArray())
8+
const y = LLE(tx, neighbor, dim)
9+
pred_cb(y)
1010
})
1111
}
1212

js/view/lsa.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ var dispLSA = function (elm, platform) {
77
.on('click', () => {
88
platform.fit((tx, ty, pred_cb) => {
99
const dim = platform.dimension
10-
let y = LSA(tx, dim)
11-
pred_cb(y.toArray())
10+
const y = LSA(tx, dim)
11+
pred_cb(y)
1212
})
1313
})
1414
}

js/view/mds.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ var dispMDS = function (elm, platform) {
44
const fitModel = cb => {
55
platform.fit((tx, ty, pred_cb) => {
66
const dim = platform.dimension
7-
let y = MDS(tx, dim)
8-
pred_cb(y.toArray())
7+
const y = MDS(tx, dim)
8+
pred_cb(y)
99
})
1010
}
1111

js/view/nmf.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import NMF from '../../lib/model/nmf.js'
22

3+
import { Matrix } from '../../lib/util/math.js'
4+
35
var dispNMF = function (elm, platform) {
46
let model = null
57

@@ -12,7 +14,7 @@ var dispNMF = function (elm, platform) {
1214
model.init(tx, k)
1315
}
1416
model.fit()
15-
const pred = model.predict()
17+
const pred = Matrix.fromArray(model.predict())
1618
pred_cb(pred.argmax(1).value.map(v => v + 1))
1719
} else {
1820
if (!model) {
@@ -22,7 +24,7 @@ var dispNMF = function (elm, platform) {
2224
}
2325
model.fit()
2426
const pred = model.predict()
25-
pred_cb(pred.toArray())
27+
pred_cb(pred)
2628
}
2729
cb && cb()
2830
})

js/view/pca.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ var dispPCA = function (elm, platform) {
1010
const dim = platform.dimension
1111
const model = new PCA(kernel)
1212
model.fit(tx)
13-
let y = model.predict(tx, dim)
14-
pred_cb(y.toArray())
13+
const y = model.predict(tx, dim)
14+
pred_cb(y)
1515
} else {
1616
const model = new AnomalyPCA()
1717
model.fit(tx)

js/view/principal_curve.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ var dispPC = function (elm, platform) {
1212
platform.fit((tx, ty, pred_cb) => {
1313
const dim = platform.dimension
1414
model.fit(tx)
15-
let y = model.predict(tx, dim)
16-
pred_cb(y.toArray())
15+
const y = model.predict(tx, dim)
16+
pred_cb(y)
1717
cb && cb()
1818
})
1919
})

js/view/random_projection.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ var dispRandomProjection = function (elm, platform) {
55
const init = elm.select('[name=init]').property('value')
66
platform.fit((tx, ty, pred_cb) => {
77
const dim = platform.dimension
8-
let y = RandomProjection(tx, dim, init)
9-
pred_cb(y.toArray())
8+
const y = RandomProjection(tx, dim, init)
9+
pred_cb(y)
1010
})
1111
}
1212

js/view/sammon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var dispSammon = function (elm, platform) {
99
model = new Sammon(tx, dim)
1010
}
1111
const pred = model.fit()
12-
pred_cb(pred.toArray())
12+
pred_cb(pred)
1313
cb && cb()
1414
})
1515
}

js/view/tsne.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ var dispTSNE = function (elm, platform) {
99
return
1010
}
1111
platform.fit((tx, ty, pred_cb) => {
12-
let y = model.fit()
13-
pred_cb(y.toArray())
12+
const y = model.fit()
13+
pred_cb(y)
1414

1515
cb && cb()
1616
})

lib/model/ica.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default class ICA {
2020
x = x.copySub(x.mean(0))
2121
const pca = new PCA()
2222
pca.fit(x)
23-
const z = pca.predict(x)
23+
const z = Matrix.fromArray(pca.predict(x))
2424
const eps = 1.0e-12
2525
const r = []
2626

@@ -68,6 +68,6 @@ export default class ICA {
6868
if (rd > 0 && rd < w.cols) {
6969
w = w.resize(w.rows, rd)
7070
}
71-
return x.dot(w)
71+
return x.dot(w).toArray()
7272
}
7373
}

lib/model/laplacian_eigenmaps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ export class LaplacianEigenmaps {
5858

5959
this._ev = L.eigenVectors()
6060
this._ev.flip(1)
61-
return this._ev.sliceCol(1, rd + 1)
61+
return this._ev.sliceCol(1, rd + 1).toArray()
6262
}
6363
}

lib/model/lda.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,5 @@ export const LinearDiscriminantAnalysis = function (x, t, rd = 0) {
174174
if (rd > 0 && rd < ev.cols) {
175175
ev = ev.resize(ev.rows, rd)
176176
}
177-
return x.dot(ev)
177+
return x.dot(ev).toArray()
178178
}

lib/model/lle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const LLE = function (x, K = 1, rd = 0) {
5656
const mtm = m.tDot(m)
5757
let ev = mtm.eigenVectors()
5858
ev.flip(1)
59-
return ev.sliceCol(1, rd + 1)
59+
return ev.sliceCol(1, rd + 1).toArray()
6060
}
6161

6262
export default LLE

lib/model/lsa.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const LSA = function (x, rd = 0) {
88
.sliceCol(0, rd)
99
.dot(Matrix.diag(s.slice(0, rd)))
1010
.dot(v.slice(0, 0, rd, rd).t)
11+
.toArray()
1112
}
1213

1314
export default LSA

lib/model/mds.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ export const MDS = function (x, rd = 1, dmat = false) {
4040
evec.multAt(i, k, Math.sqrt(evalue[k]))
4141
}
4242
}
43-
return evec.sliceCol(0, rd)
43+
return evec.sliceCol(0, rd).toArray()
4444
}

lib/model/nmf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ export default class NMF {
4444
}
4545

4646
predict() {
47-
return this._H.t
47+
return this._H.t.toArray()
4848
}
4949
}

lib/model/pca.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class PCA {
5656
w = w.resize(w.rows, rd)
5757
}
5858
x = this._gram(x)
59-
return x.dot(w)
59+
return x.dot(w).toArray()
6060
}
6161
}
6262

lib/model/pcr.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class PCR {
1212
x = Matrix.fromArray(x)
1313
y = Matrix.fromArray(y)
1414
this._pca.fit(x)
15-
let xh = this._pca.predict(x, this._rd)
15+
let xh = Matrix.fromArray(this._pca.predict(x, this._rd))
1616
xh = xh.resize(xh.rows, xh.cols + 1, 1)
1717
const xtx = xh.tDot(xh)
1818

@@ -21,7 +21,7 @@ export default class PCR {
2121

2222
predict(x) {
2323
x = Matrix.fromArray(x)
24-
let xh = this._pca.predict(x, this._rd)
24+
let xh = Matrix.fromArray(this._pca.predict(x, this._rd))
2525
xh = x.resize(xh.rows, xh.cols + 1, 1)
2626
return xh.dot(this._w).toArray()
2727
}

lib/model/principal_curve.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ export default class PrincipalCurve {
6464
}
6565

6666
predict(x, rd = 0) {
67-
return this._l
67+
return this._l.toArray()
6868
}
6969
}

lib/model/random_projection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const RandomProjection = function (x, rd = 0, init = 'uniform') {
2222
} else {
2323
w = Matrix.random(x.cols, d, -1, 1)
2424
}
25-
return x.dot(w)
25+
return x.dot(w).toArray()
2626
}
2727

2828
export default RandomProjection

lib/model/sammon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ export default class Sammon {
4949
this._y.subAt(i, j, (this._alpha * de.at(0, j)) / Math.abs(dde.at(0, j)))
5050
}
5151
}
52-
return this._y
52+
return this._y.toArray()
5353
}
5454
}

lib/model/tsne.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export class SNE {
115115
}
116116
this._epoch += 1
117117

118-
return new Matrix(n, d, this._y)
118+
return new Matrix(n, d, this._y).toArray()
119119
}
120120
}
121121

@@ -233,6 +233,6 @@ export class tSNE {
233233
}
234234
this._epoch += 1
235235

236-
return new Matrix(n, d, this._y)
236+
return new Matrix(n, d, this._y).toArray()
237237
}
238238
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ai-on-browser/data-analysis-models",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "Data analysis models written completely in Javascript",
55
"type": "module",
66
"main": "index.js",

0 commit comments

Comments
 (0)