qminer
Version:
A C++ based data analytics platform for processing large-scale real-time streams containing structured and unstructured data
1,203 lines (1,201 loc) • 62.1 kB
HTML
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3">
<meta charset="utf-8">
<title>Class: Matrix</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">QMiner JavaScript API v9.4.0</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-main" role="main">
<header class="page-header">
<div class="symbol-detail-labels"><span class="label label-kind">class</span> <span class="label label-static">static</span></div>
<h1><small><a href="module-la.html">la</a>.<wbr></small><span class="symbol-name">Matrix</span></h1>
<p class="source-link">Source: <a href="ladoc.js.html#source-line-115">ladoc.<wbr>js:115</a></p>
<div class="symbol-classdesc">
<p>Represents a dense matrix (2d array), wraps a C++ object implemented in glib/base/ds.h.</p>
</div>
<dl class="dl-compact">
</dl>
</header>
<section id="summary">
<div class="summary-callout">
<h2 class="summary-callout-heading">Properties</h2>
<div class="summary-content">
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-la.Matrix.html#cols">cols</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-la.Matrix.html#rows">rows</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
</div>
</div>
</div>
<div class="summary-callout">
<h2 class="summary-callout-heading">Methods</h2>
<div class="summary-content">
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-la.Matrix.html#at">at(rowIdx, colIdx)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#colMaxIdx">colMaxIdx(colIdx)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#colNorms">colNorms()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#diag">diag()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#frob">frob()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#getCol">getCol(colIdx)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#getColSubmatrix">getColSubmatrix(intVec)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#getRow">getRow(rowIdx)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#getSubmatrix">getSubmatrix(minRow, maxRow, minCol, maxCol)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#load">load(fin)</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-la.Matrix.html#minus">minus(mat)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#multiply">multiply(arg)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#multiplyT">multiplyT(arg)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#normalizeCols">normalizeCols()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#plus">plus(mat)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#print">print()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#put">put(rowIdx, colIdx, arg)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#rowMaxIdx">rowMaxIdx(rowIdx)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#rowNorms">rowNorms()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#save">save(fout)</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-la.Matrix.html#setCol">setCol(colIdx, vec)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#setRow">setRow(rowIdx, vec)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#solve">solve(vec)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#sparse">sparse()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#toArray">toArray()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#toMat">toMat()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#toString">toString()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Matrix.html#transpose">transpose()</a></dt>
<dd>
</dd>
</dl>
</div>
</div>
</div>
</section>
<section>
<h2 id="Matrix">new <span class="symbol-name">Matrix</span><span class="signature"><span class="signature-params">([arg])</span></span></h2>
<p>Matrix class.</p>
<section>
<h3>
Example
</h3>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create new matrix with matrixArg
var mat = new la.Matrix({"rows": 3, "cols": 2, "random": true}); // creates a 3 x 2 matrix with random values
// create a new matrix with nested arrays
var mat2 = new la.Matrix([[1, 7, 4], [-10, 0, 3]]); // creates a 2 x 3 matrix with the designated values</code></pre>
</div>
</section>
<section>
<h3>Parameter</h3>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>arg</p>
</td>
<td>
<p>(<a href="module-la.html#~matrixArg">module:la~matrixArg</a>, Array of Array of number, or <a href="module-la.Matrix.html">module:la.Matrix</a>)</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>Constructor arguments. There are three ways of constructing:
<br>1. Using the parameter object <a href="module-la.html#~matrixArg">module:la~matrixArg</a>,
<br>2. using a nested array of matrix elements (row major). Example: [[1,2],[3,4]] has two rows, the first row is [1,2],
<br>3. using a dense matrix (copy constructor).
</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
</dl>
</section>
<section>
<h2>Properties</h2>
<section>
<h3 id="cols"><span class="symbol-name">cols</span></h3>
<p>Gives the number of columns of matrix. Type <code>number</code>.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create the matrix
var mat = new la.Matrix([[1, 2], [3, 1], [-4, 5]]);
// get the number of cols
var colsN = mat.cols; // returns 2</code></pre>
</div>
</section>
<dl class="dl-compact">
</dl>
<h3 id="rows"><span class="symbol-name">rows</span></h3>
<p>Gives the number of rows of matrix. Type <code>number</code>.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create the matrix
var mat = new la.Matrix([[1, 2], [3, 1], [-4, 5]]);
// get the number of rows
var rowN = mat.rows; // returns 3</code></pre>
</div>
</section>
<dl class="dl-compact">
</dl>
</section>
<h2>Methods</h2>
<section>
<h3 id="at"><span class="symbol-name">at</span><span class="signature"><span class="signature-params">(rowIdx, colIdx)</span> → <span class="signature-returns"> number</span></span></h3>
<p>Returns an element of matrix.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create a new matrix
var mat = new la.Matrix([[2, 3], [-2, -2], [-3, 1]]);
// get the value at the index (2, 1)
var value = mat.at(2, 1); // returns the value 1</code></pre>
</div>
</section>
<section>
<h4>Parameters</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>rowIdx</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Row index (zero based).</p>
</td>
</tr>
<tr>
<td>
<p>colIdx</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Column index (zero based).</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>number</code>B The matrix element.</p>
</dd>
</dl>
<h3 id="colMaxIdx"><span class="symbol-name">colMaxIdx</span><span class="signature"><span class="signature-params">(colIdx)</span> → <span class="signature-returns"> number</span></span></h3>
<p>Gives the index of the maximum element in the given column.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create the matrix
var mat = new la.Matrix([[1, 2], [3, 1], [-4, 5]]);
// get the row id of the maximum value of the second column
var maxRow = mat.colMaxIdx(1); // returns the value 2</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>colIdx</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Column index (zero based).</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>number</code>B Row index (zero based) of the maximum value in <code>colIdx</code>-th column of matrix.</p>
</dd>
</dl>
<h3 id="colNorms"><span class="symbol-name">colNorms</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Calculates the matrix column norms.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create a new matrix
var mat = new la.Matrix([[3, 4], [4, 15/2]]);
// get the row norms of the matrix
var rowNorms = mat.colNorms(); // returns the vector [5, 17/2]</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B Vector, where the value at i-th index is the norm of the i-th column of matrix.</p>
</dd>
</dl>
<h3 id="diag"><span class="symbol-name">diag</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Returns the diagonal elements of matrix.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create a new matrix
var mat = new la.Matrix([[1, -1, 0], [15, 8, 3], [0, 1, 0]]);
// call diag function
var vec = mat.diag(); // returns a vector [1, 8, 0]</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B Vector containing the diagonal elements.</p>
</dd>
</dl>
<h3 id="frob"><span class="symbol-name">frob</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> number</span></span></h3>
<p>Returns the frobenious norm of matrix.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create the matrix
var mat = new la.Matrix([[1, 2], [3, 4]]);
// get the frobenious norm of the matrix
var frob = mat.frob(); // returns the value Math.sqrt(30)</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>number</code>B Frobenious norm of matrix.</p>
</dd>
</dl>
<h3 id="getCol"><span class="symbol-name">getCol</span><span class="signature"><span class="signature-params">(colIdx)</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Returns the corresponding column of matrix as vector.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create the matrix
var mat = new la.Matrix([[1, 2], [3, 1], [-4, 5]]);
// get the second column of the matrix
var col = mat.getCol(1);</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>colIdx</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Column index (zero based).</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B The <code>colIdx</code>-th column of matrix.</p>
</dd>
</dl>
<h3 id="getColSubmatrix"><span class="symbol-name">getColSubmatrix</span><span class="signature"><span class="signature-params">(intVec)</span> → <span class="signature-returns"> <a href="module-la.Matrix.html">module:la.Matrix</a></span></span></h3>
<p>Gets the submatrix from the column ids.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>//import la module
var la = require('qminer').la;
// create a random matrix
var mat = new la.Matrix({ rows: 10, cols: 10, random: true });
// get the submatrix containing the 1, 2 and 4 column
var submat = mat.getColSubmatrix(new la.IntVector([0, 1, 3]));</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>intVec</p>
</td>
<td>
<p><a href="module-la.IntVector.html">module:la.IntVector</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The vector containing the column ids.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Matrix.html">module:la.Matrix</a></code>B The submatrix containing the the columns of the original matrix.</p>
</dd>
</dl>
<h3 id="getRow"><span class="symbol-name">getRow</span><span class="signature"><span class="signature-params">(rowIdx)</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Returns the corresponding row of matrix as vector.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create the matrix
var mat = new la.Matrix([[1, 2], [3, 1], [-4, 5]]);
// get the first row of the matrix
var row = mat.getRow(1);</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>rowIdx</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Row index (zero based).</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B The <code>rowIdx</code>-th row of matrix.</p>
</dd>
</dl>
<h3 id="getSubmatrix"><span class="symbol-name">getSubmatrix</span><span class="signature"><span class="signature-params">(minRow, maxRow, minCol, maxCol)</span> → <span class="signature-returns"> <a href="module-la.Matrix.html">module:la.Matrix</a></span></span></h3>
<p>Gets the submatrix from the column ids.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>//import la module
var la = require('qminer').la;
// create a random matrix
var mat = new la.Matrix({ rows: 10, cols: 10, random: true });
// get the submatrix containing from the position (1, 2) to (7, 4)
var submat = mat.getSubmatrix(1, 7, 2, 4);</code></pre>
</div>
</section>
<section>
<h4>Parameters</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>minRow</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The minimum row index.</p>
</td>
</tr>
<tr>
<td>
<p>maxRow</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The maximum row index.</p>
</td>
</tr>
<tr>
<td>
<p>minCol</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The minimum column index.</p>
</td>
</tr>
<tr>
<td>
<p>maxCol</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The maximum column index.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Matrix.html">module:la.Matrix</a></code>B The submatrix of the original matrix.</p>
</dd>
</dl>
<h3 id="load"><span class="symbol-name">load</span><span class="signature"><span class="signature-params">(fin)</span> → <span class="signature-returns"> <a href="module-la.Matrix.html">module:la.Matrix</a></span></span></h3>
<p>Loads the matrix from input stream.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import the modules
var fs = require('qminer').fs;
var la = require('qminer').la;
// create an empty matrix
var mat = new la.Matrix();
// open a read stream ('mat.dat' is pre-saved)
var fin = fs.openRead('mat.dat');
// load the matrix
mat.load(fin);</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>fin</p>
</td>
<td>
<p><a href="module-fs.FIn.html">module:fs.FIn</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Input stream.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Matrix.html">module:la.Matrix</a></code>B Self. It is made out of the input stream <code>fin</code>.</p>
</dd>
</dl>
<h3 id="minus"><span class="symbol-name">minus</span><span class="signature"><span class="signature-params">(mat)</span> → <span class="signature-returns"> <a href="module-la.Matrix.html">module:la.Matrix</a></span></span></h3>
<p>Substracts two matrices.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create two matrices
var mat = new la.Matrix([[1, 2], [-1, 5]]);
var mat2 = new la.Matrix([[1, -1], [3, 2]]);
// substract the matrices
// the return matrix is
// 0 3
// -4 3
var diff = mat.minus(mat2);</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>mat</p>
</td>
<td>
<p><a href="module-la.Matrix.html">module:la.Matrix</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The second matrix.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Matrix.html">module:la.Matrix</a></code>B The difference of the matrices.</p>
</dd>
</dl>
<h3 id="multiply"><span class="symbol-name">multiply</span><span class="signature"><span class="signature-params">(arg)</span> → <span class="signature-returns"> (<a href="module-la.Matrix.html">module:la.Matrix</a> or <a href="module-la.Vector.html">module:la.Vector</a>)</span></span></h3>
<p>Right-hand side multiplication of matrix with parameter.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create a new matrix
var mat = new la.Matrix([[1, 2], [-1, 5]]);
// create a new vector
var vec = new la.Vector([1, -1]);
//multiply mat and vec
var vec2 = mat.multiply(vec); // returns vector [-1, -6]</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>arg</p>
</td>
<td>
<p>(number, <a href="module-la.Vector.html">module:la.Vector</a>, <a href="module-la.SparseVector.html">module:la.SparseVector</a>, <a href="module-la.Matrix.html">module:la.Matrix</a>, or <a href="module-la.SparseMatrix.html">module:la.SparseMatrix</a>)</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Multiplication input. Supports scalar, vector and matrix input.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>(<a href="module-la.Matrix.html">module:la.Matrix</a> or <a href="module-la.Vector.html">module:la.Vector</a>)</code>B <br>1. <a href="module-la.Matrix.html">module:la.Matrix</a>, if <code>arg</code> is a number, <a href="module-la.Matrix.html">module:la.Matrix</a> or <a href="module-la.SparseMatrix.html">module:la.SparseMatrix</a>.
<br>2. <a href="module-la.Vector.html">module:la.Vector</a>, if <code>arg</code> is a <a href="module-la.Vector.html">module:la.Vector</a> or <a href="module-la.SparseVector.html">module:la.SparseVector</a>.
</p>
</dd>
</dl>
<h3 id="multiplyT"><span class="symbol-name">multiplyT</span><span class="signature"><span class="signature-params">(arg)</span> → <span class="signature-returns"> (<a href="module-la.Matrix.html">module:la.Matrix</a> or <a href="module-la.Vector.html">module:la.Vector</a>)</span></span></h3>
<p>Matrix transpose and right-hand side multiplication of matrix with parameter.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create a new matrix
var mat = new la.Matrix([[1, 2], [-1, 5]]);
// create a new vector
var vec = new la.Vector([1, -1]);
//multiply mat and vec
var vec2 = mat.multiplyT(vec); // returns vector [2, -3]</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>arg</p>
</td>
<td>
<p>(number, <a href="module-la.Vector.html">module:la.Vector</a>, <a href="module-la.SparseVector.html">module:la.SparseVector</a>, <a href="module-la.Matrix.html">module:la.Matrix</a>, or <a href="module-la.SparseMatrix.html">module:la.SparseMatrix</a>)</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Multiplication input. Supports scalar, vector and matrix input.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>(<a href="module-la.Matrix.html">module:la.Matrix</a> or <a href="module-la.Vector.html">module:la.Vector</a>)</code>B <br>1. <a href="module-la.Matrix.html">module:la.Matrix</a>, if <code>arg</code> is a number, <a href="module-la.Matrix.html">module:la.Matrix</a> or a <a href="module-la.SparseMatrix.html">module:la.SparseMatrix</a>.
<br>2. <a href="module-la.Vector.html">module:la.Vector</a>, if <code>arg</code> is a <a href="module-la.Vector.html">module:la.Vector</a> or a <a href="module-la.SparseVector.html">module:la.SparseVector</a>.
</p>
</dd>
</dl>
<h3 id="normalizeCols"><span class="symbol-name">normalizeCols</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> <a href="module-la.Matrix.html">module:la.Matrix</a></span></span></h3>
<p>Normalizes each column of matrix.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create a new matrix
var mat = 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();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Matrix.html">module:la.Matrix</a></code>B Self. The columns of matrix are normalized.</p>
</dd>
</dl>
<h3 id="plus"><span class="symbol-name">plus</span><span class="signature"><span class="signature-params">(mat)</span> → <span class="signature-returns"> <a href="module-la.Matrix.html">module:la.Matrix</a></span></span></h3>
<p>Adds two matrices.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create two matrices
var mat = new la.Matrix([[1, 2], [-1, 5]]);
var mat2 = new la.Matrix([[1, -1], [3, 2]]);
// add the matrices
// the return matrix is
// 2 1
// 2 7
var sum = mat.plus(mat2);</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>mat</p>
</td>
<td>
<p><a href="module-la.Matrix.html">module:la.Matrix</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The second matrix.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Matrix.html">module:la.Matrix</a></code>B The sum of the matrices.</p>
</dd>
</dl>
<h3 id="print"><span class="symbol-name">print</span><span class="signature"><span class="signature-params">()</span></span></h3>
<p>Prints the matrix on-screen.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create a new matrix
var mat = new la.Matrix([[1, 2], [3, 4]]);
// print the matrix
// each row represents a row in the matrix. For this example:
// 1 2
// 3 4
mat.print();</code></pre>
</div>
</section>
<dl class="dl-compact">
</dl>
<h3 id="put"><span class="symbol-name">put</span><span class="signature"><span class="signature-params">(rowIdx, colIdx, arg)</span> → <span class="signature-returns"> <a href="module-la.Matrix.html">module:la.Matrix</a></span></span></h3>
<p>Sets an element or a block of matrix.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create a new matrix
var mat = new la.Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);
var arg = 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</code></pre>
</div>
</section>
<section>
<h4>Parameters</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>rowIdx</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Row index (zero based).</p>
</td>
</tr>
<tr>
<td>
<p>colIdx</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Column index (zero based).</p>
</td>
</tr>
<tr>
<td>
<p>arg</p>
</td>
<td>
<p>(number or <a href="module-la.Matrix.html">module:la.Matrix</a>)</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>A number or a matrix. If arg is of type <a href="module-la.Matrix.html">module:la.Matrix</a>, it gets copied, where the argument's upper left corner, <code>arg.at(0,0)</code>, gets copied to position (<code>rowIdx</code>, <code>colIdx</code>).</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Matrix.html">module:la.Matrix</a></code>B Self. The (<code>rowIdx</code>, <code>colIdx</code>) value/block is changed.</p>
</dd>
</dl>
<h3 id="rowMaxIdx"><span class="symbol-name">rowMaxIdx</span><span class="signature"><span class="signature-params">(rowIdx)</span> → <span class="signature-returns"> number</span></span></h3>
<p>Gives the index of the maximum element in the given row.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create the matrix
var mat = new la.Matrix([[1, 2], [3, 1], [-4, 5]]);
// get the column id of the maximum value of the second row
var maxRow = mat.rowMaxIdx(1); // returns the value 0</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>rowIdx</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Row index (zero based).</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>number</code>B Column index (zero based) of the maximum value in the <code>rowIdx</code>-th row of matrix.</p>
</dd>
</dl>
<h3 id="rowNorms"><span class="symbol-name">rowNorms</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Calculates the matrix row norms.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create a new matrix
var mat = new la.Matrix([[3, 4], [4, 15/2]]);
// get the row norms of the matrix
var rowNorms = mat.rowNorms(); // returns the vector [5, 17/2]</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B Vector, where the value at i-th index is the norm of the i-th row of matrix.</p>
</dd>
</dl>
<h3 id="save"><span class="symbol-name">save</span><span class="signature"><span class="signature-params">(fout)</span> → <span class="signature-returns"> <a href="module-fs.FOut.html">module:fs.FOut</a></span></span></h3>
<p>Saves the matrix as output stream.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import the modules
var fs = require('qminer').fs;
var la = require('qminer').la;
// create new matrix
var mat = new la.Matrix([[1, 2], [3, 4]]);
// open write stream
var fout = fs.openWrite('mat.dat');
// save matrix and close write stream
mat.save(fout).close();</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>fout</p>
</td>
<td>
<p><a href="module-fs.FOut.html">module:fs.FOut</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Output stream.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-fs.FOut.html">module:fs.FOut</a></code>B The output stream <code>fout</code>.</p>
</dd>
</dl>
<h3 id="setCol"><span class="symbol-name">setCol</span><span class="signature"><span class="signature-params">(colIdx, vec)</span> → <span class="signature-returns"> <a href="module-la.Matrix.html">module:la.Matrix</a></span></span></h3>
<p>Sets the column of the matrix.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create a matrix
var mat = new la.Matrix([[1, -3, 2], [9, 2, -4], [-2, 3, 3]]);
// create a vector
var vec = new la.Vector([-3, 2, 2]);
// set the first column of the matrix wi