Fermat distances can improve on ambient straight-line distances, but the useful power depends on geometry and sampling density. This article examines that interaction before any embedding into two or three dimensions. It compares complete-graph Fermat distances, ambient chords, and ordinary Euclidean nearest-neighbor graph distances on area-uniform quadratic surfaces and a Swiss roll.
The main findings are:
This complements Fermat distances and their supporting graphs on surfaces and the Fermat distance introduction. The benchmark results were completed on 2026-10-01 06:49:00 EDT; power-selection results were completed on 2026-10-01 09:21:41 EDT; this reading copy was built on 2026-11-07 16:27:37 EST. Rendering reads the frozen benchmark, saved figures, and saved surface coordinates. The teaching examples below are displayed without execution; rendering does not rerun the numerical analyses or reference searches.
For observations , the unrooted Fermat distance is
The minimum ranges over paths through any observed points, including the direct edge. At , the triangle inequality gives : adding intermediate observations cannot shorten the ambient chord. For , several short steps can cost less than a long step. More intermediate points can therefore change both the preferred route and its cost. The units are length to power ; this article takes no -th root.
A surface geodesic measures length along the underlying surface. We compare Fermat distances to that intrinsic reference after fitting one multiplicative scale. These are finite-sample experiments, not a proof of asymptotic convergence or an estimate of its rate.
Consider the saddle over . For a quadratic form matrix , the surface-area element is . Uniform draws in the parameter disk are therefore not uniform on the surface. Use the existing dgraphs sampler:
library(dgraphs)
A <- diag(c(2,-2))
geometry <- synthetic.quadform(2L,3L,forms=list(A))
sampling <- synthetic.sampling.quadform.lab('disk',extent=1,mode='area')
sample <- sample.synthetic.geometry(geometry,sampling,n=300L,seed=62117L)
X <- sample$predictors
endpoints <- 1:12
D150 <- fermat.distances(points=X[1:150,],p=1.25,backend='implicit',
sources=endpoints,targets=endpoints,rooted=FALSE)
D300 <- fermat.distances(points=X,p=1.25,backend='implicit',
sources=endpoints,targets=endpoints,rooted=FALSE)
stopifnot(all(D300 <= D150 + 1e-10))Only the requested endpoint distances are returned, but paths may use every observation in the supplied matrix. This is an exact restriction of the queries, not a landmark restriction of the paths. The check illustrates that unrooted Fermat distances cannot increase when the available path vertices expand. These small teaching observations are separate from the frozen benchmark below.
For the ordinary neighborhood baseline, construct a union-symmetric graph: an edge exists if either endpoint selects the other among its nearest neighbors. Its weights remain Euclidean lengths, without a Fermat power.
graph <- create.sknn.graph(X,k=10,neighbor.method='exact',
connect.components=FALSE)
edges <- graph.edges(graph)
ig <- igraph::graph_from_data_frame(edges[,1:2],directed=FALSE,
vertices=data.frame(name=seq_len(nrow(X))))
Dknn <- igraph::distances(ig,v=endpoints,to=endpoints,weights=edges$length)
igraph::components(ig)$noIf the graph is disconnected, some entries can be infinite. This
study records that limitation rather than adding repair edges. This is
an ordinary Euclidean kNN graph, distinct from
create.fermat.sknn.graph(), which selects neighbors using
Fermat distances.
The quadratic surfaces are
with . Principal curvature magnitudes at the origin are . Increasing also changes the surface area and curvature away from the origin; it does not uniformly multiply curvature everywhere. Both patches have area
Figure 1. The six quadratic patches. A common vertical range within each family makes the increased bending and height visible.
The seventh surface is , where and . Its arc coordinate is
Uniform draws in the rectangle with coordinates give area-uniform samples. Its exact intrinsic distance is .
An optional ivue view complements Figure 1 and also shows the Swiss roll. In interactive builds, choose a surface, drag to rotate, and scroll to zoom; Reset view restores its initial camera. Orange points are the 64 fixed endpoints, and blue points are 236 additional observations from the original first sampling repetition at . These are saved area-uniform samples, not newly generated points. The translucent mesh is a drawing approximation of the target surface.
These are target coordinates, not metric-MDS embeddings. Equal data-unit scales preserve their geometry, and common viewing bounds within each quadform family allow comparison of the three coefficients. The mesh resolution affects only the display; it is not used to estimate distances or reference geodesics.
#> The installed guide uses the static surface views in Figure 1. Interactive views are available when rebuilding with DGRAPHS_STATIC_VIGNETTES=false and the optional visualization packages.
Interactive HTML needs a WebGL-capable browser, with no running R or
Shiny session. To rebuild it interactively, install ivue and its rgl backend and
set DGRAPHS_STATIC_VIGNETTES=false. Installed guides use
compact static illustrations by default; the website uses interactive
views. The original figure files, benchmark tables and numerical results
are unchanged.
Each surface has 64 fixed sampled endpoints. Of the 2,016 unordered endpoint pairs, 500 are assigned to scale calibration and 1,000 different pairs to assessment. Pairs may share endpoints. Five independent pools of additional observations give nested total sample sizes , always including the same 64 endpoints. All observations may support paths. Repetitions measure variation from the added path vertices, conditional on one endpoint set per surface.
The power grid is . Ordinary kNN graphs use and the prespecified rule . The logarithm in that rule is natural.
Quadform references use
quadform_geodesics(method="best_of_six") with 64 search
rounds, 16 initial edges, 32 candidate draws and a 257-vertex limit.
Paraboloid pairs also use method="paraboloid_clairaut".
This is currently an internal dgraphs research interface, accessed by
the reproduction scripts; it is not presented as a stable exported API.
Best-of-six returns finite-search candidate paths, not certified
globally shortest geodesics.
All 2,100 distance conditions and 10,500 main reference pairs completed. There were no failed main reference pairs. Four ordinary kNN conditions were disconnected, all at ; 238 evaluation-pair occurrences were unreachable across those conditions. These counts are retained in the saved evidence.
For calibration pairs , evaluation pairs , estimates , and reference lengths , fit the scale and evaluate the normalized error:
Zero means proportional agreement with the reference. Plots show as a percentage. Raw errors with are saved too; they answer a different question because powered lengths have different units.
Unreachable graph pairs are excluded from their finite-distance score, and coverage is reported. Scale fitting likewise uses only finite calibration pairs. Paired differences use ambient scores on the same reachable evaluation pairs. A small error with incomplete coverage does not demonstrate recovery of the entire surface.
| rule | Minimum evaluation coverage (%) | Disconnected conditions |
|---|---|---|
| 10 | 100.0 | 0 |
| 20 | 100.0 | 0 |
| 40 | 100.0 | 0 |
| 5 | 87.5 | 4 |
| adaptive | 100.0 | 0 |
Table 1. Coverage over all surfaces, repetitions and sample sizes. “Adaptive” denotes the fixed logarithmic rule above. A disconnected component may contain no evaluated endpoints, so connectivity and pair coverage are reported separately.
Figure 2. Paraboloid errors against best-of-six references. Thin lines are individual repetitions; bold lines are means. Shading gives pointwise 95% Student- intervals with four degrees of freedom. The horizontal axis is logarithmic. All intervals here and below are conditional on the fixed endpoints and references, not simultaneous over the tested grid, and omit solver uncertainty.
At , already improves on ambient chords at : mean error is 3.73% versus 8.51%. For , error falls from 11.72% to 5.67% as the sample increases to 2,400. Thus both the choice of power and the availability of intermediate observations matter. On these three paraboloids, is the best tested complete power throughout the sample-size grid.
Figure 3. The same comparison on saddles. On the strongest saddle at , has 2.55% error versus 28.32% for ambient and 11.99% for . A power useful on a mild patch need not be sufficient on a more strongly bent patch.
Figure 4. Swiss-roll errors against exact intrinsic lengths. Ambient error is 55.84%; at , achieves 7.70%, whereas still has 51.99%. The best tested power changes from at to at .
| Surface | Best tested | Fermat error (%) | Ambient error (%) | Wins out of 5 |
|---|---|---|---|---|
| Paraboloid, | 1.25 | 1.82 | 8.51 | 5 |
| Paraboloid, | 1.25 | 2.49 | 12.36 | 5 |
| Paraboloid, | 1.25 | 4.82 | 14.54 | 5 |
| Saddle, | 1.25 | 1.75 | 8.74 | 5 |
| Saddle, | 1.25 | 1.58 | 18.47 | 5 |
| Saddle, | 1.50 | 2.55 | 28.32 | 5 |
| Swiss roll | 3.00 | 7.70 | 55.84 | 5 |
Table 2. Descriptive minima over the tested powers at . Errors are means over five repetitions; wins count paired repetitions with lower error than ambient. These powers were identified using the displayed evaluation scores, so this table is not an independent assessment of a tuned selection procedure. A separate calibration-only power search at and transfer to the other sample sizes is reported below, after the original fixed-grid comparisons.
Figure 5. Distributions of on the 1,000 evaluation pairs per surface, where is the ambient chord. One denotes equality. The axis has spacing but is labeled in ratio units; two means twice the chord length. Violin widths show density on the log-ratio scale, with medians and quartiles inside. Shared endpoints make these descriptive pair distributions.
The rolled surface exposes very large shortcuts. Quadform coefficients change the distribution too, but need not increase every pair’s distortion: curvature varies spatially, and area-uniform sampling puts more mass in steeper regions.
Figure 6. Ordinary Euclidean kNN errors on paraboloids (top), saddles (middle) and the Swiss roll (bottom). Thin lines are repetitions; bold means and error bars use conditional 95% intervals. Intervals can extend below zero, although errors cannot. The dashed ambient baseline uses all evaluation pairs; consult Table 1 before comparing it with a restricted finite-pair score.
At , is more accurate than every tested complete Fermat power on each of the seven examples. Its errors on the mild paraboloid, mild saddle and Swiss roll are 0.62%, 0.49% and 0.35%. Larger neighborhoods are not automatically better: on the roll, has 13.03% error, consistent with shortcut edges. Connectivity alone is not a test of geodesic accuracy.
These findings concern ordinary geodesic recovery under uniform sampling. They do not settle whether density-sensitive distances are useful on nonuniform biological data, where the desired geometry itself may depend on density.
Figure 7. The paraboloid comparison using Clairaut lengths. Observations, pairs and estimated distances are identical to Figure 2; only the reference and its fitted calibration scale change.
For , the error at changes from 4.82% against best-of-six to 2.05% against Clairaut. The error changes from 4.24% to 0.60%. Some apparent estimator error is therefore reference-method disagreement. The original best-of-six results remain part of the evidence.
A separate saddle diagnostic increased search rounds from 64 to 256 on 50 regularly spaced pair indices per saddle, selected without inspecting errors. The largest relative length reduction over those 150 pairs was 0.137%. This supports stability for those pairs and budgets, but does not certify global minimality or remove reference uncertainty elsewhere.
Figure 8. Scaled error minus ambient error at , in percentage points. Negative values favor Fermat. Black points are individual repetitions; blue means and intervals show conditional 95% intervals. Paired comparisons hold the endpoint set and added sample pool fixed within each repetition.
This separate follow-up tunes each of the six quadforms at , then keeps that power fixed at . It reuses the original area-uniform samples, fixed endpoints, five repetitions, and numerical reference lengths. No surface samples or reference geodesics were recomputed. The Swiss roll is outside this tuning experiment; its original results above are unchanged.
For each surface, the 500 calibration pairs were randomly assigned to five fixed folds of 100 pairs. The same folds were used for every power, repetition, and reference method. For repetition , power , and validation fold , the scale was fitted on the other 400 pairs:
Here is the calibration-pair set, the unrooted complete-graph Fermat distance, and the reference geodesic length. Selection minimizes . Pooling the out-of-fold squared residuals before taking the square root gives each pair its contribution to the same normalized error; we do not average five differently normalized fold scores.
The coarse grid has spacing on for all paraboloids and the coefficient-one saddle, and on for the two stronger saddles. The best coarse power is refined over its neighborhood in steps of , clipped to the search interval. The reported choice is the best power found at this resolution, not a continuous optimum. The ambient baseline participated in selection. Exact ties would favor the smaller power; none of the nine selected powers lies on a search boundary.
All nine choices were saved before evaluation: six using best-of-six references and three independent paraboloid selections using Clairaut references. The follow-up completed 301 surface/reference/power combinations, each with five repetitions and five folds (7,525 fold scores), and 1,275 transfer comparison records. Every transfer record uses all 500 calibration and 1,000 evaluation pairs. No distance condition failed or was excluded. The number of records includes baseline comparisons and scoring each paraboloid selection against both reference methods; it is not a count of distinct distance searches.
Figure 9. Full tuning curves at using best-of-six references. Thin lines show the five repetitions; blue curves show their mean and pale bands pointwise conditional 95% intervals. Red diamonds and dotted lines mark the selected power. Panels use different horizontal ranges because the two stronger saddles were searched through ; vertical ranges also differ. All coarse and refined grid points are included. Smaller error is better.
Figure 10. Neighborhoods within of the selected power. The horizontal coordinate is ; the vertical coordinate is , the percentage increase relative to the minimum mean error. The dashed line marks a 1% relative increase. Bands use paired differences between each candidate and the selected power within each repetition, with pointwise conditional 95% intervals divided by the observed minimum mean error. They are not confidence intervals for the optimum’s location. Dots are evaluated powers and lines only connect them.
| Surface | Selected | Within 1% of minimum | Test error, (%) | Test error, (%) |
|---|---|---|---|---|
| Paraboloid, | 1.135 | 1.130–1.135 | 1.96 | 1.13 |
| Paraboloid, | 1.200 | 1.195–1.210 | 3.32 | 2.23 |
| Paraboloid, | 1.240 | 1.230–1.260 | 5.59 | 4.78 |
| Saddle, | 1.125 | 1.120–1.130 | 2.33 | 1.00 |
| Saddle, | 1.335 | 1.325–1.345 | 3.95 | 2.00 |
| Saddle, | 1.680 | 1.665–1.700 | 6.90 | 3.25 |
Table 3. Best powers using best-of-six references, a descriptive near-minimum range, and mean held-out errors after refitting scale on all calibration pairs. The range contains the smallest and largest tested powers with mean cross-validation error no more than 1% above its minimum; it is not a confidence interval and does not classify untested powers. The 1% threshold is relative to the minimum error, not one percentage point of distance error. The minima span two to eight qualifying grid points. Their breadth varies with the surface, so the third decimal place records search resolution rather than certainty about a uniquely preferred power.
Figure 11. Transfer of the power selected at to the five sample sizes, scored against best-of-six references. Scale is refitted on the 500 calibration pairs at each size and repetition; the 1,000 evaluation pairs are unchanged. Ambient chords, fixed powers and , and ordinary Euclidean symmetric-kNN shortest paths with provide comparisons. Thin lines show repetitions; thicker lines and points show means, with pointwise conditional 95% intervals. The sample-size axis is logarithmic and panel vertical ranges differ. All displayed neighborhood graphs are connected.
The selected powers improve on ambient chords on all six surfaces at every sample size, in all five repetitions. Their mean errors decrease as the sample size increases. At , errors range from 1.00% on the mild saddle to 4.78% on the steepest paraboloid against best-of-six references. This supports useful transfer, but does not mean that selection at remains optimal at every size.
Figure 12. Selected-power error minus fixed- error on the same evaluation pairs and sample pools, in percentage points. Negative values favor the selected power. Thin lines show the five paired differences; blue means and pointwise conditional 95% intervals summarize them.
For example, on the intermediate saddle the selected has 3.95% error at , versus 5.91% for . At the ordering reverses: 2.00% versus 1.58%. On the strongest saddle, transferred reaches 3.25%, whereas the original grid’s reaches 2.55%. Selection at one sample size therefore identifies a useful finite-sample choice, not a universal power. Ordinary Euclidean graph distances remain more accurate at than these selected complete-graph Fermat distances on all six examples.
Figure 13. The same paraboloid distance estimates, calibration folds and repetitions scored against the two reference methods. Each method fits its own scales and selects its own power. Thin lines show repetitions, thicker curves their means, and symbols their selected powers. The strongest paraboloid shows the largest shift in selected power and apparent error floor.
| Surface | Best-of-six | Clairaut | Best-of-six choice error (%) | Clairaut choice error (%) |
|---|---|---|---|---|
| Paraboloid, | 1.135 | 1.130 | 1.07 | 1.03 |
| Paraboloid, | 1.200 | 1.190 | 1.54 | 1.47 |
| Paraboloid, | 1.240 | 1.210 | 1.98 | 1.77 |
Table 4. Separate paraboloid choices. Both error columns use Clairaut reference lengths at , with scales refitted against Clairaut; only the selected power differs. This separates the effect of power selection from the effect of changing the scoring reference.
Figure 14. Paraboloid transfer scored against Clairaut references. Red curves use Clairaut-selected powers, blue curves the powers selected with best-of-six. All methods refit scale against Clairaut at every size. Means, repetitions and pointwise conditional intervals have the same meaning as in Figure 11.
Clairaut selects for the three paraboloids, compared with under best-of-six. On the steepest paraboloid, the Clairaut-selected power has 1.77% error at against Clairaut; the best-of-six-selected power scores 1.98% against that same reference and 4.78% against best-of-six. Reference disagreement has a larger effect on the apparent error floor than this modest change of power.
The split protects the 1,000 evaluation pairs from this power-selection rule, but those pairs have already been examined in the earlier exploratory study. They are not a newly collected confirmatory test set. Calibration and evaluation pairs also share endpoints, and all five repetitions share the same 64 endpoints on each surface. Intervals are conditional on these endpoints and the selected power; they do not include uncertainty from repeating selection, choosing new endpoints, or numerical reference error. The experiment transfers the power, not the scale, and does not establish a population-wide optimum.
The installed snapshot can be inspected directly:
path <- system.file('extdata','fermat-density-curvature','benchmark.rds',
package='dgraphs',mustWork=TRUE)
benchmark <- readRDS(path)
nrow(benchmark$metrics) # 2,100 condition-level records
nrow(benchmark$references) # 10,500 main reference pairs
benchmark$power_tuning$selection
nrow(benchmark$power_tuning$transfer_metrics) # 1,275 follow-up records
benchmark$provenanceThe companion surface-views.rds contains only the seven
saved 300-point coordinate sets used in the interactive display;
surface-views-provenance.R records their source checksums
and sampling repetition.
The benchmark snapshot contains condition-level errors and coverage,
summaries, reference comparisons, the saddle sensitivity diagnostic, the
power-selection fold scores and transfer results, and provenance. All
data are synthetic. The companion provenance.R records
source-file checksums and the research revision from which the snapshot
and figures were imported. The full research experiment is named
fermat_density_curvature_01_oct_2026.
To reproduce the expensive calculations, copy the installed scripts to a writable directory:
src <- system.file('examples','fermat-density-curvature',package='dgraphs',
mustWork=TRUE)
work <- file.path(tempdir(),'fermat-recovery-reproduction')
dir.create(work,showWarnings=FALSE)
file.copy(list.files(src,full.names=TRUE),work,overwrite=FALSE)From that directory run the following commands. This is intentionally separate from rendering the article. It requires dgraphs, igraph and jsonlite; use one worker on platforms without forked multiprocessing.
Rscript --vanilla prepare.R
Rscript --vanilla references.R 1
Rscript --vanilla distances.R 1
Rscript --vanilla reference_sensitivity.R
Rscript --vanilla evaluate.R
Rscript --vanilla validate.R
Rscript --vanilla power_tuning.R 1
Rscript --vanilla power_transfer.R 1
Rscript --vanilla power_validate.RReference searches can be expensive. Completed chunks are reused; use a new working directory when changing the design. The scripts use an internal numerical reference interface, so retain the recorded package versions and source revision when interpreting differences between reruns. The packaged snapshot remains the fixed evidence for this article.
The follow-up tuning script refuses to overwrite a frozen selection.
Its recorded checksum is checked again during evaluation. The additional
power_summarize.R script regenerates follow-up figures
using ggplot2; article builds read saved figures and do not repeat power
selection.
The practical conclusion is to compare useful intermediate powers, sample sizes, and an ordinary neighborhood-graph baseline before attributing a result to Fermat geometry. Keep distance-estimation error separate from embedding distortion, and show reference uncertainty when it can change the comparison.