Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: plot recipes #285

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,11 @@ The series types defined are:
- `:lagrange_interp`
- `:quadratic_spline`
- `:cubic_spline`
- `:akima_interp`
- `:bspline_interp`
- `:bspline_approx`
- `:cubic_hermite_spline`
- `:pchip_interp`
- `:quintic_hermite_spline`

By and large, these accept the same keywords as their function counterparts.
6 changes: 6 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ The series types defined are:
- `:lagrange_interp`
- `:quadratic_spline`
- `:cubic_spline`
- `:akima_interp`
- `:bspline_interp`
- `:bspline_approx`
- `:cubic_hermite_spline`
- `:pchip_interp`
- `:quintic_hermite_spline`

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

Expand Down
45 changes: 15 additions & 30 deletions docs/src/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ This is a linear interpolation between the ends points of the interval of input

```@example tutorial
A = LinearInterpolation(u, t)
scatter(t, u, label = "input data")
plot!(A)
plot(A)
```

## Quadratic Interpolation
Expand All @@ -36,8 +35,7 @@ forward-looking). It is continuous and piecewise differentiable.
```@example tutorial
A = QuadraticInterpolation(u, t) # same as QuadraticInterpolation(u,t,:Forward)
# alternatively: A = QuadraticInterpolation(u,t,:Backward)
scatter(t, u, label = "input data")
plot!(A)
plot(A)
```

## Lagrange Interpolation
Expand All @@ -47,8 +45,7 @@ differentiable function.

```@example tutorial
A = LagrangeInterpolation(u, t)
scatter(t, u, label = "input data")
plot!(A)
plot(A)
```

## Akima Interpolation
Expand All @@ -59,8 +56,7 @@ fit looks more natural.

```@example tutorial
A = AkimaInterpolation(u, t)
scatter(t, u, label = "input data")
plot!(A)
plot(A)
```

## Constant Interpolation
Expand All @@ -71,16 +67,14 @@ passing the keyword argument `dir = :right`.

```@example tutorial
A = ConstantInterpolation(u, t)
scatter(t, u, label = "input data")
plot!(A)
plot(A)
```

Or using the right endpoints:

```@example tutorial
A = ConstantInterpolation(u, t, dir = :right)
scatter(t, u, label = "input data")
plot!(A)
plot(A)
```

## Quadratic Spline
Expand All @@ -92,8 +86,7 @@ nearest to it.

```@example tutorial
A = QuadraticSpline(u, t)
scatter(t, u, label = "input data")
plot!(A)
plot(A)
```

## Cubic Spline
Expand All @@ -103,8 +96,7 @@ which hits each of the data points exactly.

```@example tutorial
A = CubicSpline(u, t)
scatter(t, u, label = "input data")
plot!(A)
plot(A)
```

## B-Splines
Expand All @@ -118,8 +110,7 @@ uniformly spaced, we will use the `:ArcLen` and `:Average` choices:

```@example tutorial
A = BSplineInterpolation(u, t, 3, :ArcLen, :Average)
scatter(t, u, label = "input data")
plot!(A)
plot(A)
```

The approximating B-spline is a smoothed version of the B-spline. It again is
Expand All @@ -130,8 +121,7 @@ data. For example, if we use 4 control points, we get the result:

```@example tutorial
A = BSplineApprox(u, t, 3, 4, :ArcLen, :Average)
scatter(t, u, label = "input data")
plot!(A)
plot(A)
```

## Cubic Hermite Spline
Expand All @@ -141,8 +131,7 @@ This is the cubic (third order) Hermite interpolation. It matches the values and
```@example tutorial
du = [-0.047, -0.058, 0.054, 0.012, -0.068, 0.0011]
A = CubicHermiteSpline(du, u, t)
scatter(t, u, label = "input data")
plot!(A)
plot(A)
```

## PCHIP Interpolation
Expand All @@ -151,8 +140,7 @@ This is a type of `CubicHermiteSpline` where the derivative values `du` are deri

```@example tutorial
A = PCHIPInterpolation(u, t)
scatter(t, u, label = "input data")
plot!(A)
plot(A)
```

## Quintic Hermite Spline
Expand All @@ -163,8 +151,7 @@ This is the quintic (fifth order) Hermite interpolation. It matches the values a
ddu = [0.0, -0.00033, 0.0051, -0.0067, 0.0029, 0.0]
du = [-0.047, -0.058, 0.054, 0.012, -0.068, 0.0011]
A = QuinticHermiteSpline(ddu, du, u, t)
scatter(t, u, label = "input data")
plot!(A)
plot(A)
```

## Regularization Smoothing
Expand Down Expand Up @@ -258,8 +245,7 @@ match our data. Let's start with the guess of every `p` being zero, that is
```@example tutorial
using Optim
A = Curvefit(u, t, m, ones(4), LBFGS())
scatter(t, u, label = "points", legend = :bottomright)
plot!(A)
plot(A)
```

We can check what the fitted parameters are via:
Expand All @@ -275,8 +261,7 @@ is not good:

```@example tutorial
A = Curvefit(u, t, m, zeros(4), LBFGS())
scatter(t, u, label = "points", legend = :bottomright)
plot!(A)
plot(A)
```

And the parameters show the issue:
Expand Down
Loading
Loading