Array Module

Module to compute common statistical measure on array

Functions and values

Function or value Description

cov array1 array2

Full Usage: cov array1 array2

Parameters:
    array1 : ^T array - The first input array.
    array2 : ^T array - The second input array.

Returns: ^U sample covariance estimator (Bessel's correction by N-1)
Modifiers: inline

Computes the sample covariance of two random variables

Returns NaN if data is empty or if any entry is NaN.

array1 : ^T array

The first input array.

array2 : ^T array

The second input array.

Returns: ^U

sample covariance estimator (Bessel's correction by N-1)

covBy f array

Full Usage: covBy f array

Parameters:
    f : 'T -> ^a * ^a - A function applied to transform each element of the input array into a tuple of paired observations.
    array : 'T array - The input array.

Returns: ^U sample covariance estimator (Bessel's correction by N-1)
Modifiers: inline

Computes the sample covariance of two random variables generated by applying a function to the input array.

Returns NaN if data is empty or if any entry is NaN.

f : 'T -> ^a * ^a

A function applied to transform each element of the input array into a tuple of paired observations.

array : 'T array

The input array.

Returns: ^U

sample covariance estimator (Bessel's correction by N-1)

Example

 
 // To get the sample covariance between x and y observations:
 let xy = [| {| x = 5.; y = 2. |}
             {| x = 12.; y = 8. |}
             {| x = 18.; y = 18. |}
             {| x = -23.; y = -20. |} 
             {| x = 45.; y = 28. |} |]
 
 xy |> Array.covBy (fun x -> x.x, x.y) // evaluates to 434.90

covOfPairs array

Full Usage: covOfPairs array

Parameters:
    array : (^T * ^T) array - The input array.

Returns: ^U sample covariance estimator (Bessel's correction by N-1)
Modifiers: inline

Computes the sample covariance of two random variables. The covariance will be calculated between the paired observations.

Returns NaN if data is empty or if any entry is NaN.

array : (^T * ^T) array

The input array.

Returns: ^U

sample covariance estimator (Bessel's correction by N-1)

Example

 
 // Consider an array of paired x and y values:
 // [| (x1, y1); (x2, y2); (x3, y3); (x4, y4); ... |]
 let xy = [| (5., 2.); (12., 8.); (18., 18.); (-23., -20.); (45., 28.) |]
 
 // To get the sample covariance between x and y:
 xy |> Array.covOfPairs // evaluates to 434.90

covPopulation array1 array2

Full Usage: covPopulation array1 array2

Parameters:
    array1 : ^T array - The first input array.
    array2 : ^T array - The second input array.

Returns: ^U population covariance estimator (denominator N)
Modifiers: inline

Computes the population covariance of two random variables

Returns NaN if data is empty or if any entry is NaN.

array1 : ^T array

The first input array.

array2 : ^T array

The second input array.

Returns: ^U

population covariance estimator (denominator N)

covPopulationBy f array

Full Usage: covPopulationBy f array

Parameters:
    f : 'T -> ^a * ^a - A function applied to transform each element of the input array into a tuple of paired observations.
    array : 'T array - The input array.

Returns: ^U population covariance estimator (denominator N)
Modifiers: inline

Computes the population covariance of two random variables generated by applying a function to the input array.

Returns NaN if data is empty or if any entry is NaN.

f : 'T -> ^a * ^a

A function applied to transform each element of the input array into a tuple of paired observations.

array : 'T array

The input array.

Returns: ^U

population covariance estimator (denominator N)

Example

 
 // To get the population covariance between x and y observations:
 let xy = [| {| x = 5.; y = 2. |}
             {| x = 12.; y = 8. |}
             {| x = 18.; y = 18. |}
             {| x = -23.; y = -20. |} 
             {| x = 45.; y = 28. |} |]
 
 xy |> Array.covPopulationBy (fun x -> x.x, x.y) // evaluates to 347.92

covPopulationOfPairs array

Full Usage: covPopulationOfPairs array

Parameters:
    array : (^T * ^T) array - The input array.

Returns: ^U population covariance estimator (denominator N)
Modifiers: inline

Computes the population covariance of two random variables. The covariance will be calculated between the paired observations.

Returns NaN if data is empty or if any entry is NaN.

array : (^T * ^T) array

The input array.

Returns: ^U

population covariance estimator (denominator N)

Example

 
 // Consider an array of paired x and y values:
 // [| (x1, y1); (x2, y2); (x3, y3); (x4, y4); ... |]
 let xy = [| (5., 2.); (12., 8.); (18., 18.); (-23., -20.); (45., 28.) |]
 
 // To get the population covariance between x and y:
 xy |> Array.covPopulationOfPairs // evaluates to 347.92

dropNaN array

Full Usage: dropNaN array

Parameters:
    array : float array -

Returns: float[]

Filters out all nan values from an array

array : float array

Returns: float[]

Example

median items

Full Usage: median items

Parameters:
    items : ^T array -

Returns: ^T
Modifiers: inline
Type parameters: ^T, ^b

Computes the sample median

items : ^T array

Returns: ^T

Example

medianAbsoluteDev data

Full Usage: medianAbsoluteDev data

Parameters:
    data : float[] -

Returns: float

Median absolute deviation (MAD)

data : float[]

Returns: float

Example

partitionSortInPlace left right items

Full Usage: partitionSortInPlace left right items

Parameters:
    left : int -
    right : int -
    items : 'T array -

Returns: int
Modifiers: inline
Type parameters: 'T

Arranges the items between the left and right border, that all items left of the pivot element are smaller and bigger on the right.
Function works in place and returns the index of the pivote element (using Lomuto's partitioning algorithm)

left : int

right : int

items : 'T array

Returns: int

Example

quickSelect k items

Full Usage: quickSelect k items

Parameters:
    k : int -
    items : 'T array -

Returns: 'T
Modifiers: inline
Type parameters: 'T

Finds the kth smallest element in an unordered array (note that k is ONE-based)

k : int

items : 'T array

Returns: 'T

Example

quickSelectInPlace k items

Full Usage: quickSelectInPlace k items

Parameters:
    k : int -
    items : 'T array -

Returns: 'T
Modifiers: inline
Type parameters: 'T

Finds the kth smallest element in an unordered array (note that k is ONE-based)
Works in place and can change the order of the elements in the input array

k : int

items : 'T array

Returns: 'T

Example

quickSelectInPlaceWith left right k arr

Full Usage: quickSelectInPlaceWith left right k arr

Parameters:
    left : int -
    right : int -
    k : int -
    arr : 'T array -

Returns: 'T
Modifiers: inline
Type parameters: 'T

Finds the kth smallest element in an unordered array (note that k is ONE-based)
Works in place and can change the order of the elements in the input array

left : int

right : int

k : int

arr : 'T array

Returns: 'T

Example

range a

Full Usage: range a

Parameters:
    a : 'a array

Returns: Interval<'a>
a : 'a array
Returns: Interval<'a>

sampleWithOutReplacement rnd source k

Full Usage: sampleWithOutReplacement rnd source k

Parameters:
    rnd : Random -
    source : 'b array -
    k : int -

Returns: 'b[]

Samples from an array of obj without replacement (without putting back)

Implementation according to: http://krkadev.blogspot.de/2010/08/random-numbers-without-repetition.html

rnd : Random

source : 'b array

k : int

Returns: 'b[]

Example

sampleWithReplacement rnd source k

Full Usage: sampleWithReplacement rnd source k

Parameters:
    rnd : Random -
    source : 'a array -
    k : int -

Returns: 'a[]

Samples from an array of obj wit replacement (with putting back)

When we sample with replacement, the two sample values are independent.Practically, this means that what we get on the first one doesn't affect what we get on the second.Mathematically, this means that the covariance between the two is zero

rnd : Random

source : 'a array

k : int

Returns: 'a[]

Example

seqInit from tto length

Full Usage: seqInit from tto length

Parameters:
    from : float -
    tto : float -
    length : int -

Returns: float[]

Generates array sequence (like R! seq.int)

from : float

tto : float

length : int

Returns: float[]

Example

shuffleFisherYates arr

Full Usage: shuffleFisherYates arr

Parameters:
    arr : 'b[] -

Returns: 'b[]

Shuffels the input array (method: Fisher-Yates)

arr : 'b[]

Returns: 'b[]

Example

shuffleFisherYatesInPlace arr

Full Usage: shuffleFisherYatesInPlace arr

Parameters:
    arr : 'a[] -

Returns: 'a[]

Shuffels the input array (method: Fisher-Yates) in place

arr : 'a[]

Returns: 'a[]

Example

sort2InPlaceByKeys from count keys items

Full Usage: sort2InPlaceByKeys from count keys items

Parameters:
    from : int
    count : int
    keys : 'T array
    items : 'T array

from : int
count : int
keys : 'T array
items : 'T array

swapInPlace left right items

Full Usage: swapInPlace left right items

Parameters:
    left : int
    right : int
    items : 'T array

Modifiers: inline
Type parameters: 'T
left : int
right : int
items : 'T array

varOf mean items

Full Usage: varOf mean items

Parameters:
    mean : float -
    items : float array -

Returns: float
Modifiers: inline

Computes the Variance N-1

mean : float

items : float array

Returns: float

Example

weightedMean weights items

Full Usage: weightedMean weights items

Parameters:
    weights : ^T array -
    items : ^T array -

Returns: ^d
Modifiers: inline
Type parameters: ^T, ^c, ^d

Computes the Weighted Mean

weights : ^T array

items : ^T array

Returns: ^d

Example

weightedVariance mean weights items

Full Usage: weightedVariance mean weights items

Parameters:
    mean : ^c -
    weights : ^T array -
    items : ^T array -

Returns: ^h
Modifiers: inline
Type parameters: ^c, ^T, ^d, ^e, ^f, ^g, ^h

Computes the Weighted Variance

mean : ^c

weights : ^T array

items : ^T array

Returns: ^h

Example