{"name":"ml-matrix","version":"6.2.0","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.2.0","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":"84c74720f3d2b583d811dfc8f9dd113752362a7f","tarball":"http://registry-npm.ywwl.com/ml-matrix/download/ml-matrix-6.2.0.tgz","fileCount":40,"integrity":"sha512-J+0VWVhQrrp7qb5+pcmLb+vFJVMugb26B6ovbJ7Ku/8zZ+ZwvUbRWHQnpAmVDoFX33PF72WZCymYMwZ9oEdXxw==","signatures":[{"sig":"MEUCIA7Twa39P3UukiinIWXpU7oiynY+wuFt45B1XY8bB9CSAiEAg6Hqz+K6NpY7jmlfqL5beUc0ORiTQNLoeWpcU7hYRjM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":315897,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdMx+/CRA9TVsSAnZWagAAaMMP/1K+YIkFHOvbxXFr3qcI\nHBYbQfm2a0Em8t3Hrtw3+GlOumcSbwGMr7zvWelXI0iJ8AwguGPTUd6gvtUH\nDXTzRrQBBWqdbsHN1vidLAZ9b5nqEAy/zux9gJek0K+R6ixoaw8b4kF9pEU4\nGtdAWPx1CfTuey3nIkqezS0eHuwAvt69nyyMTwhREvQwKeVFyFPryPnACXgR\nO6WdWZ7xef+gQ+Cc4uonaXIWgxG99BRSK4Z6Hj1uFVTsuwO8iWeJj9iuK7AF\nAujkx3EPn7LatoPTUGZgP9MscCmi40oi9cPdh9iJxt9b67g548QydP/2VvbX\nA+cLmzi/if/geXG8sxfQ1uIWfzhGps6D5cCM8S7/Wvo+4glBY+YIVbtpdGIM\n+S2vCxqERC6RPBkbONVGIXBBhZI6ELz9yJdn/CEpYrgbA7hTRjYBsNFufvxB\nQYkdyLy5FCYk4UIsgHA08QSfhsPHDqKz8KakTk0OzFbIPuVvV1ubOTq8kkHZ\n3ZhOWSygsQZFL2tc796+k8dE2yipbaXzI7qfUuPRf23HIiqRSUQPXZsdkhZJ\njlyGWZHZe8Tj1Sk7DyjtM5sre0mnwXvEczAcBjs1oz5h8SEsuKXM5AzIW10F\n4ZAhjf1/rDUA+wbUpgVoiLjtM6nhI86ZcaD1/ZoqxE8+H78g9IqeqwdJvdhi\nxEcn\r\n=vCVo\r\n-----END PGP SIGNATURE-----\r\n","size":57336,"noattachment":false,"key":"/ml-matrix/-/ml-matrix-6.2.0.tgz"},"jest":{"testEnvironment":"node"},"main":"matrix.js","types":"matrix.d.ts","module":"src/index.js","gitHead":"a9d9f2a268d33598553bee996ad71322e3f838d3","scripts":{"test":"npm run test-coverage && npm run eslint","eslint":"eslint benchmark src testUtils.js","compile":"rollup -c","test-only":"jest","build-docs":"typedoc --out docs --name \"ml-matrix\" --mode file --includeDeclarations --excludeExternals --hideGenerator --excludePrivate --moduleResolution node matrix.d.ts","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.10.0","description":"Matrix manipulation and computation library","directories":{},"sideEffects":false,"_nodeVersion":"12.6.0","dependencies":{"ml-array-rescale":"^1.2.1"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^24.8.0","eslint":"^6.0.1","mathjs":"^6.0.2","rollup":"^1.16.3","numeric":"^1.2.6","typedoc":"^0.14.2","benchmark":"^2.1.4","csv-parse":"^4.4.3","pretty-hrtime":"^1.0.3","ml-dataset-iris":"^1.0.0","eslint-plugin-jest":"^22.7.1","eslint-plugin-import":"^2.18.0","eslint-config-cheminfo":"^1.20.1","jest-matcher-deep-close-to":"^1.3.0","@babel/plugin-transform-modules-commonjs":"^7.4.4"},"_npmOperationalInternal":{"tmp":"tmp/ml-matrix_6.2.0_1563631551191_0.6713526750625127","host":"s3://npm-registry-packages"},"readme":"# ml-matrix\n\nMatrix manipulation and computation library.\n\n<h3 align=\"center\">\n\n  <a href=\"https://www.zakodium.com\">\n    <img src=\"https://www.zakodium.com/brand/zakodium-logo-white.svg\" width=\"50\" alt=\"Zakodium logo\" />\n  </a>\n\n  <p>\n    Maintained by <a href=\"https://www.zakodium.com\">Zakodium</a>\n  </p>\n\n[![NPM version][npm-image]][npm-url]\n[![build status][ci-image]][ci-url]\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5644534.svg)](https://doi.org/10.5281/zenodo.5644534)\n[![npm download][download-image]][download-url]\n\n</h3>\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([\n  [1, 1],\n  [2, 2],\n]);\n\nvar B = new Matrix([\n  [3, 3],\n  [1, 1],\n]);\n\nvar C = new Matrix([\n  [3, 3],\n  [1, 1],\n]);\n```\n\n#### Operations\n```js\nconst addition       = Matrix.add(A, B);   // addition       = Matrix [[4, 4], [3, 3], rows: 2, columns: 2]\nconst subtraction    = Matrix.sub(A, B);   // subtraction    = 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\n#### Inplace Operations\n```js\nC.add(A);   // => C = C + A\nC.sub(A);   // => C = C - A\nC.mul(10);  // => C = 10 * C\nC.div(10);  // => C = C / 10\nC.mod(2);   // => C = C % 2\n```\n\n#### Math Operations\n```js\n// Standard Math operations: (abs, cos, round, etc.)\nvar A = new Matrix([\n  [ 1,  1],\n  [-1, -1],\n]);\n\nvar exponential = Matrix.exp(A);  // exponential = 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);  // absolute    = Matrix [[1, 1], [1, 1], rows: 2, columns: 2].\n// Note: you can do it inplace too as A.abs()\n```\nAvailable Methods:\n```js\nabs, 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```\n#### Manipulation of the matrix\n```js\n// remember: A = Matrix [[1, 1], [-1, -1], rows: 2, columns: 2]\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 than 1 row\nvar isColumn       = A.isColumnVector(); // false because A has more than 1 column\nvar isSquare       = A.isSquare();       // true, because A is 2 * 2 matrix\nvar isSym          = A.isSymmetric();    // false, because A is not symmetric\nA.set(1, 0, 10);                         // A = Matrix [[1, 1], [10, -1], rows: 2, columns: 2]. We have changed the second row and the first column\nvar diag           = A.diag();           // diag = [1, -1] (values in the diagonal)\nvar m              = A.mean();           // m = 2.75\nvar product        = A.prod();           // product = -10 (product of all values of the matrix)\nvar norm           = A.norm();           // norm = 10.14889156509222 (Frobenius norm of the matrix)\nvar transpose      = A.transpose();      // transpose = Matrix [[1, 10], [1, -1], rows: 2, columns: 2]\n```\n\n#### Instantiation of matrix\n```js\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);   // z = 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```js\nconst {\n  Matrix,\n  inverse,\n  solve,\n  linearDependencies,\n  QrDecomposition,\n  LuDecomposition,\n  CholeskyDecomposition,\n  EigenvalueDecomposition,\n} = require('ml-matrix');\n```\n#### Inverse and Pseudo-inverse\n```js\nvar A = new Matrix([\n  [2, 3, 5],\n  [4, 1, 6],\n  [1, 3, 0],\n]);\n\nvar inverseA = inverse(A);\nvar B = A.mmul(inverseA); // B = A * inverse(A), so B ~= Identity\n\n\n// if A is singular, you can use SVD :\nvar A = new Matrix([\n  [1, 2, 3],\n  [4, 5, 6],\n  [7, 8, 9],\n]); \n// A is singular, so the standard computation of inverse won't work (you can test if you don't trust me^^)\n\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```js\n// if you want the pseudo-inverse of a matrix :\nvar A = new Matrix([\n  [1, 2],\n  [3, 4],\n  [5, 6],\n]);\n\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#### Least square\nLeast square is the following problem: We search for `x`, such that `A.x = B` (`A`, `x` and `B` are matrix or vectors).\nBelow, how to solve least square with our function\n```js\n// If A is non singular :\nvar A = new Matrix([\n  [3,    1],\n  [4.25, 1],\n  [5.5,  1],\n  [8,    1],\n]);\n\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```js\n// If A is non singular :\nvar A = new Matrix([\n  [1, 2, 3],\n  [4, 5, 6],\n  [7, 8, 9],\n]);\n\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#### Decompositions\n\n##### QR Decomposition\n```js\nvar A = new Matrix([\n  [2, 3, 5],\n  [4, 1, 6],\n  [1, 3, 0],\n]);\n\nvar QR = new 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```js\nvar A = new Matrix([\n  [2, 3, 5],\n  [4, 1, 6],\n  [1, 3, 0],\n]);\n\nvar LU = new 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```js\nvar A = new Matrix([\n  [2, 3, 5],\n  [4, 1, 6],\n  [1, 3, 0],\n]);\n\nvar cholesky = new CholeskyDecomposition(A);\nvar L = cholesky.lowerTriangularMatrix;\n```\n##### Eigenvalues & eigenvectors\n```js\nvar A = new Matrix([\n  [2, 3, 5],\n  [4, 1, 6],\n  [1, 3, 0],\n]);\n\nvar e = new EigenvalueDecomposition(A);\nvar real = e.realEigenvalues;\nvar imaginary = e.imaginaryEigenvalues;\nvar vectors = e.eigenvectorMatrix;\n```\n#### Linear dependencies\n```js\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]);\n\nvar dependencies = linearDependencies(A);\n// 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\n[npm-url]: https://npmjs.org/package/ml-matrix\n[ci-image]: https://github.com/mljs/matrix/workflows/Node.js%20CI/badge.svg?branch=main\n[ci-url]: https://github.com/mljs/matrix/actions?query=workflow%3A%22Node.js+CI%22\n[download-image]: https://img.shields.io/npm/dm/ml-matrix.svg\n[download-url]: https://npmjs.org/package/ml-matrix\n","publish_time":1563631551368,"_cnpm_publish_time":1563631551368,"dist-tags":{"future":"3.0.0-0","latest":"6.15.1","next":"6.0.0-6"}}