{"name":"ml-matrix","version":"6.1.2","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.1.2","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":"a862febc3e5d05d756ae7a02c03114d644b5ee48","tarball":"http://registry-npm.ywwl.com/ml-matrix/download/ml-matrix-6.1.2.tgz","fileCount":39,"integrity":"sha512-JQgKXCaeQQJ22Ssy7Z4iB8mWfzN5sn6Vp7n4d/IsCIQjD13hlLz0SjSIu6xj98CCbY/cxuz8xLfSvAmlghNwmQ==","signatures":[{"sig":"MEQCICjOBt8L7snxj+4NlJLv6O7kghfaE62CFjTGMJ9ncZ9gAiBn0gDk/k0xA0ADLS28lTGFT6eSF8U00W+HNhCtKUsBTA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":309067,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdF0AACRA9TVsSAnZWagAAHWoP/0mVyOa6HGlerHK6vXFX\n/zkUgdQFGNCIRSaIlDOd7fRh/XgVoCRTC5mlpqCoUddsHQct6+H73Ave1haA\nRFDpDCkQJailJYvCGkESQNHFBnv4Cq4p0N7WDkK2uBSgfH3CCZbzHjh85SSa\nDvBO6NfuY7g6hbsoAP+kzmReSLTuDKx/iGssUUm5+47Gn/l4Fyaf3yEJa7OS\nseE++9I8gi/6r6H8gJKnXxrOelQS/Q1E+7gn3CQ7tugjCPguB//hICWfz9nd\nAUMfnx2zEBP2M7TWLWkKmVdiLN4zbIy/UW1UzPczi0ut3aCZkUNSPxmmY4qY\n6dw/odUcNTVWGsupiYIz3Q79h+eg43vFw6U38Ubv/+4H0dQBmQGLJUquDkLU\nR0KRzYiN7lP3rhWKnIp1Y6f180COu7F482MZemphtXm+/VffFJWwWVVqMGlN\n0Isgmp/7EvSxnyHgtLNK8SRn+sRt7ELCNuOiHC+TnRNwyUNHNj30LxcbdIzN\nURFjb9D881tXptW7PED98uANGZfSGM2ilP9Jt8ZKVCoJE/X80O5Pzj8fX3Qb\nuGgUYI0/ZJEDdNjrGiAjT3oW8O8EitAHbHHwEtM867ND3FiNt85jRyeurF+V\n78s7885w8JD5/MSQM5ydRi9rbDcaUXWWgnblNHfkO64IvDmUSvHbK5KcNfda\n3t9L\r\n=Pm1Y\r\n-----END PGP SIGNATURE-----\r\n","size":54454,"noattachment":false,"key":"/ml-matrix/-/ml-matrix-6.1.2.tgz"},"jest":{"testEnvironment":"node"},"main":"matrix.js","types":"matrix.d.ts","module":"src/index.js","gitHead":"7125de6ec09d8613c4aa5cb279a04149958900bc","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.9.0","description":"Matrix manipulation and computation library","directories":{},"sideEffects":false,"_nodeVersion":"12.5.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","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.1.2_1561804799529_0.9082181308775508","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":1561804799772,"_cnpm_publish_time":1561804799772,"dist-tags":{"future":"3.0.0-0","latest":"6.15.1","next":"6.0.0-6"}}