diff --git a/MathNet.Numerics.All.sln b/MathNet.Numerics.All.sln index 2dae9d3d..499da87a 100644 --- a/MathNet.Numerics.All.sln +++ b/MathNet.Numerics.All.sln @@ -8,7 +8,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Readme", "Readme", "{C2F374 CONTRIBUTING.md = CONTRIBUTING.md CONTRIBUTORS.md = CONTRIBUTORS.md LICENSE.md = LICENSE.md - MAINTAINING.md = MAINTAINING.md README.md = README.md RELEASENOTES-Native.md = RELEASENOTES-Native.md RELEASENOTES.md = RELEASENOTES.md diff --git a/MathNet.Numerics.Data.sln b/MathNet.Numerics.Data.sln index 30d9017c..1851d48a 100644 --- a/MathNet.Numerics.Data.sln +++ b/MathNet.Numerics.Data.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30723.0 +VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Matlab", "src\Data\Matlab\Matlab.csproj", "{550FB330-C86F-4C9D-9B4C-6D830CEB7520}" EndProject @@ -14,7 +14,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Readme", "Readme", "{F510F0 CONTRIBUTING.md = CONTRIBUTING.md CONTRIBUTORS.md = CONTRIBUTORS.md LICENSE.md = LICENSE.md - MAINTAINING.md = MAINTAINING.md README.md = README.md RELEASENOTES-Data.md = RELEASENOTES-Data.md RELEASENOTES.md = RELEASENOTES.md diff --git a/MathNet.Numerics.Net35Only.sln b/MathNet.Numerics.Net35Only.sln index 7635fe4b..8b069507 100644 --- a/MathNet.Numerics.Net35Only.sln +++ b/MathNet.Numerics.Net35Only.sln @@ -1,14 +1,11 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.30723.0 -MinimumVisualStudioVersion = 10.0.40219.1 +# Visual Studio 2012 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Readme", "Readme", "{C2F37492-38AE-4186-8A7F-17B0B080942C}" ProjectSection(SolutionItems) = preProject CONTRIBUTING.md = CONTRIBUTING.md CONTRIBUTORS.md = CONTRIBUTORS.md LICENSE.md = LICENSE.md - MAINTAINING.md = MAINTAINING.md README.md = README.md RELEASENOTES.md = RELEASENOTES.md EndProjectSection diff --git a/MathNet.Numerics.Portable.sln b/MathNet.Numerics.Portable.sln index 02f227a4..d3c9a049 100644 --- a/MathNet.Numerics.Portable.sln +++ b/MathNet.Numerics.Portable.sln @@ -1,14 +1,13 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30723.0 +VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Readme", "Readme", "{C2F37492-38AE-4186-8A7F-17B0B080942C}" ProjectSection(SolutionItems) = preProject CONTRIBUTING.md = CONTRIBUTING.md CONTRIBUTORS.md = CONTRIBUTORS.md LICENSE.md = LICENSE.md - MAINTAINING.md = MAINTAINING.md README.md = README.md RELEASENOTES-Native.md = RELEASENOTES-Native.md RELEASENOTES.md = RELEASENOTES.md diff --git a/MathNet.Numerics.Portable.sln.DotSettings b/MathNet.Numerics.Portable.sln.DotSettings index cd49821b..71ae4c46 100644 --- a/MathNet.Numerics.Portable.sln.DotSettings +++ b/MathNet.Numerics.Portable.sln.DotSettings @@ -66,6 +66,8 @@ OTHER DEALINGS IN THE SOFTWARE. SVD TFQMR WH + True True + True <data /> <data><IncludeFilters /><ExcludeFilters /></data> \ No newline at end of file diff --git a/MathNet.Numerics.sln b/MathNet.Numerics.sln index 041fb266..2aecf100 100644 --- a/MathNet.Numerics.sln +++ b/MathNet.Numerics.sln @@ -8,7 +8,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Readme", "Readme", "{C2F374 CONTRIBUTING.md = CONTRIBUTING.md CONTRIBUTORS.md = CONTRIBUTORS.md LICENSE.md = LICENSE.md - MAINTAINING.md = MAINTAINING.md README.md = README.md RELEASENOTES-Data.md = RELEASENOTES-Data.md RELEASENOTES-MKL.md = RELEASENOTES-MKL.md @@ -37,28 +36,28 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{039229DA-A ProjectSection(SolutionItems) = preProject docs\content\Build.md = docs\content\Build.md docs\content\Compatibility.md = docs\content\Compatibility.md - docs\content\CSV.fsx = docs\content\CSV.fsx - docs\content\DescriptiveStatistics.fsx = docs\content\DescriptiveStatistics.fsx - docs\content\Distance.fsx = docs\content\Distance.fsx - docs\content\Euclid.fsx = docs\content\Euclid.fsx - docs\content\Functions.fsx = docs\content\Functions.fsx - docs\content\Generate.fsx = docs\content\Generate.fsx - docs\content\IFsharpNotebook.fsx = docs\content\IFsharpNotebook.fsx - docs\content\index.fsx = docs\content\index.fsx - docs\content\IntegralTransforms.fsx = docs\content\IntegralTransforms.fsx - docs\content\Integration.fsx = docs\content\Integration.fsx - docs\content\Interpolation.fsx = docs\content\Interpolation.fsx - docs\content\LinearEquations.fsx = docs\content\LinearEquations.fsx - docs\content\MatlabFiles.fsx = docs\content\MatlabFiles.fsx - docs\content\Matrix.fsx = docs\content\Matrix.fsx - docs\content\MatrixMarket.fsx = docs\content\MatrixMarket.fsx + docs\content\CSV.md = docs\content\CSV.md + docs\content\DescriptiveStatistics.md = docs\content\DescriptiveStatistics.md + docs\content\Distance.md = docs\content\Distance.md + docs\content\Euclid.md = docs\content\Euclid.md + docs\content\Functions.md = docs\content\Functions.md + docs\content\Generate.md = docs\content\Generate.md + docs\content\IFsharpNotebook.md = docs\content\IFsharpNotebook.md + docs\content\index.md = docs\content\index.md + docs\content\IntegralTransforms.md = docs\content\IntegralTransforms.md + docs\content\Integration.md = docs\content\Integration.md + docs\content\Interpolation.md = docs\content\Interpolation.md + docs\content\LinearEquations.md = docs\content\LinearEquations.md + docs\content\MatlabFiles.md = docs\content\MatlabFiles.md + docs\content\Matrix.md = docs\content\Matrix.md + docs\content\MatrixMarket.md = docs\content\MatrixMarket.md docs\content\MKL.md = docs\content\MKL.md docs\content\Packages.md = docs\content\Packages.md - docs\content\Probability.fsx = docs\content\Probability.fsx - docs\content\Random.fsx = docs\content\Random.fsx - docs\content\Regression.fsx = docs\content\Regression.fsx + docs\content\Probability.md = docs\content\Probability.md + docs\content\Random.md = docs\content\Random.md + docs\content\Regression.md = docs\content\Regression.md docs\tools\templates\template.cshtml = docs\tools\templates\template.cshtml - docs\content\Users.fsx = docs\content\Users.fsx + docs\content\Users.md = docs\content\Users.md EndProjectSection EndProject Global diff --git a/docs/content/CSV.fsx b/docs/content/CSV.md similarity index 97% rename from docs/content/CSV.fsx rename to docs/content/CSV.md index c379b2ad..1a089843 100644 --- a/docs/content/CSV.fsx +++ b/docs/content/CSV.md @@ -1,9 +1,3 @@ -(*** hide ***) -#I "../../out/lib/net40" -#r "MathNet.Numerics.dll" -#r "MathNet.Numerics.FSharp.dll" - -(** Delimited Text Files (CSV & TSV) ================================ @@ -96,5 +90,3 @@ Among others: * [NIST MatrixMarket text files](MatrixMarket.html) * [MATLAB Level-5 Mat files](MatlabFiles.html) - -*) diff --git a/docs/content/DescriptiveStatistics.fsx b/docs/content/DescriptiveStatistics.md similarity index 75% rename from docs/content/DescriptiveStatistics.fsx rename to docs/content/DescriptiveStatistics.md index ce7997e1..4ffe9d26 100644 --- a/docs/content/DescriptiveStatistics.fsx +++ b/docs/content/DescriptiveStatistics.md @@ -1,11 +1,11 @@ -(*** hide ***) -#I "../../out/lib/net40" -#r "MathNet.Numerics.dll" -#r "MathNet.Numerics.FSharp.dll" -open MathNet.Numerics -open MathNet.Numerics.Statistics - -(** + [hide] + #I "../../out/lib/net40" + #r "MathNet.Numerics.dll" + #r "MathNet.Numerics.FSharp.dll" + open System.Numerics + open MathNet.Numerics + open MathNet.Numerics.Statistics + Descriptive Statistics ====================== @@ -84,18 +84,17 @@ The mean is affected by outliers, so if you need a more robust estimate consider $$$ \overline{x} = \frac{1}{N}\sum_{i=1}^N x_i -*) -let whiteNoise = Generate.Gaussian(1000, mean=10.0, standardDeviation=2.0) -// [fsi:val samples : float [] = [|12.90021939; 9.631515037; 7.810008046; 14.13301053; ...|] ] -Statistics.Mean whiteNoise -// [fsi:val it : float = 10.02162347] + [lang=fsharp] + let whiteNoise = Generate.Normal(1000, mean=10.0, standardDeviation=2.0) + // [fsi:val samples : float [] = [|12.90021939; 9.631515037; 7.810008046; 14.13301053; ...|] ] + Statistics.Mean whiteNoise + // [fsi:val it : float = 10.02162347] -let wave = Generate.Sinusoidal(1000, samplingRate=100., frequency=5., amplitude=0.5) -Statistics.Mean wave -// [fsi:val it : float = -4.133520783e-17] + let wave = Generate.Sinusoidal(1000, samplingRate=100., frequency=5., amplitude=0.5) + Statistics.Mean wave + // [fsi:val it : float = -4.133520783e-17] -(** Variance and Standard Deviation ------------------------------- @@ -119,17 +118,16 @@ Bessel's correction with an $N-1$ normalizer to a sample set of size $N$. $$$ s^2 = \frac{1}{N-1}\sum_{i=1}^N (x_i - \overline{x})^2 -*) -Statistics.Variance whiteNoise -// [fsi:val it : float = 3.819436094] -Statistics.StandardDeviation whiteNoise -// [fsi:val it : float = 1.954337764] + [lang=fsharp] + Statistics.Variance whiteNoise + // [fsi:val it : float = 3.819436094] + Statistics.StandardDeviation whiteNoise + // [fsi:val it : float = 1.954337764] -Statistics.Variance wave -// [fsi:val it : float = 0.1251251251] + Statistics.Variance wave + // [fsi:val it : float = 0.1251251251] -(** #### Combined Routines Since mean and variance are often needed together, there are routines @@ -138,12 +136,11 @@ that evaluate both in a single pass: `Statistics.MeanVariance(samples)` `ArrayStatistics.MeanVariance(samples)` `StreamingStatistics.MeanVariance(samples)` -*) -Statistics.MeanVariance whiteNoise -// [fsi:val it : float * float = (10.02162347, 3.819436094)] + [lang=fsharp] + Statistics.MeanVariance whiteNoise + // [fsi:val it : float * float = (10.02162347, 3.819436094)] -(** Covariance ---------- @@ -160,14 +157,13 @@ q = \frac{1}{N-1}\sum_{i=1}^N (x_i - \overline{x})(y_i - \overline{y}) $$$ q = \frac{1}{N}\sum_{i=1}^N (x_i - \mu_x)(y_i - \mu_y) -*) -Statistics.Covariance(whiteNoise, whiteNoise) -// [fsi:val it : float = 3.819436094] -Statistics.Covariance(whiteNoise, wave) -// [fsi:val it : float = 0.04397985084] + [lang=fsharp] + Statistics.Covariance(whiteNoise, whiteNoise) + // [fsi:val it : float = 3.819436094] + Statistics.Covariance(whiteNoise, wave) + // [fsi:val it : float = 0.04397985084] -(** Order Statistics ---------------- @@ -198,22 +194,21 @@ provided data and then on each invocation uses efficient sorted algorithms: Such Inplace and Func variants are a common pattern throughout the Statistics class and also the rest of the library. -*) - -Statistics.OrderStatistic(whiteNoise, 1) -// [fsi:val it : float = 3.633070184] -Statistics.OrderStatistic(whiteNoise, 1000) -// [fsi:val it : float = 16.65183566] - -let os = Statistics.orderStatisticFunc whiteNoise -os 250 -// [fsi:val it : float = 8.645491746] -os 500 -// [fsi:val it : float = 10.11872428] -os 750 -// [fsi:val it : float = 11.33170746] - -(** + + [lang=fsharp] + Statistics.OrderStatistic(whiteNoise, 1) + // [fsi:val it : float = 3.633070184] + Statistics.OrderStatistic(whiteNoise, 1000) + // [fsi:val it : float = 16.65183566] + + let os = Statistics.orderStatisticFunc whiteNoise + os 250 + // [fsi:val it : float = 8.645491746] + os 500 + // [fsi:val it : float = 10.11872428] + os 750 + // [fsi:val it : float = 11.33170746] + #### Median Median is a robust indicator of central tendency and much less affected by outliers @@ -228,14 +223,13 @@ The median is only unique if the sample size is odd. This implementation interna uses the default quantile definition, which is equivalent to mode 8 in R and is approximately median-unbiased regardless of the sample distribution. If you need another convention, use `QuantileCustom` instead, see below for details. -*) -Statistics.Median whiteNoise -// [fsi:val it : float = 10.11872428] -Statistics.Median wave -// [fsi:val it : float = -2.452600839e-16] + [lang=fsharp] + Statistics.Median whiteNoise + // [fsi:val it : float = 10.11872428] + Statistics.Median wave + // [fsi:val it : float = -2.452600839e-16] -(** #### Quartiles and the 5-number summary Quartiles group the ascendingly sorted data into four equal groups, where each @@ -250,14 +244,13 @@ estimates the median as discussed above. `SortedArrayStatistics.UpperQuartile(data)` `ArrayStatistics.LowerQuartileInplace(data)` `ArrayStatistics.UpperQuartileInplace(data)` -*) -Statistics.LowerQuartile whiteNoise -// [fsi:val it : float = 8.645491746] -Statistics.UpperQuartile whiteNoise -// [fsi:val it : float = 11.33213732] + [lang=fsharp] + Statistics.LowerQuartile whiteNoise + // [fsi:val it : float = 8.645491746] + Statistics.UpperQuartile whiteNoise + // [fsi:val it : float = 11.33213732] -(** Using that data we can provide a useful set of indicators usually named 5-number summary, which consists of the minimum value, the lower quartile, the median, the upper quartile and the maximum value. All these values can be visualized in the popular box plot diagrams. @@ -265,14 +258,13 @@ the maximum value. All these values can be visualized in the popular box plot di `Statistics.FiveNumberSummary(data)` `SortedArrayStatistics.FiveNumberSummary(data)` `ArrayStatistics.FiveNumberSummaryInplace(data)` -*) -Statistics.FiveNumberSummary whiteNoise -// [fsi:val it : float [] = [|3.633070184; 8.645937823; 10.12165054; 11.33213732; 16.65183566|] ] -Statistics.FiveNumberSummary wave -// [fsi:val it : float [] = [|-0.5; -0.3584185509; -2.452600839e-16; 0.3584185509; 0.5|] ] + [lang=fsharp] + Statistics.FiveNumberSummary whiteNoise + // [fsi:val it : float [] = [|3.633070184; 8.645937823; 10.12165054; 11.33213732; 16.65183566|] ] + Statistics.FiveNumberSummary wave + // [fsi:val it : float [] = [|-0.5; -0.3584185509; -2.452600839e-16; 0.3584185509; 0.5|] ] -(** The difference between the upper and the lower quartile is called inter-quartile range (IQR) and is a robust indicator of spread. In box plots the IQR is the total height of the box. @@ -281,12 +273,11 @@ and is a robust indicator of spread. In box plots the IQR is the total height of `ArrayStatistics.InterquartileRangeInplace(data)` Just like median, quartiles use the default R8 quantile definition internally. -*) -Statistics.InterquartileRange whiteNoise -// [fsi:val it : float = 2.686199498] + [lang=fsharp] + Statistics.InterquartileRange whiteNoise + // [fsi:val it : float = 2.686199498] -(** #### Percentiles Percentiles extend the concept further by grouping the sorted values into 100 @@ -300,14 +291,13 @@ The 0-percentile represents the minimum value, 25 the first quartile, 50 the med `ArrayStatistics.PercentileInplace(data, p)` Just like median, percentiles use the default R8 quantile definition internally. -*) -Statistics.Percentile(whiteNoise, 5) -// [fsi:val it : float = 6.693373507] -Statistics.Percentile(whiteNoise, 98) -// [fsi:val it : float = 13.97580653] + [lang=fsharp] + Statistics.Percentile(whiteNoise, 5) + // [fsi:val it : float = 6.693373507] + Statistics.Percentile(whiteNoise, 98) + // [fsi:val it : float = 13.97580653] -(** #### Quantiles Instead of grouping into 4 or 100 boxes, quantiles generalize the concept to an infinite number @@ -319,12 +309,11 @@ the inverse cumulative distribution function of the sample distribution. `Statistics.QuantileFunc(data)` `SortedArrayStatistics.Quantile(data, tau)` `ArrayStatistics.QuantileInplace(data, tau)` -*) -Statistics.Quantile(whiteNoise, 0.98) -// [fsi:val it : float = 13.97580653] + [lang=fsharp] + Statistics.Quantile(whiteNoise, 0.98) + // [fsi:val it : float = 13.97580653] -(** #### Quantile Conventions and Compatibility Remember that all these descriptive statistics do not *compute* but merely *estimate* @@ -354,14 +343,13 @@ The `QuantileDefinition` enumeration has the following options: * **R7**, Excel, Mode, S * **R8**, Median, Default * **R9**, Normal -*) -Statistics.QuantileCustom(whiteNoise, 0.98, QuantileDefinition.R3) -// [fsi:val it : float = 13.97113209] -Statistics.QuantileCustom(whiteNoise, 0.98, QuantileDefinition.Excel) -// [fsi:val it : float = 13.97127374] + [lang=fsharp] + Statistics.QuantileCustom(whiteNoise, 0.98, QuantileDefinition.R3) + // [fsi:val it : float = 13.97113209] + Statistics.QuantileCustom(whiteNoise, 0.98, QuantileDefinition.Excel) + // [fsi:val it : float = 13.97127374] -(** Rank Statistics --------------- @@ -381,16 +369,15 @@ Similar to `QuantileDefinition`, the `RankDefinition` enumeration controls how t `Statistics.Ranks(data, definition)` `SortedArrayStatistics.Ranks(data, definition)` `ArrayStatistics.RanksInplace(data, definition)` -*) -Statistics.Ranks(whiteNoise) -// [fsi:val it : float [] = [|634.0; 736.0; 405.0; 395.0; 197.0; 167.0; 722.0; 44.0; ...|] ] -Statistics.Ranks([| 13.0; 14.0; 11.0; 12.0; 13.0 |], RankDefinition.Average) -// [fsi:val it : float [] = [|3.5; 5.0; 1.0; 2.0; 3.5|] ] -Statistics.Ranks([| 13.0; 14.0; 11.0; 12.0; 13.0 |], RankDefinition.Sports) -// [fsi:val it : float [] = [|3.0; 5.0; 1.0; 2.0; 3.0|] ] + [lang=fsharp] + Statistics.Ranks(whiteNoise) + // [fsi:val it : float [] = [|634.0; 736.0; 405.0; 395.0; 197.0; 167.0; 722.0; 44.0; ...|] ] + Statistics.Ranks([| 13.0; 14.0; 11.0; 12.0; 13.0 |], RankDefinition.Average) + // [fsi:val it : float [] = [|3.5; 5.0; 1.0; 2.0; 3.5|] ] + Statistics.Ranks([| 13.0; 14.0; 11.0; 12.0; 13.0 |], RankDefinition.Sports) + // [fsi:val it : float [] = [|3.0; 5.0; 1.0; 2.0; 3.0|] ] -(** #### Quantile Rank Counterpart of the `Quantile` function, estimates $\tau$ of the provided $\tau$-quantile value @@ -400,14 +387,13 @@ function crosses $\tau$. `Statistics.QuantileRank(data, x, definition)` `Statistics.QuantileRankFunc(data, definition)` `SortedArrayStatistics.QuantileRank(data, x, definition)` -*) -Statistics.QuantileRank(whiteNoise, 13.0) -// [fsi:val it : float = 0.9370045563] -Statistics.QuantileRank(whiteNoise, 6.7, RankDefinition.Average) -// [fsi:val it : float = 0.04960610389] + [lang=fsharp] + Statistics.QuantileRank(whiteNoise, 13.0) + // [fsi:val it : float = 0.9370045563] + Statistics.QuantileRank(whiteNoise, 6.7, RankDefinition.Average) + // [fsi:val it : float = 0.04960610389] -(** Empirical Distribution Functions -------------------------------- @@ -416,23 +402,22 @@ Empirical Distribution Functions `Statistics.EmpiricalInvCDF(data, tau)` `Statistics.EmpiricalInvCDFFunc(data)` `SortedArrayStatistics.EmpiricalCDF(data, x)` -*) - -let ecdf = Statistics.EmpiricalCDFFunc whiteNoise -Generate.LinearSpacedMap(20, start=3.0, stop=17.0, map=ecdf) -// [fsi:val it : float [] =] -// [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.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; ] -// [fsi: 8.645491746; 9.02681611; 9.298987151; 9.522627142; 9.819352699; 10.11872428; ] -// [fsi: 10.35991046; 10.57530906; 10.8259542; 11.08605473; 11.33170746; 11.54356436; ] -// [fsi: 11.90973541; 12.4294346; 13.36889423; 16.65183566] ] - -(** + + [lang=fsharp] + let ecdf = Statistics.EmpiricalCDFFunc whiteNoise + Generate.LinearSpacedMap(20, start=3.0, stop=17.0, map=ecdf) + // [fsi:val it : float [] =] + // [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.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; ] + // [fsi: 8.645491746; 9.02681611; 9.298987151; 9.522627142; 9.819352699; 10.11872428; ] + // [fsi: 10.35991046; 10.57530906; 10.8259542; 11.08605473; 11.33170746; 11.54356436; ] + // [fsi: 11.90973541; 12.4294346; 13.36889423; 16.65183566] ] + Histograms ---------- @@ -459,4 +444,3 @@ Code Sample: Computing the correlation coefficient of 1000 samples of f(x) = 2x double[] dataF = Generate.LinearSpacedMap(1000, 0, 100, x => 2*x); double[] dataG = Generate.LinearSpacedMap(1000, 0, 100, x => x*x); double correlation = Correlation.Pearson(dataF, dataG); -*) diff --git a/docs/content/Distance.fsx b/docs/content/Distance.md similarity index 98% rename from docs/content/Distance.fsx rename to docs/content/Distance.md index 24b25e04..1285b39e 100644 --- a/docs/content/Distance.fsx +++ b/docs/content/Distance.md @@ -1,9 +1,3 @@ -(*** hide ***) -#I "../../out/lib/net40" -#r "MathNet.Numerics.dll" -#r "MathNet.Numerics.FSharp.dll" - -(** Distance Metrics ================ @@ -195,4 +189,3 @@ It is a fundamental distance measure in information theory but less relevant in [lang=csharp] double d = Distance.Hamming(x, y); -*) diff --git a/docs/content/Euclid.fsx b/docs/content/Euclid.md similarity index 97% rename from docs/content/Euclid.fsx rename to docs/content/Euclid.md index eeacc8f0..aa2d668f 100644 --- a/docs/content/Euclid.fsx +++ b/docs/content/Euclid.md @@ -1,9 +1,3 @@ -(*** hide ***) -#I "../../out/lib/net40" -#r "MathNet.Numerics.dll" -#r "MathNet.Numerics.FSharp.dll" - -(** Euclid & Number Theory ====================== @@ -105,5 +99,3 @@ Closely related to the GCD, `LeastCommonMultiple` returns the **LCM** of two or [lang=csharp] Euclid.LeastCommonMultiple(3, 5, 6); // 30 - -*) diff --git a/docs/content/Functions.fsx b/docs/content/Functions.md similarity index 98% rename from docs/content/Functions.fsx rename to docs/content/Functions.md index 21a338ac..69278a6e 100644 --- a/docs/content/Functions.fsx +++ b/docs/content/Functions.md @@ -1,9 +1,3 @@ -(*** hide ***) -#I "../../out/lib/net40" -#r "MathNet.Numerics.dll" -#r "MathNet.Numerics.FSharp.dll" - -(** Special Functions ================= @@ -381,5 +375,3 @@ for both real and complex arguments. * **Hyperbolic Area**: Asinh, Acosh, Atanh, Acoth, Asech, Acsch * **Sinc**: Normalized sinc function $x \mapsto \frac{\sin\pi x}{\pi x}$ * Conversion routines between radian, degree and grad. - -*) diff --git a/docs/content/Generate.fsx b/docs/content/Generate.md similarity index 79% rename from docs/content/Generate.fsx rename to docs/content/Generate.md index 027f560a..28c70b5a 100644 --- a/docs/content/Generate.fsx +++ b/docs/content/Generate.md @@ -1,12 +1,12 @@ -(*** hide ***) -#I "../../out/lib/net40" -#r "MathNet.Numerics.dll" -#r "MathNet.Numerics.FSharp.dll" -open System -open MathNet.Numerics -let a = [| 2.0; 4.0; 3.0; 6.0 |] - -(** + [hide] + #I "../../out/lib/net40" + #r "MathNet.Numerics.dll" + #r "MathNet.Numerics.FSharp.dll" + open System.Numerics + open MathNet.Numerics + open MathNet.Numerics.Statistics + let a = [| 2.0; 4.0; 3.0; 6.0 |] + Generating Data =============== @@ -28,14 +28,13 @@ and either a provided step or a step of 1.0. Linear range is equivalent to the single colon `:` and double colon `::` operators in MATLAB. F# has built in linear range support in array comprehensions with the colon operator: -*) -[ 10.0 .. 2.0 .. 15.0 ] -// [fsi:val it : float list = [10.0; 12.0; 14.0] ] -[ for x in 10.0 .. 2.0 .. 15.0 -> sin x ] -// [fsi:val it : float list = [-0.5440211109; -0.536572918; 0.9906073557] ] + [lang=fsharp] + [ 10.0 .. 2.0 .. 15.0 ] + // [fsi:val it : float list = [10.0; 12.0; 14.0] ] + [ for x in 10.0 .. 2.0 .. 15.0 -> sin x ] + // [fsi:val it : float list = [-0.5440211109; -0.536572918; 0.9906073557] ] -(** In C# you can get the same result with `LinearRange`: [lang=csharp] @@ -61,15 +60,14 @@ This is equivalent to the linspace and logspace operators in MATLAB. Generate.LinearSpacedMap(15, 0.0, Math.Pi, Math.Sin); // applies sin(x) to each value In F# you can also use: -*) -Generate.linearSpacedMap 15 0.0 Math.PI sin -// [fsi:val it : float [] = ] -// [fsi: [|0.0; 0.222520934; 0.4338837391; 0.6234898019; 0.7818314825; 0.9009688679; ] -// [fsi: 0.9749279122; 1.0; 0.9749279122; 0.9009688679; 0.7818314825; 0.6234898019; ] -// [fsi: 0.4338837391; 0.222520934; 1.224606354e-16|] ] + [lang=fsharp] + Generate.linearSpacedMap 15 0.0 Math.PI sin + // [fsi:val it : float [] = ] + // [fsi: [|0.0; 0.222520934; 0.4338837391; 0.6234898019; 0.7818314825; 0.9009688679; ] + // [fsi: 0.9749279122; 1.0; 0.9749279122; 0.9009688679; 0.7818314825; 0.6234898019; ] + // [fsi: 0.4338837391; 0.222520934; 1.224606354e-16|] ] -(** `LogSpaced` works the same way but instead of the values $10^x$ it spaces the decade exponents $x$ linearly between the provided two exponents. @@ -94,15 +92,15 @@ $$$ s[n] = A\cdot\delta[n-d] = \begin{cases} 0 &\mbox{if } n \ne d \\ A & \mbox{if } n = d\end{cases} There is also a periodic version in `PeriodicImpulse` which accepts an additional `period` parameter. -*) -Generate.Impulse(8, 2.0, 3) -// [fsi:val it : float [] = [|0.0; 0.0; 0.0; 2.0; 0.0; 0.0; 0.0; 0.0|] ] + [lang=fsharp] + Generate.Impulse(8, 2.0, 3) + // [fsi:val it : float [] = [|0.0; 0.0; 0.0; 2.0; 0.0; 0.0; 0.0; 0.0|] ] + + Generate.PeriodicImpulse(8, 3, 10.0, 1) + // [fsi:val it : float [] = [|0.0; 10.0; 0.0; 0.0; 10.0; 0.0; 0.0; 10.0|] ] -Generate.PeriodicImpulse(8, 3, 10.0, 1) -// [fsi:val it : float [] = [|0.0; 10.0; 0.0; 0.0; 10.0; 0.0; 0.0; 10.0|] ] -(** Heaviside Step -------------- @@ -118,13 +116,12 @@ The `Step` routines generates a Heaviside step, but just like the Kronecker Delt $$$ s[n] = A\cdot H[n-d] = \begin{cases} 0 &\mbox{if } n < d \\ A & \mbox{if } n \ge d\end{cases} -*) -Generate.Step(8, 2.0, 3) -// [fsi:val it : float [] = [|0.0; 0.0; 0.0; 2.0; 2.0; 2.0; 2.0; 2.0|] ] + [lang=fsharp] + Generate.Step(8, 2.0, 3) + // [fsi:val it : float [] = [|0.0; 0.0; 0.0; 2.0; 2.0; 2.0; 2.0; 2.0|] ] -(** Periodic Sawtooth ----------------- @@ -154,14 +151,14 @@ normalized to strictly $0\le\alpha < A$. * **Delay**: Optional initial delay, in samples. Contributes to $\theta$. The equivalent map function accepts a custom map lambda as second argument after the length: -*) -Generate.periodicMap 15 ((+) 100.0) 1000.0 100.0 10.0 0.0 0 -// [fsi:val it : float [] = ] -// [fsi: [|100.0; 101.0; 102.0; 103.0; 104.0; 105.0; 106.0; 107.0; 108.0; 109.0; ] -// [fsi: 100.0; 101.0; 102.0; 103.0; 104.0|] ] + [lang=fsharp] + Generate.periodicMap 15 ((+) 100.0) 1000.0 100.0 10.0 0.0 0 + // [fsi:val it : float [] = ] + // [fsi: [|100.0; 101.0; 102.0; 103.0; 104.0; 105.0; 106.0; 107.0; 108.0; 109.0; ] + // [fsi: 100.0; 101.0; 102.0; 103.0; 104.0|] ] + -(** Sinusoidal ---------- @@ -200,8 +197,8 @@ generated using the variants with the `Sequence` suffix, e.g. `UniformMap2Sequen Instead of uniform we can also sample from other distributions. -* `Gaussian` - sample an array or sequence form a normal or standard distribution -* `Stable` - sample from a Levy alpha-stable distribution. +* `Normal` - sample an array or sequence form a normal distribution +* `Standard` - sample an array or sequence form a standard distribution In addition, the `Random` functions accept a custom distribution instance to sample from. See the section about random numbers and probability distributions for details. @@ -218,12 +215,11 @@ the the corresponding value in the input data. Generate.Map(a, x => x + 1.0); // returns array { 3.0, 5.0, 4.0, 7.0 } In F# you'd typically use the Array module to the same effect (and should continue to do so): -*) -Array.map ((+) 1.0) a -// [fsi:val it : float [] = [|3.0; 5.0; 4.0; 7.0|] ] + [lang=fsharp] + Array.map ((+) 1.0) a + // [fsi:val it : float [] = [|3.0; 5.0; 4.0; 7.0|] ] -(** ...but no equivalent operation is available in the .NET base class libraries (BCL) for C#. You can use LINQ, but that operates on sequences instead of arrays: @@ -231,22 +227,19 @@ You can use LINQ, but that operates on sequences instead of arrays: a.Select(x => x + 1.0).ToArray(); Similarly, with `Map2` you can also map a function accepting two inputs to two input arrays: -*) -let b = [| 1.0; -1.0; 2.0; -2.0 |] -Generate.Map2(a, b, fun x y -> x + y) -// [fsi:val it : float [] = [|3.0; 3.0; 5.0; 4.0|] ] + [lang=fsharp] + let b = [| 1.0; -1.0; 2.0; -2.0 |] + Generate.Map2(a, b, fun x y -> x + y) + // [fsi:val it : float [] = [|3.0; 3.0; 5.0; 4.0|] ] -(** Typical F# equivalent: -*) -Array.map2 (+) a b -// [fsi:val it : float [] = [|3.0; 3.0; 5.0; 4.0|] ] + [lang=fsharp] + Array.map2 (+) a b + // [fsi:val it : float [] = [|3.0; 3.0; 5.0; 4.0|] ] -(** And in C# with LINQ: [lang=csharp] a.Zip(b, (x, y) => x + y).ToArray(); -*) diff --git a/docs/content/IFsharpNotebook.fsx b/docs/content/IFsharpNotebook.md similarity index 94% rename from docs/content/IFsharpNotebook.fsx rename to docs/content/IFsharpNotebook.md index 8db2a9db..370b98b0 100644 --- a/docs/content/IFsharpNotebook.fsx +++ b/docs/content/IFsharpNotebook.md @@ -1,4 +1,11 @@ -(** + [hide] + #I "../../out/lib/net40" + #r "MathNet.Numerics.dll" + #r "MathNet.Numerics.FSharp.dll" + open System.Numerics + open MathNet.Numerics + open MathNet.Numerics.LinearAlgebra + IF# Notebook ============ @@ -36,6 +43,7 @@ Unfortunately loading this script requires the exact version in the path - if yo Alternatively you can also use the code below and adapt it to your needs, e.g. if you want it to show more rows. + [lang=fsharp] open MathNet.Numerics.LinearAlgebra let inline (|Float|_|) (v:obj) = @@ -82,5 +90,3 @@ Alternatively you can also use the code below and adapt it to your needs, e.g. i { ContentType = "text/latex"; Data = formatVector x }) App.AddDisplayPrinter (fun (x:Vector) -> { ContentType = "text/latex"; Data = formatVector x }) - -*) diff --git a/docs/content/IntegralTransforms.fsx b/docs/content/IntegralTransforms.md similarity index 95% rename from docs/content/IntegralTransforms.fsx rename to docs/content/IntegralTransforms.md index b76c581d..f9282a0e 100644 --- a/docs/content/IntegralTransforms.fsx +++ b/docs/content/IntegralTransforms.md @@ -1,9 +1,11 @@ -(*** hide ***) -#I "../../out/lib/net40" -#r "MathNet.Numerics.dll" -#r "MathNet.Numerics.FSharp.dll" + [hide] + #I "../../out/lib/net40" + #r "MathNet.Numerics.dll" + #r "MathNet.Numerics.FSharp.dll" + open System.Numerics + open MathNet.Numerics + open MathNet.Numerics.IntegralTransforms -(** Fourier and related linear integral transforms ============================================== @@ -16,6 +18,7 @@ The transforms implement a separate forward and inverse transform method. How the forward and inverse methods are related to each other and what exact definition is to be used can be specified by an additional _options_ parameter. + Fourier Space: Discrete Fourier Transform and FFT ------------------------------------------------- @@ -61,9 +64,8 @@ Useful symmetries of the Fourier transform: * h(t) is imaginary-valued even <=> H(f) is imaginary-valued even * h(t) is imaginary-valued odd <=> H(f) is real-valued odd + Hartley Space: Discrete Hartley Transform ----------------------------------------- ... - -*) diff --git a/docs/content/Integration.fsx b/docs/content/Integration.md similarity index 50% rename from docs/content/Integration.fsx rename to docs/content/Integration.md index 2d422d4c..ddb34755 100644 --- a/docs/content/Integration.fsx +++ b/docs/content/Integration.md @@ -1,19 +1,22 @@ -(*** hide ***) -#I "../../out/lib/net40" -#r "MathNet.Numerics.dll" -#r "MathNet.Numerics.FSharp.dll" + [hide] + #I "../../out/lib/net40" + #r "MathNet.Numerics.dll" + #r "MathNet.Numerics.FSharp.dll" + open System.Numerics + open MathNet.Numerics + open MathNet.Numerics.Integration -(** Numerical Integration ===================== + Simpson's Rule -------------- + Newton Cotes Trapezium Rule --------------------------- + Double-Exponential Transformation --------------------------------- - -*) diff --git a/docs/content/Interpolation.fsx b/docs/content/Interpolation.md similarity index 90% rename from docs/content/Interpolation.fsx rename to docs/content/Interpolation.md index 5024f2d2..384e1d71 100644 --- a/docs/content/Interpolation.fsx +++ b/docs/content/Interpolation.md @@ -1,9 +1,11 @@ -(*** hide ***) -#I "../../out/lib/net40" -#r "MathNet.Numerics.dll" -#r "MathNet.Numerics.FSharp.dll" + [hide] + #I "../../out/lib/net40" + #r "MathNet.Numerics.dll" + #r "MathNet.Numerics.FSharp.dll" + open System.Numerics + open MathNet.Numerics + open MathNet.Numerics.Interpolation -(** Interpolation ============= @@ -24,11 +26,13 @@ If unsure, we recommend using _RationalWithoutPoles_ for most cases. Alternatively you can also use the algorithms directly, they're publicly available in the _Algorithms_ sub-namespace for those who want to use a specific algorithm. The following algorithms are available: + Interpolation on equidistant sample points ------------------------------------------ * *Polynomial*: Barycentric Algorithm + Interpolation on arbitrary sample points ---------------------------------------- @@ -40,11 +44,10 @@ Interpolation on arbitrary sample points * *Natural Cubic Spline* * *Akima Cubic Spline* + Interpolation with additional data ---------------------------------- * *Generic Barycentric Interpolation*, requires barycentric weights * *Generic Spline*, requires spline coefficients * *Generic Cubic Hermite Spline*, requires the derivatives - -*) diff --git a/docs/content/LinearEquations.fsx b/docs/content/LinearEquations.md similarity index 84% rename from docs/content/LinearEquations.fsx rename to docs/content/LinearEquations.md index d28f1cd0..4d09a969 100644 --- a/docs/content/LinearEquations.fsx +++ b/docs/content/LinearEquations.md @@ -1,10 +1,11 @@ -(*** hide ***) -#I "../../out/lib/net40" -#r "MathNet.Numerics.dll" -#r "MathNet.Numerics.FSharp.dll" -open MathNet.Numerics.LinearAlgebra + [hide] + #I "../../out/lib/net40" + #r "MathNet.Numerics.dll" + #r "MathNet.Numerics.FSharp.dll" + open System.Numerics + open MathNet.Numerics + open MathNet.Numerics.LinearAlgebra -(** Linear Equation Systems ======================= @@ -72,15 +73,15 @@ Which we can solve explicitly with the LU-decomposition, or simply by using the The resulting $\mathbf{x}$ is $[1,\;-2,\;-2]$, hence the solution $x=1,\;y=-2,\;z=-2$. In F# the syntax is a bit lighter: -*) -let A = matrix [[ 3.0; 2.0; -1.0 ] - [ 2.0; -2.0; 4.0 ] - [ -1.0; 0.5; -1.0 ]] -let b = vector [ 1.0; -2.0; 0.0 ] -let x = A.Solve(b) // 1;-2;-2 + [lang=fsharp] + let A = matrix [[ 3.0; 2.0; -1.0 ] + [ 2.0; -2.0; 4.0 ] + [ -1.0; 0.5; -1.0 ]] + let b = vector [ 1.0; -2.0; 0.0 ] + let x = A.Solve(b) // 1;-2;-2 + -(** Normalizing Equation Systems ---------------------------- @@ -121,11 +122,11 @@ $$$ \begin{bmatrix}0\\0\\20\\0\end{bmatrix} Which is in standard from, so we can solve normally: -*) - -let A' = matrix [[ 3.0; 4.0; -1.0; 0.0 ] - [ 4.0; 5.0; 0.0; -1.0 ] - [ 5.0; 6.0; 0.0; 0.0; ] - [ 6.0; 7.0; 0.0; 0.0 ]] -let b' = vector [ 0.0; 0.0; 20.0; 0.0 ] -let x' = A'.Solve(b') // -140; 120; 60; 40 + + [lang=fsharp] + let A' = matrix [[ 3.0; 4.0; -1.0; 0.0 ] + [ 4.0; 5.0; 0.0; -1.0 ] + [ 5.0; 6.0; 0.0; 0.0; ] + [ 6.0; 7.0; 0.0; 0.0 ]] + let b' = vector [ 0.0; 0.0; 20.0; 0.0 ] + let x' = A'.Solve(b') // -140; 120; 60; 40 diff --git a/docs/content/MatlabFiles.fsx b/docs/content/MatlabFiles.md similarity index 96% rename from docs/content/MatlabFiles.fsx rename to docs/content/MatlabFiles.md index 225bf2a5..4604151d 100644 --- a/docs/content/MatlabFiles.fsx +++ b/docs/content/MatlabFiles.md @@ -1,9 +1,3 @@ -(*** hide ***) -#I "../../out/lib/net40" -#r "MathNet.Numerics.dll" -#r "MathNet.Numerics.FSharp.dll" - -(** MATLAB Level-5 Mat Files ======================== @@ -86,5 +80,3 @@ Among others: * [Delimited Text Files (CSV & TSV)](CSV.html) * [NIST MatrixMarket text files](MatrixMarket.html) - -*) diff --git a/docs/content/MatrixMarket.fsx b/docs/content/MatrixMarket.md similarity index 95% rename from docs/content/MatrixMarket.fsx rename to docs/content/MatrixMarket.md index 730202ea..26779268 100644 --- a/docs/content/MatrixMarket.fsx +++ b/docs/content/MatrixMarket.md @@ -1,9 +1,3 @@ -(*** hide ***) -#I "../../out/lib/net40" -#r "MathNet.Numerics.dll" -#r "MathNet.Numerics.FSharp.dll" - -(** NIST MatrixMarket Text Files ============================ @@ -58,5 +52,3 @@ Among others: * [Delimited Text Files (CSV & TSV)](CSV.html) * [MATLAB Level-5 Mat files](MatlabFiles.html) - -*) diff --git a/docs/content/Probability.fsx b/docs/content/Probability.md similarity index 68% rename from docs/content/Probability.fsx rename to docs/content/Probability.md index 253e59dc..3069d88b 100644 --- a/docs/content/Probability.fsx +++ b/docs/content/Probability.md @@ -1,11 +1,12 @@ -(*** hide ***) -#I "../../out/lib/net40" -#r "MathNet.Numerics.dll" -#r "MathNet.Numerics.FSharp.dll" -open MathNet.Numerics.Random -open MathNet.Numerics.Distributions - -(** + [hide] + #I "../../out/lib/net40" + #r "MathNet.Numerics.dll" + #r "MathNet.Numerics.FSharp.dll" + open System.Numerics + open MathNet.Numerics + open MathNet.Numerics.Random + open MathNet.Numerics.Distributions + Probability Distributions ========================= @@ -125,26 +126,24 @@ as last argument. gamma2.RandomSource = new Mrg32k3a(); A few more examples, this time in F#: -*) -// some probability distributions -let normal = Normal.WithMeanVariance(3.0, 1.5, a) -let exponential = Exponential(2.4) -let gamma = Gamma(2.0, 1.5, Random.crypto()) -let cauchy = Cauchy(0.0, 1.0, Random.mrg32k3aWith 10 false) -let poisson = Poisson(3.0) -let geometric = Geometric(0.8, Random.system()) + [lang=fsharp] + // some probability distributions + let normal = Normal.WithMeanVariance(3.0, 1.5, a) + let exponential = Exponential(2.4) + let gamma = Gamma(2.0, 1.5, Random.crypto()) + let cauchy = Cauchy(0.0, 1.0, Random.mrg32k3aWith 10 false) + let poisson = Poisson(3.0) + let geometric = Geometric(0.8, Random.system()) -(** Some of the distributions also have routines for maximum-likelihood parameter estimation from a set of samples: -*) -let estimation = LogNormal.Estimate([| 2.0; 1.5; 2.1; 1.2; 3.0; 2.4; 1.8 |]) -let mean, variance = estimation.Mean, estimation.Variance -let moreSamples = estimation.Samples() |> Seq.take 10 |> Seq.toArray + [lang=fsharp] + let estimation = LogNormal.Estimate([| 2.0; 1.5; 2.1; 1.2; 3.0; 2.4; 1.8 |]) + let mean, variance = estimation.Mean, estimation.Variance + let moreSamples = estimation.Samples() |> Seq.take 10 |> Seq.toArray -(** or in C#: [lang=csharp] @@ -162,38 +161,31 @@ to provide uniform random numbers. By default, this member is an instance of Sys but one can easily replace this with more sophisticated random number generators from `MathNet.Numerics.Random` (see [Random Numbers](Random.html) for details). -*) - -// sample some random numbers from these distributions -// continuous distributions sample to floating-point numbers: -let continuous = - [ yield normal.Sample() - yield exponential.Sample() - yield! gamma.Samples() |> Seq.take 10 ] - -// discrete distributions on the other hand sample to integers: -let discrete = - [ poisson.Sample() - poisson.Sample() - geometric.Sample() ] + [lang=fsharp] + // sample some random numbers from these distributions + // continuous distributions sample to floating-point numbers: + let continuous = + [ yield normal.Sample() + yield exponential.Sample() + yield! gamma.Samples() |> Seq.take 10 ] -(** + // discrete distributions on the other hand sample to integers: + let discrete = + [ poisson.Sample() + poisson.Sample() + geometric.Sample() ] Instead of creating a distribution object we can also sample directly with static functions. Note that no intermediate value caching is possible this way and parameters must be validated on each call. -*) - -// using the default number generator (SystemRandomSource.Default) -let w = Rayleigh.Sample(1.5) -let x = Hypergeometric.Sample(100, 20, 5) - -// or by manually providing the uniform random number generator -let u = Normal.Sample(Random.system(), 2.0, 4.0) -let v = Laplace.Samples(Random.mersenneTwister(), 1.0, 3.0) |> Seq.take 100 |> List.ofSeq + [lang=fsharp] + // using the default number generator (SystemRandomSource.Default) + let w = Rayleigh.Sample(1.5) + let x = Hypergeometric.Sample(100, 20, 5) - -(** + // or by manually providing the uniform random number generator + let u = Normal.Sample(Random.system(), 2.0, 4.0) + let v = Laplace.Samples(Random.mersenneTwister(), 1.0, 3.0) |> Seq.take 100 |> List.ofSeq If you need to sample not just one or two values but a large number of them, there are routines that either fill an existing array or return an enumerable. @@ -207,12 +199,12 @@ Let's sample 100'000 values from a laplace distribution with mean 1.0 and scale Laplace.Samples(samples, 1.0, 2.0); Let's do some random walks in F# (TODO: Graph): -*) -Seq.scan (+) 0.0 (Normal.Samples(0.0, 1.0)) |> Seq.take 10 |> Seq.toArray -Seq.scan (+) 0.0 (Cauchy.Samples(0.0, 1.0)) |> Seq.take 10 |> Seq.toArray + [lang=fsharp] + Seq.scan (+) 0.0 (Normal.Samples(0.0, 1.0)) |> Seq.take 10 |> Seq.toArray + Seq.scan (+) 0.0 (Cauchy.Samples(0.0, 1.0)) |> Seq.take 10 |> Seq.toArray + -(** Distribution Functions and Properties ------------------------------------- @@ -221,52 +213,52 @@ Once parametrized they can compute a variety of distribution properties or evaluate distribution functions. Because it is often numerically more stable and faster to compute and work with such quantities in the logarithmic domain, some of them are also available with the `Ln`-suffix. -*) - -// distribution properties of the gamma we've configured above -let gammaStats = - ( gamma.Mean, - gamma.Variance, - gamma.StdDev, - gamma.Entropy, - gamma.Skewness, - gamma.Mode ) - -// probability distribution functions of the normal we've configured above. -let nd = normal.Density(4.0) (* PDF *) -let ndLn = normal.DensityLn(4.0) (* ln(PDF) *) -let nc = normal.CumulativeDistribution(4.0) (* CDF *) -let nic = normal.InverseCumulativeDistribution(0.7) (* CDF^(-1) *) - -// Distribution functions can also be evaluated without creating an object, -// but then you have to pass in the distribution parameters as first arguments: -let nd2 = Normal.PDF(3.0, sqrt 1.5, 4.0) -let ndLn2 = Normal.PDFLn(3.0, sqrt 1.5, 4.0) -let nc2 = Normal.CDF(3.0, sqrt 1.5, 4.0) -let nic2 = Normal.InvCDF(3.0, sqrt 1.5, 0.7) - -(** + + [lang=fsharp] + // distribution properties of the gamma we've configured above + let gammaStats = + ( gamma.Mean, + gamma.Variance, + gamma.StdDev, + gamma.Entropy, + gamma.Skewness, + gamma.Mode ) + + // probability distribution functions of the normal we've configured above. + let nd = normal.Density(4.0) (* PDF *) + let ndLn = normal.DensityLn(4.0) (* ln(PDF) *) + let nc = normal.CumulativeDistribution(4.0) (* CDF *) + let nic = normal.InverseCumulativeDistribution(0.7) (* CDF^(-1) *) + + // Distribution functions can also be evaluated without creating an object, + // but then you have to pass in the distribution parameters as first arguments: + let nd2 = Normal.PDF(3.0, sqrt 1.5, 4.0) + let ndLn2 = Normal.PDFLn(3.0, sqrt 1.5, 4.0) + let nc2 = Normal.CDF(3.0, sqrt 1.5, 4.0) + let nic2 = Normal.InvCDF(3.0, sqrt 1.5, 0.7) + + Composing Distributions ----------------------- Specifically for F# there is also a `Sample` module that allows a somewhat more functional view on distribution sampling functions by having the random source passed in as last argument. This way they can be composed and transformed arbitrarily if curried: -*) -/// Transform a sample from a distribution -let s1 rng = tanh (Sample.normal 2.0 0.5 rng) + [lang=fsharp] + /// Transform a sample from a distribution + let s1 rng = tanh (Sample.normal 2.0 0.5 rng) -/// But we really want to transform the function, not the resulting sample: -let s1f rng = Sample.map tanh (Sample.normal 2.0 0.5) rng + /// But we really want to transform the function, not the resulting sample: + let s1f rng = Sample.map tanh (Sample.normal 2.0 0.5) rng -/// Exactly the same also works with functions generating full sequences -let s1s rng = Sample.mapSeq tanh (Sample.normalSeq 2.0 0.5) rng + /// Exactly the same also works with functions generating full sequences + let s1s rng = Sample.mapSeq tanh (Sample.normalSeq 2.0 0.5) rng -/// Now with multiple distributions, e.g. their product: -let s2 rng = (Sample.normal 2.0 1.5 rng) * (Sample.cauchy 2.0 0.5 rng) -let s2f rng = Sample.map2 (*) (Sample.normal 2.0 1.5) (Sample.cauchy 2.0 0.5) rng -let s2s rng = Sample.mapSeq2 (*) (Sample.normalSeq 2.0 1.5) (Sample.cauchySeq 2.0 0.5) rng + /// Now with multiple distributions, e.g. their product: + let s2 rng = (Sample.normal 2.0 1.5 rng) * (Sample.cauchy 2.0 0.5 rng) + let s2f rng = Sample.map2 (*) (Sample.normal 2.0 1.5) (Sample.cauchy 2.0 0.5) rng + let s2s rng = Sample.mapSeq2 (*) (Sample.normalSeq 2.0 1.5) (Sample.cauchySeq 2.0 0.5) rng -// Taking some samples from the composed function -Seq.take 10 (s2s (Random.system())) |> Seq.toArray + // Taking some samples from the composed function + Seq.take 10 (s2s (Random.system())) |> Seq.toArray diff --git a/docs/content/Random.fsx b/docs/content/Random.md similarity index 84% rename from docs/content/Random.fsx rename to docs/content/Random.md index 41b89b36..2c4b01e6 100644 --- a/docs/content/Random.fsx +++ b/docs/content/Random.md @@ -1,11 +1,12 @@ -(*** hide ***) -#I "../../out/lib/net40" -#r "MathNet.Numerics.dll" -#r "MathNet.Numerics.FSharp.dll" -open MathNet.Numerics.Random -open MathNet.Numerics.Distributions - -(** + [hide] + #I "../../out/lib/net40" + #r "MathNet.Numerics.dll" + #r "MathNet.Numerics.FSharp.dll" + open System.Numerics + open MathNet.Numerics + open MathNet.Numerics.Random + open MathNet.Numerics.Distributions + Pseudo-Random Numbers ===================== @@ -57,22 +58,21 @@ $X\sim\mathcal{U}(0,1)$, such that $0 \le x < 1$: decimal sampled = rng.NextDecimal(); In F# we can do exactly the same, or alternatively use the `Random` module: -*) -let samples = Random.doubles 1000 + [lang=fsharp] + let samples = Random.doubles 1000 -// overwrite the whole array with new random values -Random.doubleFill samples + // overwrite the whole array with new random values + Random.doubleFill samples -// create an infinite sequence: -let sampleSeq = Random.doubleSeq () + // create an infinite sequence: + let sampleSeq = Random.doubleSeq () -// take a single random value -let rng = Random.shared -let sample = rng.NextDouble() -let sampled = rng.NextDecimal() + // take a single random value + let rng = Random.shared + let sample = rng.NextDouble() + let sampled = rng.NextDecimal() -(** If you have used the .Net BCL random number generators before, you have likely noticed a few differences: we used special routines to create a full array or sequence in one go, we were able to sample a decimal number, an we used static functions @@ -125,19 +125,19 @@ and is often unwanted. That's why all Math.NET Numerics RNGs are by default initialized with a robust seed taken from the `CryptoRandomSource` if available, or else a combination of a random number from a shared RNG, the time and a Guid (which are supposed to be generated uniquely, worldwide). -*) -let someTimeSeed = RandomSeed.Time() // not recommended -let someGuidSeed = RandomSeed.Guid() -let someRobustSeed = RandomSeed.Robust() // recommended, used by default + [lang=fsharp] + let someTimeSeed = RandomSeed.Time() // not recommended + let someGuidSeed = RandomSeed.Guid() + let someRobustSeed = RandomSeed.Robust() // recommended, used by default -(** Let's generate random numbers like before, but this time with custom seed 42: *) +Let's generate random numbers like before, but this time with custom seed 42: -let samplesSeeded = Random.doublesSeed 42 1000 -Random.doubleFillSeed 42 samplesSeeded -let samplesSeqSeeded = Random.doubleSeqSeed 42 + [lang=fsharp] + let samplesSeeded = Random.doublesSeed 42 1000 + Random.doubleFillSeed 42 samplesSeeded + let samplesSeqSeeded = Random.doubleSeqSeed 42 -(** Or without the F# Random module, e.g. in C#: [lang=csharp] @@ -179,23 +179,23 @@ Let's sample a few uniform random values using Mersenne Twister in C#: In F# you can use the constructor as well, or alternatively use the `Random` module. In case of the latter, all objects will be cast to their common base type `System.Random`: -*) -// By using the normal constructor (random1 has type MersenneTwister) -let random1 = MersenneTwister() -let random1b = MersenneTwister(42) // with seed + [lang=fsharp] + // By using the normal constructor (random1 has type MersenneTwister) + let random1 = MersenneTwister() + let random1b = MersenneTwister(42) // with seed -// By using the Random module (random2 has type System.Random) -let random2 = Random.mersenneTwister () -let random2b = Random.mersenneTwisterSeed 42 // with seed -let random2c = Random.mersenneTwisterWith 42 false // opt-out of thread-safety + // By using the Random module (random2 has type System.Random) + let random2 = Random.mersenneTwister () + let random2b = Random.mersenneTwisterSeed 42 // with seed + let random2c = Random.mersenneTwisterWith 42 false // opt-out of thread-safety + + // Using some other algorithms: + let random3 = Random.crypto () + let random4 = Random.xorshift () + let random5 = Random.wh2006 () -// Using some other algorithms: -let random3 = Random.crypto () -let random4 = Random.xorshift () -let random5 = Random.wh2006 () -(** Shared Instances and Thread Safety ---------------------------------- @@ -224,15 +224,15 @@ For convenience a few generators provide a thread-safe shared instance var b = MersenneTwister.Default; Or with the F# module: -*) -let a = Random.systemShared -let b = Random.mersenneTwisterShared + [lang=fsharp] + let a = Random.systemShared + let b = Random.mersenneTwisterShared + + // or if you don't care, simply + let c = Random.shared; -// or if you don't care, simply -let c = Random.shared; -(** Non-Uniform Random Numbers -------------------------- @@ -253,4 +253,3 @@ distributions in the `MathNet.Numerics.Distributions` namespace. Normal.Samples(c, 0.0, 1.0); See [Probability Distributions](Probability.html) for details. -*) diff --git a/docs/content/Regression.fsx b/docs/content/Regression.md similarity index 96% rename from docs/content/Regression.fsx rename to docs/content/Regression.md index 7e6d60a0..8af543f2 100644 --- a/docs/content/Regression.fsx +++ b/docs/content/Regression.md @@ -1,12 +1,12 @@ -(*** hide ***) -#I "../../out/lib/net40" -#r "MathNet.Numerics.dll" -#r "MathNet.Numerics.FSharp.dll" -open MathNet.Numerics -open MathNet.Numerics.LinearRegression -open MathNet.Numerics.LinearAlgebra - -(** + [hide] + #I "../../out/lib/net40" + #r "MathNet.Numerics.dll" + #r "MathNet.Numerics.FSharp.dll" + open System.Numerics + open MathNet.Numerics + open MathNet.Numerics.LinearRegression + open MathNet.Numerics.LinearAlgebra + Curve Fitting: Linear Regression ================================ @@ -40,11 +40,10 @@ parameters of the least squares fit: double b = p.Item2; // == 0.5; slope Or in F#: -*) -let a, b = Fit.Line ([|10.0;20.0;30.0|], [|15.0;20.0;25.0|]) + [lang=fsharp] + let a, b = Fit.Line ([|10.0;20.0;30.0|], [|15.0;20.0;25.0|]) -(** How well do these parameters fit the data? The data points happen to be positioned exactly on a line. Indeed, the [coefficient of determination](https://en.wikipedia.org/wiki/Coefficient_of_determination) confirms the perfect fit: @@ -259,7 +258,6 @@ are dependent on the point of interest $t$. Regularization -------------- + Iterative Methods ----------------- - -*)