diff --git a/graph-gallery.html b/graph-gallery.html index bb1f183..c8c0a5d 100644 --- a/graph-gallery.html +++ b/graph-gallery.html @@ -112,7 +112,7 @@

diff --git a/graph-gallery/scatter/fsharp.html b/graph-gallery/scatter/fsharp.html index f1bd7e1..c815f5b 100644 --- a/graph-gallery/scatter/fsharp.html +++ b/graph-gallery/scatter/fsharp.html @@ -163,12 +163,12 @@

select language:

- - csharp - fsharp + + csharp +
diff --git a/images/Cheby.png b/images/Cheby.png new file mode 100644 index 0000000..d6d55c2 Binary files /dev/null and b/images/Cheby.png differ diff --git a/index.html b/index.html index 24572d1..c563c0e 100644 --- a/index.html +++ b/index.html @@ -111,24 +111,24 @@

- +
- post preview image + post preview image

- - Multiple testing correction: q values + + Chebyshev function approximation

- This tutorial explains the key concepts of q values and how to calculate them using FSharp.Stats. + This tutorial demonstrates how to use Chebyshev spaced knots to approximate functions.
- Posted on 2022-3-20 by + Posted on 2023-8-31 by Benedikt Venn @@ -150,7 +150,7 @@

- Data Science [7] + Data Science [8]

@@ -193,7 +193,7 @@

- +
post preview image
@@ -201,7 +201,7 @@

- + Scatter plots in F# and C# using Plotly.NET

@@ -211,12 +211,12 @@

Scatter plots are one of the most fundamental ways of visualizing two-dimensional data. In this post I will showcase common use cases for Scatter plots and create them in both F# and C# using Plotly.NET

Posted on 2023-3-16 by diff --git a/posts/categories/Datascience.html b/posts/categories/Datascience.html index 34e3c2c..d9a87d7 100644 --- a/posts/categories/Datascience.html +++ b/posts/categories/Datascience.html @@ -86,6 +86,45 @@

+
+
+
+
+

+ 2023-8-31 +

+
+ + +
+
+ This tutorial demonstrates how to use Chebyshev spaced knots to approximate functions. +
+ Posted on 2023-8-31 by + + Benedikt Venn + + in + + Data Science + +
+
+
+
+
@@ -211,17 +250,27 @@

2021-7-28

+
+
+ his tutorial demonstrates hierarchical clustering with FSharp.Stats and how to visualize the results with Plotly.NET. +
Posted on 2021-7-28 by - - Kevin Frey + + Benedikt Venn in @@ -240,27 +289,17 @@

2021-7-28

-
-
- his tutorial demonstrates hierarchical clustering with FSharp.Stats and how to visualize the results with Plotly.NET. -
Posted on 2021-7-28 by - - Benedikt Venn + + Kevin Frey in diff --git a/posts/categories/Fsharp.html b/posts/categories/Fsharp.html index 88dda8c..edb1e96 100644 --- a/posts/categories/Fsharp.html +++ b/posts/categories/Fsharp.html @@ -96,8 +96,8 @@

@@ -125,8 +125,8 @@

diff --git a/posts/chebyshev-approximation.html b/posts/chebyshev-approximation.html new file mode 100644 index 0000000..6f0730e --- /dev/null +++ b/posts/chebyshev-approximation.html @@ -0,0 +1,1344 @@ + + + + + + Chebyshev function approximation + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+
+
+
+

+ Chebyshev function approximation +

+
+

+ Posted on 2023-8-31 by + + Benedikt Venn + + in + + Data Science + +

