Comparing version 2.2.0 to 2.3.0
@@ -0,1 +1,11 @@ | ||
<a name="2.3.0"></a> | ||
# [2.3.0](https://github.com/mljs/matrix/compare/v2.2.0...v2.3.0) (2017-02-28) | ||
### Features | ||
* add pseudoinverse function based on SVD ([3279a15](https://github.com/mljs/matrix/commit/3279a15)) | ||
<a name="2.2.0"></a> | ||
@@ -2,0 +12,0 @@ # [2.2.0](https://github.com/mljs/matrix/compare/v2.1.0...v2.2.0) (2016-12-14) |
{ | ||
"name": "ml-matrix", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "Matrix manipulation and computation library", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -6,2 +6,3 @@ 'use strict'; | ||
var LuDecomposition = require('./dc/lu'); | ||
var SvDecomposition = require('./dc/svd'); | ||
var arrayUtils = require('ml-array-utils'); | ||
@@ -1549,2 +1550,28 @@ var util = require('./util'); | ||
} | ||
/** | ||
* Returns inverse of a matrix if it exists or the pseudoinverse | ||
* @param {number} threshold - threshold for taking inverse of singular values (default = 1e-15) | ||
* @return {Matrix} the (pseudo)inverted matrix. | ||
*/ | ||
pseudoInverse(threshold) { | ||
if (threshold === undefined) threshold = Number.EPSILON; | ||
var svdSolution = new SvDecomposition(this, {autoTranspose: true}); | ||
var U = svdSolution.leftSingularVectors; | ||
var V = svdSolution.rightSingularVectors; | ||
var s = svdSolution.diagonal; | ||
for (var i = 0; i < s.length; i++) { | ||
if (Math.abs(s[i]) > threshold) { | ||
s[i] = 1.0 / s[i]; | ||
} else { | ||
s[i] = 0.0; | ||
} | ||
} | ||
// convert list to diagonal | ||
s = this.constructor[Symbol.species].diag(s); | ||
return V.mmul(s.mmul(U.transposeView())); | ||
} | ||
} | ||
@@ -1551,0 +1578,0 @@ |
'use strict'; | ||
var Matrix = require('../matrix').Matrix; | ||
var Matrix = require('../matrix'); | ||
var util = require('./util'); | ||
@@ -13,3 +13,3 @@ var hypotenuse = util.hypotenuse; | ||
} | ||
value = Matrix.checkMatrix(value); | ||
value = Matrix.Matrix.checkMatrix(value); | ||
@@ -422,4 +422,4 @@ options = options || {}; | ||
get leftSingularVectors() { | ||
if (!Matrix.isMatrix(this.U)) { | ||
this.U = new Matrix(this.U); | ||
if (!Matrix.Matrix.isMatrix(this.U)) { | ||
this.U = new Matrix.Matrix(this.U); | ||
} | ||
@@ -429,4 +429,4 @@ return this.U; | ||
get rightSingularVectors() { | ||
if (!Matrix.isMatrix(this.V)) { | ||
this.V = new Matrix(this.V); | ||
if (!Matrix.Matrix.isMatrix(this.V)) { | ||
this.V = new Matrix.Matrix(this.V); | ||
} | ||
@@ -436,3 +436,3 @@ return this.V; | ||
get diagonalMatrix() { | ||
return Matrix.diag(this.s); | ||
return Matrix.Matrix.diag(this.s); | ||
}, | ||
@@ -444,3 +444,3 @@ solve: function (value) { | ||
scols = this.s.length, | ||
Ls = Matrix.zeros(scols, scols), | ||
Ls = Matrix.Matrix.zeros(scols, scols), | ||
i; | ||
@@ -462,3 +462,3 @@ | ||
urows = U.length, | ||
VLU = Matrix.zeros(vrows, urows), | ||
VLU = Matrix.Matrix.zeros(vrows, urows), | ||
j, k, sum; | ||
@@ -479,3 +479,3 @@ | ||
solveForDiagonal: function (value) { | ||
return this.solve(Matrix.diag(value)); | ||
return this.solve(Matrix.Matrix.diag(value)); | ||
}, | ||
@@ -487,3 +487,3 @@ inverse: function () { | ||
vcols = V[0].length, | ||
X = new Matrix(vrows, this.s.length), | ||
X = new Matrix.Matrix(vrows, this.s.length), | ||
i, j; | ||
@@ -505,3 +505,3 @@ | ||
ucols = U[0].length, | ||
Y = new Matrix(vrows, urows), | ||
Y = new Matrix.Matrix(vrows, urows), | ||
k, sum; | ||
@@ -508,0 +508,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
135805
3669