Simulator first commit
This commit is contained in:
2
node_modules/stats-incremental/.npmignore
generated
vendored
Normal file
2
node_modules/stats-incremental/.npmignore
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
examples
|
||||
test
|
9
node_modules/stats-incremental/LICENSE
generated
vendored
Normal file
9
node_modules/stats-incremental/LICENSE
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) Bryce B. Baril <bryce@ravenwall.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
169
node_modules/stats-incremental/README.md
generated
vendored
Normal file
169
node_modules/stats-incremental/README.md
generated
vendored
Normal file
@ -0,0 +1,169 @@
|
||||
stats-incremental
|
||||
=====
|
||||
|
||||
[](https://nodei.co/npm/stats-incremental/)
|
||||
|
||||
A light statstical package for incremental (i.e. rolling, streaming) sets of numbers.
|
||||
|
||||
E.g. given a source of numbers of unknown length that you would like to at any given time know any of:
|
||||
|
||||
* count
|
||||
* min
|
||||
* max
|
||||
* sum
|
||||
* variance
|
||||
* standard_deviation
|
||||
* simple moving average
|
||||
|
||||
This module can be used either with Node `streams` via a wrapper such as `through2` or without being streaming.
|
||||
|
||||
Example
|
||||
---
|
||||
|
||||
Non-streaming:
|
||||
|
||||
```javascript
|
||||
var Stats = require("stats-incremental")
|
||||
|
||||
var dice = require("dice")
|
||||
var s = Stats()
|
||||
|
||||
var rolls = []
|
||||
for (var i = 0; i < 100; i++) {
|
||||
s.update(dice.sum(dice.roll("2d6")))
|
||||
console.log(s.getAll())
|
||||
}
|
||||
|
||||
/* E.g.
|
||||
{ n: 97,
|
||||
min: 2,
|
||||
max: 12,
|
||||
sum: 673,
|
||||
mean: 6.938144329896907,
|
||||
variance: 5.851843979168881,
|
||||
standard_deviation: 2.419058490233107,
|
||||
sma50: 6.82 }
|
||||
*/
|
||||
|
||||
|
||||
console.log(s.mean)
|
||||
console.log(s.standard_deviation)
|
||||
|
||||
```
|
||||
|
||||
With streams:
|
||||
|
||||
```js
|
||||
var spigot = require("stream-spigot")
|
||||
var through2 = require("through2")
|
||||
var terminus = require("terminus")
|
||||
|
||||
var Stats = require("stats-incremental")
|
||||
var s = Stats()
|
||||
|
||||
var statStream = through2.obj(function (chunk, encoding, callback) {
|
||||
s.update(chunk)
|
||||
if (s.n % 100000 === 0) {
|
||||
console.log(s.getAll())
|
||||
}
|
||||
this.push(chunk)
|
||||
callback()
|
||||
})
|
||||
|
||||
spigot.sync({objectMode: true}, Math.random)
|
||||
.pipe(statStream)
|
||||
.pipe(terminus.devnull({objectMode: true}))
|
||||
|
||||
/*
|
||||
{ n: 100000,
|
||||
min: 2.0884908735752106e-7,
|
||||
max: 0.9999937505926937,
|
||||
sum: 49861.06196602131,
|
||||
mean: 0.49861061966021336,
|
||||
variance: 0.08331362954827709,
|
||||
standard_deviation: 0.28864100462040576,
|
||||
sma50: 0.5422519558777934 }
|
||||
{ n: 200000,
|
||||
min: 2.0884908735752106e-7,
|
||||
max: 0.9999937505926937,
|
||||
sum: 99904.73041411326,
|
||||
mean: 0.49952365207056687,
|
||||
variance: 0.08316120223669865,
|
||||
standard_deviation: 0.2883768406732736,
|
||||
sma50: 0.4396136475716979 }
|
||||
*/
|
||||
|
||||
```
|
||||
|
||||
API
|
||||
===
|
||||
|
||||
## `const Stats = require("stats-incremental")`
|
||||
## `var stats = new Stats(smaBins)`
|
||||
|
||||
Create a new incremental stats aggregator. The `smaBins` argument is optional (default 50) and will choose the size of recent window to retain to calculate the Simple Moving Average on the recent data.
|
||||
|
||||
## `stats.update(value)`
|
||||
|
||||
Update the aggregator with a value. Converted to a Number via parseFloat. If this results in NaN the update is skipped.
|
||||
|
||||
## `stats.getAll()`
|
||||
|
||||
Get a up-to-date clone of all of the stats stored.
|
||||
|
||||
E.g.
|
||||
|
||||
```js
|
||||
{ n: 97,
|
||||
min: 2,
|
||||
max: 12,
|
||||
sum: 673,
|
||||
mean: 6.938144329896907,
|
||||
variance: 5.851843979168881,
|
||||
standard_deviation: 2.419058490233107,
|
||||
sma50: 6.82 }
|
||||
```
|
||||
|
||||
## `stats.n`
|
||||
|
||||
The count of observations.
|
||||
|
||||
## `stats.min`
|
||||
|
||||
The min value observed.
|
||||
|
||||
## `stats.max`
|
||||
|
||||
The max value observed.
|
||||
|
||||
## `stats.sum`
|
||||
|
||||
The sum of all values observed.
|
||||
|
||||
## `stats.mean`
|
||||
|
||||
The arithmetic mean of the observations.
|
||||
|
||||
## `stats.variance`
|
||||
|
||||
The variance from the mean.
|
||||
|
||||
## `stats.standard_deviation`
|
||||
|
||||
The standard deviation of the values from the mean.
|
||||
|
||||
## `stats.smaXX`
|
||||
|
||||
Get the Simple Moving Average of the recent data. Default is to store 50 recent records and expose an `sma50` property with the simple moving average. If the `Stats` object is created with an argument of a number of SMA bins, the property will reflect the number of bins, e.g. `Stats(100)` will have an `sma100` instead of `sma50` property.
|
||||
|
||||
Alternatives
|
||||
---
|
||||
|
||||
[stats-lite](http://npm.im/stats-lite) Operates on complete sets of numbers.
|
||||
|
||||
[stream-statistics](http://npm.im/stream-statistics) Is a similar module dedicated to streams.
|
||||
|
||||
LICENSE
|
||||
=======
|
||||
|
||||
MIT
|
78
node_modules/stats-incremental/package.json
generated
vendored
Normal file
78
node_modules/stats-incremental/package.json
generated
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
{
|
||||
"_from": "stats-incremental@^1.2.1",
|
||||
"_id": "stats-incremental@1.2.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-fvlXGCxi2HkFjHpHNauI0qxFxrU=",
|
||||
"_location": "/stats-incremental",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "stats-incremental@^1.2.1",
|
||||
"name": "stats-incremental",
|
||||
"escapedName": "stats-incremental",
|
||||
"rawSpec": "^1.2.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.2.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/mumble-client"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/stats-incremental/-/stats-incremental-1.2.1.tgz",
|
||||
"_shasum": "7ef957182c62d879058c7a4735ab88d2ac45c6b5",
|
||||
"_spec": "stats-incremental@^1.2.1",
|
||||
"_where": "/home/sergiu/linx-audio-simulator/node_modules/mumble-client",
|
||||
"author": {
|
||||
"name": "Bryce B. Baril"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/brycebaril/stats-incremental/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"stats-lite": "^2.1.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "A simple tool for calculating incremental stats on numeric streams.",
|
||||
"devDependencies": {
|
||||
"standard": "~10.0.2",
|
||||
"tape": "~4.7.0"
|
||||
},
|
||||
"directories": {
|
||||
"example": "examples",
|
||||
"test": "test"
|
||||
},
|
||||
"homepage": "https://github.com/brycebaril/stats-incremental",
|
||||
"jshintConfig": {
|
||||
"asi": true,
|
||||
"globalstrict": true,
|
||||
"validthis": true,
|
||||
"eqnull": true,
|
||||
"node": true,
|
||||
"loopfunc": true,
|
||||
"newcap": false,
|
||||
"eqeqeq": false
|
||||
},
|
||||
"keywords": [
|
||||
"stats",
|
||||
"statistics",
|
||||
"numbers",
|
||||
"math",
|
||||
"sum",
|
||||
"mean",
|
||||
"average",
|
||||
"variance",
|
||||
"deviation"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "stats.js",
|
||||
"name": "stats-incremental",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/brycebaril/stats-incremental.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test/ && standard"
|
||||
},
|
||||
"version": "1.2.1"
|
||||
}
|
83
node_modules/stats-incremental/stats.js
generated
vendored
Normal file
83
node_modules/stats-incremental/stats.js
generated
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
'use strict'
|
||||
|
||||
const statslite = require('stats-lite')
|
||||
|
||||
module.exports = Stats
|
||||
|
||||
function Stats (smaBins) {
|
||||
if (!(this instanceof Stats)) return new Stats(smaBins)
|
||||
this.n = 0
|
||||
this.min = Number.MAX_VALUE
|
||||
this.max = -Number.MAX_VALUE
|
||||
this.sum = 0
|
||||
this.mean = 0
|
||||
if (smaBins == null || smaBins <= 0) {
|
||||
smaBins = 50
|
||||
}
|
||||
if (smaBins !== (smaBins | 0)) {
|
||||
throw new Error('SMA option must be an integer')
|
||||
}
|
||||
Object.defineProperty(this, 'smaBins', {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: smaBins
|
||||
})
|
||||
Object.defineProperty(this, '_bins', {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: []
|
||||
})
|
||||
Object.defineProperty(this, 'q', {
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
value: 0
|
||||
})
|
||||
Object.defineProperty(this, 'variance', {
|
||||
enumerable: true,
|
||||
get: () => { return this.q / this.n }
|
||||
})
|
||||
Object.defineProperty(this, 'standard_deviation', {
|
||||
enumerable: true,
|
||||
get: () => { return Math.sqrt(this.q / this.n) }
|
||||
})
|
||||
Object.defineProperty(this, `sma${smaBins}`, {
|
||||
enumerable: true,
|
||||
get: () => { return statslite.mean(this._bins) }
|
||||
})
|
||||
}
|
||||
|
||||
Stats.prototype.update = function update (value) {
|
||||
var num = parseFloat(value)
|
||||
if (isNaN(num)) {
|
||||
// Sorry, no NaNs
|
||||
return
|
||||
}
|
||||
this.n++
|
||||
this.min = Math.min(this.min, num)
|
||||
this.max = Math.max(this.max, num)
|
||||
this.sum += num
|
||||
var prevMean = this.mean
|
||||
this.mean = this.mean + (num - this.mean) / this.n
|
||||
this.q = this.q + (num - prevMean) * (num - this.mean)
|
||||
this._bins.push(value)
|
||||
if (this._bins.length > this.smaBins) {
|
||||
this._bins.shift()
|
||||
}
|
||||
}
|
||||
|
||||
Stats.prototype.getAll = function getAll () {
|
||||
if (this.n === 0) {
|
||||
return null
|
||||
}
|
||||
var s = {
|
||||
n: this.n,
|
||||
min: this.min,
|
||||
max: this.max,
|
||||
sum: this.sum,
|
||||
mean: this.mean,
|
||||
variance: this.variance,
|
||||
standard_deviation: this.standard_deviation
|
||||
}
|
||||
s[`sma${this.smaBins}`] = this[`sma${this.smaBins}`]
|
||||
return s
|
||||
}
|
Reference in New Issue
Block a user