Skip to content

Commit 109c76e

Browse files
authored
Change the convergence check of eigenJacobi (#930)
* Change the convergence check of eigenJacobi * Extend timeout period of MDS test
1 parent ea223e4 commit 109c76e

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

lib/util/matrix.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -4819,8 +4819,9 @@ export default class Matrix {
48194819
const P = Matrix.eye(this.rows, this.cols)
48204820
P.add(0)
48214821
const tol = 1.0e-15
4822-
let lastMaxValue = 0
4822+
const recentMaxValues = [0]
48234823
const n = this.rows
4824+
const length = this.length
48244825
let maxCount = maxIteration
48254826
while (1) {
48264827
let maxValue = 0
@@ -4838,13 +4839,19 @@ export default class Matrix {
48384839
}
48394840
if (maxValue < tol) {
48404841
break
4841-
} else if (maxValue === lastMaxValue) {
4842-
break
48434842
} else if (maxCount-- < 0) {
48444843
console.log(new MatrixException('eigenJacobi not converged.', [this, maxValue]))
48454844
break
48464845
}
4847-
lastMaxValue = maxValue
4846+
if (maxIteration - maxCount > length / 2 && recentMaxValues.length >= 12) {
4847+
const avg = recentMaxValues.reduce((s, v) => s + v, 0)
4848+
const navg = avg - recentMaxValues.pop() + maxValue
4849+
if (Math.abs(avg - navg) / recentMaxValues.length < tol) {
4850+
break
4851+
}
4852+
recentMaxValues.pop()
4853+
}
4854+
recentMaxValues.unshift(maxValue)
48484855
const app = a[p * n + p]
48494856
const apq = a[p * n + q]
48504857
const aqq = a[q * n + q]

tests/gui/view/mds.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ describe('dimensionality reduction', () => {
3838
await svg.waitForSelector('.tile circle')
3939
const circles = await svg.$$('.tile circle')
4040
expect(circles).toHaveLength(300)
41-
})
41+
}, 60000)
4242
})

tests/lib/util/matrix.test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('Matrix', () => {
7373
}
7474
}
7575
})
76-
76+
7777
test('array', () => {
7878
const mat = Matrix.zeros([2, 3])
7979
for (let i = 0; i < 2; i++) {
@@ -93,7 +93,7 @@ describe('Matrix', () => {
9393
}
9494
}
9595
})
96-
96+
9797
test('array', () => {
9898
const mat = Matrix.ones([2, 3])
9999
for (let i = 0; i < 2; i++) {
@@ -7236,7 +7236,6 @@ describe('Matrix', () => {
72367236
let orgLog
72377237
beforeAll(() => {
72387238
orgLog = console.log
7239-
console.log = jest.fn()
72407239
})
72417240

72427241
afterAll(() => {

0 commit comments

Comments
 (0)