qminer
Version:
A C++ based data analytics platform for processing large-scale real-time streams containing structured and unstructured data
386 lines (382 loc) • 16 kB
HTML
<html>
<head>
<meta name="generator" content="JSDoc 3">
<meta charset="utf-8">
<title>Class: NNet</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-analytics.html">analytics</a>.<wbr></small><span class="symbol-name">NNet</span></h1>
<p class="source-link">Source: <a href="analyticsdoc.js.html#source-line-1393">analyticsdoc.<wbr>js:1393</a></p>
<div class="symbol-classdesc">
<p>Holds online/offline neural network model.</p>
</div>
<dl class="dl-compact">
</dl>
</header>
<section id="summary">
<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-analytics.NNet.html#fit">fit(X, Y)</a></dt>
<dd>
</dd>
<dt><a href="module-analytics.NNet.html#getParams">getParams()</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-analytics.NNet.html#predict">predict(vec)</a></dt>
<dd>
</dd>
<dt><a href="module-analytics.NNet.html#save">save(fout)</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-analytics.NNet.html#setParams">setParams()</a></dt>
<dd>
</dd>
</dl>
</div>
</div>
</div>
</section>
<section>
<h2 id="NNet">new <span class="symbol-name">NNet</span><span class="signature"><span class="signature-params">([arg])</span></span></h2>
<p>Neural Network Model.</p>
<section>
<h3>
Example
</h3>
<div>
<pre class="prettyprint"><code>// import module
var analytics = require('qminer').analytics;
// create a new Neural Networks model
var nnet = new analytics.NNet({ layout: [3, 5, 2], learnRate: 0.2, momentum: 0.6 });
// create the matrices for the fitting of the model
var matIn = new la.Matrix([[1, 0], [0, 1], [1, 1]]);
var matOut = new la.Matrix([[-1, 8], [-3, -3]]);
// fit the model
nnet.fit(matIn, matOut);
// create the vector for the prediction
var test = new la.Vector([1, 1, 2]);
// predict the value of the vector
var prediction = nnet.predict(test);</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-analytics.html#~nnetParam">module:analytics~nnetParam</a> or <a href="module-fs.FIn.html">module:fs.FIn</a>)</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>Construction arguments. There are two ways of constructing:
<br>1. Using the <a href="module-analytics.html#~nnetParam">module:analytics~nnetParam</a> object,
<br>2. using the file input stream <a href="module-fs.FIn.html">module:fs.FIn</a>.
</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
</dl>
</section>
<section>
<h2>Methods</h2>
<section>
<h3 id="fit"><span class="symbol-name">fit</span><span class="signature"><span class="signature-params">(X, Y)</span> → <span class="signature-returns"> <a href="module-analytics.NNet.html">module:analytics.NNet</a></span></span></h3>
<p>Fits the model.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a Neural Networks model
var nnet = new analytics.NNet({ layout: [2, 3, 4] });
// create the matrices for the fitting of the model
var matIn = new la.Matrix([[1, 0], [0, 1]]);
var matOut = new la.Matrix([[1, 1], [1, 2], [-1, 8], [-3, -3]]);
// fit the model
nnet.fit(matIn, matOut);</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>X</p>
</td>
<td>
<p>(<a href="module-la.Vector.html">module:la.Vector</a> or <a href="module-la.Matrix.html">module:la.Matrix</a>)</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The input data.</p>
</td>
</tr>
<tr>
<td>
<p>Y</p>
</td>
<td>
<p>(<a href="module-la.Vector.html">module:la.Vector</a> or <a href="module-la.Matrix.html">module:la.Matrix</a>)</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The output data.
<br> If <code>X</code> and <code>Y</code> are both <a href="module-la.Vector.html">module:la.Vector</a>, then the fitting is in online mode.
<br> If <code>X</code> and <code>Y</code> are both <a href="module-la.Matrix.html">module:la.Matrix</a>, then the fitting is in batch mode.
</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-analytics.NNet.html">module:analytics.NNet</a></code>B Self. The model has been updated.</p>
</dd>
</dl>
<h3 id="getParams"><span class="symbol-name">getParams</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> <a href="module-analytics.html#~nnetParam">module:analytics~nnetParam</a></span></span></h3>
<p>Get the parameters of the model.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import analytics module
var analytics = require('qminer').analytics;
// create a Neural Networks model
var nnet = new analytics.NNet();
// get the parameters
var params = nnet.getParams();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-analytics.html#~nnetParam">module:analytics~nnetParam</a></code>B The constructor parameters.</p>
</dd>
</dl>
<h3 id="predict"><span class="symbol-name">predict</span><span class="signature"><span class="signature-params">(vec)</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Gets the prediction of the vector.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a Neural Networks model
var nnet = new analytics.NNet({ layout: [2, 3, 4] });
// create the matrices for the fitting of the model
var matIn = new la.Matrix([[1, 0], [0, 1]]);
var matOut = new la.Matrix([[1, 1], [1, 2], [-1, 8], [-3, -3]]);
// fit the model
nnet.fit(matIn, matOut);
// create the vector for the prediction
var test = new la.Vector([1, 1]);
// predict the value of the vector
var prediction = nnet.predict(test);</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>vec</p>
</td>
<td>
<p><a href="module-la.Vector.html">module:la.Vector</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The prediction vector.</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 prediction of vector <code>vec</code>.</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 model.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
var fs = require('qminer').fs;
// create a Neural Networks model
var nnet = new analytics.NNet({ layout: [2, 3, 4] });
// create the matrices for the fitting of the model
var matIn = new la.Matrix([[1, 0], [0, 1]]);
var matOut = new la.Matrix([[1, 1], [1, 2], [-1, 8], [-3, -3]]);
// fit the model
nnet.fit(matIn, matOut);
// create an output stream object and save the model
var fout = fs.openWrite('nnet_example.bin');
nnet.save(fout);
fout.close();
// load the Neural Network model from the binary
var fin = fs.openRead('nnet_example.bin');
var nnet2 = new analytics.NNet(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>fout</p>
</td>
<td>
<p><a href="module-fs.FOut.html">module:fs.FOut</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The 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="setParams"><span class="symbol-name">setParams</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> <a href="module-analytics.NNet.html">module:analytics.NNet</a></span></span></h3>
<p>Sets the parameters of the model.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import analytics module
var analytics = require('qminer').analytics;
// create a Neural Networks model
var nnet = new analytics.NNet();
// set the parameters
nnet.setParams({ learnRate: 1, momentum: 10, layout: [1, 4, 3] });</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-analytics.NNet.html">module:analytics.NNet</a></code>B Self. The model parameters have been updated.</p>
</dd>
</dl>
</section>
</section>
</div>
</div>
<nav id="jsdoc-toc-nav" role="navigation"></nav>
</div>
</div>
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
</p>
</div>
</footer>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/tree.jquery.js"></script>
<script src="scripts/prettify.js"></script>
<script src="scripts/jsdoc-toc.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/scrollanchor.js"></script>
</body>
</html>