@@ -4220,17 +4220,18 @@ export default class Matrix {
4220
4220
/**
4221
4221
* Returns eigenvalues by LU decomposition.
4222
4222
*
4223
+ * @param {number } [maxIteration=1.0e5] Maximum iteration
4223
4224
* @returns {number[] } Eigenvalues
4224
4225
*/
4225
- eigenValuesLR ( ) {
4226
+ eigenValuesLR ( maxIteration = 1.0e5 ) {
4226
4227
if ( ! this . isSquare ( ) ) {
4227
4228
throw new MatrixException ( 'Eigen values only define square matrix.' , this )
4228
4229
}
4229
4230
4230
4231
let a = this
4231
4232
const n = a . rows
4232
4233
const tol = 1.0e-15
4233
- let maxCount = 1.0e5
4234
+ let maxCount = maxIteration
4234
4235
while ( maxCount -- > 0 ) {
4235
4236
const [ l , u ] = a . lu ( )
4236
4237
a = u . dot ( l )
@@ -4253,9 +4254,10 @@ export default class Matrix {
4253
4254
/**
4254
4255
* Returns eigenvalues by QR decomposition.
4255
4256
*
4257
+ * @param {number } [maxIteration=1.0e6] Maximum iteration
4256
4258
* @returns {number[] } Eigenvalues
4257
4259
*/
4258
- eigenValuesQR ( ) {
4260
+ eigenValuesQR ( maxIteration = 1.0e6 ) {
4259
4261
if ( ! this . isSquare ( ) ) {
4260
4262
throw new MatrixException ( 'Eigen values only define square matrix.' , this )
4261
4263
}
@@ -4264,7 +4266,7 @@ export default class Matrix {
4264
4266
const ev = [ ]
4265
4267
const tol = 1.0e-8
4266
4268
for ( let n = a . rows ; n > 2 ; n -- ) {
4267
- let maxCount = 1.0e6
4269
+ let maxCount = maxIteration
4268
4270
while ( 1 ) {
4269
4271
const am = a . block ( n - 2 , n - 2 ) . eigenValues ( )
4270
4272
if ( isNaN ( am [ 0 ] ) ) {
@@ -4383,9 +4385,10 @@ export default class Matrix {
4383
4385
/**
4384
4386
* Returns the maximum eigenvalue and its eigenvector.
4385
4387
*
4388
+ * @param {number } [maxIteration=1.0e4] Maximum iteration
4386
4389
* @returns {[number, Matrix] } Maximum eigenvalue and its eigenvector
4387
4390
*/
4388
- eigenPowerIteration ( ) {
4391
+ eigenPowerIteration ( maxIteration = 1.0e4 ) {
4389
4392
if ( ! this . isSquare ( ) ) {
4390
4393
throw new MatrixException ( 'Eigen vectors only define square matrix.' , this )
4391
4394
}
@@ -4395,7 +4398,7 @@ export default class Matrix {
4395
4398
let px = Matrix . randn ( n , 1 )
4396
4399
px . div ( px . norm ( ) )
4397
4400
let pl = Infinity
4398
- let maxCount = 1.0e4
4401
+ let maxCount = maxIteration
4399
4402
while ( maxCount -- > 0 ) {
4400
4403
const x = this . dot ( px )
4401
4404
let lnum = 0 ,
@@ -4420,9 +4423,10 @@ export default class Matrix {
4420
4423
* Returns the nearest eigenvalue and its eigenvector to the specified value.
4421
4424
*
4422
4425
* @param {number } [ev=0.0] Target value
4426
+ * @param {number } [maxIteration=1.0e4] Maximum iteration
4423
4427
* @returns {[number, Matrix] } Eigenvalue and eigenvector
4424
4428
*/
4425
- eigenInverseIteration ( ev = 0.0 ) {
4429
+ eigenInverseIteration ( ev = 0.0 , maxIteration = 1.0e4 ) {
4426
4430
if ( ! this . isSquare ( ) ) {
4427
4431
throw new MatrixException ( 'Eigen vectors only define square matrix.' , this )
4428
4432
}
@@ -4437,7 +4441,7 @@ export default class Matrix {
4437
4441
let py = Matrix . randn ( n , 1 )
4438
4442
py . div ( py . norm ( ) )
4439
4443
let pl = Infinity
4440
- let maxCount = 1.0e4
4444
+ let maxCount = maxIteration
4441
4445
while ( maxCount -- > 0 ) {
4442
4446
const y = a . dot ( py )
4443
4447
let lnum = 0 ,
0 commit comments