{"name":"ml-matrix","version":"6.0.0-5","keywords":["matrix","decomposition","SVD","singular","value","EVD","eigenvalue","LU","Qr","Cholesky","data","mining","datamining","machine","learning"],"author":{"name":"Michaël Zasso"},"license":"MIT","_id":"ml-matrix@6.0.0-5","maintainers":[{"name":"andcastillo","email":"andcastillo@gmail.com"},{"name":"jeffersonh44","email":"swrt_9950@hotmail.com"},{"name":"lpatiny","email":"lpatiny@gmail.com"},{"name":"maasencioh","email":"maasencioh@gmail.com"},{"name":"ml-bot","email":"admin@cheminfo.org"},{"name":"stropitek","email":"kostro.d@gmail.com"},{"name":"targos","email":"targos@live.com"}],"homepage":"https://github.com/mljs/matrix","bugs":{"url":"https://github.com/mljs/matrix/issues"},"dist":{"shasum":"4948c5ddd579bae5829a42add5758c7be92e8abb","tarball":"http://registry-npm.ywwl.com/ml-matrix/download/ml-matrix-6.0.0-5.tgz","fileCount":35,"integrity":"sha512-CfWNC4Q7aBVI6dD9i+3MMCnkfbzhGNo0qv5sqDPGUGfsBepykeBa1mpcx1Om76HaichjRcrX93sOkfPN2nvWTQ==","signatures":[{"sig":"MEYCIQCQJVJRPtMnLxaAdNb2S6MvAZU46aPnLtLPqoJCqGMM1gIhALMx5d8u9h7ws8l26Ixcn7aTIJzfBUxynmWstw1ejojU","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":268410,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcuO0mCRA9TVsSAnZWagAAAuMQAIzyPlAu9fMMfVouhhbh\nJRysCDz1hsQ+oghC6I/ZAZpwV3Qh8peXEpVqwSGXDcITiCKFYQPMcLrt+fIa\nYCNdkYBKETy6svU0oUKkEoSPaXTNTIvJfsjStZVT83cbnkMxGCzCyZALPOcE\nyMpmOd9Zjh5g1GXkkYUUX8orkgM27LbUWtqLHf6bjDUSKmKOCQBPA9JhIy/S\ngG0ntrcPR1tjEpiUWvMpk1MlG+jY46nrhWl5ZCdj6MOsTQdJVRx4a9Ac7ucn\n5o3c+hCobWuUhw+q4jllsUe4pl8GYq4iXwuk68VdSSI3VW56jZxoaBbOxJM8\nRwxhsdMLCsW5KknWnjBojMLefa1tVNZXd+EyCtxTu51ueinmPveMqjvhCZjI\nopGrFAZKFSyUVZLDZocREtTDipLWmeqwyVzJaeKu7yPG22c6o/lDI7K2za4a\ngK82/XO4cupKy0Z03/EleIcSVsn+Mp2UhHqWojG3NBJfC+jCT3iwNNRJMtHr\nzVoHmJb5GaSYqkMdI1oG2tvAIqrjaGDWC24FQRntdx3QIg36K5xHMPgIY368\nn/auV7N1bS4gbfxp0oOJWVvxXLuW+Ta6azrkFKDBFTDXFT/0pZVu4cLOrbSG\nbxD7UmKwr6pmXIVz5rgw4lwAZ9Kut+3NT+hoD/3fjQZFZ68p2nHnmsnCZCNF\nW+7k\r\n=RGaR\r\n-----END PGP SIGNATURE-----\r\n","size":53536,"noattachment":false,"key":"/ml-matrix/-/ml-matrix-6.0.0-5.tgz"},"jest":{"testEnvironment":"node"},"main":"matrix.js","types":"matrix.d.ts","module":"src/index.js","readme":"# ml-matrix\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![npm download][download-image]][download-url]\n\nMatrix manipulation and computation library.\n\n## Installation\n\n`$ npm install ml-matrix`\n\n## Usage\n\n### As an ES module\n\n```js\nimport { Matrix } from 'ml-matrix';\n\nconst matrix = Matrix.ones(5, 5);\n```\n\n### As a CommonJS module\n\n```js\nconst { Matrix } = require('ml-matrix');\n\nconst matrix = Matrix.ones(5, 5);\n```\n\n## [API Documentation](https://mljs.github.io/matrix/)\n\n## Examples\n\n### Standard operations\n\n```js\nconst { Matrix } = require('ml-matrix');\n\nvar A = new Matrix([[1, 1], [2, 2]]);\nvar B = new Matrix([[3, 3], [1, 1]]);\nvar C = new Matrix([[3, 3], [1, 1]]);\n\n// ============================\n// Operations with the matrix :\n// =============================\n\n// operations :\nconst addition = Matrix.add(A, B); // addition = Matrix [[4, 4], [3, 3], rows: 2, columns: 2]\nconst substraction = Matrix.sub(A, B); // substraction = Matrix [[-2, -2], [1, 1], rows: 2, columns: 2]\nconst multiplication = A.mmul(B); // multiplication = Matrix [[4, 4], [8, 8], rows: 2, columns: 2]\nconst mulByNumber = Matrix.mul(A, 10); // mulByNumber = Matrix [[10, 10], [20, 20], rows: 2, columns: 2]\nconst divByNumber = Matrix.div(A, 10); // divByNumber = Matrix [[0.1, 0.1], [0.2, 0.2], rows: 2, columns: 2]\nconst modulo = Matrix.mod(B, 2); // modulo = Matrix [[ 1, 1], [1, 1], rows: 2, columns: 2]\nconst maxMatrix = Matrix.max(A, B); // max = Matrix [[3, 3], [2, 2], rows: 2, columns: 2]\nconst minMatrix = Matrix.min(A, B); // max = Matrix [[1, 1], [1, 1], rows: 2, columns: 2]\n\n// Inplace operations : (consider that Cinit = C before all the operations below)\nC.add(A); // => C = Cinit + A\nC.sub(A); // => C = Cinit\nC.mul(10); // => C = 10 * Cinit\nC.div(10); // => C = Cinit\nC.mod(2); // => C = Cinit % 2\n\n// Standard Math operations : (abs, cos, round, etc.)\nvar A = new Matrix([[1, 1], [-1, -1]]);\nvar expon = Matrix.exp(A); // expon = Matrix [[Math.exp(1), Math.exp(1)], [Math.exp(-1), Math.exp(-1)], rows: 2, columns: 2].\nvar cosinus = Matrix.cos(A); // cosinus = Matrix [[Math.cos(1), Math.cos(1)], [Math.cos(-1), Math.cos(-1)], rows: 2, columns: 2].\nvar absolute = Matrix.abs(A); // expon = absolute [[1, 1], [1, 1], rows: 2, columns: 2].\n// you can use 'abs', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atanh', 'cbrt', 'ceil', 'clz32', 'cos', 'cosh', 'exp', 'expm1', 'floor', 'fround', 'log', 'log1p', 'log10', 'log2', 'round', 'sign', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc'\n// Note : you can do it inplace too as A.abs()\n\n// ============================\n// Manipulation of the matrix :\n// =============================\n\nvar numberRows = A.rows; // A has 2 rows\nvar numberCols = A.columns; // A has 2 columns\nvar firstValue = A.get(0, 0); // get(rows, columns)\nvar numberElements = A.size; // 2 * 2 = 4 elements\nvar isRow = A.isRowVector(); // false because A has more that 1 row\nvar isColumn = A.isColumnVector(); // false because A has more that 1 column\nvar isSquare = A.isSquare(); // true, because A is 2 * 2 matrix\nvar isSym = A.isSymmetric(); // false, because A is not symmetric\n// remember : A = Matrix [[1, 1], [-1, -1], rows: 2, columns: 2]\nA.set(1, 0, 10); // A = Matrix [[1, 1], [10, -1], rows: 2, columns: 2]. We have change the second row and the first column\nvar diag = A.diag(); // diag = [1, -1], i.e values in the diagonal.\nvar m = A.mean(); // m = 2.75\nvar product = A.prod(); // product = -10, i.e product of all values of the matrix\nvar norm = A.norm(); // norm = 10.14889156509222, i.e Frobenius norm of the matrix\nvar transpose = A.transpose(); // tranpose = Matrix [[1, 10], [1, -1], rows: 2, columns: 2]\n\n// ============================\n// Instanciation of matrix :\n// =============================\n\nvar z = Matrix.zeros(3, 2); // z = Matrix [[0, 0], [0, 0], [0, 0], rows: 3, columns: 2]\nvar z = Matrix.ones(2, 3); // z = Matrix [[1, 1, 1], [1, 1, 1], rows: 2, columns: 3]\nvar z = Matrix.eye(3, 4); // Matrix [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], rows: 3, columns: 4]. there are 1 only in the diagonal\n```\n\n### Maths\n\n```js\nconst {\n  Matrix,\n  inverse,\n  solve,\n  linearDependencies,\n  QrDecomposition,\n  LuDecomposition,\n  CholeskyDecomposition\n} = require('ml-matrix');\n\n//===========================\n// inverse and pseudo-inverse\n//===========================\n\nvar A = new Matrix([[2, 3, 5], [4, 1, 6], [1, 3, 0]]);\nvar inverseA = inverse(A);\nvar B = A.mmul(inverseA); // B = A * inverse(A), so B ~= Identity\n\n// if A is singular, you can use SVD :\nvar A = new Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]); // A is singular, so the standard computation of inverse won't work (you can test if you don't trust me^^)\nvar inverseA = inverse(A, (useSVD = true)); // inverseA is only an approximation of the inverse, by using the Singular Values Decomposition\nvar B = A.mmul(inverseA); // B = A * inverse(A), but inverse(A) is only an approximation, so B doesn't really be identity.\n\n// if you want the pseudo-inverse of a matrix :\nvar A = new Matrix([[1, 2], [3, 4], [5, 6]]);\nvar pseudoInverseA = A.pseudoInverse();\nvar B = A.mmul(pseudoInverseA).mmul(A); // with pseudo inverse, A*pseudo-inverse(A)*A ~= A. It's the case here\n\n//=============\n// Least square\n//=============\n\n// Least square is the following problem : We search x, such as A.x = b (A, x and b are matrix or vectors).\n// Below, how to solve least square with our function\n\n// If A is non singular :\nvar A = new Matrix([[3, 1], [4.25, 1], [5.5, 1], [8, 1]]);\nvar b = Matrix.columnVector([4.5, 4.25, 5.5, 5.5]);\nvar x = solve(A, b);\nvar error = Matrix.sub(b, A.mmul(x)); // The error enables to evaluate the solution x found.\n\n// If A is non singular :\nvar A = new Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);\nvar b = Matrix.columnVector([8, 20, 32]);\nvar x = solve(A, b, (useSVD = true)); // there are many solutions. x can be [1, 2, 1].transpose(), or [1.33, 1.33, 1.33].transpose(), etc.\nvar error = Matrix.sub(b, A.mmul(x)); // The error enables to evaluate the solution x found.\n\n//===============\n// Decompositions\n//===============\n\n// QR Decomposition\n\nvar A = new Matrix([[2, 3, 5], [4, 1, 6], [1, 3, 0]]);\nvar QR = QrDecomposition(A);\nvar Q = QR.orthogonalMatrix;\nvar R = QR.upperTriangularMatrix;\n// So you have the QR decomposition. If you multiply Q by R, you'll see that A = Q.R, with Q orthogonal and R upper triangular\n\n// LU Decomposition\n\nvar A = new Matrix([[2, 3, 5], [4, 1, 6], [1, 3, 0]]);\nvar LU = LuDecomposition(A);\nvar L = LU.lowerTriangularMatrix;\nvar U = LU.upperTriangularMatrix;\nvar P = LU.pivotPermutationVector;\n// So you have the LU decomposition. P includes the permutation of the matrix. Here P = [1, 2, 0], i.e the first row of LU is the second row of A, the second row of LU is the third row of A and the third row of LU is the first row of A.\n\n// Cholesky Decomposition\n\nvar A = new Matrix([[2, 3, 5], [4, 1, 6], [1, 3, 0]]);\nvar cholesky = CholeskyDecomposition(A);\nvar L = cholesky.lowerTriangularMatrix;\n\n// Eigenvalues & eigenvectors\n\nvar A = new Matrix([[2, 3, 5], [4, 1, 6], [1, 3, 0]]);\nvar e = EigenvalueDecomposition(A);\nvar real = e.realEigenvalues;\nvar imaginary = e.imaginaryEigenvalues;\nvar vectors = e.eigenvectorMatrix;\n\n//=======\n// Others\n//=======\n\n// Linear dependencies\nvar A = new Matrix([\n  [2, 0, 0, 1],\n  [0, 1, 6, 0],\n  [0, 3, 0, 1],\n  [0, 0, 1, 0],\n  [0, 1, 2, 0]\n]);\nvar dependencies = linearDependencies(A); // dependencies is a matrix with the dependencies of the rows. When we look row by row, we see that the first row is [0, 0, 0, 0, 0], so it means that the first row is independent, and the second row is [ 0, 0, 0, 4, 1 ], i.e the second row = 4 times the 4th row + the 5th row.\n```\n\n## License\n\n[MIT](./LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/ml-matrix.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/ml-matrix\n[travis-image]: https://img.shields.io/travis/mljs/matrix/master.svg?style=flat-square\n[travis-url]: https://travis-ci.org/mljs/matrix\n[codecov-image]: https://img.shields.io/codecov/c/github/mljs/matrix.svg?style=flat-square\n[codecov-url]: https://codecov.io/github/mljs/matrix\n[download-image]: https://img.shields.io/npm/dm/ml-matrix.svg?style=flat-square\n[download-url]: https://npmjs.org/package/ml-matrix\n","gitHead":"b8b2c9f43659a68743e44011666fd16b4fa583a3","scripts":{"test":"npm run test-coverage && npm run eslint","eslint":"eslint benchmark src testUtils.js","compile":"rollup -c","test-only":"jest","eslint-fix":"npm run eslint -- --fix","test-coverage":"jest --coverage","prepublishOnly":"npm run compile"},"_npmUser":{"name":"targos","email":"targos+npm@protonmail.com"},"repository":{"url":"git+https://github.com/mljs/matrix.git","type":"git"},"_npmVersion":"6.7.0","description":"Matrix manipulation and computation library","directories":{},"_nodeVersion":"11.14.0","dependencies":{"ml-array-rescale":"^1.2.1"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jest":"^24.7.1","eslint":"^5.16.0","mathjs":"^5.9.0","rollup":"^1.10.0","numeric":"^1.2.6","benchmark":"^2.1.4","csv-parse":"^4.4.0","pretty-hrtime":"^1.0.3","eslint-plugin-jest":"^22.4.1","eslint-plugin-import":"^2.17.2","eslint-config-cheminfo":"^1.20.1","jest-matcher-deep-close-to":"^1.3.0","@babel/plugin-transform-modules-commonjs":"^7.4.3"},"_npmOperationalInternal":{"tmp":"tmp/ml-matrix_6.0.0-5_1555623205375_0.7056892320177359","host":"s3://npm-registry-packages"},"publish_time":1555623205546,"_cnpm_publish_time":1555623205546,"dist-tags":{"future":"3.0.0-0","latest":"6.15.1","next":"6.0.0-6"}}