-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add least squares approximation (#93)
* allow using different node set for centers * add example and test * add unit tests
- Loading branch information
1 parent
56f338e
commit f713f46
Showing
7 changed files
with
133 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using KernelInterpolation | ||
using Plots | ||
|
||
# interpolate Franke function | ||
function f(x) | ||
0.75 * exp(-0.25 * ((9 * x[1] - 2)^2 + (9 * x[2] - 2)^2)) + | ||
0.75 * exp(-(9 * x[1] + 1)^2 / 49 - (9 * x[2] + 1) / 10) + | ||
0.5 * exp(-0.25 * ((9 * x[1] - 7)^2 + (9 * x[2] - 3)^2)) - | ||
0.2 * exp(-(9 * x[1] - 4)^2 - (9 * x[2] - 7)^2) | ||
end | ||
|
||
n = 1089 | ||
nodeset = random_hypercube(n; dim = 2) | ||
values = f.(nodeset) .+ 0.03 * randn(n) | ||
M = 81 | ||
centers = random_hypercube(M; dim = 2) | ||
|
||
kernel = ThinPlateSplineKernel{dim(nodeset)}() | ||
ls = interpolate(nodeset, centers, values, kernel) | ||
itp = interpolate(nodeset, values, kernel) | ||
|
||
N = 40 | ||
many_nodes = homogeneous_hypercube(N; dim = 2) | ||
|
||
p1 = plot(many_nodes, ls, st = :surface, training_nodes = false) | ||
p2 = plot(many_nodes, itp, st = :surface, training_nodes = false) | ||
|
||
plot(p1, p2, layout = (2, 1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters