Namespace: Deedle

Nested types and modules


Represents the moments as calculated during online processing (nobs is the count, sum is the sum, M1 to M4 are moments)


When calculating moments, this record is used to keep track of the count (nobs), sum of values (sum), sum of squares (sum2), sum of values to the power of 3 and 3 (sum3 and sum4)

Functions and values

Function or valueDescription
Signature: proj:(Moments -> float) -> series:Series<'K,'V> -> Series<'K,float>
Type parameters: 'K, 'V

Given a series, calculates expanding moments (using online updateMoments) The specified proj function is used to calculate the resulting value

Signature: moment:int -> winSize:int -> proj:(Sums -> float) -> series:Series<'K,'V> -> Series<'K,float>
Type parameters: 'K, 'V

Apply moving window transformation based on Sums calculation. The proj function calculates the statistics from Sums value and the moment specifies which of the Sums properties are calculated during the processing.

applySeriesProj proj series
Signature: proj:(seq<float opt> -> float []) -> series:Series<'K,float> -> Series<'K,float>
Type parameters: 'K

Apply transformation on series elements. The projection function proj always returns float, but may return nan to indicate that the value is not available. The resulting sequence should have the same number of values as the input sequence

Signature: initState:'?662207 -> fupdate:('?662207 -> '?662208 -> '?662207) -> ftransf:('?662207 -> '?662209) -> source:seq<'?662208> -> seq<'?662209>
Type parameters: '?662207, '?662208, '?662209

Helper for expanding window calculations


  • initState is the initial state of the computation
initSumsDense moment init
Signature: moment:int -> init:float [] -> Sums

Given an initial array of values, calculate the initial Sums value (only required elements of Sums are calculated based on moment)

initSumsSparse moment init
Signature: moment:int -> init:'V opt [] -> Sums
Type parameters: 'V

Pick only available values from the input array and call initSumsDense (no need to handle nan values, because those are returned as Missing by Deedle)

Signature: s:Sums -> float

Calculate kurtosis from Sums; requires moment=4

movingMinMaxHelper winSize cmp s
Signature: winSize:int -> cmp:(float -> float -> bool) -> s:seq<OptionalValue<float>> -> float []

O(n) moving min/max calculator

Keeps double-ended queue of values sorted acording to the specified order, such that the front is the min/max value. During the iteration, new value is added to the end (and all values that are greater/smaller than the new value are removed before it is appended).

Signature: winSize:int -> finit:('?662182 [] -> '?662183) -> fupdate:('?662183 -> '?662182 -> '?662182 -> '?662183) -> ftransf:('?662183 -> float) -> source:seq<'?662182> -> seq<float>
Type parameters: '?662182, '?662183

Helper for moving window calculations (adopted from Seq.windowed in F# code base) When calling finit, we do not copy the array - this is fine, because the function is internal (and the only use in applyMovingSumsTransform is correct)


  • winSize - The size of the window to create
  • finit takes the first fully populated window array to an initial state
  • fupdate takes the current state, incoming observation, and out-going observation to the next state
  • ftransf takes the current state to the current output
quickSelectInplace n arr
Signature: n:int -> arr:float [] -> float

Returns the nth smallest element from the specified array. (QuickSelect implementation based on:

Signature: s:Sums -> float

Calculate skewness from Sums; requires moment=3

Signature: arg00:obj -> float
trySeriesExtreme f series
Signature: f:('V -> 'V -> 'V) -> series:Series<'K,'V> -> 'V option
Type parameters: 'V, 'K

Calculates minimum or maximum using the specified function 'f' Returns None when there are no values or Some.

updateMoments state x
Signature: state:Moments -> x:float -> Moments

Updates the moments using the Knuth/Welford algorithm for online stats updating (See:

updateMomentsSparse state curr
Signature: state:Moments -> curr:float opt -> Moments

Updates the moments using updateMoments, but skips over missing values

updateSumsDense moment state curr outg
Signature: moment:int -> state:Sums -> curr:float -> outg:float -> Sums

Given an existing state of type Sums, new incoming element and an old outgoing element, update the sums value (only required elements of Sums are calculated based on moment)

updateSumsSparse moment state curr outg
Signature: moment:int -> state:Sums -> curr:float opt -> outg:float opt -> Sums

Update Sums value using updateSumsDense, but handle the case when removing/adding value that is missing (OptionalValue.Missing)

Signature: series:Series<'?662227,'?662228> -> OptionalValue<'?662228> []
Type parameters: '?662227, '?662228

Returns all values of a series as an array of OptionalValues

Signature: s:Sums -> float

Calculate variance from Sums; requires moment=2

Fork me on GitHub