+
+
+
+
+
+ + +
+
+ + \ No newline at end of file diff --git a/posts/chebyshev-approximation.ipynb b/posts/chebyshev-approximation.ipynb new file mode 100644 index 0000000..3ed82bf --- /dev/null +++ b/posts/chebyshev-approximation.ipynb @@ -0,0 +1,931 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chebyshev function approximation using FSharp.Stats\n", + "\n", + "_Summary: This blogpost introduces the concept of function approximation by using knots spaced according to Chebyshev._\n", + "\n", + "This post is inspired by [M. Scroggs blog post](https://www.mscroggs.co.uk/blog/57) and shows how to perform function approximation in F#. \n", + "\n", + "Lets start by generating data in a two dimensional space. The aim is to interpolate the data using a single polynomial. Why in certain cases this is a sensible thing to do will be discussed later. We'll need [FSharp.Stats](https://github.com/fslaborg/FSharp.Stats) for all the data handling and [Plotly.NET](https://github.com/plotly/Plotly.NET) for visualization.\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "fsharp" + }, + "polyglot_notebook": { + "kernelName": "fsharp" + } + }, + "outputs": [], + "source": [ + "#r \"nuget: Plotly.NET.Interactive, 4.2.1\"\n", + "#r \"nuget: FSharp.Stats, 0.5.0\"\n", + "//#r \"nuget: FSharp.Stats, 0.5.1\"" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Defining data\n", + "\n", + "We define a short data sample, that should be interpolated using polynomials, and visualize it using a scatter plot.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "dotnet_interactive": { + "language": "fsharp" + }, + "polyglot_notebook": { + "kernelName": "fsharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "\n", + "open Plotly.NET\n", + "open FSharp.Stats\n", + "open FSharp.Stats.Interpolation\n", + "\n", + "let xs = [|0. .. 0.2 .. 3.|]\n", + "let ys = [|5.;5.5;6.;6.1;4.;1.;0.7;0.3;0.5;0.9;5.;9.;9.;8.;6.5;5.;|]\n", + "\n", + "Chart.Point(xs,ys,Name=\"raw\")\n", + "|> Chart.withTemplate ChartTemplates.lightMirrored\n", + "\n" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## The problem\n", + "\n", + "Your task is to approximate a function that interpolate these data points to get predictions of the regions between the knots. The simplest and most common way to solve this problem is to just connect the points by straight line segments. This linear segments can be predicted using linear splines from FSharp.Stats.Interpolation:" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "dotnet_interactive": { + "language": "fsharp" + }, + "polyglot_notebook": { + "kernelName": "fsharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "// Get linear spline coefficients that completely describe the curve.\n", + "// In the case of linear splines, these coefficients consist of the x values, their intercepts and segment slopes\n", + "let linearCoefficients = Interpolation.interpolate(xs,ys,InterpolationMethod.LinearSpline)\n", + "\n", + "// by using Interpolation.predict(coef) x you can predict any point on the curve\n", + "let yAt2_19 = Interpolation.predict(linearCoefficients) 2.19\n", + "\n", + "\n", + "let chebyChart = Chart.Line(xs,ys,Name=\"raw_nodes\",ShowMarkers=true)\n", + "\n", + "[\n", + "chebyChart\n", + "Chart.Point([2.19,yAt2_19],Name=\"prediction\")\n", + "]\n", + "|> Chart.combine\n", + "|> Chart.withTemplate ChartTemplates.lightMirrored" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The drawback of this strategy is the discontinuouity of the function. At each knot, the function value is defined, but its slope and curvature isn't. Additionally the segments are not influenced by neighbouring segments. While integration is possible in principle, there is no single function that enables its calculation. You have to sum up the individual segment areas individually. \n", + "\n", + "## Polynomials to the rescue\n", + "A solution is to use interpolationg polynomials. Polynomials are easy to define and differentiation as well as integration is straight forward. Any data can be interpolated by a single function with a degree of #points-1. With the example data the polynomial has the form of:\n", + "$$f(x) = ax^{15} + bx^{14} + cx^{13} + ... + dx^2 + ex + g$$" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "dotnet_interactive": { + "language": "fsharp" + }, + "polyglot_notebook": { + "kernelName": "fsharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
16
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "let coef = Interpolation.interpolate(xs,ys,InterpolationMethod.Polynomial)\n", + "\n", + "match coef with \n", + "| InterpolationCoefficients.PolynomialCoef x -> x.C0_CX.Length\n", + "\n", + "//coef.GetPolynomialCoef() //available from 0.5.1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As proved in the cell above, there are n coefficients defining a polynomial of degree n-1. To check the resulting polynomial curve, the function is plotted with a small step size to investigate the regions between the knots in detail" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "dotnet_interactive": { + "language": "fsharp" + }, + "polyglot_notebook": { + "kernelName": "fsharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "// by using Interpolation.predict(coef) x you can predict any point on the curve\n", + "let interpolationChart = \n", + " [0. .. 0.005 .. 3.] |> List.map (fun x -> x,Interpolation.predict(coef) x) |> Chart.Line |> Chart.withTraceInfo \"interpol_polynomial\"\n", + "\n", + "[\n", + "Chart.Point(xs,ys,Name=\"raw\")\n", + "interpolationChart\n", + "Chart.Point([2.19,Interpolation.predict(coef) 2.19],Name=\"prediction\")\n", + "]\n", + "|> Chart.combine\n", + "|> Chart.withTemplate ChartTemplates.lightMirrored\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Runge's phenomenon\n", + "\n", + "As seen above the resulting interpolating function is worse than the connecting straights. A common problem of polynomial interpolation is Runge's phenomenon, also called Runge's spikes. The only constraints the function must satisfy is to pass through the knots. Obviously between the knots the prediction is quite bad, because it wasn't optimised to be smooth (as in e.g. cubic spline interpolation). \n", + "\n", + "This overfitting gets more extreme the nearer it is to the outmost segments. Thereby the interpolation function is rendered useless for predicting internal points or calculating slopes/integrals. Imagine you should calculate the integral of the range [0,0.2], which obviously should be approximately 1.05 (xRange=0.2, yRange=5.25), but definetely greater than 0.\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "dotnet_interactive": { + "language": "fsharp" + }, + "polyglot_notebook": { + "kernelName": "fsharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
-10.429018827227397
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "Interpolation.getIntegralBetween(coef,0.,0.2) // available from version 0.5.1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Because of the spikes, the integral is totally unintuitive and its likely, that the result is wrong. It would be detrimental if this function approximation is used to investigate signal properties.\n", + "\n", + "A clever way of reducing the occurence of these wiggles is to use an x value spacing accrding to Chebyshev. Thereby the x values are not sorted equally spaced like it is common for such interpolation tasks. Instead, they are expanded in the signal center and compressed to the outward knots. This is achieved by streching the x values to a semicircle and from there projecting the x values back to a linear axis. In the picture seen below ([from M.Scroggs](https://www.mscroggs.co.uk/img/full/chebdef.png)), x values are equally spaced onto a semicircle and subsequently back projected to the linear x axis. Thereby the desired spacing is achieved.\n", + "\n", + "\"Alt\n", + "\n", + "Mathematically the transformation it is defined within the interval [a,b] as: \n", + "
\n", + "\"Alt\n", + "
\n", + "\n", + "\n", + "In FSharp.Stats this can be done as follows. The spacing of the x values is visualized as scatter plot.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "dotnet_interactive": { + "language": "fsharp" + }, + "polyglot_notebook": { + "kernelName": "fsharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "// new x values are determined in the x axis range of the data. These should reduce overshooting behaviour.\n", + "// since the original data consisted of 16 points, 16 nodes are initialized within the original interval\n", + "let xs_cheby = \n", + " Interpolation.Approximation.chebyshevNodes (Interval.CreateClosed(0.,3.)) 16\n", + "\n", + "[\n", + "Chart.Point(x=xs, y=Array.init xs_cheby.Length (fun _ -> 0.), Name=\"Original knots\")\n", + "Chart.Point(x=xs_cheby, y=Array.init xs_cheby.Length (fun _ -> 1.), Name=\"Chebyshev knots\")\n", + "]\n", + "|> Chart.combine\n", + "|> Chart.withTemplate ChartTemplates.lightMirrored\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Of course the corresponding y values are missing. Here linear spline are used to predict the new function values at the chebyshev knots (Note: Alternatively, you could predict them by using cubic interpolating splines)." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "dotnet_interactive": { + "language": "fsharp" + }, + "polyglot_notebook": { + "kernelName": "fsharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "// to get the corresponding y values to the xs_cheby a linear spline is generated that approximates the new y values\n", + "let ys_cheby =\n", + " let ls = Interpolation.LinearSpline.interpolate xs ys\n", + " xs_cheby |> Vector.map (Interpolation.LinearSpline.predict ls)\n", + "\n", + "[\n", + " chebyChart\n", + " Chart.Line(xs_cheby,ys_cheby,Name=\"transformed signal\",ShowMarkers=true)\n", + "]\n", + "|> Chart.combine" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "With the new data, a simple polynomial interpolation is performed as before. Of course these procedures can be achieved directly by calling `Interpolation.Approximation.approxWithPolynomialFromValues`." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "dotnet_interactive": { + "language": "fsharp" + }, + "polyglot_notebook": { + "kernelName": "fsharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
{ C0_CX =\\n vector [|5.019201925; -0.7533214741; 88.83097648; -931.9524978; 5021.556986;\\n -16205.09493; 34581.04672; -51920.40174; 56337.21571; -44418.89323;\\n 25289.04892; -10235.17511; 2861.178305; -523.8910412; 56.45234065;\\n -2.711273142|] }
C0_CX
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
InternalValues
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Values
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
OpsData
Some(FSharp.Stats.Instances+FloatNumerics@116)
Value
FSharp.Stats.Instances+FloatNumerics@116
Length
16
NumRows
16
ElementOps
FSharp.Stats.Instances+FloatNumerics@116
DebugDisplay
vector [5.019201925;-0.7533214741;88.83097648;-931.9524978;5021.556986;-16205.09493;34581.04672;-51920.40174;56337.21571;-44418.89323;25289.04892;-10235.17511;2861.178305;-523.8910412;56.45234065;-2.711273142]
Capacity
209
MaxCapacity
2147483647
Length
209
StructuredDisplayAsArray
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Details
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Transpose
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
InternalValues
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Values
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
OpsData
Some(FSharp.Stats.Instances+FloatNumerics@116)
Value
FSharp.Stats.Instances+FloatNumerics@116
Length
16
NumCols
16
ElementOps
FSharp.Stats.Instances+FloatNumerics@116
DebugDisplay
rowvec [5.019201925;-0.7533214741;88.83097648;-931.9524978;5021.556986;-16205.09493;34581.04672;-51920.40174;56337.21571;-44418.89323;25289.04892;-10235.17511;2861.178305;-523.8910412;56.45234065;-2.711273142]
Capacity
209
MaxCapacity
2147483647
Length
209
StructuredDisplayAsArray
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Details
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Transpose
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
InternalValues
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Values
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
OpsData
Some(FSharp.Stats.Instances+FloatNumerics@116)
Value
FSharp.Stats.Instances+FloatNumerics@116
Length
16
NumRows
16
ElementOps
FSharp.Stats.Instances+FloatNumerics@116
DebugDisplay
vector [5.019201925;-0.7533214741;88.83097648;-931.9524978;5021.556986;-16205.09493;34581.04672;-51920.40174;56337.21571;-44418.89323;25289.04892;-10235.17511;2861.178305;-523.8910412;56.45234065;-2.711273142]
Capacity
209
MaxCapacity
2147483647
Length
209
StructuredDisplayAsArray
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Details
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Transpose
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
InternalValues
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Values
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
OpsData
Some(FSharp.Stats.Instances+FloatNumerics@116)
ValueFSharp.Stats.Instances+FloatNumerics@116
Length
16
NumCols
16
ElementOps
FSharp.Stats.Instances+FloatNumerics@116
DebugDisplay
rowvec [5.019201925;-0.7533214741;88.83097648;-931.9524978;5021.556986;-16205.09493;34581.04672;-51920.40174;56337.21571;-44418.89323;25289.04892;-10235.17511;2861.178305;-523.8910412;56.45234065;-2.711273142]
Capacity209
MaxCapacity2147483647
Length209
StructuredDisplayAsArray
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Details
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Transpose
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
InternalValues[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Values[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
OpsDataSome(FSharp.Stats.Instances+FloatNumerics@116)
Length16
NumRows16
ElementOpsFSharp.Stats.Instances+FloatNumerics@116
DebugDisplayvector [5.019201925;-0.7533214741;88.83097648;-931.9524978;5021.556986;-16205.09493;34581.04672;-51920.40174;56337.21571;-44418.89323;25289.04892;-10235.17511;2861.178305;-523.8910412;56.45234065;-2.711273142]
StructuredDisplayAsArray[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Details[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Transpose[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
(values)
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
(values)
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
(values)
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
(values)
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
(values)
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Predict
FSharp.Stats.InterpolationModule+Polynomial+get_Predict@51
this
{ C0_CX =\\n vector [|5.019201925; -0.7533214741; 88.83097648; -931.9524978; 5021.556986;\\n -16205.09493; 34581.04672; -51920.40174; 56337.21571; -44418.89323;\\n 25289.04892; -10235.17511; 2861.178305; -523.8910412; 56.45234065;\\n -2.711273142|] }
C0_CX
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
InternalValues
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Values
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
OpsData
Some(FSharp.Stats.Instances+FloatNumerics@116)
Value
FSharp.Stats.Instances+FloatNumerics@116
Length
16
NumRows
16
ElementOps
FSharp.Stats.Instances+FloatNumerics@116
DebugDisplay
vector [5.019201925;-0.7533214741;88.83097648;-931.9524978;5021.556986;-16205.09493;34581.04672;-51920.40174;56337.21571;-44418.89323;25289.04892;-10235.17511;2861.178305;-523.8910412;56.45234065;-2.711273142]
Capacity
209
MaxCapacity
2147483647
Length
209
StructuredDisplayAsArray
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Details
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Transpose
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
InternalValues
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Values
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
OpsData
Some(FSharp.Stats.Instances+FloatNumerics@116)
ValueFSharp.Stats.Instances+FloatNumerics@116
Length
16
NumCols
16
ElementOps
FSharp.Stats.Instances+FloatNumerics@116
DebugDisplay
rowvec [5.019201925;-0.7533214741;88.83097648;-931.9524978;5021.556986;-16205.09493;34581.04672;-51920.40174;56337.21571;-44418.89323;25289.04892;-10235.17511;2861.178305;-523.8910412;56.45234065;-2.711273142]
Capacity209
MaxCapacity2147483647
Length209
StructuredDisplayAsArray
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Details
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Transpose
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
InternalValues[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Values[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
OpsDataSome(FSharp.Stats.Instances+FloatNumerics@116)
Length16
NumRows16
ElementOpsFSharp.Stats.Instances+FloatNumerics@116
DebugDisplayvector [5.019201925;-0.7533214741;88.83097648;-931.9524978;5021.556986;-16205.09493;34581.04672;-51920.40174;56337.21571;-44418.89323;25289.04892;-10235.17511;2861.178305;-523.8910412;56.45234065;-2.711273142]
StructuredDisplayAsArray[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Details[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Transpose[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
(values)
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
(values)
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
(values)
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Predict
FSharp.Stats.InterpolationModule+Polynomial+get_Predict@51
this
{ C0_CX =\\n vector [|5.019201925; -0.7533214741; 88.83097648; -931.9524978; 5021.556986;\\n -16205.09493; 34581.04672; -51920.40174; 56337.21571; -44418.89323;\\n 25289.04892; -10235.17511; 2861.178305; -523.8910412; 56.45234065;\\n -2.711273142|] }
C0_CX
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
InternalValues[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Values[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
OpsDataSome(FSharp.Stats.Instances+FloatNumerics@116)
Length16
NumRows16
ElementOpsFSharp.Stats.Instances+FloatNumerics@116
DebugDisplayvector [5.019201925;-0.7533214741;88.83097648;-931.9524978;5021.556986;-16205.09493;34581.04672;-51920.40174;56337.21571;-44418.89323;25289.04892;-10235.17511;2861.178305;-523.8910412;56.45234065;-2.711273142]
StructuredDisplayAsArray[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Details[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Transpose[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
(values)
[ 5.019201924823986, -0.7533214741322293, 88.83097647738644, -931.9524977725528, 5021.556985929983, -16205.094934904337, 34581.04671553936, -51920.40174004338, 56337.215710140226, -44418.8932327272, 25289.048919873298, -10235.175112455037, 2861.17830460304, -523.8910411644107, 56.452340646091066, -2.7112731416610663 ]
Predict
FSharp.Stats.InterpolationModule+Polynomial+get_Predict@51
this{ C0_CX =\n", + " vector [|5.019201925; -0.7533214741; 88.83097648; -931.9524978; 5021.556986;\n", + " -16205.09493; 34581.04672; -51920.40174; 56337.21571; -44418.89323;\n", + " 25289.04892; -10235.17511; 2861.178305; -523.8910412; 56.45234065;\n", + " -2.711273142|] }
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "// again polynomial interpolation coefficients are determined, but here with the x and y data that correspond to the chebyshev spacing\n", + "let coeffs_cheby = Interpolation.Polynomial.interpolate xs_cheby ys_cheby\n", + "\n", + "\n", + "// Note: the upper panels can be summarized by the following function:\n", + "// returns the polynomical coefficients that approximate the given data\n", + "let polynomialCoefficients = Interpolation.Approximation.approxWithPolynomialFromValues(xData=xs,yData=ys,n=16,spacing=Interpolation.Approximation.Spacing.Chebyshev)\n", + "\n", + "polynomialCoefficients" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Using the determined polynomial coefficients, the standard approach for fitting can be used to plot the signal together with the function approximation. The chebyshev spacing of the x-nodes drastically reduces the overfitting in the outer areas of the signal." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "dotnet_interactive": { + "language": "fsharp" + }, + "polyglot_notebook": { + "kernelName": "fsharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "\n", + "// function using the cheby_coefficients to get y values of given x value\n", + "let interpolating_cheby x = Interpolation.Polynomial.predict coeffs_cheby x\n", + "\n", + "let interpolChart_cheby =\n", + " let ys_interpol_cheby = \n", + " vector [|0. .. 0.01 .. 3.|] \n", + " |> Seq.map (fun x -> x,interpolating_cheby x)\n", + "\n", + " Chart.Line(ys_interpol_cheby,Name=\"interpol_cheby\")\n", + " |> Chart.withTemplate ChartTemplates.lightMirrored\n", + " |> Chart.withXAxisStyle \"xs\"\n", + " |> Chart.withYAxisStyle \"ys\"\n", + "\n", + "\n", + "[\n", + "chebyChart\n", + "interpolationChart\n", + "Chart.Line(xs_cheby,ys_cheby,ShowMarkers=true,Name=\"cheby_nodes\") |> Chart.withTemplate ChartTemplates.lightMirrored|> Chart.withXAxisStyle \"xs\"|> Chart.withYAxisStyle \"ys\"\n", + "interpolChart_cheby\n", + "]\n", + "|> Chart.combine\n", + "|> Chart.withXAxisStyle \"xs\"\n", + "|> Chart.withTitle(Title.init(\"Chebyshev spacing for function interpolation\",X=0.5))\n", + "|> Chart.withSize(800.,500.)\n", + "|> Chart.withYAxisStyle \"ys\"\n", + "|> Chart.withTemplate ChartTemplates.lightMirrored\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now we can again approximate the integral of the function between [0,0.2]. The result now should be much closer at the expected value of 1.05." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "dotnet_interactive": { + "language": "fsharp" + }, + "polyglot_notebook": { + "kernelName": "fsharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
1.0508141233095727
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "coeffs_cheby.GetIntegralBetween 0. 0.2 // available from version 0.5.1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Approximating a polynomial from a function\n", + "\n", + "Instead of starting from data points you can also transform any function you like to easy-to-use polynomials. This comes handy when investigating function properties with complex functions that cannot be differentiated easily. As seen below, a function with y \n", + "axial symmetry is approximated. While an even number of knots very well approximates the tails, an uneven number precisely predicts the center point. The simple interpolation with equally spaced points nicely depicts a drastic overshoot (Runge's phenomenon).\n" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "dotnet_interactive": { + "language": "fsharp" + }, + "polyglot_notebook": { + "kernelName": "fsharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "// this example is the Runge function and is inspired by the wonderful blog post of Matthew Scroggs (https://www.mscroggs.co.uk/blog/57)\n", + "let myFunctionToSimplify (x: float) =\n", + " 1. / (1. + 25. * x * x)\n", + "\n", + "// using 20 knots that are spaced according to chebyshev\n", + "let myFunctionAsPolynomial_C20 = Interpolation.Approximation.approxWithPolynomial(myFunctionToSimplify,Interval.CreateClosed(-1.,1.), 200, spacing=Interpolation.Approximation.Spacing.Chebyshev)\n", + "// using 25 knots that are spaced according to chebyshev\n", + "let myFunctionAsPolynomial_C25 = Interpolation.Approximation.approxWithPolynomial(myFunctionToSimplify,Interval.CreateClosed(-1.,1.), 25, spacing=Interpolation.Approximation.Spacing.Chebyshev)\n", + "// using 20 knots that are equally spaced\n", + "let myFunctionAsPolynomial_E20 = Interpolation.Approximation.approxWithPolynomial(myFunctionToSimplify,Interval.CreateClosed(-1.,1.), 20, spacing=Interpolation.Approximation.Spacing.Equally)\n", + "\n", + "[\n", + "[-1. .. 0.01 .. 1.] |> List.map (fun x -> x,myFunctionToSimplify x) |> Chart.Line |> Chart.withTraceInfo(\"original function\")\n", + "[-1. .. 0.01 .. 1.] |> List.map (fun x -> x,myFunctionAsPolynomial_E20.Predict x) |> Chart.Line |> Chart.withTraceInfo(\"approximation(equally) k=20\")\n", + "[-1. .. 0.01 .. 1.] |> List.map (fun x -> x,myFunctionAsPolynomial_C20.Predict x) |> Chart.Line |> Chart.withTraceInfo(\"approximation(Chebyshev) k=20\")\n", + "[-1. .. 0.01 .. 1.] |> List.map (fun x -> x,myFunctionAsPolynomial_C25.Predict x) |> Chart.Line |> Chart.withTraceInfo(\"approximation(Chebyshev) k=25\")\n", + "]\n", + "|> Chart.combine\n", + "|> Chart.withTemplate ChartTemplates.lightMirrored\n", + "|> Chart.withTitle(Title.init(\"Approximated Runges function\",X=0.5))\n", + "|> Chart.withSize(800.,500.)\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Use cases\n", + "\n", + "- function approximaion of nonlinear relations (e.g. Schrödingers function) with only a few terms\n", + "- optimization techniques\n", + "- numerical solution of integral equations\n", + "- improving wavelet transforms by enhancing the accuracy in outer areas\n", + "\n", + "## Drawbacks\n", + "\n", + "- The Chebychev knots are interpolated linearly. The points that are interpolated don't exist in the original data. As alternative one may use cubic splines to get a better approximation of the transformed knots, but since the presented strategy aims to minimize computing ressources, it wouldn't make much sense to use cubic splines and then go back to polynomials.\n", + "\n", + "## Other techniques to mitigate Runge's phenomenon\n", + "\n", + "- using lower degree polynomials: Thereby you automatically move to linear regression instead of interpolation\n", + "- switching to splines: Splines are perfect to reduce high oscillating behaviour of regression curves\n", + "\n", + "## References\n", + "\n", + " - [M. Scroggs blog post](https://www.mscroggs.co.uk/blog/57) with its [Github repo](https://github.com/mscroggs/RungeBot)\n", + " - [Youtube - Beware the Runge Spikes! from Matt Parker](https://www.youtube.com/watch?v=F_43oTnTXiw)\n", + " - [FSharp.Stats documentation](https://fslab.org/FSharp.Stats/Interpolation.html#Chebyshev-function-approximation)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".NET (C#)", + "language": "C#", + "name": ".net-csharp" + }, + "language_info": { + "name": "polyglot-notebook" + }, + "polyglot_notebook": { + "kernelInfo": { + "defaultKernelName": "csharp", + "items": [ + { + "aliases": [], + "name": ".NET" + }, + { + "aliases": [ + "C#", + "c#" + ], + "languageName": "C#", + "name": "csharp" + }, + { + "aliases": [ + "F#", + "f#" + ], + "languageName": "F#", + "name": "fsharp" + }, + { + "aliases": [], + "languageName": "HTML", + "name": "html" + }, + { + "aliases": [], + "languageName": "KQL", + "name": "kql" + }, + { + "aliases": [], + "languageName": "Mermaid", + "name": "mermaid" + }, + { + "aliases": [ + "powershell" + ], + "languageName": "PowerShell", + "name": "pwsh" + }, + { + "aliases": [], + "languageName": "SQL", + "name": "sql" + }, + { + "aliases": [], + "name": "value" + }, + { + "aliases": [ + "frontend" + ], + "name": "vscode" + } + ] + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}