You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/NDLPwriteup.jl
+77-22Lines changed: 77 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ using InteractiveUtils
8
8
using Plots, QuadGK, DataInterpolations, LinearAlgebra, StaticArrays, TypedTables
9
9
10
10
# ╔═╡ ad7b8fa0-e966-4c3b-8163-02d2817b1c9d
11
-
using ForwardDiff:derivative as D #AD derivatives
11
+
using ForwardDiff:derivative as D #Automatic derivatives
12
12
13
13
# ╔═╡ 4e8f4214-f9b3-4dbf-9507-eea0504a6933
14
14
md"""
@@ -137,11 +137,11 @@ Note that while the deviation estimate that is the basis of this parameterizatio
137
137
md"""
138
138
### Results
139
139
140
-
We evaluate each method on the test curves defined above, using a maximum segment length of `Δs=1/20` and a deviation limit of $d_n$=`devlimit=1/100`. The results are summarized in the tables below, reporting the following metrics:
141
-
- `L∞δ`: the maximum deviation scaled by the allowed deviation (should be close to 1),
142
-
- `σ`: the stretching/efficiency, defined as the excess percentage of segments needed to hit the deviation limit (lower is better),
143
-
- `Rₜᵥ`: the total variation of segment lengths scaled by total curve length (lower is better),
144
-
- `R∞`: the maximum variation of segment lengths scaled by $\Delta s$ (lower is better).
140
+
We evaluate each method on the test curves defined above, using a maximum segment length of $\Delta s=L/20$ and a deviation limit of $d_n=1/100$. The results are summarized in the tables below, reporting the following metrics:
141
+
- `δ∞`=$\max(\delta)/(d_n\Delta s)$: the scaled normal deviation,
142
+
- `σ`=$N\Delta s/L-1$: the scaled number of extra segments needed to hit the deviation limit (lower is better),
143
+
- `Rₜᵥ`=$\sum(R)/L$ where $R_i=|Δl_{i+1}-Δl_i|$: the scale total variation of segment lengths (lower is better),
144
+
- `R∞`=$\max(R)/\Delta s$: the scale maximum variation of segment lengths (lower is better).
145
145
146
146
The NDLP segmentation consistently produces a max deviation which is tight to the prescribed limit, resulting in with minimal excess segments, outperforming both adaptive subdivision and curvature-weighted sampling. In particular the measured deviation is within ±4% of the deviation limit, while the curvature weighted method has a ±15% variation **even after tuning**, and the subdivision method can be up to 50% oversampled.
147
147
@@ -150,13 +150,13 @@ Adjacent segment lengths under NDLP sampling differ by at most $O(\Delta s)$, in
150
150
151
151
# ╔═╡ b38c2b1c-a48c-4f1f-954b-95faaba680d7
152
152
begin# sample `r` using `method`, and report metrics
153
-
function metrics(method, r, u₀, u₁, Δs, devlimit)
153
+
function metrics(method, r, u₀, u₁, Δs, dₙ)
154
154
L = quadgk(arcspeed(r), u₀, u₁)[1]; Δs *= L
155
-
u = method(r, u₀, u₁, Δs, devlimit); N =
155
+
u = method(r, u₀, u₁, Δs, dₙ); N =
156
156
dl,δ = seg_len(r,u),seg_dev(r,u)
157
-
(;L∞δ= maximum(δ)/(Δs*devlimit), # scaled max deviation, should => 1!
158
-
σ = length(δ)*Δs/L-1, # extra segments needed to hit devlimit
159
-
Rₜᵥ = sum(abs,diff(dl))/L, # total variation of segment length
157
+
(;δ∞= maximum(δ)/(Δs*dₙ), # scaled max deviation, should => 1!
158
+
σ = length(δ)*Δs/L-1, # extra segments needed to hit dₙ
159
+
Rₜᵥ = sum(abs,diff(dl))/L, # total variation of segment length
160
160
R∞ = maximum(abs,diff(dl))/Δs # max variation of segment length
We also evaluate the convergence of the NDLP segmentation metrics as the $\Delta s$ and $d_n$ limits vary. We use the cubic spline fish as a representative curve.
252
+
253
+
Holding $d_n=1$% constant and *reducing* $\Delta s$ shows two distance phases.
254
+
- In the first phase, the deviation $\max(\delta)$ goes rapidly to the limit $d_n\Delta s$ and holds steady while the excess number of segments and total variation in the panel lengths drops to zero quadratically with $\Delta s$. (Note the scaling of $\max(R)$ by $\Delta s$ makes this look linear in the plot.)
255
+
- In the second phase the deviation limit is no longer active, so $\max(\delta)$ goes to zero without any additional segments or any length variation.
plot!(title="NDLP segmentation metrics with fixed dₙ=1%")
271
+
end
272
+
273
+
# ╔═╡ 67eba604-640b-4388-bc08-928f4e5e62ca
274
+
md"""
275
+
Holding $\Delta s=L/100$ and _increasing_ $d_n$ shows a similar trend.
276
+
- Again, in the first phase, the deviation limit is honored while the excess segments and total variation in segment lengths drop to zero. The key difference is that the $\max(R)$ remains roughly constant through this range; approximately $\Delta s/3$ for this example. Again, this indicates Lipschitz-continuous spacing, even for finite $\Delta s$ and large $d_n$.
277
+
- In the second phase, the $d_n$ limit deactivates, letting $\max(\delta)$ scaled by $d_n$ and $\max(R)$ both drop to zero as the sampling becomes uniformly spaced.
0 commit comments