UNPKG

qminer

Version:

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

169 lines (161 loc) 8.23 kB
<!doctype html> <html> <head> <meta name="generator" content="JSDoc 3"> <meta charset="utf-8"> <title>Source: statdoc.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: statdoc.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. */ /** * Statistics module. * @module statistics * @example * // import the modules * var qm &#x3D; require(&#x27;qminer&#x27;); * var statistics &#x3D; qm.statistics; * // create a vector * var vec &#x3D; new qm.la.Vector([0, 1, 2, -1, -2]); * // calculate the mean value of the vector * var mean &#x3D; statistics.mean(vec); // returns 0 */ /** * Calculates the mean value(s). * @param {(module:la.Vector | module:la.Matrix)} input - The input the method is used on. * @returns {(number | module:la.Vector)} * &amp;lt;br&gt;1. If input is {@link module:la.Vector}, returns the mean of the vector. * &amp;lt;br&gt;2. If input is {@link module:la.Matrix}, returns a vector of where the i-th value is the mean of i-th column. * @example * // import modules * var qm &#x3D; require(&#x27;qminer&#x27;); * var la &#x3D; qm.la; * var statistics &#x3D; qm.statistics; * // create a matrix * var mat &#x3D; new la.Matrix([[1, 2, 1], [-1, 2, -1], [3, 2, 3]]); * // calculate the mean of the matrix columns * // vector contains the elements [1, 2, 1] * var mean &#x3D; statistics.mean(mat); */ exports.mean &#x3D; function (input) { return input instanceof Object.create(require(&#x27;qminer&#x27;).la.Vector) ? 0.0 : Object.create(require(&#x27;qminer&#x27;).la.Vector.prototype); } /** * Calculates the standard deviation(s). * @param {(module:la.Vector | module:la.Matrix)} X - The input the method is used on. * @param {number} [flag&#x3D;0] - If set to to 0, it normalizes X by n-1; If set to 1 to, it normalizes by n. * @param {number} [dim&#x3D;1] - Computes the standard deviations along the dimension of X specified by parameter &#x60;dim&#x60;. * If set to 1, calculates the column standard deviation. If set to 2, calculates the row standard deviation. * @returns {(number | module:la.Vector)} * &amp;lt;br&gt;1. If X is {@link module:la.Vector}, returns standard deviation of the vector. * &amp;lt;br&gt;2. If X is {@link module:la.Matrix}, returns a vector where the i-th value is the standard deviation of the i-th column(row). * @example * // import modules * var qm &#x3D; require(&#x27;qminer&#x27;); * var la &#x3D; qm.la; * var statistics &#x3D; qm.statistics; * // create a matrix * var mat &#x3D; new la.Matrix([[1, 2, 1], [-1, 2, -1], [3, 2, 3]]); * // calculate the standard deviation of the matrix columns * var mean &#x3D; statistics.std(mat); */ exports.std &#x3D; function (X, flag, dim) { return input instanceof Object.create(require(&#x27;qminer&#x27;).la.Vector) ? 0.0 : Object.create(require(&#x27;qminer&#x27;).la.Vector.prototype); } /** * Returns an object containing the standard deviation of each column of matrix, mean vector and z-score matrix. * @param {module:la.Matrix} mat - The matrix. * @param {number} [flag&#x3D;0] - If set to 0, it normalizes mat by n-1; if set to 1, it normalizes by n. * @param {number} [dim&#x3D;1] - Computes the standard deviations along the dimension of mat specified by parameter &#x60;dim&#x60;. * If set to 1, calculates the column standard deviation. If set to 2, calculates the row standard deviation. * @returns {Object} The object &#x60;zscoreResult&#x60; containing: * &amp;lt;br&gt;&#x60;zscoreResult.sigma&#x60; - {@link module:la.Vector} of standard deviations of mat used to compute the z-scores. * &amp;lt;br&gt;&#x60;zscoreResult.mu&#x60; - {@link module:la.Vector} of mean values of mat used to compute the z-scores. * &amp;lt;br&gt;&#x60;zscoreResult.Z&#x60; - {@link module:la.Matrix} of z-scores that has mean 0 and variance 1. * @example * // import modules * var qm &#x3D; require(&#x27;qminer&#x27;); * var la &#x3D; qm.la; * var statistics &#x3D; qm.statistics; * // create a matrix * var mat &#x3D; new la.Matrix([[1, 2, 1], [-1, 2, -1], [3, 2, 3]]); * // calculate the standard deviation of the matrix columns * var mean &#x3D; statistics.zscore(mat); */ exports.zscore &#x3D; function (mat, flag, dim) { return {sigma: Object.create(require(&#x27;qminer&#x27;).la.Vector.prototype), mu: Object.create(require(&#x27;qminer&#x27;).la.Vector.prototype), Z: Object.create(require(&#x27;qminer&#x27;).la.Matrix.prototype)}; } /** * function studentCdf calculates Student&#x27;s t cumulative distribution function (PDF integral from -inf to t) * function studentCdf returns &#x27;Alpha&#x27; as in the p-value of a Student t-test * If you already have a t-value than the studentCdf function has 2 inputs: t-value and degrees of freedom * @param {number} val - The t-value value of the sample you want to calculate the p-value for * @param {number} df - Degrees of freedom for the sample (if your sample is big n than degrees of freedom in n-1) * If you don&#x27;t have the t-value than studentCdf function has 4 inputs: Value, Mean, Standard deviation and degrees of freedom * @param {number} val - The average value of the sample you want to calculate the p-value for * @param {number} mean - The mean value of the sample you want to calculate the p-value for * @param {number} std - The sample standard deviation of the sample you want to calculate the p-value for * @param {number} df - Degrees of freedom for the sample (if your sample is n big then degrees of freedom is n-1) * @returns {Alpha} */ /** * Calculates the z-score for a point sampled from a Gaussian distribution. The z-score indicates * how many standard deviations an element is from the meam and can be calculated using * the following formula: &#x60;z &#x3D; (x - mu) / sigma&#x60;. * @param {Number} x - The sampled point. * @param {Number} mu - Mean of the distribution. * @param {Number} sigma - Variance of the distribution. * @returns {number} The z-score of the sampled point. * @example * // import modules * var stat &#x3D; require(&#x27;qminer&#x27;).statistics; * // calculate the z-score of the sampled point * var point &#x3D; 10; * var mu &#x3D; 5; * var sigma &#x3D; 5; * var zScore &#x3D; stat.getZScore(point, mu, sigma); // returns 1 */ exports.getZScore &#x3D; function (x, mu, sigma) { return (x - mu) / sigma; } </code></pre> </article> </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>