Browse Source

Fsharp functions should use 'Func' instead of just 'F' as suffix

pull/197/head
Christoph Ruegg 13 years ago
parent
commit
ed940a85b2
  1. 4
      docs/content/DescriptiveStatistics.fsx
  2. 6
      src/FSharp/Fit.fs
  3. 16
      src/FSharp/Statistics.fs
  4. 4
      src/FSharpUnitTests/FitTests.fs

4
docs/content/DescriptiveStatistics.fsx

@ -205,7 +205,7 @@ Statistics.OrderStatistic(whiteNoise, 1)
Statistics.OrderStatistic(whiteNoise, 1000)
// [fsi:val it : float = 16.65183566]
let os = Statistics.orderStatisticF whiteNoise
let os = Statistics.orderStatisticFunc whiteNoise
os 250
// [fsi:val it : float = 8.645491746]
os 500
@ -424,7 +424,7 @@ Generate.LinearSpacedMap(20, start=3.0, stop=17.0, map=ecdf)
// [fsi: [|0.0; 0.001; 0.002; 0.005; 0.022; 0.05; 0.094; 0.172; 0.278; 0.423; 0.555; ]
// [fsi: 0.705; 0.843; 0.921; 0.944; 0.983; 0.992; 0.997; 0.999; 1.0|] ]
let eicdf = Statistics.empiricalInvCdfF whiteNoise
let eicdf = Statistics.empiricalInvCDFFunc whiteNoise
[ for tau in 0.0..0.05..1.0 -> eicdf tau ]
// [fsi:val it : float [] =]
// [fsi: [3.633070184; 6.682142043; 7.520000817; 8.040513497; 8.347587493; ]

6
src/FSharp/Fit.fs

@ -45,7 +45,7 @@ module Fit =
/// Least-Squares fitting the points (x,y) to a line y : x -> a+b*x,
/// returning a function y' for the best fitting line.
let lineF x y = Fit.LineFunc(x,y) |> tofs
let lineFunc x y = Fit.LineFunc(x,y) |> tofs
/// Least-Squares fitting the points (x,y) to a k-order polynomial y : x -> p0 + p1*x + p2*x^2 + ... + pk*x^k,
@ -54,7 +54,7 @@ module Fit =
/// Least-Squares fitting the points (x,y) to a k-order polynomial y : x -> p0 + p1*x + p2*x^2 + ... + pk*x^k,
/// returning a function y' for the best fitting polynomial.
let polynomialF order x y = Fit.PolynomialFunc(x,y,order) |> tofs
let polynomialFunc order x y = Fit.PolynomialFunc(x,y,order) |> tofs
/// Least-Squares fitting the points (x,y) to an arbitrary linear combination y : x -> p0*f0(x) + p1*f1(x) + ... + pk*fk(x),
@ -68,6 +68,6 @@ module Fit =
/// Least-Squares fitting the points (x,y) to an arbitrary linear combination y : x -> p0*f0(x) + p1*f1(x) + ... + pk*fk(x),
/// returning a function y' for the best fitting combination.
let linearF functions x y =
let linearFunc functions x y =
let parts = linear functions x y |> List.zip functions
in fun z -> parts |> List.fold (fun s (f,p) -> s+p*(f z)) 0.0

16
src/FSharp/Statistics.fs

@ -37,11 +37,11 @@ module Statistics =
let private tofs (f:Func<_,_>) = fun a -> f.Invoke(a)
let quantileF (data : float seq) = Statistics.QuantileFunc(data) |> tofs
let quantileCustomF (data : float seq) definition = Statistics.QuantileCustomFunc(data, definition) |> tofs
let percentileF (data : float seq) = Statistics.PercentileFunc(data) |> tofs
let orderStatisticF (data : float seq) = Statistics.OrderStatisticFunc(data) |> tofs
let quantileRankF (data : float seq) = Statistics.QuantileRankFunc(data) |> tofs
let quantileRankCustomF (data : float seq) definition = Statistics.QuantileRankFunc(data, definition) |> tofs
let empiricalCdfF (data : float seq) = Statistics.EmpiricalCDFFunc(data) |> tofs
let empiricalInvCdfF (data : float seq) = Statistics.EmpiricalInvCDFFunc(data) |> tofs
let quantileFunc (data : float seq) = Statistics.QuantileFunc(data) |> tofs
let quantileCustomFunc (data : float seq) definition = Statistics.QuantileCustomFunc(data, definition) |> tofs
let percentileFunc (data : float seq) = Statistics.PercentileFunc(data) |> tofs
let orderStatisticFunc (data : float seq) = Statistics.OrderStatisticFunc(data) |> tofs
let quantileRankFunc (data : float seq) = Statistics.QuantileRankFunc(data) |> tofs
let quantileRankCustomFunc (data : float seq) definition = Statistics.QuantileRankFunc(data, definition) |> tofs
let empiricalCDFFunc (data : float seq) = Statistics.EmpiricalCDFFunc(data) |> tofs
let empiricalInvCDFFunc (data : float seq) = Statistics.EmpiricalInvCDFFunc(data) |> tofs

4
src/FSharpUnitTests/FitTests.fs

@ -18,7 +18,7 @@ module FitTests =
a |> should (equalWithin 1.0e-12) 4.0
b |> should (equalWithin 1.0e-12) -1.5
let fres = Fit.lineF x y
let fres = Fit.lineFunc x y
in x |> Array.iter (fun x -> fres x |> should (equalWithin 1.0e-12) (f x))
[<Test>]
@ -34,5 +34,5 @@ module FitTests =
(x,y) ||> Fit.linear [(fun _ -> 1.0); (Math.Sin); (Math.Cos) ]
|> should (equalWithin 1.0e-4) [ -0.287476; 4.02159; -1.46962 ]
let fres = Fit.linearF [(fun z -> 1.0); (fun z -> Math.Sin(z)); (fun z -> Math.Cos(z))] x y
let fres = Fit.linearFunc [(fun z -> 1.0); (fun z -> Math.Sin(z)); (fun z -> Math.Cos(z))] x y
in x |> Array.iter (fun x -> fres x |> should (equalWithin 1.0e-4) (4.02159*Math.Sin(x) - 1.46962*Math.Cos(x) - 0.287476))

Loading…
Cancel
Save