From 8ff9d2c0bb9e0d115a1512753014ea9911f21ff3 Mon Sep 17 00:00:00 2001 From: "Documenter.jl" Date: Tue, 6 Feb 2024 00:30:20 +0000 Subject: [PATCH] build based on d76cdc8 --- dev/.documenter-siteinfo.json | 2 +- dev/assets/Manifest.toml | 8 +- dev/index.html | 10 +- dev/interface/index.html | 2 +- dev/methods/{2a45f9c3.svg => 1776a4ff.svg} | 82 ++-- dev/methods/{fc6dd49e.svg => 534e4780.svg} | 82 ++-- dev/methods/{cdfed1ff.svg => 60f53e83.svg} | 96 ++--- dev/methods/{feaecfd7.svg => 674d43d6.svg} | 78 ++-- dev/methods/{087592a1.svg => 7edd06df.svg} | 82 ++-- dev/methods/{2612a471.svg => 7ef9477d.svg} | 468 ++++++++++----------- dev/methods/{5b214705.svg => 9771a179.svg} | 86 ++-- dev/methods/{a96da2c4.svg => a7a20c98.svg} | 82 ++-- dev/methods/{d2e8b078.svg => af163bf5.svg} | 86 ++-- dev/methods/{9e638fa2.svg => ba7fca14.svg} | 82 ++-- dev/methods/{c51fc27c.svg => c0d5db56.svg} | 262 ++++++------ dev/methods/{25ae9f99.svg => c99ba59e.svg} | 262 ++++++------ dev/methods/{e7c1bf53.svg => d9ba0985.svg} | 90 ++-- dev/methods/index.html | 28 +- 18 files changed, 944 insertions(+), 944 deletions(-) rename dev/methods/{2a45f9c3.svg => 1776a4ff.svg} (97%) rename dev/methods/{fc6dd49e.svg => 534e4780.svg} (97%) rename dev/methods/{cdfed1ff.svg => 60f53e83.svg} (86%) rename dev/methods/{feaecfd7.svg => 674d43d6.svg} (97%) rename dev/methods/{087592a1.svg => 7edd06df.svg} (97%) rename dev/methods/{2612a471.svg => 7ef9477d.svg} (80%) rename dev/methods/{5b214705.svg => 9771a179.svg} (97%) rename dev/methods/{a96da2c4.svg => a7a20c98.svg} (97%) rename dev/methods/{d2e8b078.svg => af163bf5.svg} (97%) rename dev/methods/{9e638fa2.svg => ba7fca14.svg} (97%) rename dev/methods/{c51fc27c.svg => c0d5db56.svg} (95%) rename dev/methods/{25ae9f99.svg => c99ba59e.svg} (95%) rename dev/methods/{e7c1bf53.svg => d9ba0985.svg} (97%) diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index 82eb7ddd..3090d829 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.10.0","generation_timestamp":"2024-02-04T20:51:51","documenter_version":"1.2.1"}} \ No newline at end of file +{"documenter":{"julia_version":"1.10.0","generation_timestamp":"2024-02-06T00:30:15","documenter_version":"1.2.1"}} \ No newline at end of file diff --git a/dev/assets/Manifest.toml b/dev/assets/Manifest.toml index 327af428..0b7d401d 100644 --- a/dev/assets/Manifest.toml +++ b/dev/assets/Manifest.toml @@ -766,9 +766,9 @@ version = "0.5.5+0" [[deps.Optim]] deps = ["Compat", "FillArrays", "ForwardDiff", "LineSearches", "LinearAlgebra", "MathOptInterface", "NLSolversBase", "NaNMath", "Parameters", "PositiveFactorizations", "Printf", "SparseArrays", "StatsBase"] -git-tree-sha1 = "47fea72de134f75b105a5d4a1abe5c6aec89d390" +git-tree-sha1 = "d024bfb56144d947d4fafcd9cb5cafbe3410b133" uuid = "429524aa-4258-5aef-a3af-852621145aeb" -version = "1.9.1" +version = "1.9.2" [[deps.Opus_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] @@ -828,9 +828,9 @@ version = "1.4.0" [[deps.Plots]] deps = ["Base64", "Contour", "Dates", "Downloads", "FFMPEG", "FixedPointNumbers", "GR", "JLFzf", "JSON", "LaTeXStrings", "Latexify", "LinearAlgebra", "Measures", "NaNMath", "Pkg", "PlotThemes", "PlotUtils", "PrecompileTools", "Printf", "REPL", "Random", "RecipesBase", "RecipesPipeline", "Reexport", "RelocatableFolders", "Requires", "Scratch", "Showoff", "SparseArrays", "Statistics", "StatsBase", "UUIDs", "UnicodeFun", "UnitfulLatexify", "Unzip"] -git-tree-sha1 = "38a748946dca52a622e79eea6ed35c6737499109" +git-tree-sha1 = "c4fa93d7d66acad8f6f4ff439576da9d2e890ee0" uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" -version = "1.40.0" +version = "1.40.1" [deps.Plots.extensions] FileIOExt = "FileIO" diff --git a/dev/index.html b/dev/index.html index 5660fc7c..4e8797a6 100644 --- a/dev/index.html +++ b/dev/index.html @@ -3,8 +3,8 @@ Pkg.add("DataInterpolations")

