From 36b7da514c4035ec7073e05a81e20c4f89c06214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=BChlhaus?= Date: Fri, 5 May 2017 17:14:10 +0200 Subject: [PATCH] Add docs distributions --- FSharp.Stats.sln | 2 + docs/content/Distributions.fsx | 64 ++++++++++++++++++++ docs/content/Testing.fsx | 19 ++++++ docs/content/index.fsx | 56 ++++------------- src/FSharp.Stats/Distributions/Continuous.fs | 1 - 5 files changed, 98 insertions(+), 44 deletions(-) create mode 100644 docs/content/Distributions.fsx create mode 100644 docs/content/Testing.fsx diff --git a/FSharp.Stats.sln b/FSharp.Stats.sln index 55388b4b..0ae8d227 100644 --- a/FSharp.Stats.sln +++ b/FSharp.Stats.sln @@ -28,10 +28,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{83F16175 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "content", "content", "{8E6D5255-776D-4B61-85F9-73C37AA1FB9A}" ProjectSection(SolutionItems) = preProject + docs\content\Distributions.fsx = docs\content\Distributions.fsx docs\content\index.fsx = docs\content\index.fsx docs\content\Matrix_Vector.fsx = docs\content\Matrix_Vector.fsx docs\content\Optimization.fsx = docs\content\Optimization.fsx docs\content\SpecialFunctions.fsx = docs\content\SpecialFunctions.fsx + docs\content\Testing.fsx = docs\content\Testing.fsx docs\content\tutorial.fsx = docs\content\tutorial.fsx EndProjectSection EndProject diff --git a/docs/content/Distributions.fsx b/docs/content/Distributions.fsx new file mode 100644 index 00000000..421b823d --- /dev/null +++ b/docs/content/Distributions.fsx @@ -0,0 +1,64 @@ +(*** hide ***) +// This block of code is omitted in the generated HTML documentation. Use +// it to define helpers that you do not want to show in the documentation. +#I "../../bin" +#r "../../packages/build/FSharp.Plotly/lib/net40/Fsharp.Plotly.dll" +open FSharp.Plotly +(** +Probability Distributions +========================= + +FSharp.Stats a provides a wide range of probability distributions. Given the +distribution parameters they can be used to investigate their statistical properties +or to sample non-uniform random numbers. + +*) +#r "FSharp.Stats.dll" +open FSharp.Stats +open FSharp.Stats.Distributions + + +// https://en.wikipedia.org/wiki/Student%27s_t-distribution +let tmp = + Seq.init 100 + (fun _ -> Continuous.StudentT.Sample 1. 1. 1.) + |> Empirical.create 0.1 + + + + +let studentTParams = [(1.,1.,1.);(1.,1.,2.);(1.,1.,5.);] +let xStudentT = [-4. ..0.1.. 4.] + +let pdfStudentT mu tau dof = + xStudentT + |> List.map (Continuous.StudentT.PDF mu tau dof) + |> List.zip xStudentT + +studentTParams +|> List.map (fun (mu,tau,dof) -> Chart.Spline(pdfStudentT mu tau dof,Name=sprintf "mu=%.1f tau=%.1f dof=%.1f" mu tau dof,ShowMarkers=false)) +(*** define-output:PdfStudentT ***) +|> Chart.Combine +|> Chart.withX_AxisStyle("x",MinMax=(-4.,4.)) +|> Chart.withY_AxisStyle("P(x)",MinMax=(0.,0.4)) +|> Chart.withSize (500., 450.) +(*** include-it:PdfStudentT ***) +|> Chart.Show + + +let cdfStudentT mu tau dof = + xStudentT + |> List.map (Continuous.StudentT.CDF mu tau dof) + |> List.zip xStudentT + +studentTParams +|> List.map (fun (mu,tau,dof) -> Chart.Spline(cdfStudentT mu tau dof,Name=sprintf "mu=%.1f tau=%.1f dof=%.1f" mu tau dof,ShowMarkers=false)) +(*** define-output:CdfStudentT ***) +|> Chart.Combine +|> Chart.withX_AxisStyle("x",MinMax=(-4.,4.)) +|> Chart.withY_AxisStyle("P(x)",MinMax=(0.,1.)) +|> Chart.withSize (500., 450.) +(*** include-it:CdfStudentT ***) +|> Chart.Show + + diff --git a/docs/content/Testing.fsx b/docs/content/Testing.fsx new file mode 100644 index 00000000..1ebca753 --- /dev/null +++ b/docs/content/Testing.fsx @@ -0,0 +1,19 @@ +(*** hide ***) +// This block of code is omitted in the generated HTML documentation. Use +// it to define helpers that you do not want to show in the documentation. +#I "../../bin" +#r "../../packages/build/FSharp.Plotly/lib/net40/Fsharp.Plotly.dll" +open FSharp.Plotly +(** +Statistical testing +=================== + +FSharp.Stats a provides +A hypothesis test is a statistical test that is used to determine whether there is enough evidence +in a sample of data to infer that a certain condition is true for the entire population. +A hypothesis test examines two opposing hypotheses about a population: the null hypothesis and the alternative hypothesis. + + +*) +#r "FSharp.Stats.dll" +open FSharp.Stats diff --git a/docs/content/index.fsx b/docs/content/index.fsx index 681e8dc2..29a47765 100644 --- a/docs/content/index.fsx +++ b/docs/content/index.fsx @@ -5,63 +5,33 @@ (** FSharp.Stats -====================== +============ -Documentation +FSharp.Stats aims to be a user-friendly library for numerical and statistical computation written in F#. -
-
-
-
- The FSharp.Stats library can be installed from NuGet: -
PM> Install-Package FSharp.Stats
-
-
-
-
Example ------- -This example demonstrates using a function defined in this sample library. +This example demonstrates using a function defined in FSharp.Stats library. *) #r "FSharp.Stats.dll" open FSharp.Stats -printfn "hello = %i" <| Library.hello 0 -(** -Some more info - -Samples & documentation ------------------------ +// let A = +// matrix [ [ 1.0; 7.0; 2.0 ] +// [ 1.0; 3.0; 1.0 ] +// [ 2.0; 9.0; 1.0 ] ] -The library comes with comprehensible documentation. -It can include tutorials automatically generated from `*.fsx` files in [the content folder][content]. -The API reference is automatically generated from Markdown comments in the library implementation. +// let B = +// matrix [ [ 10.0; 70.0; 20.0 ] +// [ 10.0; 30.0; 10.0 ] +// [ 20.0; 90.0; 10.0 ] ] - * [Tutorial](tutorial.html) contains a further explanation of this sample library. - * [API Reference](reference/index.html) contains automatically generated documentation for all types, modules - and functions in the library. This includes additional brief samples on using most of the - functions. - -Contributing and copyright --------------------------- +// let v = +// vector [|2.0; 20.0; 1.|] -The project is hosted on [GitHub][gh] where you can [report issues][issues], fork -the project and submit pull requests. If you're adding a new public API, please also -consider adding [samples][content] that can be turned into a documentation. You might -also want to read the [library design notes][readme] to understand how it works. -The library is available under Public Domain license, which allows modification and -redistribution for both commercial and non-commercial purposes. For more information see the -[License file][license] in the GitHub repository. - - [content]: https://github.com/fsprojects/FSharp.Stats/tree/master/docs/content - [gh]: https://github.com/fsprojects/FSharp.Stats - [issues]: https://github.com/fsprojects/FSharp.Stats/issues - [readme]: https://github.com/fsprojects/FSharp.Stats/blob/master/README.md - [license]: https://github.com/fsprojects/FSharp.Stats/blob/master/LICENSE.txt -*) diff --git a/src/FSharp.Stats/Distributions/Continuous.fs b/src/FSharp.Stats/Distributions/Continuous.fs index 2b5e49d8..48b413a5 100644 --- a/src/FSharp.Stats/Distributions/Continuous.fs +++ b/src/FSharp.Stats/Distributions/Continuous.fs @@ -545,7 +545,6 @@ module Continuous = /// Computes the cumulative distribution function. static member CDF mu tau dof x = studentTCheckParam mu tau dof - failwith "Not implemented yet." let k = (x - mu) / tau let h = dof / (dof + (k * k)) let ib = 0.5 * SpecialFunctions.Beta.lowerIncomplete (dof/2.0) 0.5 h