Statistical functions

Some basic statistics functions in F#, including erfc, erfcinv, normcdf, normpdf, norminv, additiveCorrection, multiplicativeCorrection, a Box-Mueller RandomSampler and a unitized type for a Gaussian distribution. Based on Ralf Herbrich's samples at http://blogs.technet.com/b/apg/archive/2008/04/05/trueskill-through-time.aspx

Copy Source
Copy Link
Tools:
  1: 
  2: /// Some basic statistics functions in F#, including erfc, erfcinv, normcdf, normpdf, 
  3: /// norminv, additiveCorrection, multiplicativeCorrection, a Box-Mueller RandomSampler
  4: /// and a unitized type for a Gaussian distribution. 
  5: ///
  6: /// Based on Ralf Herbrich's samples at http://blogs.technet.com/b/apg/archive/2008/04/05/trueskill-through-time.aspx
  7: 
  8: module Gaussians = 
  9: 
 10:     open System
 11:     
 12:     /// Compute the square of a unitized number
 13:     let sqr (x:float<'u>) = x * x 
 14: 
 15:     /// Computes the complementary error function. This function is defined 
 16:     /// by 2/sqrt(pi) * integral from x to infinity of exp (-t^2) dt
 17:     let erfc x =
 18:         if (Double.IsNegativeInfinity x) then 2.0
 19:         elif (Double.IsPositiveInfinity x) then 0.0
 20:         else
 21:             let z = abs x
 22:             let t = 1.0 / (1.0 + 0.5 * z) 
 23:             let res = t * exp (-z * z - 1.26551223 + t * (1.00002368 + t * (0.37409196 + t * (0.09678418 + t * (-0.18628806 + t * (0.27886807 + t * (-1.13520398 + t * (1.48851587 + t * (-0.82215223 + t * 0.17087277))))))))) 
 24:             if (x >= 0.0) then res else 2.0 - res
 25: 
 26:     /// Computes the inverse of the complementary error function
 27:     let erfcinv y = 
 28:         if (y < 0.0 || y > 2.0) then
 29:             failwith "Inverse complementary function not defined outside [0,2]."
 30:         elif y = 0.0 then Double.PositiveInfinity
 31:         elif y = 2.0 then Double.NegativeInfinity
 32:         else 
 33:             let x = 
 34:                 if (y >= 0.0485 && y <= 1.9515) then
 35:                     let q = y - 1.0 
 36:                     let r = q * q 
 37:                     (((((0.01370600482778535*r - 0.3051415712357203)*r + 1.524304069216834)*r - 3.057303267970988)*r + 2.710410832036097)*r - 0.8862269264526915) * q /
 38:                     (((((-0.05319931523264068*r + 0.6311946752267222)*r - 2.432796560310728)*r + 4.175081992982483)*r - 3.320170388221430)*r + 1.0)
 39:                 else if (y < 0.0485) then
 40:                     let q = sqrt (-2.0 * log (y / 2.0)) 
 41:                     (((((0.005504751339936943*q + 0.2279687217114118)*q + 1.697592457770869)*q + 1.802933168781950)*q + -3.093354679843504)*q - 2.077595676404383) / 
 42:                     ((((0.007784695709041462*q + 0.3224671290700398)*q + 2.445134137142996)*q + 3.754408661907416)*q + 1.0)
 43:                 else if (y > 1.9515) then
 44:                     let q = sqrt (-2.0 * log (1.0 - y / 2.0)) 
 45:                     (-(((((0.005504751339936943*q + 0.2279687217114118)*q + 1.697592457770869)*q + 1.802933168781950)*q + -3.093354679843504)*q - 2.077595676404383) / 
 46:                      ((((0.007784695709041462*q + 0.3224671290700398)*q + 2.445134137142996)*q + 3.754408661907416)*q + 1.0))
 47:                 else 0.0
 48:             let u = (erfc x - y) / (-2.0 / sqrt Math.PI * exp (-x * x)) 
 49:             x - u / (1.0 + x * u)
 50: 
 51:     /// Computes the cummulative Gaussian distribution at a specified point of interest
 52:     let normcdf t = 
 53:         let sqrt2 = 1.4142135623730951 
 54:         (erfc (-t / sqrt2)) / 2.0
 55: 
 56:     /// Computes the Gaussian density at a specified point of interest
 57:     let normpdf (t:float) = 
 58:         let invsqrt2pi = 0.398942280401433
 59:         invsqrt2pi * exp (- (t * t / 2.0))
 60:         
 61:     /// Computes the inverse of the cummulative Gaussian distribution (quantile function) at a specified point of interest
 62:     let norminv p = 
 63:         let sqrt2 = 1.4142135623730951 
 64:         (-sqrt2 * erfcinv (2.0 * p))
 65: 
 66:     /// Computes the additive correction (v) of a single-sided truncated Gaussian with unit variance
 67:     let additiveCorrection t = 
 68:         match normcdf t with
 69:         | denom when denom < 2.222758749e-162   -> -t
 70:         | denom                                 -> (normpdf t) / denom                             
 71: 
 72:     /// Computes the multiplicative correction (w) of a single-sided truncated Gaussian with unit variance
 73:     let multiplicativeCorrection t =
 74:         match normcdf t with
 75:         | denom when denom < 2.222758749e-162   -> if (t < 0.0) then 1.0 else 0.0
 76:         | denom                                 -> let vt = additiveCorrection t in vt * (vt + t)
 77: 
 78:     /// Computes the additive correction of a double-sided truncated Gaussian with unit variance
 79:     let additiveCorrection0 t epsilon = 
 80:         let v = abs t
 81:         match normcdf (epsilon - v) - normcdf (-epsilon - v) with
 82:         | denom when denom < 2.222758749e-162   -> if t < 0.0 then -t-epsilon else -t+epsilon
 83:         | denom                                 -> let num = normpdf (-epsilon-v) - normpdf (epsilon-v) in if t < 0.0 then -num/denom else num/denom
 84: 
 85:     /// Computes the multiplicative correction of a double-sided truncated Gaussian with unit variance
 86:     let multiplicativeCorrection0 t epsilon =
 87:         let v = abs t
 88:         match normcdf (epsilon - v) - normcdf (-epsilon - v) with
 89:         | denom when denom < 2.222758749e-162   -> 1.0
 90:         | denom                                 -> let vt = additiveCorrection0 v epsilon in vt*vt + ((epsilon-v) * normpdf (epsilon-v) - (-epsilon-v) * normpdf (-epsilon-v))/denom
 91: 
 92: 
 93:     /// Computes a random sampler using the Box-Mueller formula
 94:     type RandomSampler(seed:int) =
 95:         /// The internal state of the sampler
 96:         let sampler = System.Random (seed)
 97:         let mutable buffered = false
 98:         let mutable buffer = 0.0
 99:         // Generate a new pair of standard Gaussian distributed variables using the Box-Mueller algorithm.
100:         let rec nextSample () = 
101:             let u = sampler.NextDouble () 
102:             let v = sampler.NextDouble () 
103:             if (u = 0.0 || v = 0.0) then
104:                 nextSample ()
105:             else
106:                 let x = sqrt (-2.0 * log (u)) 
107:                 (x * sin (2.0 * Math.PI * v), x * cos (2.0 * Math.PI * v)) 
108: 
109:         /// Generate a new normal sample distributed according to the standard Gaussian distribution
110:         member __.Sample () =
111: 
112:             if buffered then
113:                 buffered <- not buffered
114:                 buffer
115:             else
116:                 let (x,y) = nextSample () 
117:                 buffered <- not buffered
118:                 buffer <- y
119:                 x    
120: 
121:     let globalSampler = RandomSampler(42)
122: 
123: 
124:     /// A unitized Gaussian distribution based on float numbers (struct type for memory efficency) 
125:     /// in exponential parameterisation. 
126:     [<Struct>]
127:     type Gaussian<[<Measure>] 'u>(precisionMean:float<1/'u>,precision:float<1/'u^2>) = 
128:         static member FromMeanAndVariance(mean:float<'u>, variance:float<'u^2>) = 
129:             Gaussian<'u>(mean/variance, 1.0 / variance)
130:         static member FromMeanAndDeviation(mean:float<'u>, standardDeviation:float<'u>) = 
131:             let sigma = standardDeviation*standardDeviation
132:             Gaussian<'u>.FromMeanAndVariance(mean, sigma)
133:         /// Precision times the mean of the Gaussian
134:         member __.PrecisionMean  = precisionMean
135:         /// Precision of the Gaussian
136:         member __.Precision = precision
137:         /// Mean of the Gaussian
138:         member this.Mu = precisionMean / precision
139:         /// Mean of the Gaussian
140:         member this.Mean = this.Mu
141:         /// Variance of the Gaussian
142:         member this.Variance = 1.0 / precision
143:         /// Standard deviation of the Gaussian
144:         member this.StandardDeviation = sqrt this.Variance
145:         /// Standard deviation of the Gaussian
146:         member this.Sigma = this.StandardDeviation
147: 
148:         /// Multiplies two Gaussians  
149:         static member (*) (a:Gaussian<'u>,b:Gaussian<'u>) = 
150:             Gaussian<'u> (a.PrecisionMean + b.PrecisionMean, a.Precision + b.Precision)
151:         /// Divides two Gaussians
152:         static member (/) (a:Gaussian<'u>,b:Gaussian<'u>) =
153:             Gaussian<'u> (a.PrecisionMean - b.PrecisionMean, a.Precision - b.Precision)
154:         /// Computes the absolute difference between two Gaussians
155:         static member AbsoluteDifference (a:Gaussian<'u>) (b:Gaussian<'u>) = 
156:             max (abs (a.PrecisionMean - b.PrecisionMean)) (sqrt (abs (a.Precision - b.Precision)))
157:             //max (abs (a.PrecisionMean - b.PrecisionMean)) (abs (a.Precision - b.Precision))
158:         /// Computes the absolute difference between two Gaussians
159:         static member (-) (a:Gaussian<'u>,b:Gaussian<'u>) = Gaussian<'u>.AbsoluteDifference a b
160:         /// Used for string serialisation
161:         override this.ToString () = (string this.Mu) + ";" + (string this.Variance) 
162:         /// Generate a sample of this Gaussian using the global sampler
163:         member this.Sample() = this.Mean + this.Sigma * globalSampler.Sample()
164:         /// Computes the log-normalisation factor when two normalised Gaussians gets multiplied
165:         static member LogProductNormalisation (a:Gaussian<'u>,b:Gaussian<'u>) =
166:             if a.Precision = 0.0<_> then 
167:                 0.0
168:             elif b.Precision = 0.0<_> then
169:                 0.0
170:             else
171:                 let varSum = a.Variance + b.Variance
172:                 let muDiff = a.Mean - b.Mean
173:                 -0.91893853320467267 - log(float varSum)/2.0 - muDiff*muDiff/(2.0 * varSum)
174:         /// Computes the log-normalisation factor when two normalised Gaussians gets divided
175:         static member LogRatioNormalisation (a:Gaussian<'u>,b:Gaussian<'u>) =
176:             if a.Precision = 0.0<_> then 
177:                 0.0
178:             elif b.Precision = 0.0<_> then
179:                 0.0
180:             else
181:                 let v2 = b.Variance
182:                 let varDiff = v2 - a.Variance
183:                 let muDiff = a.Mean - b.Mean
184:                 if varDiff = 0.0<_> then
185:                     0.0
186:                 else
187:                     log(float v2) + 0.91893853320467267 - log(float varDiff)/2.0 + muDiff*muDiff/(2.0 * varDiff)
188: 
189: #if INTERACTIVE
190: module Tests = 
191:     open Gaussians
192:         
193:     for x in [ 0.0; 0.000001; 0.1; 1.0; 10.0 ] do 
194:         printfn "erfc %g = %g" x (erfc x)
195: 
196:         printfn "erfcinv (erfc %g) - %g" x (abs (Gaussians.erfcinv (Gaussians.erfc x) - x))
197: 
198: 
199:     //#endif
200: 
201:     let x = RandomSampler 10
202:     let samples1 = [ for i in 0 .. 10000 -> x.Sample() ]
203:     // the mean is approximately 1.0:
204:     let mean1 = samples1 |> Seq.average
205:     // the variance is approximately 1.0:
206:     let stddev1 = samples1 |> Seq.averageBy (fun x -> x*x) |> sqrt
207: 
208:     // A Gaussian of scores in a test centered on 50.0, standard deviation of 10.0
209:     [<Measure>] type score 
210:     let g = Gaussian<score>.FromMeanAndDeviation (mean=50.0<score>, standardDeviation=10.0<score>) 
211:     let scoreA = g.Sample()
212:     let scoreB = g.Sample()
213:     let samples2 = [ for i in 0 .. 10000 -> g.Sample() ] 
214:     let mean  = samples2 |> Seq.average
215:     let variance2 = samples2 |> Seq.averageBy (fun x -> sqr(mean - x))  
216:     let stddev2 = sqrt variance2
217: #endif
218: 
namespace System
val sqr : float<'u> -> float<'u ^ 2>

Full name: Snippet.Gaussians.sqr

Compute the square of a unitized number
val x : float<'u>

  type: float<'u>
  implements: IComparable
  implements: IConvertible
  implements: IFormattable
  implements: IComparable<float<'u>>
  implements: IEquatable<float<'u>>
  inherits: ValueType
Multiple items
val float : 'T -> float (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.float

--------------------

type float<'Measure> = float

Full name: Microsoft.FSharp.Core.float<_>

  type: float<'Measure>
  implements: IComparable
  implements: IConvertible
  implements: IFormattable
  implements: IComparable<float<'Measure>>
  implements: IEquatable<float<'Measure>>
  inherits: ValueType


--------------------

type float = Double

Full name: Microsoft.FSharp.Core.float

  type: float
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<float>
  implements: IEquatable<float>
  inherits: ValueType
val erfc : float -> float

Full name: Snippet.Gaussians.erfc

Computes the complementary error function. This function is defined
 by 2/sqrt(pi) * integral from x to infinity of exp (-t^2) dt

val x : float

  type: float
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<float>
  implements: IEquatable<float>
  inherits: ValueType
type Double =
  struct
    member CompareTo : obj -> int
    member CompareTo : float -> int
    member Equals : obj -> bool
    member Equals : float -> bool
    member GetHashCode : unit -> int
    member GetTypeCode : unit -> System.TypeCode
    member ToString : unit -> string
    member ToString : string -> string
    member ToString : System.IFormatProvider -> string
    member ToString : string * System.IFormatProvider -> string
    static val MinValue : float
    static val MaxValue : float
    static val Epsilon : float
    static val NegativeInfinity : float
    static val PositiveInfinity : float
    static val NaN : float
    static member IsInfinity : float -> bool
    static member IsNaN : float -> bool
    static member IsNegativeInfinity : float -> bool
    static member IsPositiveInfinity : float -> bool
    static member Parse : string -> float
    static member Parse : string * System.Globalization.NumberStyles -> float
    static member Parse : string * System.IFormatProvider -> float
    static member Parse : string * System.Globalization.NumberStyles * System.IFormatProvider -> float
    static member TryParse : string * float -> bool
    static member TryParse : string * System.Globalization.NumberStyles * System.IFormatProvider * float -> bool
  end

Full name: System.Double

  type: Double
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<float>
  implements: IEquatable<float>
  inherits: ValueType
Double.IsNegativeInfinity(d: float) : bool
Double.IsPositiveInfinity(d: float) : bool
val z : float

  type: float
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<float>
  implements: IEquatable<float>
  inherits: ValueType
val abs : 'T -> 'T (requires member Abs)

Full name: Microsoft.FSharp.Core.Operators.abs
val t : float

  type: float
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<float>
  implements: IEquatable<float>
  inherits: ValueType
val res : float

  type: float
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<float>
  implements: IEquatable<float>
  inherits: ValueType
val exp : 'T -> 'T (requires member Exp)

Full name: Microsoft.FSharp.Core.Operators.exp
val erfcinv : float -> float

Full name: Snippet.Gaussians.erfcinv

Computes the inverse of the complementary error function
val y : float

  type: float
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<float>
  implements: IEquatable<float>
  inherits: ValueType
val failwith : string -> 'T

Full name: Microsoft.FSharp.Core.Operators.failwith
field Double.PositiveInfinity = Infinity
field Double.NegativeInfinity = -Infinity
val q : float

  type: float
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<float>
  implements: IEquatable<float>
  inherits: ValueType
val r : float

  type: float
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<float>
  implements: IEquatable<float>
  inherits: ValueType
val sqrt : 'T -> 'U (requires member Sqrt)

Full name: Microsoft.FSharp.Core.Operators.sqrt
val log : 'T -> 'T (requires member Log)

Full name: Microsoft.FSharp.Core.Operators.log
val u : float

  type: float
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<float>
  implements: IEquatable<float>
  inherits: ValueType
type Math =
  class
    static val PI : float
    static val E : float
    static member Abs : System.SByte -> System.SByte
    static member Abs : int16 -> int16
    static member Abs : int -> int
    static member Abs : int64 -> int64
    static member Abs : float32 -> float32
    static member Abs : float -> float
    static member Abs : decimal -> decimal
    static member Acos : float -> float
    static member Asin : float -> float
    static member Atan : float -> float
    static member Atan2 : float * float -> float
    static member BigMul : int * int -> int64
    static member Ceiling : decimal -> decimal
    static member Ceiling : float -> float
    static member Cos : float -> float
    static member Cosh : float -> float
    static member DivRem : int * int * int -> int
    static member DivRem : int64 * int64 * int64 -> int64
    static member Exp : float -> float
    static member Floor : decimal -> decimal
    static member Floor : float -> float
    static member IEEERemainder : float * float -> float
    static member Log : float -> float
    static member Log : float * float -> float
    static member Log10 : float -> float
    static member Max : System.SByte * System.SByte -> System.SByte
    static member Max : System.Byte * System.Byte -> System.Byte
    static member Max : int16 * int16 -> int16
    static member Max : uint16 * uint16 -> uint16
    static member Max : int * int -> int
    static member Max : uint32 * uint32 -> uint32
    static member Max : int64 * int64 -> int64
    static member Max : uint64 * uint64 -> uint64
    static member Max : float32 * float32 -> float32
    static member Max : float * float -> float
    static member Max : decimal * decimal -> decimal
    static member Min : System.SByte * System.SByte -> System.SByte
    static member Min : System.Byte * System.Byte -> System.Byte
    static member Min : int16 * int16 -> int16
    static member Min : uint16 * uint16 -> uint16
    static member Min : int * int -> int
    static member Min : uint32 * uint32 -> uint32
    static member Min : int64 * int64 -> int64
    static member Min : uint64 * uint64 -> uint64
    static member Min : float32 * float32 -> float32
    static member Min : float * float -> float
    static member Min : decimal * decimal -> decimal
    static member Pow : float * float -> float
    static member Round : float -> float
    static member Round : decimal -> decimal
    static member Round : float * int -> float
    static member Round : float * System.MidpointRounding -> float
    static member Round : decimal * int -> decimal
    static member Round : decimal * System.MidpointRounding -> decimal
    static member Round : float * int * System.MidpointRounding -> float
    static member Round : decimal * int * System.MidpointRounding -> decimal
    static member Sign : System.SByte -> int
    static member Sign : int16 -> int
    static member Sign : int -> int
    static member Sign : int64 -> int
    static member Sign : float32 -> int
    static member Sign : float -> int
    static member Sign : decimal -> int
    static member Sin : float -> float
    static member Sinh : float -> float
    static member Sqrt : float -> float
    static member Tan : float -> float
    static member Tanh : float -> float
    static member Truncate : decimal -> decimal
    static member Truncate : float -> float
  end

Full name: System.Math
field Math.PI = 3.14159265359
val normcdf : float -> float

Full name: Snippet.Gaussians.normcdf

Computes the cummulative Gaussian distribution at a specified point of interest
val sqrt2 : float

  type: float
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<float>
  implements: IEquatable<float>
  inherits: ValueType
val normpdf : float -> float

Full name: Snippet.Gaussians.normpdf

Computes the Gaussian density at a specified point of interest
val invsqrt2pi : float

  type: float
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<float>
  implements: IEquatable<float>
  inherits: ValueType
val norminv : float -> float

Full name: Snippet.Gaussians.norminv

Computes the inverse of the cummulative Gaussian distribution (quantile function) at a specified point of interest
val p : float

  type: float
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<float>
  implements: IEquatable<float>
  inherits: ValueType
val additiveCorrection : float -> float

Full name: Snippet.Gaussians.additiveCorrection

Computes the additive correction (v) of a single-sided truncated Gaussian with unit variance
val denom : float

  type: float
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<float>
  implements: IEquatable<float>
  inherits: ValueType
val multiplicativeCorrection : float -> float

Full name: Snippet.Gaussians.multiplicativeCorrection

Computes the multiplicative correction (w) of a single-sided truncated Gaussian with unit variance
val vt : float

  type: float
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<float>
  implements: IEquatable<float>
  inherits: ValueType
val additiveCorrection0 : float -> float -> float

Full name: Snippet.Gaussians.additiveCorrection0

Computes the additive correction of a double-sided truncated Gaussian with unit variance
val epsilon : float

  type: float
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<float>
  implements: IEquatable<float>
  inherits: ValueType
val v : float

  type: float
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<float>
  implements: IEquatable<float>
  inherits: ValueType
val num : float

  type: float
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<float>
  implements: IEquatable<float>
  inherits: ValueType
val multiplicativeCorrection0 : float -> float -> float

Full name: Snippet.Gaussians.multiplicativeCorrection0

Computes the multiplicative correction of a double-sided truncated Gaussian with unit variance
type RandomSampler =
  class
    new : seed:int -> RandomSampler
    member Sample : unit -> float
  end

Full name: Snippet.Gaussians.RandomSampler

Computes a random sampler using the Box-Mueller formula
val seed : int

  type: int
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<int>
  implements: IEquatable<int>
  inherits: ValueType
Multiple items
val int : 'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------

type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>

  type: int<'Measure>
  implements: IComparable
  implements: IConvertible
  implements: IFormattable
  implements: IComparable<int<'Measure>>
  implements: IEquatable<int<'Measure>>
  inherits: ValueType


--------------------

type int = int32

Full name: Microsoft.FSharp.Core.int

  type: int
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<int>
  implements: IEquatable<int>
  inherits: ValueType
val sampler : Random

The internal state of the sampler
type Random =
  class
    new : unit -> System.Random
    new : int -> System.Random
    member Next : unit -> int
    member Next : int -> int
    member Next : int * int -> int
    member NextBytes : System.Byte [] -> unit
    member NextDouble : unit -> float
  end

Full name: System.Random
val mutable buffered : bool

  type: bool
  implements: IComparable
  implements: IConvertible
  implements: IComparable<bool>
  implements: IEquatable<bool>
  inherits: ValueType
val mutable buffer : float

  type: float
  implements: IComparable
  implements: IFormattable
  implements: IConvertible
  implements: IComparable<float>
  implements: IEquatable<float>
  inherits: ValueType
val nextSample : (unit -> float * float)
Random.NextDouble() : float
val sin : 'T -> 'T (requires member Sin)

Full name: Microsoft.FSharp.Core.Operators.sin
val cos : 'T -> 'T (requires member Cos)

Full name: Microsoft.FSharp.Core.Operators.cos
member RandomSampler.Sample : unit -> float

Full name: Snippet.Gaussians.RandomSampler.Sample

Generate a new normal sample distributed according to the standard Gaussian distribution
val not : bool -> bool

Full name: Microsoft.FSharp.Core.Operators.not
val globalSampler : RandomSampler

Full name: Snippet.Gaussians.globalSampler
type StructAttribute =
  class
    inherit Attribute
    new : unit -> StructAttribute
  end

Full name: Microsoft.FSharp.Core.StructAttribute

  type: StructAttribute
  implements: Runtime.InteropServices._Attribute
  inherits: Attribute
type Gaussian<'u> =
  struct
    new : precisionMean:float</'u> * precision:float</'u ^ 2> -> Gaussian<'u>
    member Sample : unit -> float<'u>
    override ToString : unit -> string
    member Mean : float<'u>
    member Mu : float<'u>
    member Precision : float</'u ^ 2>
    member PrecisionMean : float</'u>
    member Sigma : float<'u>
    member StandardDeviation : float<'u>
    member Variance : float<'u ^ 2>
    static member AbsoluteDifference : a:Gaussian<'u> -> b:Gaussian<'u> -> float</'u>
    static member FromMeanAndDeviation : mean:float<'u> * standardDeviation:float<'u> -> Gaussian<'u>
    static member FromMeanAndVariance : mean:float<'u> * variance:float<'u ^ 2> -> Gaussian<'u>
    static member LogProductNormalisation : a:Gaussian<'u> * b:Gaussian<'u> -> float
    static member LogRatioNormalisation : a:Gaussian<'u> * b:Gaussian<'u> -> float
    static member ( / ) : a:Gaussian<'u> * b:Gaussian<'u> -> Gaussian<'u>
    static member ( * ) : a:Gaussian<'u> * b:Gaussian<'u> -> Gaussian<'u>
    static member ( - ) : a:Gaussian<'u> * b:Gaussian<'u> -> float</'u>
  end

Full name: Snippet.Gaussians.Gaussian<_>

  type: Gaussian<'u>
  implements: IEquatable<Gaussian<'u>>
  implements: Collections.IStructuralEquatable
  implements: IComparable<Gaussian<'u>>
  implements: IComparable
  implements: Collections.IStructuralComparable
  inherits: ValueType


A unitized Gaussian distribution based on float numbers (struct type for memory efficency)
 in exponential parameterisation.

Multiple items
module Measure

from Microsoft.FSharp.Math

--------------------

type MeasureAttribute =
  class
    inherit Attribute
    new : unit -> MeasureAttribute
  end

Full name: Microsoft.FSharp.Core.MeasureAttribute

  type: MeasureAttribute
  implements: Runtime.InteropServices._Attribute
  inherits: Attribute
val precisionMean : float</'u>

  type: float</'u>
  implements: IComparable
  implements: IConvertible
  implements: IFormattable
  implements: IComparable<float</'u>>
  implements: IEquatable<float</'u>>
  inherits: ValueType
val precision : float</'u ^ 2>

  type: float</'u ^ 2>
  implements: IComparable
  implements: IConvertible
  implements: IFormattable
  implements: IComparable<float</'u ^ 2>>
  implements: IEquatable<float</'u ^ 2>>
  inherits: ValueType
static member Gaussian.FromMeanAndVariance : mean:float<'u> * variance:float<'u ^ 2> -> Gaussian<'u>

Full name: Snippet.Gaussians.Gaussian.FromMeanAndVariance
val mean : float<'u>

  type: float<'u>
  implements: IComparable
  implements: IConvertible
  implements: IFormattable
  implements: IComparable<float<'u>>
  implements: IEquatable<float<'u>>
  inherits: ValueType
val variance : float<'u ^ 2>

  type: float<'u ^ 2>
  implements: IComparable
  implements: IConvertible
  implements: IFormattable
  implements: IComparable<float<'u ^ 2>>
  implements: IEquatable<float<'u ^ 2>>
  inherits: ValueType
static member Gaussian.FromMeanAndDeviation : mean:float<'u> * standardDeviation:float<'u> -> Gaussian<'u>

Full name: Snippet.Gaussians.Gaussian.FromMeanAndDeviation
val standardDeviation : float<'u>

  type: float<'u>
  implements: IComparable
  implements: IConvertible
  implements: IFormattable
  implements: IComparable<float<'u>>
  implements: IEquatable<float<'u>>
  inherits: ValueType
val sigma : float<'u ^ 2>

  type: float<'u ^ 2>
  implements: IComparable
  implements: IConvertible
  implements: IFormattable
  implements: IComparable<float<'u ^ 2>>
  implements: IEquatable<float<'u ^ 2>>
  inherits: ValueType
member Gaussian.PrecisionMean : float</'u>

Full name: Snippet.Gaussians.Gaussian.PrecisionMean

Precision times the mean of the Gaussian
val __ : byref<Gaussian<'u>>
member Gaussian.Precision : float</'u ^ 2>

Full name: Snippet.Gaussians.Gaussian.Precision

Precision of the Gaussian
val this : byref<Gaussian<'u>>
member Gaussian.Mu : float<'u>

Full name: Snippet.Gaussians.Gaussian.Mu

Mean of the Gaussian
member Gaussian.Mean : float<'u>

Full name: Snippet.Gaussians.Gaussian.Mean

Mean of the Gaussian
property Gaussian.Mu: float<'u>

Mean of the Gaussian
member Gaussian.Variance : float<'u ^ 2>

Full name: Snippet.Gaussians.Gaussian.Variance

Variance of the Gaussian
member Gaussian.StandardDeviation : float<'u>

Full name: Snippet.Gaussians.Gaussian.StandardDeviation

Standard deviation of the Gaussian
member Gaussian.Sigma : float<'u>

Full name: Snippet.Gaussians.Gaussian.Sigma

Standard deviation of the Gaussian
val a : Gaussian<'u>

  type: Gaussian<'u>
  implements: IEquatable<Gaussian<'u>>
  implements: Collections.IStructuralEquatable
  implements: IComparable<Gaussian<'u>>
  implements: IComparable
  implements: Collections.IStructuralComparable
  inherits: ValueType
val b : Gaussian<'u>

  type: Gaussian<'u>
  implements: IEquatable<Gaussian<'u>>
  implements: Collections.IStructuralEquatable
  implements: IComparable<Gaussian<'u>>
  implements: IComparable
  implements: Collections.IStructuralComparable
  inherits: ValueType
property Gaussian.PrecisionMean: float</'u>

Precision times the mean of the Gaussian
property Gaussian.Precision: float</'u ^ 2>

Precision of the Gaussian
static member Gaussian.AbsoluteDifference : a:Gaussian<'u> -> b:Gaussian<'u> -> float</'u>

Full name: Snippet.Gaussians.Gaussian.AbsoluteDifference

Computes the absolute difference between two Gaussians
val max : 'T -> 'T -> 'T (requires comparison)

Full name: Microsoft.FSharp.Core.Operators.max
override Gaussian.ToString : unit -> string

Full name: Snippet.Gaussians.Gaussian.ToString

Used for string serialisation
Multiple items
val string : 'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------

type string = String

Full name: Microsoft.FSharp.Core.string

  type: string
  implements: IComparable
  implements: ICloneable
  implements: IConvertible
  implements: IComparable<string>
  implements: seq<char>
  implements: Collections.IEnumerable
  implements: IEquatable<string>
member Gaussian.Sample : unit -> float<'u>

Full name: Snippet.Gaussians.Gaussian.Sample

Generate a sample of this Gaussian using the global sampler
member RandomSampler.Sample : unit -> float

Generate a new normal sample distributed according to the standard Gaussian distribution
static member Gaussian.LogProductNormalisation : a:Gaussian<'u> * b:Gaussian<'u> -> float

Full name: Snippet.Gaussians.Gaussian.LogProductNormalisation

Computes the log-normalisation factor when two normalised Gaussians gets multiplied
val varSum : float<'u ^ 2>

  type: float<'u ^ 2>
  implements: IComparable
  implements: IConvertible
  implements: IFormattable
  implements: IComparable<float<'u ^ 2>>
  implements: IEquatable<float<'u ^ 2>>
  inherits: ValueType
property Gaussian.Variance: float<'u ^ 2>

Variance of the Gaussian
val muDiff : float<'u>

  type: float<'u>
  implements: IComparable
  implements: IConvertible
  implements: IFormattable
  implements: IComparable<float<'u>>
  implements: IEquatable<float<'u>>
  inherits: ValueType
property Gaussian.Mean: float<'u>

Mean of the Gaussian
static member Gaussian.LogRatioNormalisation : a:Gaussian<'u> * b:Gaussian<'u> -> float

Full name: Snippet.Gaussians.Gaussian.LogRatioNormalisation

Computes the log-normalisation factor when two normalised Gaussians gets divided
val v2 : float<'u ^ 2>

  type: float<'u ^ 2>
  implements: IComparable
  implements: IConvertible
  implements: IFormattable
  implements: IComparable<float<'u ^ 2>>
  implements: IEquatable<float<'u ^ 2>>
  inherits: ValueType
val varDiff : float<'u ^ 2>

  type: float<'u ^ 2>
  implements: IComparable
  implements: IConvertible
  implements: IFormattable
  implements: IComparable<float<'u ^ 2>>
  implements: IEquatable<float<'u ^ 2>>
  inherits: ValueType

More information

Link: http://fssnip.net/bD
Posted: 2 years ago
Author: Robert Herman (website)
Tags: Statistics, Gaussian, Normal, Distributions erfc, erfcinv, Sampling