Lua Running Stats Module
1. Overview
Calculates the running count, mean, variance, and standard deviation. The module is globally registered and returned by the require function.
2. Example Usage
require "streaming_algorithms.running_stats"
local stat = streaming_algorithms.running_stats.new()
for i = 1, 100 do
stat:add(i)
end
local cnt = stat:count()
-- cnt == 100
3. Module
3.1. Functions
3.1.1. new
local rs = require "streaming_algorithms.running_stats"
local stat = rs.new()
Creates a new running_stats userdata object.
Arguments
- none
Return
- running_stats userdata object
3.2. Methods
3.2.1. add
stat:add(1.3243)
Add the value to the running stats.
Arguments
- value (number)
Return
- none
3.2.2. avg
local avg = stat:avg()
Returns the current average.
Arguments
- none
Return
- avg (number)
3.2.3. clear
stat:clear()
Resets the stats to zero.
Arguments
- none
Return
- none
3.2.4. count
local count = stat:count()
Returns the total number of values.
Arguments
- none
Return
- count (number)
3.2.5. fromstring
stat:fromstring(tostring(stat1))
Restores the stats to the previously serialized state.
Arguments
- serialization (string) tostring output
Return
- none or throws an error
3.2.6. sd
local sd = stat:sd()
Returns the current corrected sample standard deviation.
Arguments
- none
Return
- sd (number)
3.2.7. usd
local sd = stat:usd()
Returns the current uncorrected sample standard deviation.
Arguments
- none
Return
- sd (number)
3.2.8. variance
local variance = stat:variance()
Returns the current variance.
Arguments
- none
Return
- variance (number)