Available Interpolations

In all cases, u an AbstractVector of values and t is an AbstractVector of timepoints corresponding to (u,t) pairs.

Extension Methods

The following methods require extra dependencies and will be loaded as package extensions.

Plotting

DataInterpolations.jl is tied into the Plots.jl ecosystem, by way of RecipesBase. Any interpolation can be plotted using the plot command (or any other), since they have type recipes associated with them.

For convenience, and to allow keyword arguments to propagate properly, DataInterpolations.jl also defines several series types, corresponding to different interpolations.

The series types defined are:

By and large, these accept the same keywords as their function counterparts.

Contributing

Reproducibility

The documentation of this SciML package was built using these direct dependencies,
Status `~/work/DataInterpolations.jl/DataInterpolations.jl/docs/Project.toml`
   [82cc6244] DataInterpolations v4.6.0 `~/work/DataInterpolations.jl/DataInterpolations.jl`
   [e30172f5] Documenter v1.2.1
-  [429524aa] Optim v1.9.1
-  [91a5bcdd] Plots v1.40.0
+  [429524aa] Optim v1.9.2
+  [91a5bcdd] Plots v1.40.1
   [29dad682] RegularizationTools v0.6.0
   [860ef19b] StableRNGs v1.0.1
and using this machine and Julia version.
Julia Version 1.10.0
 Commit 3120989f39b (2023-12-25 18:01 UTC)
@@ -82,14 +82,14 @@
   [d41bc354] NLSolversBase v7.8.3
   [77ba4419] NaNMath v1.0.2
   [4d8831e6] OpenSSL v1.4.1
-  [429524aa] Optim v1.9.1
+  [429524aa] Optim v1.9.2
   [bac558e1] OrderedCollections v1.6.3
   [d96e819e] Parameters v0.12.3
   [69de0a69] Parsers v2.8.1
   [b98c9c47] Pipe v1.3.0
   [ccf2f8ad] PlotThemes v3.1.0
   [995b91a9] PlotUtils v1.4.0
-  [91a5bcdd] Plots v1.40.0
+  [91a5bcdd] Plots v1.40.1
   [85a6dd25] PositiveFactorizations v0.2.4
   [aea7be01] PrecompileTools v1.2.0
   [21216c6a] Preferences v1.4.1
@@ -249,4 +249,4 @@
   [8e850b90] libblastrampoline_jll v5.8.0+1
   [8e850ede] nghttp2_jll v1.52.0+1
   [3f19e933] p7zip_jll v17.4.0+2
-Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated -m`

You can also download the manifest file and the project file.

+Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated -m`

You can also download the manifest file and the project file.

diff --git a/dev/interface/index.html b/dev/interface/index.html index 49289b46..5949e142 100644 --- a/dev/interface/index.html +++ b/dev/interface/index.html @@ -26,4 +26,4 @@ DataInterpolations.derivative(A2, 300.0)
-0.23144961208831108

Integrals

Integrals of the interpolated curves can also be computed easily.

Note

