{"name":"ml-matrix","version":"1.3.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@1.3.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":"b0b0efa47cb16b5c29099700e0c5c13abfea4cd4","tarball":"http://registry-npm.ywwl.com/ml-matrix/download/ml-matrix-1.3.0.tgz","integrity":"sha512-sIl7MRhPJktKSbkl5I2pngVKU1/3EPP/W/Pb9tKLbowEQ5ouVjT3yy2gygHycP3STlz/VUdXNRRN17LfUd2eUw==","signatures":[{"sig":"MEUCIQDS2+J24uCskyZHRkhrARMkuPIG4ADCQH1eC59GlofWtwIgG0O0BNtpDgMG482CvrA7Wu+6sVsg7BllzAuNw7w0vjM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"size":18539,"noattachment":false,"key":"/ml-matrix/-/ml-matrix-1.3.0.tgz"},"main":"src/index.js","_from":".","files":["src"],"_shasum":"b0b0efa47cb16b5c29099700e0c5c13abfea4cd4","engines":{"node":">=2.0.0"},"gitHead":"cd393cd2303698e0befe79eb90d80a9b1d889404","scripts":{"doc":"jsdoc2md src/matrix.js > Documentation.md","test":"mocha --require should-approximately-deep --reporter mocha-better-spec-reporter --recursive"},"_npmUser":{"name":"stropitek","email":"kostro.d@gmail.com"},"repository":{"url":"git+https://github.com/mljs/matrix.git","type":"git"},"_npmVersion":"3.10.3","description":"Matrix manipulation and computation library","directories":{"lib":"src","test":"test"},"_nodeVersion":"6.3.0","dependencies":{"ml-array-utils":"^0.2.4"},"devDependencies":{"mocha":"^2.2.5","mathjs":"^3.2.1","should":"^9.0.2","numeric":"^1.2.6","benchmark":"^2.1.0","csv-parse":"^1.0.0","pretty-hrtime":"^1.0.0","jsdoc-to-markdown":"^1.1.1","should-approximately-deep":"^1.1.0","mocha-better-spec-reporter":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/ml-matrix-1.3.0.tgz_1469452714350_0.2348087893333286","host":"packages-12-west.internal.npmjs.com"},"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":1469452716130,"_cnpm_publish_time":1469452716130,"dist-tags":{"future":"3.0.0-0","latest":"6.15.1","next":"6.0.0-6"}}