-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathindex.fsx
More file actions
205 lines (142 loc) · 5.87 KB
/
index.fsx
File metadata and controls
205 lines (142 loc) · 5.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
(*** hide ***)
(*** condition: prepare ***)
#r "nuget: FSharpAux.Core, 2.0.0"
#r "nuget: FSharpAux, 2.0.0"
#r "nuget: FSharpAux.IO, 2.0.0"
#r "nuget: OptimizedPriorityQueue, 5.1.0"
#r "nuget: FsMath, 0.0.2"
#I "../src/FSharp.Stats/bin/Release/.net8.0/"
#r "FSharp.Stats.dll"
#r "nuget: Plotly.NET, 4.0.0"
open FsMath
Plotly.NET.Defaults.DefaultDisplayOptions <-
Plotly.NET.DisplayOptions.init (PlotlyJSReference = Plotly.NET.PlotlyJSReference.NoReference)
(*** condition: ipynb ***)
#if IPYNB
#r "nuget: Plotly.NET, 4.0.0"
#r "nuget: Plotly.NET.Interactive, 4.0.0"
#r "nuget: FSharp.Stats"
open Plotly.NET
#endif // IPYNB
(**
# FSharp.Stats
[](https://mybinder.org/v2/gh/fslaborg/FSharp.Stats/gh-pages?urlpath=/tree/home/jovyan/index.ipynb)
[]({{root}}{{fsdocs-source-basename}}.ipynb)
FSharp.Stats is a multipurpose project for statistical testing, linear algebra, machine learning, fitting and signal processing.
## Installation
**From Nuget.org:**
You can get all FSharp.Stats packages from nuget at https://www.nuget.org/packages/FSharp.Stats/.
**To build the binaries yourself:**
**Windows**:
- Install [.Net Core SDK](https://www.microsoft.com/net/download)
- navigate to project folder
- use the console command `./build.cmd`
**Linux(Ubuntu, using Mono)**:
- Install [.Net Core SDK](https://www.microsoft.com/net/download/linux-package-manager/ubuntu14-04/sdk-current)
- navigate to project folder
- make the script executable with `chmod +x ./build.sh`
- use the console command `./build.sh`
**Documentation**:
- While editing the documentation you can preview the documentation in your browser via `dotnet fsdocs watch --eval`
---
## Example
The following examples show how easy it is to start working with FSharp.Stats.
*)
(**
### Distributions
*)
open Plotly.NET
open FSharp.Stats
// initialize a normal distribution with mean 25 and standard deviation 0.1
let normalDistribution = Distributions.Continuous.Normal.Init 25. 0.1
// draw independently 30 times from the given distribution
let sample = Array.init 30 (fun _ -> normalDistribution.Sample())
(*** include-value:sample ***)
(**
### Basic descriptive statistics
*)
// calculate the mean of the given sample
let mean = Seq.mean sample
(*** include-value:mean ***)
// calculate the bessel corrected sample standard deviation of the given sample
let stDev = Seq.stDev sample
(*** include-value:stDev ***)
// calculate the coefficient of variation of the given sample
// Attention: CV is valid only if a hypothetical real zero value exists for the data.
let cv = Seq.cv sample
(*** include-value:cv ***)
(**
### Vectors, Matrices and linear algebra
*)
// create a vector
let vecB = vector [19.;11.;35.]
// create a matrix
let matA = matrix [[3.;4.;0.];[1.;2.;2.];[5.;0.;5.]]
(*** include-value:vecX ***)
(**
### Interpolation
*)
let xData = vector [|1. .. 10.|]
let yData = vector [|4.;7.;9.;12.;15.;17.;16.;23.;5.;30.|]
// get coefficients of interpolating polynomial
let interpolatingCoefficients =
Interpolation.Polynomial.interpolate xData yData
// get fitting function of interpolating polynomial
let interpolFitFunc =
Interpolation.Polynomial.predict interpolatingCoefficients
(*** hide ***)
// create line chart of interpolating polynomial
let interpolChart =
[1. .. 0.1 .. 10.]
|> List.map (fun x -> x,interpolFitFunc x)
|> fun data -> Chart.Line(data,Name="interpol polynomial")
(**
### Regression
*)
// get coefficients of 3rd order regression polynomial
let regressionCoefficients =
Fitting.LinearRegression.fit(xData,yData,FittingMethod=Fitting.Method.Polynomial 3)
// get fitting function of 3rd order regression polynomial
let regressionPredictionFunc: float -> float =
Fitting.LinearRegression.predict regressionCoefficients
(*** hide ***)
// create line chart of regression polynomial
let regressionChart =
[1. .. 0.1 .. 10.]
|> List.map (fun x -> x,regressionPredictionFunc x)
|> fun data -> Chart.Line(data,Name="regression polynomial")
let combChart =
let rawChart = Chart.Point(xData,yData)
[rawChart;interpolChart;regressionChart]
|> Chart.combine
|> Chart.withTemplate ChartTemplates.lightMirrored
(**
The resulting interpolating and regression polynomials are plotted below using [Plotly.NET](https://github.com/plotly/Plotly.NET).
*)
(***hide***)
combChart |> GenericChart.toChartHTML
(***include-it-raw***)
(**
Samples & documentation
-----------------------
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.
* [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
--------------------------
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/fslaborg/FSharp.Stats/tree/developer/docs
[gh]: https://github.com/fslaborg/FSharp.Stats
[issues]: https://github.com/fslaborg/FSharp.Stats/issues
[readme]: https://github.com/fslaborg/FSharp.Stats/blob/developer/README.md
[license]: https://github.com/fslaborg/FSharp.Stats/blob/developer/LICENSE
*)