Skip to content

Commit 91430f7

Browse files
authored
Set the default predicted value at the beginning of the fit in CLUES (#755)
1 parent 3529fde commit 91430f7

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/model/clues.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default class CLUES {
4040
const T = Math.max(1, Math.round(this._alpha * n))
4141
let smax = -Infinity
4242

43-
let clusters_star = null
43+
let clusters_star = Array(n).fill(0)
4444
let g_star = Infinity
4545
let y = datas
4646
for (let t = 1; t <= T; t++) {

tests/lib/model/clues.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,17 @@ describe('clustering', () => {
4242
const ri = randIndex(y, t)
4343
expect(ri).toBeGreaterThan(0.9)
4444
})
45+
46+
test('small data', () => {
47+
const model = new CLUES(0.8)
48+
const x = Matrix.random(5, 2, -0.1, 0.1).toArray()
49+
50+
model.fit(x)
51+
const y = model.predict()
52+
expect(y).toHaveLength(x.length)
53+
expect(model.size).toBe(1)
54+
for (let i = 0; i < y.length; i++) {
55+
expect(y[i]).toBe(0)
56+
}
57+
})
4558
})

0 commit comments

Comments
 (0)