Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Statistics.Sample.WelfordOnlineMeanVariance
Synopsis
- data WelfordExistingAggregate a
- class WelfordOnline a where
- newWelfordAggregateDef :: WelfordOnline a => a -> WelfordExistingAggregate a
- newWelfordAggregate :: WelfordExistingAggregate a
- welfordCount :: WelfordExistingAggregate a -> Int
- mWelfordMean :: WelfordExistingAggregate a -> Maybe a
- welfordMeanDef :: WelfordOnline a => a -> WelfordExistingAggregate a -> a
- addValue :: WelfordOnline a => WelfordExistingAggregate a -> a -> WelfordExistingAggregate a
- addValues :: (WelfordOnline a, Foldable f) => WelfordExistingAggregate a -> f a -> WelfordExistingAggregate a
- mFinalize :: WelfordOnline a => WelfordExistingAggregate a -> Maybe (Mean a, Variance a, SampleVariance a)
- finalize :: WelfordOnline a => WelfordExistingAggregate a -> (Mean a, Variance a, SampleVariance a)
- nextValue :: WelfordOnline a => WelfordExistingAggregate a -> a -> (WelfordExistingAggregate a, (Mean a, Variance a, SampleVariance a))
- isWelfordExistingAggregateEmpty :: WelfordExistingAggregate a -> Bool
- normaliseToZeroMeanUnitVariance :: WelfordOnline a => WelfordExistingAggregate a -> a -> a
- denormaliseFromZeroMeanUnitVariance :: WelfordOnline a => WelfordExistingAggregate a -> a -> a
- type Mean a = a
- type Variance a = a
- type SampleVariance a = a
Documentation
data WelfordExistingAggregate a Source #
For the storage of required information.
Constructors
WelfordExistingAggregateEmpty | Emtpy aggregate. Needed as |
WelfordExistingAggregate | |
Fields
|
Instances
class WelfordOnline a where Source #
Class for all data structures that can be used to computer the Welford approximation.
For instance, this can be used to compute the Welford algorithm on a Vector
s of Fractional
,
while only requiring to handle one WelfordExistingAggregate
.
Methods
Arguments
:: a | |
-> a | |
-> a | Addition. |
Arguments
:: a | |
-> a | |
-> a | Subtraction. |
Arguments
:: a | |
-> a | |
-> a | Multiplication. |
Arguments
:: a | |
-> a | |
-> a | Division. |
Arguments
:: a | |
-> Int | |
-> a | Division by Integer. |
Arguments
:: a | |
-> Int | |
-> a | Takes one example vector and a integer value and returns a vector of this integer. |
Arguments
:: a | |
-> a | Compute the square root. Ensure the output is >=1e-3. Used for normalisation. |
Arguments
:: Double | |
-> a | |
-> a | Clip the value(s) to the given range. Used for normalisation. |
Instances
newWelfordAggregateDef :: WelfordOnline a => a -> WelfordExistingAggregate a Source #
Create a new empty Aggreate by specifying an example a
value. It is safe to use the `*Unsafe` record field selectors from `WelfordExistingAggregate a`, when creating the data structure using
this fuction.
newWelfordAggregate :: WelfordExistingAggregate a Source #
Create a new empty Aggreate for the calculation.
welfordCount :: WelfordExistingAggregate a -> Int Source #
Get counter.
mWelfordMean :: WelfordExistingAggregate a -> Maybe a Source #
Get mean safely, returns Nothing if WelfordExistingAggregateEmpty
as the type of a
(e.g. length of vector) is unknown.
welfordMeanDef :: WelfordOnline a => a -> WelfordExistingAggregate a -> a Source #
Get mean with specifying a default value.
addValue :: WelfordOnline a => WelfordExistingAggregate a -> a -> WelfordExistingAggregate a Source #
Add one value to the current aggregate.
addValues :: (WelfordOnline a, Foldable f) => WelfordExistingAggregate a -> f a -> WelfordExistingAggregate a Source #
Add multiple values to the current aggregate. This is `foldl addValue`.
mFinalize :: WelfordOnline a => WelfordExistingAggregate a -> Maybe (Mean a, Variance a, SampleVariance a) Source #
Calculate mean, variance and sample variance from aggregate. Safe function.
finalize :: WelfordOnline a => WelfordExistingAggregate a -> (Mean a, Variance a, SampleVariance a) Source #
Calculate mean, variance and sample variance from aggregate. Calls error
for WelfordExistingAggregateEmpty
.
nextValue :: WelfordOnline a => WelfordExistingAggregate a -> a -> (WelfordExistingAggregate a, (Mean a, Variance a, SampleVariance a)) Source #
Add a new sample to the aggregate and compute mean and variances.
isWelfordExistingAggregateEmpty :: WelfordExistingAggregate a -> Bool Source #
Check if it is aggregate is empty
normaliseToZeroMeanUnitVariance :: WelfordOnline a => WelfordExistingAggregate a -> a -> a Source #
Normalise the given input assuming the learned standard deviation with sample variance to zero mean
and unit variance. For the first 100 values the output is clipped to (-3, 3)
.
denormaliseFromZeroMeanUnitVariance :: WelfordOnline a => WelfordExistingAggregate a -> a -> a Source #
Denormalise from a zero mean unit variance normalised value (see normaliseToZeroMeanUnitVariance
) to
the original value(s).
type SampleVariance a = a Source #