File tree 3 files changed +14
-8
lines changed
3 files changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -4819,8 +4819,9 @@ export default class Matrix {
4819
4819
const P = Matrix . eye ( this . rows , this . cols )
4820
4820
P . add ( 0 )
4821
4821
const tol = 1.0e-15
4822
- let lastMaxValue = 0
4822
+ const recentMaxValues = [ 0 ]
4823
4823
const n = this . rows
4824
+ const length = this . length
4824
4825
let maxCount = maxIteration
4825
4826
while ( 1 ) {
4826
4827
let maxValue = 0
@@ -4838,13 +4839,19 @@ export default class Matrix {
4838
4839
}
4839
4840
if ( maxValue < tol ) {
4840
4841
break
4841
- } else if ( maxValue === lastMaxValue ) {
4842
- break
4843
4842
} else if ( maxCount -- < 0 ) {
4844
4843
console . log ( new MatrixException ( 'eigenJacobi not converged.' , [ this , maxValue ] ) )
4845
4844
break
4846
4845
}
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 )
4848
4855
const app = a [ p * n + p ]
4849
4856
const apq = a [ p * n + q ]
4850
4857
const aqq = a [ q * n + q ]
Original file line number Diff line number Diff line change @@ -38,5 +38,5 @@ describe('dimensionality reduction', () => {
38
38
await svg . waitForSelector ( '.tile circle' )
39
39
const circles = await svg . $$ ( '.tile circle' )
40
40
expect ( circles ) . toHaveLength ( 300 )
41
- } )
41
+ } , 60000 )
42
42
} )
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ describe('Matrix', () => {
73
73
}
74
74
}
75
75
} )
76
-
76
+
77
77
test ( 'array' , ( ) => {
78
78
const mat = Matrix . zeros ( [ 2 , 3 ] )
79
79
for ( let i = 0 ; i < 2 ; i ++ ) {
@@ -93,7 +93,7 @@ describe('Matrix', () => {
93
93
}
94
94
}
95
95
} )
96
-
96
+
97
97
test ( 'array' , ( ) => {
98
98
const mat = Matrix . ones ( [ 2 , 3 ] )
99
99
for ( let i = 0 ; i < 2 ; i ++ ) {
@@ -7236,7 +7236,6 @@ describe('Matrix', () => {
7236
7236
let orgLog
7237
7237
beforeAll ( ( ) => {
7238
7238
orgLog = console . log
7239
- console . log = jest . fn ( )
7240
7239
} )
7241
7240
7242
7241
afterAll ( ( ) => {
You can’t perform that action at this time.
0 commit comments