Integrals for LagrangeInterpolation, BSplineInterpolation, BSplineApprox, Curvefit will error as there are no simple analytical solutions available. Please use numerical methods instead, such as Integrals.jl.

To compute the integrals from the start of time points provided during interpolation to any point, we can do:

# integral(A, t)
 DataInterpolations.integral(A1, 5.0)
129.64386171415265

If we want to compute integrals between two points, we can do:

# integral(A, t1, t2)
 DataInterpolations.integral(A1, 1.0, 5.0)
114.9694509973317

Again, if the interpolation is defined with extrapolate=true, the integral can be computed beyond the range of the timepoints.

# integral(A, t1, t2)
-DataInterpolations.integral(A2, 200.0, 300.0)
1065.2015077631368
Note

If the times provided in the integral go beyond the range of the time points provided during interpolation, it uses extrapolation methods to compute the values, and hence the integral can be misrepsentative and might not reflect the true nature of the data.

+DataInterpolations.integral(A2, 200.0, 300.0)
1065.2015077631368
Note

If the times provided in the integral go beyond the range of the time points provided during interpolation, it uses extrapolation methods to compute the values, and hence the integral can be misrepsentative and might not reflect the true nature of the data.

diff --git a/dev/methods/2a45f9c3.svg b/dev/methods/1776a4ff.svg similarity index 97% rename from dev/methods/2a45f9c3.svg rename to dev/methods/1776a4ff.svg index be711cfd..a39e01c8 100644 --- a/dev/methods/2a45f9c3.svg +++ b/dev/methods/1776a4ff.svg @@ -1,55 +1,55 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/fc6dd49e.svg b/dev/methods/534e4780.svg similarity index 97% rename from dev/methods/fc6dd49e.svg rename to dev/methods/534e4780.svg index cffccc6c..9c680bbd 100644 --- a/dev/methods/fc6dd49e.svg +++ b/dev/methods/534e4780.svg @@ -1,55 +1,55 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/cdfed1ff.svg b/dev/methods/60f53e83.svg similarity index 86% rename from dev/methods/cdfed1ff.svg rename to dev/methods/60f53e83.svg index 5e8c4986..cd8ae0ab 100644 --- a/dev/methods/cdfed1ff.svg +++ b/dev/methods/60f53e83.svg @@ -1,62 +1,62 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/feaecfd7.svg b/dev/methods/674d43d6.svg similarity index 97% rename from dev/methods/feaecfd7.svg rename to dev/methods/674d43d6.svg index 40a0885b..625665f2 100644 --- a/dev/methods/feaecfd7.svg +++ b/dev/methods/674d43d6.svg @@ -1,53 +1,53 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/087592a1.svg b/dev/methods/7edd06df.svg similarity index 97% rename from dev/methods/087592a1.svg rename to dev/methods/7edd06df.svg index b858c284..4740ebff 100644 --- a/dev/methods/087592a1.svg +++ b/dev/methods/7edd06df.svg @@ -1,55 +1,55 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/2612a471.svg b/dev/methods/7ef9477d.svg similarity index 80% rename from dev/methods/2612a471.svg rename to dev/methods/7ef9477d.svg index 9401a5dc..24b581ca 100644 --- a/dev/methods/2612a471.svg +++ b/dev/methods/7ef9477d.svg @@ -1,248 +1,248 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/5b214705.svg b/dev/methods/9771a179.svg similarity index 97% rename from dev/methods/5b214705.svg rename to dev/methods/9771a179.svg index 1a9df828..b3ad73d4 100644 --- a/dev/methods/5b214705.svg +++ b/dev/methods/9771a179.svg @@ -1,57 +1,57 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/a96da2c4.svg b/dev/methods/a7a20c98.svg similarity index 97% rename from dev/methods/a96da2c4.svg rename to dev/methods/a7a20c98.svg index 8be732ce..32ea97a8 100644 --- a/dev/methods/a96da2c4.svg +++ b/dev/methods/a7a20c98.svg @@ -1,55 +1,55 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/d2e8b078.svg b/dev/methods/af163bf5.svg similarity index 97% rename from dev/methods/d2e8b078.svg rename to dev/methods/af163bf5.svg index a8f2ad43..2235f52f 100644 --- a/dev/methods/d2e8b078.svg +++ b/dev/methods/af163bf5.svg @@ -1,57 +1,57 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/9e638fa2.svg b/dev/methods/ba7fca14.svg similarity index 97% rename from dev/methods/9e638fa2.svg rename to dev/methods/ba7fca14.svg index 8e438e0f..0c3d7493 100644 --- a/dev/methods/9e638fa2.svg +++ b/dev/methods/ba7fca14.svg @@ -1,55 +1,55 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/c51fc27c.svg b/dev/methods/c0d5db56.svg similarity index 95% rename from dev/methods/c51fc27c.svg rename to dev/methods/c0d5db56.svg index bac56450..772485de 100644 --- a/dev/methods/c51fc27c.svg +++ b/dev/methods/c0d5db56.svg @@ -1,145 +1,145 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/25ae9f99.svg b/dev/methods/c99ba59e.svg similarity index 95% rename from dev/methods/25ae9f99.svg rename to dev/methods/c99ba59e.svg index 9bb1b426..827c5804 100644 --- a/dev/methods/25ae9f99.svg +++ b/dev/methods/c99ba59e.svg @@ -1,145 +1,145 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/e7c1bf53.svg b/dev/methods/d9ba0985.svg similarity index 97% rename from dev/methods/e7c1bf53.svg rename to dev/methods/d9ba0985.svg index 4d9a73bd..ed4a2010 100644 --- a/dev/methods/e7c1bf53.svg +++ b/dev/methods/d9ba0985.svg @@ -1,59 +1,59 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/methods/index.html b/dev/methods/index.html index 37996cdb..a0a8f530 100644 --- a/dev/methods/index.html +++ b/dev/methods/index.html @@ -13,24 +13,24 @@ 205.8 252.3

