Skip to content

Commit

Permalink
Add docs distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
muehlhaus committed May 5, 2017
1 parent 3750aa5 commit 36b7da5
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 44 deletions.
2 changes: 2 additions & 0 deletions FSharp.Stats.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 64 additions & 0 deletions docs/content/Distributions.fsx
Original file line number Diff line number Diff line change
@@ -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


19 changes: 19 additions & 0 deletions docs/content/Testing.fsx
Original file line number Diff line number Diff line change
@@ -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
56 changes: 13 additions & 43 deletions docs/content/index.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,33 @@

(**
FSharp.Stats
======================
============
Documentation
FSharp.Stats aims to be a user-friendly library for numerical and statistical computation written in F#.
<div class="row">
<div class="span1"></div>
<div class="span6">
<div class="well well-small" id="nuget">
The FSharp.Stats library can be <a href="https://nuget.org/packages/FSharp.Stats">installed from NuGet</a>:
<pre>PM> Install-Package FSharp.Stats</pre>
</div>
</div>
<div class="span1"></div>
</div>
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
*)
1 change: 0 additions & 1 deletion src/FSharp.Stats/Distributions/Continuous.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 36b7da5

Please sign in to comment.