qminer
Version:
A C++ based data analytics platform for processing large-scale real-time streams containing structured and unstructured data
449 lines (443 loc) • 18.8 kB
HTML
<html>
<head>
<meta name="generator" content="JSDoc 3">
<meta charset="utf-8">
<title>Class: BufferedTDigest</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">BufferedTDigest</span></h1>
<p class="source-link">Source: <a href="analyticsdoc.js.html#source-line-2316">analyticsdoc.<wbr>js:2316</a></p>
<div class="symbol-classdesc">
<p>TDigest is a methods that approximates the CDF function of streaming measurements.
Data structure useful for percentile and quantile estimation for online data streams.
It can be added to any anomaly detector to set the number of alarms triggered as a percentage of the total samples.
Adding new samples to the distribution is achieved through <code>insert</code> and querying the model (computing quantiles)
is implemented by <code>quantile</code> function.
<br> This is based on the Data Lib Sketch Implementation: <a href="https://github.com/vega/datalib-sketch/blob/master/src/t-digest.js">t-digest.js</a>
<br> Paper: Ted Dunning, Otmar Ertl - <a href="https://github.com/tdunning/t-digest/blob/master/docs/t-digest-paper/histo.pdf">Computing Extremely Accurate Quantiles Using t-Digests</a>.
</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-analytics.BufferedTDigest.html#.memory">memory</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-analytics.BufferedTDigest.html#.size">size</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-analytics.BufferedTDigest.html#init">init</a></dt>
<dd>
</dd>
</dl>
</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-analytics.BufferedTDigest.html#flush">flush()</a></dt>
<dd>
</dd>
<dt><a href="module-analytics.BufferedTDigest.html#getParams">getParams()</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-analytics.BufferedTDigest.html#insert">insert(x)</a></dt>
<dd>
</dd>
<dt><a href="module-analytics.BufferedTDigest.html#quantile">quantile(x)</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-analytics.BufferedTDigest.html#save">save(fout)</a></dt>
<dd>
</dd>
</dl>
</div>
</div>
</div>
</section>
<section>
<h2 id="BufferedTDigest">new <span class="symbol-name">BufferedTDigest</span><span class="signature"><span class="signature-params">([arg])</span></span></h2>
<p>TDigest quantile estimation on streams</p>
<section>
<h3>
Example
</h3>
<div>
<pre class="prettyprint"><code>// import modules
var qm = require('qminer');
var fs = qm.fs;
var analytics = qm.analytics;
// create the default BufferedTDigest object
var tdigest = new analytics.quantiles.BufferedTDigest();
// create the data used for calculating quantiles
var inputs = [10, 1, 2, 8, 9, 5, 6, 4, 7, 3];
// fit the BufferedTDigest model
for (var i = 0; i < inputs.length; i++) {
tdigest.insert(inputs[i]);
}
// make the estimation for the 0.1 quantile
var quant = tdigest.quantile(0.1);
// save the model
tdigest.save(fs.openWrite('tdigest.bin')).close();
// open the tdigest model under a new variable
var tdigest2 = new analytics.quantiles.BufferedTDigest(fs.openRead('tdigest.bin'));</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>(module:analytics.quantiles~BufferedTDigestParam 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 module:analytics.quantiles~BufferedTDigestParam 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>Properties</h2>
<section>
<div class="symbol-detail-labels"><span class="label label-static">static</span></div>
<h3 id=".memory"><span class="symbol-name">memory</span></h3>
<p>Returns the models current memory consumption.</p>
<dl class="dl-compact">
</dl>
<div class="symbol-detail-labels"><span class="label label-static">static</span></div>
<h3 id=".size"><span class="symbol-name">size</span></h3>
<p>Returns the current size of the algorithms summary in number of tuples.</p>
<dl class="dl-compact">
</dl>
<h3 id="init"><span class="symbol-name">init</span></h3>
<p>Returns true when the model has enough data to initialize. Type <code>boolean</code>.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import modules
var qm = require('qminer');
var analytics = qm.analytics;
var fs = qm.fs;
// create the default BufferedTDigest object
var tdigest = new analytics.quantiles.BufferedTDigest();
// check if the model has enough data to initialize
if (tdigest.init) { console.log("Ready to initialize"); }</code></pre>
</div>
</section>
<dl class="dl-compact">
</dl>
</section>
<h2>Methods</h2>
<section>
<h3 id="flush"><span class="symbol-name">flush</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> module:analytics.quantiles.BufferedTDigest</span></span></h3>
<p>Flushed the input buffer.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import modules
var qm = require('qminer');
var analytics = qm.analytics;
// create the default BufferedTDigest object
var tdigest = new analytics.quantiles.BufferedTDigest();
// create the data used for calculating quantiles
var inputs = [10, 1, 2, 8, 9, 5, 6, 4, 7, 3];
// fit the BufferedTDigest model
for (var i = 0; i < inputs.length; i++) {
tdigest.insert(inputs[i]);
}
tdigest.flush()
// make the estimation for the 0.1 quantile
var quant = tdigest.quantile(0.1);</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>module:analytics.quantiles.BufferedTDigest</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"> module:analytics.quantiles~BufferedTDigestParam</span></span></h3>
<p>Returns the parameters.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import modules
var qm = require('qminer');
var analytics = qm.analytics;
// create the default BufferedTDigest object
var tdigest = new analytics.quantiles.BufferedTDigest();
// get the parameters of the object
var params = tdigest.getParams();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>module:analytics.quantiles~BufferedTDigestParam</code>B The construction parameters.</p>
</dd>
</dl>
<h3 id="insert"><span class="symbol-name">insert</span><span class="signature"><span class="signature-params">(x)</span> → <span class="signature-returns"> module:analytics.quantiles.BufferedTDigest</span></span></h3>
<p>Adds a new measurement to the model and updates the approximation of the data distribution.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import modules
var qm = require('qminer');
var analytics = qm.analytics;
// create the default BufferedTDigest object
var tdigest = new analytics.quantiles.BufferedTDigest();
// create the data used for calculating quantiles
var inputs = [10, 1, 2, 8, 9, 5, 6, 4, 7, 3];
// fit the BufferedTDigest model with all input values
for (var i = 0; i < inputs.length; i++) {
tdigest.insert(inputs[i]);
}</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>x</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Input number.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>module:analytics.quantiles.BufferedTDigest</code>B Self. The model has been updated.</p>
</dd>
</dl>
<h3 id="quantile"><span class="symbol-name">quantile</span><span class="signature"><span class="signature-params">(x)</span> → <span class="signature-returns"> number</span></span></h3>
<p>Returns a quantile given input number, that is the approximate fraction of samples smaller than the input (0.05 means that 5% of data is smaller than the input value).</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import modules
var qm = require('qminer');
var analytics = qm.analytics;
// create the default BufferedTDigest object
var tdigest = new analytics.quantiles.BufferedTDigest();
// create the data used for calculating quantiles
var inputs = [10, 1, 2, 8, 9, 5, 6, 4, 7, 3];
// fit the BufferedTDigest model
for (var i = 0; i < inputs.length; i++) {
tdigest.insert(inputs[i]);
}
tdigest.flush()
// make the estimation for the 0.1 quantile
var quant = tdigest.quantile(0.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>x</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Input number.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>number</code>B Quantile (between 0 and 1).</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 BufferedTDigest internal state into (binary) file.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import modules
var qm = require('qminer');
var analytics = qm.analytics;
var fs = qm.fs;
// create the default BufferedTDigest object
var tdigest = new analytics.quantiles.BufferedTDigest();
// create the data used for calculating quantiles
var inputs = [10, 1, 2, 8, 9, 5, 6, 4, 7, 3];
// fit the BufferedTDigest model
for (var i = 0; i < inputs.length; i++) {
tdigest.insert(inputs[i]);
}
// save the model
tdigest.save(fs.openWrite('tdigest.bin')).close();
// open the tdigest model under a new variable
var tdigest2 = new analytics.quantiles.BufferedTDigest(fs.openRead('tdigest.bin'));</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>
</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>