For each method, we will show how to perform the fit and use the plot recipe to show the fitting curve.

Linear Interpolation

This is a linear interpolation between the ends points of the interval of input data points.

A = LinearInterpolation(u, t)
 scatter(t, u, label = "input data")
-plot!(A)
Example block output

Quadratic Interpolation

This function fits a parabola passing through the two nearest points from the input data point as well as the next-closest point on the right or left, depending on whether the forward- or backward-looking mode is selected (default mode is forward-looking). It is continuous and piecewise differentiable.

A = QuadraticInterpolation(u, t) # same as QuadraticInterpolation(u,t,:Forward)
+plot!(A)
Example block output

Quadratic Interpolation

This function fits a parabola passing through the two nearest points from the input data point as well as the next-closest point on the right or left, depending on whether the forward- or backward-looking mode is selected (default mode is forward-looking). It is continuous and piecewise differentiable.

A = QuadraticInterpolation(u, t) # same as QuadraticInterpolation(u,t,:Forward)
 # alternatively: A = QuadraticInterpolation(u,t,:Backward)
 scatter(t, u, label = "input data")
-plot!(A)
Example block output

Lagrange Interpolation

It fits a polynomial of degree d (=length(t)-1), and is thus a continuously differentiable function.

A = LagrangeInterpolation(u, t)
+plot!(A)
Example block output

Lagrange Interpolation

It fits a polynomial of degree d (=length(t)-1), and is thus a continuously differentiable function.

A = LagrangeInterpolation(u, t)
 scatter(t, u, label = "input data")
-plot!(A)
Example block output

Constant Interpolation

This function is constant between data points. By default, it takes the value at the left end of the interval. One can change that behavior by passing the keyword argument dir = :right.

A = ConstantInterpolation(u, t)
+plot!(A)
Example block output

Constant Interpolation

This function is constant between data points. By default, it takes the value at the left end of the interval. One can change that behavior by passing the keyword argument dir = :right.

A = ConstantInterpolation(u, t)
 scatter(t, u, label = "input data")
-plot!(A)
Example block output

Or using the right endpoints:

A = ConstantInterpolation(u, t, dir = :right)
+plot!(A)
Example block output

Or using the right endpoints:

A = ConstantInterpolation(u, t, dir = :right)
 scatter(t, u, label = "input data")
-plot!(A)
Example block output

Quadratic Spline

