UNPKG

qminer

Version:

A C++ based data analytics platform for processing large-scale real-time streams containing structured and unstructured data

1,027 lines (1,025 loc) 158 kB
<!doctype html> <html> <head> <meta name="generator" content="JSDoc 3"> <meta charset="utf-8"> <title>Source: ladoc.js</title> <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css"> <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css"> <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css"> <link href="css/baseline.css" rel="stylesheet"> </head> <body onload="prettyPrint()"> <nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar"> <div id="jsdoc-navbar-container"> <div id="jsdoc-navbar-content"> <a href="index.html" class="jsdoc-navbar-package-name">Home</a> </div> </div> </nav> <div id="jsdoc-body-container"> <div id="jsdoc-content"> <div id="jsdoc-content-container"> <div id="jsdoc-banner" role="banner"> </div> <div id="jsdoc-main" role="main"> <header class="page-header"> <h1>Source: ladoc.js</h1> </header> <article> <pre class="prettyprint linenums"><code>/** * Copyright (c) 2015, Jozef Stefan Institute, Quintelligence d.o.o. and contributors * All rights reserved. * * This source code is licensed under the FreeBSD license found in the * LICENSE file in the root directory of this source tree. */ /** * Linear algebra module. * @module la * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a random matrix * var mat &#x3D; new la.Matrix({ rows: 10, cols: 5, random: true }); * // create a vector * var vec &#x3D; new la.Vector([1, 2, 3, 0, -1]); * // multiply the matrix and vector * var vec2 &#x3D; mat.multiply(vec); * // calculate the svd decomposition of the matrix * var svd &#x3D; la.svd(mat, 3); */ /** * Computes the truncated SVD decomposition. * @param {module:la.Matrix | module:la.SparseMatrix} mat - The matrix. * @param {number} k - The number of singular vectors to be computed. * @param {Object} [json] - The JSON object. * @param {number} [json.iter &#x3D; 100] - The number of iterations used for the algorithm. * @param {number} [json.tol &#x3D; 1e-6] - The tolerance number. * @param {function} [callback] - The callback function, that takes the error parameters (err) and the result parameter (res). * &amp;lt;i&gt;Only for the asynchronous function.&amp;lt;/i&gt; * @returns {Object} The JSON object &#x60;svdRes&#x60; which contains the SVD decomposition U*S*V^T matrices: * &amp;lt;br&gt;&#x60;svdRes.U&#x60; - The dense matrix of the decomposition. Type {@link module:la.Matrix}. * &amp;lt;br&gt;&#x60;svdRes.V&#x60; - The dense matrix of the decomposition. Type {@link module:la.Matrix}. * &amp;lt;br&gt;&#x60;svdRes.s&#x60; - The vector containing the singular values of the decomposition. Type {@link module:la.Vector}. * @example &amp;lt;caption&gt;Asynchronous function&amp;lt;/caption&gt; * // import the modules * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a random matrix * var A &#x3D; new la.Matrix({ rows: 10, cols: 5, random: true }); * // set the parameters for the calculation * var k &#x3D; 2; // number of singular vectors * var param &#x3D; { iter: 1000, tol: 1e-4 }; * // calculate the svd * la.svd(A, k, param, function (err, result) { * if (err) { console.log(err); } * // successful calculation * var U &#x3D; result.U; * var V &#x3D; result.V; * var s &#x3D; result.s; * }); * @example &amp;lt;caption&gt;Synchronous function&amp;lt;/caption&gt; * // import the modules * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a random matrix * var A &#x3D; new la.Matrix({ rows: 10, cols: 5, random: true }); * // set the parameters for the calculation * var k &#x3D; 2; // number of singular vectors * var param &#x3D; { iter: 1000, tol: 1e-4 }; * // calculate the svd * var result &#x3D; la.svd(A, k, param); * // successful calculation * var U &#x3D; result.U; * var V &#x3D; result.V; * var s &#x3D; result.s; */ exports.prototype.svd &#x3D; function (mat, k, json) { return { U: Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype), V: Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype), s: Object.create(require(&#x27;qminer&#x27;).la.Vector.prototype) } } /** * Computes the QR decomposition. * @param {module:la.Matrix} mat - The matrix. * @param {number} [tol &#x3D; 1e-6] - The tolerance number. * @returns {Object} A JSON object &#x60;qrRes&#x60; which contains the decomposition matrices: * &amp;lt;br&gt;&#x60;qrRes.Q&#x60; - The orthogonal matrix Q of the QR decomposition. Type {@link module:la.Matrix}. * &amp;lt;br&gt;&#x60;qrRes.R&#x60; - The upper triangular matrix R of the QR decomposition. Type {@link module:la.Matrix}. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a random matrix * var mat &#x3D; new la.Matrix({ rows: 10, cols: 5, random: true }); * // calculate the QR decomposition of mat * var qrRes &#x3D; la.qr(mat); */ exports.prototype.qr &#x3D; function (mat, tol) { return { Q: Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype), R: Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype) } } /** * Copyright (c) 2015, Jozef Stefan Institute, Quintelligence d.o.o. and contributors * All rights reserved. * * This source code is licensed under the FreeBSD license found in the * LICENSE file in the root directory of this source tree. */ /** * Matrix constructor parameter object. * @typedef {Object} matrixArg * @property {number} rows - Number of rows. * @property {number} cols - Number of columns. * @property {boolean} [random&#x3D;false] - Generate a random matrix with entries sampled from a uniform [0,1] distribution. If set to false, a zero matrix is created. */ /** * Matrix class. * @classdesc Represents a dense matrix (2d array), wraps a C++ object implemented in glib/base/ds.h. * @class * @param {(module:la~matrixArg | Array&amp;lt;Array&amp;lt;number&gt;&gt; | module:la.Matrix)} [arg] - Constructor arguments. There are three ways of constructing: * &amp;lt;br&gt;1. Using the parameter object {@link module:la~matrixArg}, * &amp;lt;br&gt;2. using a nested array of matrix elements (row major). Example: [[1,2],[3,4]] has two rows, the first row is [1,2], * &amp;lt;br&gt;3. using a dense matrix (copy constructor). * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create new matrix with matrixArg * var mat &#x3D; new la.Matrix({&quot;rows&quot;: 3, &quot;cols&quot;: 2, &quot;random&quot;: true}); // creates a 3 x 2 matrix with random values * // create a new matrix with nested arrays * var mat2 &#x3D; new la.Matrix([[1, 7, 4], [-10, 0, 3]]); // creates a 2 x 3 matrix with the designated values */ exports.Matrix &#x3D; function(arg) { return Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype); } /** * Returns an element of matrix. * @param {number} rowIdx - Row index (zero based). * @param {number} colIdx - Column index (zero based). * @returns {number} The matrix element. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new matrix * var mat &#x3D; new la.Matrix([[2, 3], [-2, -2], [-3, 1]]); * // get the value at the index (2, 1) * var value &#x3D; mat.at(2, 1); // returns the value 1 */ exports.Matrix.prototype.at &#x3D; function(rowIdx, colIdx) { return 0.0; } /** * Sets an element or a block of matrix. * @param {number} rowIdx - Row index (zero based). * @param {number} colIdx - Column index (zero based). * @param {(number | module:la.Matrix)} arg - A number or a matrix. If arg is of type {@link module:la.Matrix}, it gets copied, where the argument&#x27;s upper left corner, &amp;lt;code&gt;arg.at(0,0)&amp;lt;/code&gt;, gets copied to position (&amp;lt;code&gt;rowIdx&amp;lt;/code&gt;, &amp;lt;code&gt;colIdx&amp;lt;/code&gt;). * @returns {module:la.Matrix} Self. The (&amp;lt;code&gt;rowIdx&amp;lt;/code&gt;, &amp;lt;code&gt;colIdx&amp;lt;/code&gt;) value/block is changed. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new matrix * var mat &#x3D; new la.Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]); * var arg &#x3D; new la.Matrix([[10, 11], [12, 13]]); * mat.put(0, 1, arg); * // updates the matrix to * // 1 10 11 * // 4 12 13 * // 7 8 9 */ exports.Matrix.prototype.put &#x3D; function(rowIdx, colIdx, arg) { return Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype); } /** * Right-hand side multiplication of matrix with parameter. * @param {(number | module:la.Vector | module:la.SparseVector | module:la.Matrix | module:la.SparseMatrix)} arg - Multiplication input. Supports scalar, vector and matrix input. * @returns {(module:la.Matrix | module:la.Vector)} * &amp;lt;br&gt;1. {@link module:la.Matrix}, if &amp;lt;code&gt;arg&amp;lt;/code&gt; is a number, {@link module:la.Matrix} or {@link module:la.SparseMatrix}. * &amp;lt;br&gt;2. {@link module:la.Vector}, if &amp;lt;code&gt;arg&amp;lt;/code&gt; is a {@link module:la.Vector} or {@link module:la.SparseVector}. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new matrix * var mat &#x3D; new la.Matrix([[1, 2], [-1, 5]]); * // create a new vector * var vec &#x3D; new la.Vector([1, -1]); * //multiply mat and vec * var vec2 &#x3D; mat.multiply(vec); // returns vector [-1, -6] */ exports.Matrix.prototype.multiply &#x3D; function(arg) { return (arg instanceof require(&#x27;qminer&#x27;).la.Vector | arg instanceof require(&#x27;qminer&#x27;).la.SparseVector) ? Object.create(require(&#x27;qminer&#x27;).la.Vector.prototype) : Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype); } /** * Matrix transpose and right-hand side multiplication of matrix with parameter. * @param {(number | module:la.Vector | module:la.SparseVector | module:la.Matrix | module:la.SparseMatrix)} arg - Multiplication input. Supports scalar, vector and matrix input. * @returns {(module:la.Matrix | module:la.Vector)} * &amp;lt;br&gt;1. {@link module:la.Matrix}, if &amp;lt;code&gt;arg&amp;lt;/code&gt; is a number, {@link module:la.Matrix} or a {@link module:la.SparseMatrix}. * &amp;lt;br&gt;2. {@link module:la.Vector}, if &amp;lt;code&gt;arg&amp;lt;/code&gt; is a {@link module:la.Vector} or a {@link module:la.SparseVector}. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new matrix * var mat &#x3D; new la.Matrix([[1, 2], [-1, 5]]); * // create a new vector * var vec &#x3D; new la.Vector([1, -1]); * //multiply mat and vec * var vec2 &#x3D; mat.multiplyT(vec); // returns vector [2, -3] */ exports.Matrix.prototype.multiplyT &#x3D; function(arg) { return (arg instanceof require(&#x27;qminer&#x27;).la.Vector | arg instanceof require(&#x27;qminer&#x27;).la.SparseVector) ? Object.create(require(&#x27;qminer&#x27;).la.Vector.prototype) : Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype); } /** * Adds two matrices. * @param {module:la.Matrix} mat - The second matrix. * @returns {module:la.Matrix} The sum of the matrices. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create two matrices * var mat &#x3D; new la.Matrix([[1, 2], [-1, 5]]); * var mat2 &#x3D; new la.Matrix([[1, -1], [3, 2]]); * // add the matrices * // the return matrix is * // 2 1 * // 2 7 * var sum &#x3D; mat.plus(mat2); */ exports.Matrix.prototype.plus &#x3D; function(mat2) { return Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype); } /** * Substracts two matrices. * @param {module:la.Matrix} mat - The second matrix. * @returns {module:la.Matrix} The difference of the matrices. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create two matrices * var mat &#x3D; new la.Matrix([[1, 2], [-1, 5]]); * var mat2 &#x3D; new la.Matrix([[1, -1], [3, 2]]); * // substract the matrices * // the return matrix is * // 0 3 * // -4 3 * var diff &#x3D; mat.minus(mat2); */ exports.Matrix.prototype.minus &#x3D; function(mat2) { return Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype); } /** * Transposes the matrix. * @returns {module:la.Matrix} Transposed matrix. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a matrix * var mat &#x3D; new la.Matrix([[2, -5], [3, 1]]); * // transpose the matrix * // the return matrix is * // 2 3 * // -5 1 * var trans &#x3D; mat.transpose(); */ exports.Matrix.prototype.transpose &#x3D; function() { return Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype); } /** * Solves the linear system. * @param {module:la.Vector} vec - The right-hand side of the equation. * @returns {module:la.Vector} The solution of the linear system. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new matrix * var M &#x3D; new la.Matrix([[1, 2], [-1, -5]]); * // create a new vector * var b &#x3D; new la.Vector([-1, -6]); * // solve the linear system M*x &#x3D; b * var x &#x3D; M.solve(b); // returns vector [1, -1] */ exports.Matrix.prototype.solve &#x3D; function (vec) { return Object.create(require(&#x27;qminer&#x27;).la.Vector.prototype); } /** * Calculates the matrix row norms. * @returns {module:la.Vector} Vector, where the value at i-th index is the norm of the i-th row of matrix. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new matrix * var mat &#x3D; new la.Matrix([[3, 4], [4, 15/2]]); * // get the row norms of the matrix * var rowNorms &#x3D; mat.rowNorms(); // returns the vector [5, 17/2] */ exports.Matrix.prototype.rowNorms &#x3D; function () { return Object.create(require(&#x27;qminer&#x27;).la.Vector.prototype); } /** * Calculates the matrix column norms. * @returns {module:la.Vector} Vector, where the value at i-th index is the norm of the i-th column of matrix. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new matrix * var mat &#x3D; new la.Matrix([[3, 4], [4, 15/2]]); * // get the row norms of the matrix * var rowNorms &#x3D; mat.colNorms(); // returns the vector [5, 17/2] */ exports.Matrix.prototype.colNorms &#x3D; function () { return Object.create(require(&#x27;qminer&#x27;).la.Vector.prototype); } /** * Normalizes each column of matrix. * @returns {module:la.Matrix} Self. The columns of matrix are normalized. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new matrix * var mat &#x3D; new la.Matrix([[3, 4], [4, 15/2]]); * // normalize the columns of the matrix * // the matrix is going to be of the form: * // 3/5 8/17 * // 4/5 15/17 * mat.normalizeCols(); */ exports.Matrix.prototype.normalizeCols &#x3D; function () { return Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype); } /** * Returns the matrix as string. * @returns {string} Dense matrix as string. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new matrix * var mat &#x3D; new la.Matrix([[1, 2], [3, 5]]); * // get matrix as string * var text &#x3D; mat.toString(); // returns &#x60;1 2 \n3 5 \n\n&#x60; */ exports.Matrix.prototype.toString &#x3D; function () { return &quot;&quot;; } /** * Transforms the matrix from dense to sparse format. * @returns {module:la.SparseMatrix} Sparse column matrix representation of dense matrix. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create the matrix * var mat &#x3D; new la.Matrix([[1, 2], [0, 3], [-4, 0]]); * // transform the matrix into the sparse form * var spMat &#x3D; mat.sparse(); */ exports.Matrix.prototype.sparse &#x3D; function () { return Object.create(require(&#x27;qminer&#x27;).la.SparseMatrix.prototype); } /** * Returns the frobenious norm of matrix. * @returns {number} Frobenious norm of matrix. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create the matrix * var mat &#x3D; new la.Matrix([[1, 2], [3, 4]]); * // get the frobenious norm of the matrix * var frob &#x3D; mat.frob(); // returns the value Math.sqrt(30) */ exports.Matrix.prototype.frob &#x3D; function () { return 0.0; } /** * Gives the number of rows of matrix. Type &#x60;number&#x60;. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create the matrix * var mat &#x3D; new la.Matrix([[1, 2], [3, 1], [-4, 5]]); * // get the number of rows * var rowN &#x3D; mat.rows; // returns 3 */ exports.Matrix.prototype.rows &#x3D; 0; /** * Gives the number of columns of matrix. Type &#x60;number&#x60;. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create the matrix * var mat &#x3D; new la.Matrix([[1, 2], [3, 1], [-4, 5]]); * // get the number of cols * var colsN &#x3D; mat.cols; // returns 2 */ exports.Matrix.prototype.cols &#x3D; 0; /** * Gives the index of the maximum element in the given row. * @param {number} rowIdx - Row index (zero based). * @returns {number} Column index (zero based) of the maximum value in the &amp;lt;code&gt;rowIdx&amp;lt;/code&gt;-th row of matrix. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create the matrix * var mat &#x3D; new la.Matrix([[1, 2], [3, 1], [-4, 5]]); * // get the column id of the maximum value of the second row * var maxRow &#x3D; mat.rowMaxIdx(1); // returns the value 0 */ exports.Matrix.prototype.rowMaxIdx &#x3D; function (rowIdx) { return 0; } /** * Gives the index of the maximum element in the given column. * @param {number} colIdx - Column index (zero based). * @returns {number} Row index (zero based) of the maximum value in &amp;lt;code&gt;colIdx&amp;lt;/code&gt;-th column of matrix. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create the matrix * var mat &#x3D; new la.Matrix([[1, 2], [3, 1], [-4, 5]]); * // get the row id of the maximum value of the second column * var maxRow &#x3D; mat.colMaxIdx(1); // returns the value 2 */ exports.Matrix.prototype.colMaxIdx &#x3D; function (colIdx) { return 0; } /** * Returns the corresponding column of matrix as vector. * @param {number} colIdx - Column index (zero based). * @returns {module:la.Vector} The &amp;lt;code&gt;colIdx&amp;lt;/code&gt;-th column of matrix. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create the matrix * var mat &#x3D; new la.Matrix([[1, 2], [3, 1], [-4, 5]]); * // get the second column of the matrix * var col &#x3D; mat.getCol(1); */ exports.Matrix.prototype.getCol &#x3D; function (colIdx) { return Object.create(require(&#x27;qminer&#x27;).la.Vector.prototype); } /** * Sets the column of the matrix. * @param {number} colIdx - Column index (zero based). * @param {module:la.Vector} vec - The new column of matrix. * @returns {module:la.Matrix} Self. The &amp;lt;code&gt;colIdx&amp;lt;/code&gt;-th column is changed. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a matrix * var mat &#x3D; new la.Matrix([[1, -3, 2], [9, 2, -4], [-2, 3, 3]]); * // create a vector * var vec &#x3D; new la.Vector([-3, 2, 2]); * // set the first column of the matrix with the vector * // the changed matrix is now * // -3 -3 2 * // 2 2 -4 * // 2 3 3 * mat.setCol(0, vec); */ exports.Matrix.prototype.setCol &#x3D; function (colIdx, vec) { return Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype); } /** * Gets the submatrix from the column ids. * @param {module:la.IntVector} intVec - The vector containing the column ids. * @returns {module:la.Matrix} The submatrix containing the the columns of the original matrix. * @example * //import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a random matrix * var mat &#x3D; new la.Matrix({ rows: 10, cols: 10, random: true }); * // get the submatrix containing the 1, 2 and 4 column * var submat &#x3D; mat.getColSubmatrix(new la.IntVector([0, 1, 3])); */ exports.Matrix.prototype.getColSubmatrix &#x3D; function (intVec) { return Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype); } /** * Gets the submatrix from the column ids. * @param {number} minRow - The minimum row index. * @param {number} maxRow - The maximum row index. * @param {number} minCol - The minimum column index. * @param {number} maxCol - The maximum column index. * @returns {module:la.Matrix} The submatrix of the original matrix. * @example * //import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a random matrix * var mat &#x3D; new la.Matrix({ rows: 10, cols: 10, random: true }); * // get the submatrix containing from the position (1, 2) to (7, 4) * var submat &#x3D; mat.getSubmatrix(1, 7, 2, 4); */ exports.Matrix.prototype.getSubmatrix &#x3D; function (minRow, maxRow, minCol, maxCol) { return Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype); } /** * Returns the corresponding row of matrix as vector. * @param {number} rowIdx - Row index (zero based). * @returns {module:la.Vector} The &amp;lt;code&gt;rowIdx&amp;lt;/code&gt;-th row of matrix. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create the matrix * var mat &#x3D; new la.Matrix([[1, 2], [3, 1], [-4, 5]]); * // get the first row of the matrix * var row &#x3D; mat.getRow(1); */ exports.Matrix.prototype.getRow &#x3D; function (rowIdx) { return Object.create(require(&#x27;qminer&#x27;).la.Vector.prototype); } /** * Sets the row of matrix. * @param {number} rowIdx - Row index (zero based). * @param {module:la.Vector} vec - The new row of matrix. * @returns {module:la.Matrix} Self. The &amp;lt;code&gt;rowIdx&amp;lt;/code&gt;-th row is changed. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a matrix * var mat &#x3D; new la.Matrix([[1, -3, 2], [9, 2, -4], [-2, 3, 3]]); * // create a vector * var vec &#x3D; new la.Vector([-3, 2, 2]); * // set the first row of the matrix with the vector * // the changed matrix is now * // -3 2 2 * // 9 2 -4 * // -2 3 3 * mat.setRow(0, vec); */ exports.Matrix.prototype.setRow &#x3D; function (rowIdx, vec) { return Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype); } /** * Returns the diagonal elements of matrix. * @returns {module:la.Vector} Vector containing the diagonal elements. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new matrix * var mat &#x3D; new la.Matrix([[1, -1, 0], [15, 8, 3], [0, 1, 0]]); * // call diag function * var vec &#x3D; mat.diag(); // returns a vector [1, 8, 0] */ exports.Matrix.prototype.diag &#x3D; function () { return Object.create(require(&#x27;qminer&#x27;).la.Vector.prototype); } /** * Saves the matrix as output stream. * @param {module:fs.FOut} fout - Output stream. * @returns {module:fs.FOut} The output stream &amp;lt;code&gt;fout&amp;lt;/code&gt;. * @example * // import the modules * var fs &#x3D; require(&#x27;qminer&#x27;).fs; * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create new matrix * var mat &#x3D; new la.Matrix([[1, 2], [3, 4]]); * // open write stream * var fout &#x3D; fs.openWrite(&#x27;mat.dat&#x27;); * // save matrix and close write stream * mat.save(fout).close(); */ exports.Matrix.prototype.save &#x3D; function (fout) { return Object.create(require(&#x27;qminer&#x27;).fs.FOut.prototype); } /** * Loads the matrix from input stream. * @param {module:fs.FIn} fin - Input stream. * @returns {module:la.Matrix} Self. It is made out of the input stream &amp;lt;code&gt;fin&amp;lt;/code&gt;. * @example * // import the modules * var fs &#x3D; require(&#x27;qminer&#x27;).fs; * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create an empty matrix * var mat &#x3D; new la.Matrix(); * // open a read stream (&#x27;mat.dat&#x27; is pre-saved) * var fin &#x3D; fs.openRead(&#x27;mat.dat&#x27;); * // load the matrix * mat.load(fin); */ exports.Matrix.prototype.load &#x3D; function (FIn) { return Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype); } /** * Sparse Vector. * @classdesc Sparse vector is an array of (int,double) pairs that represent column indices and values. * @class * @param {(Array&amp;lt;Array&amp;lt;number&gt;&gt; | module:la.SparseVector)} [arg] - Constructor arguments. There are two ways of constructing: * &amp;lt;br&gt;1. Using a nested array of vector elements. Example: &#x60;[[0, 2],[2, 3]]&#x60; has two nonzero values, first value is 2 at position 0, second value is 3 at position 2, * &amp;lt;br&gt;2. using a sparse vector (copy constructor). * @param {number} [dim] - Maximum length of sparse vector. &amp;lt;i&gt;It is only in combinantion with nested array of vector elements.&amp;lt;/i&gt; * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create new sparse vector with arrays * var spVec &#x3D; new la.SparseVector([[0, 1], [2, 3], [3, 6]]); // sparse vector [1, 0, 3, 6] * // create new sparse vector with dim * var spVec2 &#x3D; new la.SparseVector([[0, 1], [2, 3], [3, 6]], 5); // largest index (zero based) is 4 */ exports.SparseVector &#x3D; function(arg, dim) { return Object.create(require(&#x27;qminer&#x27;).la.SparseVector.prototype); } /** * Returns an element of the sparse vector. * @param {number} idx - Index (zero based). * @returns {number} Sparse vector element. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a sparse vector * var vec &#x3D; new la.SparseVector([[0, 1], [3, 2], [4, -5]]); * // get the value at the position 3 * vec.at(3); // returns the value 2 */ exports.SparseVector.prototype.at &#x3D; function (idx) { return 0.0; } /** * Puts a new element in sparse vector. * @param {number} idx - Index (zero based). * @param {number} num - Input value. * @returns {module:la.SparseVector} Self. It puts/changes the values with the index &#x60;idx&#x60; to the value &#x60;num&#x60;. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse vector * var vec &#x3D; new la.SparseVector([[0, 1], [3, 2], [4, -5]]); * // set the new values at position 2 * vec.put(2, -4); */ exports.SparseVector.prototype.put &#x3D; function (idx, num) { return Object.create(require(&#x27;qminer&#x27;).la.SparseVector.prototype); } /** * Returns the sum of all values in sparse vector. * @returns {number} The sum of all values in sparse vector. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse vector * var vec &#x3D; new la.SparseVector([[0, 1], [3, 2], [4, -5]]); * // get the sum of the values in the vector * vec.sum(); // returns -2 */ exports.SparseVector.prototype.sum &#x3D; function () { return 0.0; } /** * Returns the inner product of the parameter and the sparse vector. * @param {(module:la.Vector | module:la.SparseVector)} arg - The inner product input. * @returns {number} The inner product of the two vectors. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create two vectors, one sparse and one dense * var sparse &#x3D; new la.SparseVector([[0, 1], [3, 2], [4, -5]]); * var dense &#x3D; new la.Vector([3, -4, 2, 0.5, -1]); * // get the inner product of the vectors * sparse.inner(dense); // returns the value 9 */ exports.SparseVector.prototype.inner &#x3D; function (arg) { return 0.0; } /** * Multiplies the sparse vector with a scalar. * @param {number} num - The scalar. * @returns {module:la.SparseVector} The product of &#x60;num&#x60; and sparse vector. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse vector * var spVec &#x3D; new la.SparseVector([[0, 1], [2, 3], [3, 6]]); * // multiply sparse vector with scalar 3.14 * var spVec2 &#x3D; spVec.multiply(3.14); // returns sparse vector [3.14, 0, 9.42, 18.84] */ exports.SparseVector.prototype.multiply &#x3D; function (num) { return Object.create(require(&#x27;qminer&#x27;).la.SparseVector.prototype); } /** * Normalizes the sparse vector. * @returns {module:la.SparseVector} Self. The vector is normalized. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse vector * var spVec &#x3D; new la.SparseVector([[0, 1], [2, 3], [3, 6]]); * // normalize the sparse vector * spVec.normalize(); */ exports.SparseVector.prototype.normalize &#x3D; function () { return Object.create(require(&#x27;qminer&#x27;).la.SparseVector.prototype); } /** * Returns the number of non-zero values. Type &#x60;number&#x60;. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse vector * var vec &#x3D; new la.SparseVector([[0, 2], [3, 1], [7, 5], [11, 4]]); * // check the number of nonzero values in sparse vector * // returns 4 * var nonz &#x3D; vec.nnz; */ exports.SparseVector.prototype.nnz &#x3D; 0; /** * Returns the dimension of sparse vector. Type &#x60;number&#x60;. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse vector and designate the dimension of the vector * var vec &#x3D; new la.SparseVector([[0, 2], [3, 1], [7, 5], [11, 4]], 15); * // get the dimension of the sparse vector * // returns 15 * var dim &#x3D; vec.dim; */ exports.SparseVector.prototype.dim &#x3D; 0; /** * Returns the norm of sparse vector. * @returns {number} Norm of sparse vector. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse vector * var vec &#x3D; new la.SparseVector([[0, 2], [3, 1], [7, 5], [11, 4]]); * // get the norm of the vector * var norm &#x3D; vec.norm(); */ exports.SparseVector.prototype.norm &#x3D; function () { return 0.0; } /** * Returns the dense vector representation of the sparse vector. * @returns {module:la.Vector} The dense vector representation. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse vector * var vec &#x3D; new la.SparseVector([[0, 2], [3, 1], [7, 5], [11, 4]]); * // create a dense representation of the vector * var dense &#x3D; vec.full(); */ exports.SparseVector.prototype.full &#x3D; function () { return Object.create(require(&#x27;qminer&#x27;).la.Vector.prototype); } /** * Returns a dense vector of values of non-zero elements of sparse vector. * @returns {module:la.Vector} A dense vector of values. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse vector * var vec &#x3D; new la.SparseVector([[0, 2], [3, 1], [7, 5], [11, 4]]); * // get the non-zero values of the sparse vector * var valVec &#x3D; vec.valVec(); */ exports.SparseVector.prototype.valVec &#x3D; function () { return Object.create(require(&#x27;qminer&#x27;).la.Vector.prototype); } /** * Returns a dense vector of indices (zero based) of non-zero elements of sparse vector. * @returns {module:la.Vector} A dense vector of indeces. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sprase vector * var vec &#x3D; new la.SparseVector([[0, 2], [3, 1], [7, 5], [11, 4]]); * // get the non-zero indeces of the sparse vector * var idxVec &#x3D; vec.idxVec(); */ exports.SparseVector.prototype.idxVec &#x3D; function () { return Object.create(require(&#x27;qminer&#x27;).la.Vector.prototype); } /** * Returns the string representation. * @returns {string} The string representation of the sparse vector. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse vector * var spVec &#x3D; new la.SparseVector([[0, 1], [2, 3]]); * // get the string representation of the vector * spVec.toString(); // returns the string &#x27;[(0, 1), (2, 3)]&#x27; */ exports.SparseVector.prototype.toString &#x3D; function () { return &quot;&quot;; } /** * Sparse Matrix * @classdesc Sparse Matrix is represented as a dense vector of sparse vectors which correspond to matrix columns. * @class * @param {(Array&amp;lt;Array&amp;lt;Array&amp;lt;number&gt;&gt;&gt; | module:la.SparseMatrix)} [arg] - Constructor arguments. There are two ways of constructing: * &amp;lt;br&gt;1. using a nested array of sparse vectors (columns). A sparse vector is a nested array of pairs, first value is index, second is value. Example: [[[0, 2]], [[0, 1], [2, 3]]] has 2 columns. * The second non-zero element in second column has a value 3 at index 2, * &amp;lt;br&gt;2. using a sparse matrix (copy constructor). * @param {number} [rows] - Maximal number of rows in sparse vector. &amp;lt;i&gt;It is only in combinantion with nested array of vector elements.&amp;lt;/i&gt; * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse matrix with array * var mat &#x3D; new la.SparseMatrix([[[0, 2]], [[0, 1], [2, 3]]]); * // create a new sparse matrix with specified max rows * var mat2 &#x3D; new la.SparseMatrix([[[0, 2]], [[0, 1], [2, 3]]], 3); */ exports.SparseMatrix &#x3D; function(arg) { return Object.create(require(&#x27;qminer&#x27;).la.SparseMatrix.prototype); } /** * Returns an element of the sparse matrix at the given location. * @param {number} rowIdx - Row index (zero based). * @param {number} colIdx - Column index (zero based). * @returns {number} Matrix value. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a sparse matrix * var mat &#x3D; new la.SparseMatrix([[[0, 2]], [[0, 1], [2, 3]]]); * // get the value at the position (1, 1) * mat.at(1, 1); // returns 3 */ exports.SparseMatrix.prototype.at &#x3D; function (rowIdx, colIdx) { return 0.0; } /** * Puts an element in sparse matrix. * @param {number} rowIdx - Row index (zero based). * @param {number} colIdx - Column index (zero based). * @param {number} num - Element value. * @returns {module:la.SparseMatrix} Self. The value at position (&#x60;rowIdx&#x60;, &#x60;colIdx&#x60;) is changed. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse matrix * var mat &#x3D; new la.SparseMatrix([[[0, 3], [1, 2]], [[1, -2], [3, 4]], [[10, 8]]]); * // set the value at position (2, 2) to -4 * mat.put(2, 2, -4); */ exports.SparseMatrix.prototype.put &#x3D; function (rowIdx, colIdx, num) { return Object.create(require(&#x27;qminer&#x27;).la.SparseMatrix.prototype); } /** * Returns the column of the sparse matrix. * @param {number} colIdx - The column index (zero based). * @returns {module:la.SparseVector} Sparse vector corresponding to the &#x60;colIdx&#x60;-th column of sparse matrix. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a sparse matrix * var mat &#x3D; new la.SparseMatrix([[[0, 3], [1, 2]], [[1, -2], [3, 4]], [[10, 8]]]); * // get the first column as a vector * var first &#x3D; mat.getCol(0); // returns the first column of the sparse matrix */ exports.SparseMatrix.prototype.getCol &#x3D; function (colIdx) { return Object.create(require(&#x27;qminer&#x27;).la.SparseVector.prototype); } /** * Sets a column in sparse matrix. * @param {number} colIdx - Column index (zero based). * @param {module:la.SparseVector} spVec - The new column sparse vector. * @returns {module:la.SparseMatrix} Self. The &#x60;colIdx&#x60;-th column has been replaced with &#x60;spVec&#x60;. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse matrix * var mat &#x3D; new la.SparseMatrix([[[0, 3], [1, 2]], [[1, -2], [3, 4]], [[10, 8]]]); * // create a new sparse vector to replace the third column * var vec &#x3D; new la.SparseVector([[0, 3], [2, -5]]); * // set the third column of mat to vec * mat.setCol(2, vec); // returns mat with the third column changed */ exports.SparseMatrix.prototype.setCol &#x3D; function (colIdx, spVec) { return Object.create(require(&#x27;qminer&#x27;).la.SparseVector.prototype); } /** * Attaches a column to the sparse matrix. * @param {module:la.SparseVector} spVec - Attached column as sparse vector. * @returns {module:la.SparseMatrix} Self. The last column is now the added &#x60;spVec&#x60; and the number of columns is now bigger by one. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse vector * var mat &#x3D; new la.SparseMatrix([[[0, 2], [3, 5]], [[1, -3]]]); * // create a new vector * var vec &#x3D; new la.SparseVector([[0, 2], [2, -3]]); * // push the newly created vector to the matrix * // the new matrix is going to be (in sparse form) * // 2 0 2 * // 0 -3 0 * // 0 0 -3 * // 5 0 0 * mat.push(vec); */ exports.SparseMatrix.prototype.push &#x3D; function (spVec) { return Object.create(require(&#x27;qminer&#x27;).la.SparseMatrix.prototype); } /** * Multiplies argument with sparse maatrix. * @param {(number | module:la.Vector | module:la.SparseVector | module:la.Matrix | module:la.SparseMatrix)} arg - Multiplication input. * @returns {(module:la.Vector | module:la.Matrix)} * &amp;lt;br&gt;1. {@link module:la.Matrix}, if &#x60;arg&#x60; is number, {@link module:la.Matrix} or {@link module:la.SparseMatrix}. * &amp;lt;br&gt;2. {@link module:la.Vector}, if &#x60;arg&#x60; is {@link module:la.Vector} or {@link module:la.SparseVector}. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create new sparse matrix * var mat &#x3D; new la.SparseMatrix([[[0, 2], [3, 5]], [[1, -3]]]); * // create a vector * var vec &#x3D; new la.Vector([3, -2]); * // multiply the matrix and vector * var vec2 &#x3D; mat.multiply(vec); */ exports.SparseMatrix.prototype.multiply &#x3D; function (arg) { return (arg instanceof require(&#x27;qminer&#x27;).la.Vector | arg instanceof require(&#x27;qminer&#x27;).la.SparseVector) ? Object.create(require(&#x27;qminer&#x27;).la.Vector.prototype) : Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype); } /** * Sparse matrix transpose and multiplies with argument. * @param {(number | module:la.Vector | module:la.SparseVector | module:la.Matrix | module:la.SparseMatrix)} arg - Multiplication input. * @returns {(module:la.Vector | module:la.Matrix)} * &amp;lt;br&gt;1. {@link module:la.Matrix}, if &#x60;arg&#x60; is number, {@link module:la.Matrix} or {@link module:la.SparseMatrix}. * &amp;lt;br&gt;2. {@link module:la.Vector}, if &#x60;arg&#x60; is {@link module:la.Vector} or {@link module:la.SparseVector}. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create new sparse matrix * var mat &#x3D; new la.SparseMatrix([[[0, 2], [3, 5]], [[1, -3]]]); * // create a dense matrix * var mat2 &#x3D; new la.Matrix([[0, 1], [2, 3], [4, 5], [-1, 3]]); * // transpose mat and multiply it with mat2 * var mat3 &#x3D; mat.multiplyT(mat2); */ exports.SparseMatrix.prototype.multiplyT &#x3D; function (arg) { return (arg instanceof require(&#x27;qminer&#x27;).la.Vector | arg instanceof require(&#x27;qminer&#x27;).la.SparseVector) ? Object.create(require(&#x27;qminer&#x27;).la.Vector.prototype) : Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype); } /** * Addition of two matrices. * @param {module:la.SparseMatrix} mat - The second sparse matrix. * @returns {module:la.SparseMatrix} Sum of the two sparse matrices. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create two sparse matrices * var mat &#x3D; new la.SparseMatrix([[[0, 1], [3, 2]], [[1, -3]]]); * var mat2 &#x3D; new la.SparseMatrix([[[0, 3]],[[2, 1]]]); * // get the sum of the two matrices * // returns the sum ( insparse form) * // 4 0 * // 0 -3 * // 0 1 * // 2 0 * var sum &#x3D; mat.plus(mat2); */ exports.SparseMatrix.prototype.plus &#x3D; function (spMat) { return Object.create(require(&#x27;qminer&#x27;).la.SparseMatrix.prototype); } /** * Substraction of two matrices. * @param {module:la.SparseMatrix} mat - The second sparse matrix. * @returns {module:la.SparseMatrix} The difference of the two sparse matrices. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create two sparse matrices * var mat &#x3D; new la.SparseMatrix([[[0, 1], [3, 2]], [[1, -3]]]); * var mat2 &#x3D; new la.SparseMatrix([[[0, 3]],[[2, 1]]]); * // get the sum of the two matrices * // returns the sum ( insparse form) * // -2 0 * // 0 -3 * // 0 -1 * // 2 0 * var diff &#x3D; mat.minus(mat2); */ exports.SparseMatrix.prototype.minus &#x3D; function (spMat) { return Object.create(require(&#x27;qminer&#x27;).la.SparseMatrix.prototype); } /** * Returns the transposed sparse matrix. * @returns {module:la.SparseMatrix} Transposed sparse matrix. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse matrix * var mat &#x3D; new la.SparseMatrix([[[0, 2], [2, -3]], [[1, 1], [3, -2]]]); * // transpose the sparse matrix * // returns the transposed matrix (in sparse form) * // 2 0 -3 0 * // 0 1 0 -2 * mat.transpose(); */ exports.SparseMatrix.prototype.transpose &#x3D; function () { return Object.create(require(&#x27;qminer&#x27;).la.SparseMatrix.prototype); } /** * Returns a submatrix containing only selected columns. * Columns are identified by a vector of ids. * @param {module:la.IntVector} columnIdVec - Integer vector containing selected column ids. * @returns {module:la.SparseMatrix} The submatrix containing the the columns of the original matrix. * @example * //import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse matrix * var mat &#x3D; new la.SparseMatrix([[[0, 2], [2, -3]], [[1, 1], [3, -2]]]); * // get the submatrix containing the 1, 2 and 4 column * var submat &#x3D; mat.getColSubmatrix(new la.IntVector([1])); */ exports.SparseMatrix.prototype.getColSubmatrix &#x3D; function (columnIdVec) { return Object.create(require(&#x27;qminer&#x27;).la.SparseMatrix.prototype); } /** * Clear content of the matrix and sets its row dimension to -1. * @returns {module:la.SparseMatrix} Self. All the content has been cleared. * @example * //import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse matrix * var mat &#x3D; new la.SparseMatrix([[[0, 2], [2, -3]], [[1, 1], [3, -2]]]); * // clear the matrix * mat.clear(); */ exports.SparseMatrix.prototype.clear &#x3D; function () { return Object.create(require(&#x27;qminer&#x27;).la.SparseMatrix.prototype); } /** * Returns the vector of column norms of sparse matrix. * @returns {module:la.Vector} Vector of column norms. Ihe i-th value of the return vector is the norm of i-th column of sparse matrix. * @example * //import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse matrix * var mat &#x3D; new la.SparseMatrix([[[0, 2], [2, -3]], [[1, 1], [3, -2]]]); * // get the column norms * var norms &#x3D; mat.colNorms(); */ exports.SparseMatrix.prototype.colNorms &#x3D; function () { return Object.create(require(&#x27;qminer&#x27;).la.Vector.prototype); } /** * Normalizes columns of sparse matrix. * @returns {module:la.SparseMatrix} Self. The columns of the sparse matrix are normalized. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse matrix * var mat &#x3D; new la.SparseMatrix([[[0, 2]], [[0, 1], [2, 3]]]); * // normalize matrix columns * // The new matrix elements are: * // 1 0.316227 * // 0 0 * // 0 0.948683 * mat.normalizeCols(); */ exports.SparseMatrix.prototype.normalizeCols &#x3D; function () { return Object.create(require(&#x27;qminer&#x27;).la.SparseMatrix.prototype); } /** * Returns the dense representation of sparse matrix. * @returns {module:la.Matrix} Dense representation of sparse matrix. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse matrix * var mat &#x3D; new la.SparseMatrix([[[0, 2]], [[0, 1], [2, 3]]]); * // create a dense representation of sparse matrix * // returns the dense matrix: * // 2 1 * // 0 0 * // 0 3 * mat.full(); */ exports.SparseMatrix.prototype.full &#x3D; function () { return Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype); } /** * Returns the frobenious norm of sparse matrix. * @returns {number} Frobenious norm of sparse matrix. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse matrix * var mat &#x3D; new la.SparseMatrix([[[0, 1], [1, 3]], [[0, 2], [1, 4]]]); * // get the frobenious norm of sparse matrix * var norm &#x3D; mat.frob(); // returns sqrt(30) */ exports.SparseMatrix.prototype.frob &#x3D; function () { return 0.0; } /** * Gives the number of rows of sparse matrix. Type &#x60;number&#x60;. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse matrix * var mat &#x3D; new la.SparseMatrix([[[0, 2]], [[0, 1], [2, 3]]]); * // check the number of rows in sparse matrix * mat.rows; */ exports.SparseMatrix.prototype.rows &#x3D; 0; /** * Gives the number of columns of sparse matrix. Type &#x60;number&#x60;. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse matrix * var mat &#x3D; new la.SparseMatrix([[[0, 2]], [[0, 1], [2, 3]]]); * // check the number of columns in sparse matrix * mat.cols; */ exports.SparseMatrix.prototype.cols &#x3D; 0; /** * Prints sparse matrix on screen. * @example * // import la module * var la &#x3D; require(&#x27;qminer&#x27;).la; * // create a new sparse matrix * var spMat &#x3D; new la.SparseMatrix([[[0, 1]], [[0, 3], [1, 8]]]); * // print sparse matrix on screen * // each row represents a nonzero element, where first value is row index, second * // value is column index and third value is element value. For this matrix: * // 0 0 1.000000 * // 0 1 3.000000 * // 1 1 8.000000 * spMat.print(); */ exports.SparseMatrix.prototype.print &#x3D; function () {} /** * Saves the sparse matrix as output stream. * @param {module:fs.FOut} fout - Output stream. * @param {boolean} [saveMatlab&#x3D;false] - If true, saves using matlab three column text format. Otherwise, saves using binary format. * @returns {module:fs.FOut} The output stream &#x60;fout&#x60;. * @example * //