This is the quadratic spline. It is a continuously differentiable interpolation which hits each of the data points exactly. Splines are a local interpolation method, meaning that the curve in a given spot is only affected by the points nearest to it.

A = QuadraticSpline(u, t)
+plot!(A)
Example block output

Quadratic Spline

This is the quadratic spline. It is a continuously differentiable interpolation which hits each of the data points exactly. Splines are a local interpolation method, meaning that the curve in a given spot is only affected by the points nearest to it.

A = QuadraticSpline(u, t)
 scatter(t, u, label = "input data")
-plot!(A)
Example block output

Cubic Spline

This is the cubic spline. It is a continuously twice differentiable interpolation which hits each of the data points exactly.

A = CubicSpline(u, t)
+plot!(A)
Example block output

Cubic Spline

This is the cubic spline. It is a continuously twice differentiable interpolation which hits each of the data points exactly.

A = CubicSpline(u, t)
 scatter(t, u, label = "input data")
-plot!(A)
Example block output

B-Splines

This is an interpolating B-spline. B-splines are a global method, meaning that every data point is taken into account for each point of the curve. The interpolating B-spline is the version which hits each of the points. This method is described in more detail here. Let's plot a cubic B-spline (3rd order). Since the data points are not close to uniformly spaced, we will use the :ArcLen and :Average choices:

A = BSplineInterpolation(u, t, 3, :ArcLen, :Average)
+plot!(A)
Example block output

B-Splines

This is an interpolating B-spline. B-splines are a global method, meaning that every data point is taken into account for each point of the curve. The interpolating B-spline is the version which hits each of the points. This method is described in more detail here. Let's plot a cubic B-spline (3rd order). Since the data points are not close to uniformly spaced, we will use the :ArcLen and :Average choices:

A = BSplineInterpolation(u, t, 3, :ArcLen, :Average)
 scatter(t, u, label = "input data")
-plot!(A)
Example block output

The approximating B-spline is a smoothed version of the B-spline. It again is a global method. In this case, we need to give a number of control points length(t)>h and this method fits a B-spline through the control points which is a least square approximation. This has a natural effect of smoothing the data. For example, if we use 4 control points, we get the result:

A = BSplineApprox(u, t, 3, 4, :ArcLen, :Average)
+plot!(A)
Example block output

The approximating B-spline is a smoothed version of the B-spline. It again is a global method. In this case, we need to give a number of control points length(t)>h and this method fits a B-spline through the control points which is a least square approximation. This has a natural effect of smoothing the data. For example, if we use 4 control points, we get the result:

A = BSplineApprox(u, t, 3, 4, :ArcLen, :Average)
 scatter(t, u, label = "input data")
-plot!(A)
Example block output

Regularization Smoothing

Smoothing by regularization (a.k.a. ridge regression) finds a function $\hat{u}$ that minimizes the objective function:

$Q(\hat{u}) = \int_{t_1}^{t_N} |\hat{u}(t) - u(t)|^2 \mathrm{d}t + \lambda \int_{\hat{t}_1}^{\hat{t}_N} |\hat{u}^{(d)}(\hat{t})|^2 \mathrm{d} \hat{t}$

where $(d)$ denotes derivative order and $\lambda$ is the regularization (smoothing) parameter. The integrals are evaluated numerically at the set of $t$ values for the first term and $\hat{t}$ values for the second term (equal to $t$ if not provided). Regularization smoothing is a global method that creates a smooth curve directly. See Stickel (2010) Comput. Chem. Eng. 34:467 for details. The implementation in this package uses cubic splines to interpolate between the smoothed points after they are determined.

using RegularizationTools
+plot!(A)
Example block output

Regularization Smoothing

Smoothing by regularization (a.k.a. ridge regression) finds a function $\hat{u}$ that minimizes the objective function:

$Q(\hat{u}) = \int_{t_1}^{t_N} |\hat{u}(t) - u(t)|^2 \mathrm{d}t + \lambda \int_{\hat{t}_1}^{\hat{t}_N} |\hat{u}^{(d)}(\hat{t})|^2 \mathrm{d} \hat{t}$

where $(d)$ denotes derivative order and $\lambda$ is the regularization (smoothing) parameter. The integrals are evaluated numerically at the set of $t$ values for the first term and $\hat{t}$ values for the second term (equal to $t$ if not provided). Regularization smoothing is a global method that creates a smooth curve directly. See Stickel (2010) Comput. Chem. Eng. 34:467 for details. The implementation in this package uses cubic splines to interpolate between the smoothed points after they are determined.

using RegularizationTools
 d = 2
 λ = 1e3
 A = RegularizationSmooth(u, t, d; λ = λ, alg = :fixed)
@@ -42,7 +42,7 @@
 lw = 1.5
 scatter(t, u, label = "data")
 scatter!(t, û, marker = :square, label = "smoothed data")
-plot!(titp, uitp, lw = lw, label = "smoothed interpolation")
Example block output

Dense Data Demonstration

Some methods are better suited for dense data. Let's generate such data to demonstrate these methods.

import StableRNGs: StableRNG
+plot!(titp, uitp, lw = lw, label = "smoothed interpolation")
Example block output

Dense Data Demonstration

Some methods are better suited for dense data. Let's generate such data to demonstrate these methods.

import StableRNGs: StableRNG
 rng = StableRNG(318)
 t = sort(10 .* rand(rng, 100))
 u = sin.(t) .+ 0.5 * randn(rng, 100);
100-element Vector{Float64}:
@@ -76,17 +76,17 @@
 scatter(t, u, label = "simulated data", legend = :top)
 scatter!(t, û, marker = (:square, 4), label = "smoothed data")
 plot!(titp, uitp, lw = lw, label = "smoothed interpolation")
-plot!(titp, ûm, lw = lw, linestyle = :dash, label = "smoothed, more points")
Example block output

Curve Fits

A curve fit works with both dense and sparse data. We will demonstrate the curve fit on the dense data since we generated it based on sin(t), so this is the curve we want to fit through it. To do so, let's define a similar function with parameters. Let's choose the form:

m(t, p) = @. p[1] * sin(p[2] * t) + p[3] * cos(p[4] * t)
m (generic function with 1 method)

Notice that this is a function on the whole array of t and expects an array for the predicted u out. This choice of m is based on the assumption that our function is of the form p1*sin(p2*t)+p3*cos(p4*t). We want to find the p to match our data. Let's start with the guess of every p being zero, that is p=ones(4). Then we would fit this curve using:

using Optim
+plot!(titp, ûm, lw = lw, linestyle = :dash, label = "smoothed, more points")
Example block output

Curve Fits

A curve fit works with both dense and sparse data. We will demonstrate the curve fit on the dense data since we generated it based on sin(t), so this is the curve we want to fit through it. To do so, let's define a similar function with parameters. Let's choose the form:

m(t, p) = @. p[1] * sin(p[2] * t) + p[3] * cos(p[4] * t)
m (generic function with 1 method)

Notice that this is a function on the whole array of t and expects an array for the predicted u out. This choice of m is based on the assumption that our function is of the form p1*sin(p2*t)+p3*cos(p4*t). We want to find the p to match our data. Let's start with the guess of every p being zero, that is p=ones(4). Then we would fit this curve using:

using Optim
 A = Curvefit(u, t, m, ones(4), LBFGS())
 scatter(t, u, label = "points", legend = :bottomright)
-plot!(A)
Example block output

We can check what the fitted parameters are via:

A.pmin
4-element Vector{Float64}:
+plot!(A)
Example block output

We can check what the fitted parameters are via:

A.pmin
4-element Vector{Float64}:
   1.00251731850411
   1.0396588440319725
  -0.13178842465264956
   1.0670107400675999

Notice that it essentially made p3=0 with p1=p2=1, meaning it approximately found sin(t)! But note that the ability to fit is dependent on the initial parameters. For example, with p=zeros(4) as the initial parameters, the fit is not good:

A = Curvefit(u, t, m, zeros(4), LBFGS())
 scatter(t, u, label = "points", legend = :bottomright)
-plot!(A)
Example block output

And the parameters show the issue:

A.pmin
4-element Vector{Float64}:
+plot!(A)
Example block output

And the parameters show the issue:

A.pmin
4-element Vector{Float64}:
  0.0
  0.0
  0.042632088464589324
- 0.0
+ 0.0