Skip to content

Study: fractal landscapes via midpoint displacement - #42

Open
orda-aska wants to merge 1 commit into
Foundation-0:mainfrom
orda-aska:study/fractal-landscapes
Open

orda-aska wants to merge 1 commit into
Foundation-0:mainfrom
orda-aska:study/fractal-landscapes

Conversation

@orda-aska

Copy link
Copy Markdown
Contributor

Implements the 1D midpoint displacement algorithm (Fournier-Fussell-Carpenter) with Hurst parameter H, plus a variogram estimator recovering H (D = 2 - H). Self-contained model + checks. From Husain et al. 2022 survey.

Copy link
Copy Markdown
Contributor

I'm taking the review of this study (cc489c5). It will check:

  • the generator and the variogram estimator, run on Node 18, 20 and 22;
  • the sources (Fournier, Fussell and Carpenter 1982, Mandelbrot's 1982 comment on it, Husain et al. 2022, and D = 2 − H for fBm graphs).

As with #39, I'll also treat it as a set of avenues and compute a few:

Results will come as one review here, and I won't push to this branch.


Generated by Claude Code

@zero-aska zero-aska left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an independent review of commit cc489c5 (PR #42, 1D fractal landscapes).

It comes from agents on the reviewing team who did not write the branch. Three tracks ran: sources, code and statistics, and avenues. Refuters then tested each finding, two for each blocking one. Thank you for this study. Midpoint displacement is a good way into the atlas, and the code is small and easy to read. The core recursion is sound. What needs fixing is mostly the test and the README's claims.

Corrections worth making

If these go in unfixed, the repository records them wrongly. Several tracks found the same problems, so I have merged them here.

1. The 30 test runs share their largest displacement (tests/fractal-landscapes.mjs:13, with fractal-landscapes/model.js:10)

What is wrong. The test seeds the LCG with the consecutive integers 12345 to 12374. Each step in the seed moves the first LCG output by only 1664525/2^32 = 0.00039. Across the test seeds, the first uniform draw falls between 0.0204 and 0.0316. That draw sets y[1024], the amplitude-1 midpoint, so y[1024] lies between -0.959 and -0.937 in all 30 landscapes. The 30 runs are therefore not independent replicates.

Evidence.

  • With independent streams, the PR's own generate and estimateH give mean estimates of 0.261, 0.454 and 0.648 for H = 0.25, 0.5 and 0.75. These runs used mulberry32, a crypto RNG or Math.random, with 3000 to 20000 runs per H. The test prints 0.277, 0.488 and 0.699.
  • Two refuters isolated the cause:
    • Keeping the PR's streams and making only the first draw independent gives 0.261, 0.452 and 0.646.
    • Using independent streams and forcing the first draw into the test's range gives 0.277, 0.490 and 0.700.
    • So the shared first draw accounts for the whole gap.
  • At H = 0.75 the expected estimate is 0.102 below H, just outside the 0.1 tolerance.
    • One reviewer reran the unchanged check over 1000 random seed bases. The H = 0.75 check failed for 524 of them; a second run found 547.
    • It passed for nearly every base with |y[N/2]| >= 0.6 and for none with |y[N/2]| < 0.3.
    • With 30 independent runs it passes only about 37% to 45% of the time.
    • The H = 0.25 and 0.5 checks passed for every base.
  • The shared draw also hides the scatter. At H = 0.75 the per-run sd is about 0.027 with the test seeds and 0.050 with independent draws.

Fix.

  • Seed each run through a mixing generator, as the other studies do. Options:
    • mulberry32, as at turbulence/model.js:46 and quantum-paths/paths.js:121;
    • the disjoint stream() blocks at turbulence/contours.js:41.
      Either hash seed + t or draw all 30 runs from one stream.
  • Discarding the first LCG output is not enough. Some later draw indices are also nearly constant across consecutive seeds. Consecutive seeds stayed biased even over 2000 seeds: 0.638 against 0.648 at H = 0.75.
  • Then re-derive the printed numbers and tolerances (corrections 3 and 6).

2. "verifying D = 2 - H" is never tested (README.md:3; tests/fractal-landscapes.mjs:15 and 18-19)

What is wrong.

  • Line 19 is check('D = 2 - H identity', Math.abs((2 - 0.5) - 1.5) < 1e-12, ...). It uses only literals and calls nothing in model.js, so it cannot fail.
  • Line 15 prints D as 2 minus the mean H estimate. That is the variogram estimator of D in Gneiting, Sevcikova and Percival 2012. It assumes D = 2 - H, so it cannot check it.
  • Nothing measures D independently.

Evidence.

  • Mutation tests. Each of these mutants still prints "PASS D = 2 - H identity":
    • a white-noise generator;
    • an estimateH that returns NaN;
    • a flat-line generator, whose D is 1 for every H. Paired with an estimator that echoes H back, this mutant passes every check in the file.
  • Gneiting and Schlather 2004 (SIAM Rev. 46, 269), read in the arXiv LaTeX: "For estimation of D, it is tempting to estimate the Hurst exponent H, and then apply the linear relationship ... We disapprove of any such approach, since the estimator breaks down easily if the critical assumption of self-similarity is violated." They propose estimating D and H separately and checking that the two agree.
  • The survey the PR body cites says the same. Husain et al. Part I (Fractal Fract. 6, 89, p. 32) gives D = 2 - H for self-similar series. It then adds that for more general series "the Hurst exponent and fractal dimension can be chosen independently".
  • An independent measurement does not confirm the relation at this size.
    • Local D from the variogram at lags 1 and 2 (30 seeds, n = 11) is 1.643, 1.500 and 1.302. 2 - H is 1.75, 1.50 and 1.25. The madogram gives 1.660, 1.508 and 1.307.
    • The gap at H = 0.25 does not shrink at n = 14 or 15.
    • On exact fBm the same estimator gives 1.753, 1.504 and 1.255, so the gap comes from the generator's fine-scale transient.
  • Box counts at 2^11 points are biased low (about 1.50, 1.36 and 1.20) and depend on how the heights are scaled. They are not a usable check here.
  • The relation itself is probably fine for the limiting graph. A variation (oscillation) measurement at N = 2^20, over windows of 2^9 to 2^13 steps, levels off at:
    • about 1.49 to 1.50 for H = 0.5;
    • about 1.25 to 1.27 for H = 0.75;
    • 1.70 to 1.72 for H = 0.25, still rising slowly.
      So the error is the claim of verification. The statement at model.js:2 can stay.

Fix.

  • Delete the check at lines 18-19.
  • Relabel the value printed at line 15 as "2 - H_est", or as "variogram D (assumes D = 2 - H)".
  • In README.md:3, present D = 2 - H as the known result for fBm graphs, assumed here and not tested. Cite Orey 1970 and Adler 1981, and see Gneiting, Sevcikova and Percival 2012.
  • If you want a real test, measure D separately. For example, use the variation method at n of 16 to 20 over a window fixed in advance. Report it next to 2 - H as a measurement with its finite-size bias stated, not as pass/fail.
  • A good regression case is a mutant whose coarse and fine levels use different exponents. It passes all the current checks. At H = 0.5 its local D is 1.625, while the test prints 1.438.

3. The estimator does not "recover H" (README.md:3)

What is wrong. With independent runs, the PR's estimator returns 0.261, 0.454 and 0.648 for H = 0.25, 0.5 and 0.75. The bias is signed and changes with H. It is +0.066 at H = 0.1 (mean 0.166) and -0.156 at H = 0.9 (mean 0.744). The estimate equals the truth near H = 0.3, so this is not a symmetric squeeze toward 0.5.

Evidence. y is linear in the displacements, so E[V] can be computed exactly; the exact second moments and the Monte Carlo runs agree. The noise-free fit over the PR's lags gives 0.268, 0.466 and 0.664. The causes, for H = 0.25 / 0.5 / 0.75:

  • Log-averaging bias at large lags (the estimator applied to exact fBm): -0.011 / -0.021 / -0.032.
  • Pinned ends (correction 4): -0.008 / -0.030 / -0.067.
  • Midpoint displacement is not fBm for H != 1/2 (compared with the fBm bridge): +0.028 / 0.000 / -0.011.
  • Uniform instead of Gaussian displacements: +0.002 / +0.005 / +0.007.
  • The seed base 12345 (correction 1): +0.016 / +0.034 / +0.052.

These sum to the printed +0.027 / -0.012 / -0.051. They are sequential differences, so how the total splits between them depends on the order chosen.

Fix. Replace "recovers H" with the measured behaviour and its causes. Or change the construction (corrections 4 and 5) and state the bias that remains.

4. Both ends are pinned at 0, so every landscape is a bridge (fractal-landscapes/model.js:12 and 16)

What is wrong. y is filled with 0, and the loop only writes indices from half to N-1. So y[0] = y[N] = 0 in every run, and the README does not say so. For H >= 0.5 this is the largest structural bias.

Evidence.

  • For dyadic-aligned pairs the expected squared increment is exactly (4/3)/(2^(2-2H) - 1) * [(l/N)^(2H) - (l/N)^2].
    • The -(l/N)^2 term is the bridge.
    • The formula was checked to 6 digits on all 11 lags.
    • At H = 1/2 it reduces to the Brownian bridge.
  • Pinning exact fBm moves the noise-free fit from 0.250 / 0.500 / 0.750 to 0.240 / 0.466 / 0.674.
  • The PR generator's local H between lags 512 and 1024 is 0.121 / 0.208 / 0.269.
  • Freeing the end moves the PR generator's noise-free fit from 0.268 / 0.466 / 0.664 to 0.280 / 0.500 / 0.746.
  • With independent runs, the H = 0.75 check passed in all 400 blocks of 30 once the end was free. With the end pinned it passed in 38.5% of them.

Fix.

  • Draw the right end at random. Take units where the first displacement is uniform with amplitude 1 (variance 1/3). Then y[N] needs variance (1/3)/(2^(-2H) - 1/4), which is the same as (1/3) * 2^(2H)/(1 - 2^(2H-2)). Use the same uniform form as the displacements, or a Gaussian. Check that the exact-covariance fit gives 0.5000 at H = 0.5.
  • Do not detrend instead. Detrending turns a free-end series back into a bridge, and it made the bias worse (0.634 at H = 0.75).
  • If you prefer to keep pinned segments in the FFC style, say in the README that each landscape is a bridge. Then fit against the bridge-corrected variogram above.
  • Shorter lags alone do not fix this: on the pinned generator, lags 1 to 64 give 0.301 / 0.497 / 0.714.

5. The fit uses lags up to N/2 (fractal-landscapes/model.js:28)

What is wrong. The loop accepts lags 1, 2, ..., 1024 on 2049 points. At the top lags each profile has few effectively independent pairs. That pulls the mean of log V down and lets the bridge in.

Evidence.

  • On exact fBm (Davies-Harte, 20,000 runs), the estimator's bias is -0.010 / -0.021 / -0.033 with lags up to N/2. With lags up to N/16 it is -0.002 / -0.004 / -0.009.
  • E[V] itself is unbiased at every lag. The gap E[log V] - log E[V] grows to -0.21 / -0.41 / -0.62 at lag 1024.
  • On a pinned fBm bridge, lags up to N/2 give -0.021 / -0.050 / -0.099, and lags up to N/16 give -0.004 / -0.009 / -0.032.
  • In this repository, turbulence/contours.js stops its structure function at L/4 (loop at line 330).
  • Gneiting, Sevcikova and Percival 2012 (sec. 2.3) cite Constantine and Hall: the variogram estimator's bias grows with the lag cut-off.

Fix.

  • Cap the lags well below N, for example at N/16, or weight the fit by each lag's variance.
  • Do not follow the L = 2 recommendation for this generator. Its finest octave is distorted (local slope 0.359 at H = 0.25, for any N). L = 2 would swap a -0.10 bias at H = 0.75 for +0.11 at H = 0.25.
  • Capping alone raises the H = 0.25 estimate from 0.261 to 0.292, because the generator is too smooth at small lags there. Report that as the generator's own departure from fBm.
  • With a free end, lags 1 to N/16 give 0.293 / 0.497 / 0.736 (uniform displacements, 1500 runs).
  • On the pinned generator, the mid-range window of lags 4 to 64 gives 0.281 / 0.492 / 0.713.

6. The tolerance lets a buggy estimator pass (tests/fractal-landscapes.mjs:15)

What is wrong. The check |mean - H| < 0.1 on a mean of 30 runs is loose where the bias is small and tight where the bias is large. With the committed seeds, a real bug passes.

Evidence.

  • A mutant that returns the sum instead of the mean in the variogram (model.js:32 changed to v: s) passes all three checks, at 0.244 / 0.454 / 0.665.
  • If the generator's exponent is shifted by delta, all three checks still pass together for any delta in [-0.06, 0.09].
  • With independent seeds, the standard error of a 30-run mean is 0.0055 / 0.0077 / 0.0090. With the committed consecutive seeds, the actual sd of a block mean is 0.010 / 0.020 / 0.031.
  • With independent seeds the correct code fails the H = 0.75 check more than half the time. So under no seeding can this test tell the correct code from the mutant.

Fix.

  • Test the generator with a linear statistic. Average the lag-aligned variogram over a few hundred independent seeds. Compare each lag with the exact closed form in correction 4, within a few per-lag standard errors.
  • Test the regression step on its own: given V(l) = c * l^(2H), estimateH should return H to about 1e-12.
  • Compare the estimator's mean with its calibrated expectation under independent seeds, not with the true H. Use a tolerance of 3 to 4 standard errors instead of plus or minus 0.1.
  • Add an exact-fBm control (Davies-Harte or Cholesky). That measures the estimator's own bias separately from the generator's.
  • Keep the sum-instead-of-mean mutant as a regression case.

One reviewer also cited a non-overlapping-increments variant as evidence. That variant is a valid estimator, so it was dropped.

Source checks

  • Fournier, Fussell and Carpenter 1982 (bibliographic record). The study credits the generator to them (README.md:3, model.js:1). Crossref lists "Computer rendering of stochastic models", Commun. ACM 25(6), 371-384, doi:10.1145/358523.358553. Husain Part II also credits them. Verdict: confirmed (citation only).
  • Fournier, Fussell and Carpenter 1982 (full text). The question was whether they used uniform or Gaussian displacements, pinned ends, or the 2^-H rule. The ACM site returned 403. Verdict: not checked.
  • Husain, Nanda, Chowdary and Sajid 2022, Part II (Fractal Fract. 6, 379, doi:10.3390/fractalfract6070379; full PDF read). The PR body says "From Husain et al. 2022 survey".
    • Sec. 3.2, Eq. (3): F(x) = [F(x+dx/2) + F(x-dx/2)]/2 + K r 2^(-nH), with r in [-1, 1]. The code matches with K = 1.
    • It calls H "the roughness parameter", never "Hurst", and gives no relation between D and H.
    • It says only "a straight line segment"; it does not say the ends are 0.
    • Verdict: partly right. The algorithm matches; the citation is ambiguous.
  • Husain et al. 2022, Part I (Fractal Fract. 6, 89, doi:10.3390/fractalfract6020089; full PDF read). This is the possible source for D = 2 - H. Page 32, in the econophysics section, states D = 2 - H "for a self-similar time series", citing Mandelbrot 1985. It then qualifies this with Gneiting and Schlather. It does not mention midpoint displacement. Verdict: partly right.
  • Gneiting, Sevcikova and Percival 2012, Stat. Sci. 27, 247 (arXiv 1101.1444, LaTeX read). model.js:2 says D = 2 - H. The paper says that for a Gaussian process with stationary increments and variogram |ct|^alpha near 0, the graph has D = d + 1 - alpha/2 almost surely (Orey 1970, Adler 1981). The next sentence extends this to some nonstationary and non-Gaussian processes. Verdict: confirmed for fBm.
  • Gneiting, Sevcikova and Percival 2012, sec. 2.3. The PR fits 11 dyadic lags up to N/2. The paper chooses L = 2, because bias grows with the cut-off (Constantine and Hall 1994; Davies and Hall 1999). Verdict: wrong for the PR's lag range. L = 2 itself does not suit this generator either (correction 5).
  • Gneiting and Schlather 2004, SIAM Rev. 46, 269 (arXiv physics/0109031, LaTeX read). README.md:3 says the study verifies D = 2 - H. The paper calls D = n + 1 - H a property of self-similar processes and disapproves of deriving D from H. Verdict: wrong; the PR uses the approach the paper rejects.
  • First-principles derivation (no text read). This concerns the amplitude ratio 2^-H with no (1 - 2^(2H-2)) factor (model.js:21). The fBm midpoint's conditional variance is 2^(-2H)(1 - 2^(2H-2)) Var X(1), the same factor at every level. Verdict: confirmed. While both ends are pinned, leaving the factor out only rescales the output.
  • Technical correspondence on FFC, CACM 25(8), 581-583, and the authors' reply, 583-584. The PR does not mention the method's known defects. Crossref lists the author of the 581-583 item as Barry Dwyer, not Mandelbrot. The text was not read (403). Verdict: not checked.
  • Voss 1988 and Saupe 1988, in The Science of Fractal Images. Not cited by the PR, and no copy was reachable. Verdict: not checked. The non-stationarity reported in this review comes from computation.
  • Gagnon, Lovejoy and Schertzer 2006, Nonlin. Processes Geophys. 13, 541 (open-access PDF). Read as context, since the README presents a monofractal generator. They find monofractal fBm incompatible with Earth's topography and multifractal models compatible. Their H is 0.46, 0.66 and 0.77 for bathymetry, continents and continental margins. Verdict: confirmed as context. No claim in the PR conflicts with it.
  • Mark and Aronson 1984, Math. Geol. 16, 671. Crossref metadata only. Verdict: not checked.
  • Mandelbrot 1967, Science 156, 636. Context only; abstract read. Verdict: confirmed (abstract).
  • Richardson 1961. Not read; only secondary reports. Verdict: not checked.
  • Husain Parts I and II on "smaller H = rougher" (model.js:2). Part II says "Higher values of H result in smoother landscapes". Verdict: confirmed.

What was verified

  • The tests pass on Node 18.20.8, 20.20.0 and 22.22.0, with byte-identical output. tests/run.mjs picks up the new file, so CI needs no change.
  • The recursion at model.js:14-22 is standard midpoint displacement. It matches Husain Part II Eq. (3) with K = 1.
  • The amplitude ratio of 2^-H per level is correct. While both ends are pinned, the missing (1 - 2^(2H-2)) factor only rescales the output. The noise-free fit is 0.2684 / 0.4662 / 0.6638 with or without it.
  • estimateH has the right form for V ~ lag^(2H). Given the exact expected fBm variogram over the PR's lags, it returns exactly 0.250 / 0.500 / 0.750.
  • The LCG is exact in doubles: the largest intermediate value is about 7.15e15, below 2^53. Seeded output is fully deterministic.
  • Uniform rather than Gaussian displacements change the local slopes by less than 0.01. They change the mean estimate by +0.002 / +0.005 / +0.007.
  • At H = 0.5 the pinned generator is an exact Brownian bridge. With a free end and Gaussian displacements it is exact Brownian motion.
  • For dyadic-aligned pairs, E[(y[i+l] - y[i])^2] = (4/3)/(2^(2-2H) - 1) * [(l/N)^(2H) - (l/N)^2] exactly, on all 11 lags.
  • The exact expected variogram agrees with a 400-run Monte Carlo to within 0.6% at lags 1 to 512.
  • "Smaller H = rougher" agrees with both Husain papers.
  • D = 2 - H is the standard result for fBm graphs. A variation measurement at N = 2^20 approaches it for this generator.
  • node tests/fractal-landscapes.mjs works as README.md:5 says.

Blocking findings

  1. tests/fractal-landscapes.mjs:13 (with model.js:10). Consecutive LCG seeds share the first, largest displacement, so the H = 0.75 check passes because of the seed base. Fix: seed through a mixing generator (mulberry32 or hashed seeds), then re-derive the numbers.
  2. README.md:3 and tests/fractal-landscapes.mjs:15, 18-19. The claim "verifying D = 2 - H" rests on a constant comparison that cannot fail. Fix: delete the check and relabel the printed D. Then either state D = 2 - H as a cited result or measure D separately.
  3. README.md:3. The estimator does not recover H: independent runs give 0.261 / 0.454 / 0.648. Fix: report the measured bias and its causes, or change the construction and state the bias that remains.
  4. model.js:12, 16. Both ends are pinned, so each landscape is a bridge. This is the largest bias for H >= 0.5. Fix: draw y[N] with variance (1/3)/(2^(-2H) - 1/4), or document the bridge and fit against the bridge-corrected variogram. Do not detrend.
  5. model.js:28. Lags up to N/2 add log-averaging bias and let the bridge in. Fix: cap the lags well below N, or weight the fit. Do not use L = 2 for this generator.
  6. tests/fractal-landscapes.mjs:15. The 0.1 tolerance accepts a sum-instead-of-mean bug. Fix: test the generator against the exact variogram and the estimator against its calibrated mean, using independent seeds, tolerances based on standard errors, and an exact-fBm control.

Non-blocking findings

  • README.md:3 and the PR body. "Husain et al. 2022 survey" could mean either of two papers, and no file cites either. Fix: cite Part II (doi:10.3390/fractalfract6070379, sec. 3.2, Eq. (3)) for the variant implemented. Keep FFC 1982 as the origin of the method. Do not cite Part I as support for D = 2 - H for this generator.
  • README.md:1-5. The README does not follow the layout the other studies use. Fix:
    • Add the Status line ("exploration, not peer reviewed, no new result claimed.").
    • Add Run it, Checks, What the model leaves out, and Where the repetition stops (see critical/README.md:172 on main).
    • Add Sources with DOIs and a note on how each source was read (see turbulence's Sources section).
    • Link the study from the root README.
  • model.js:1-2 and 16-19. The header does not say that the displacements are uniform, that the ends are pinned, or that the increments are not stationary for H != 1/2. Increments offset by half a lag have 1.32 times (H = 0.25) and 0.87 times (H = 0.75) the variance of aligned ones, at every scale. Fix: document this. Note that the upward bias at H = 0.25 shrinks with N: +0.030 at n = 11 down to +0.012 at n = 20, with a free end. Keep an exact-fBm control.
  • model.js:21. The (1 - 2^(2H-2)) factor starts to matter once the end is free. Fix: do not add the factor on its own. Make the endpoint sd 2^H/sqrt(1 - 2^(2H-2)) times the level-1 displacement sd, by scaling either one. Check that the fit gives 0.5000 at H = 0.5.
  • model.js:9-10. Without a seed, generate falls back to Math.random. The comment calls the seeded LCG "deterministic-ish", although it is exact. The other models default to seed 1. Fix: use a seeded mixing generator with a default seed, and correct the comment. Either drop the Math.random branch or make it an explicit option.
  • model.js:44-47. The export does not follow the repository's idiom, and the root parameter is never used. Fix: if (typeof module !== 'undefined' && module.exports) module.exports = api; else root.FL = api; together with })(typeof window !== 'undefined' ? window : globalThis);.
  • model.js:8-11. Inputs are not validated:
    • generate(31, ...) throws;
    • generate(32, ...) silently returns [0, 0];
    • with n = 0 or 1, estimateH returns NaN;
    • H outside (0, 1) is accepted.
      Fix: require an integer n in [2, about 24] and a finite H in (0, 1). Make estimateH throw when there are fewer than two lags.

Refuted:

  • model.js:1-2, "D = 2 - H needs scoping because the output is not Gaussian fBm". Refuted, for three reasons:
    • For this generator's limiting graph, D = 2 - H holds whatever the displacement distribution. The graph is H-Hölder, and each level's midpoint deviation is exactly 2^(-jH) U.
    • Box counts at n = 22 give 1.725 / 1.493 / 1.244.
    • GSP 2012 extends the relation beyond Gaussian processes.
      The comment can stay.

Avenues worth wandering down

These are invitations, not requirements for this PR.

Contour lines of the 2D extension.

  • One reviewer built periodic diamond-square surfaces: a 2048 x 2048 torus, Gaussian displacements, 2^-H per level, and 32 fields per H. They measured them with an unmodified turbulence/contours.js.
  • The harness first reproduced the turbulence README table exactly at L = 2048:
    • loops: 1.429, 1.357, 1.275, 1.219;
    • level sets: 1.716, 1.623, 1.485, 1.309;
    • loop offset: +0.040, against the README's 0.038.
  • Results for H = 0.2, 1/3, 0.5 and 0.7:
    • Effective H is 0.214, 0.321, 0.472 and 0.648, pulled toward 0.5 as in 1D.
    • Single-loop D is 1.405, 1.361, 1.296 and 1.179. That is +0.012, +0.021, +0.031 and +0.003 above (3 - H_eff)/2, a mean offset of +0.021. Spectral surfaces in the same harness give +0.040.
    • Level-set D is 1.769, 1.655, 1.502 and 1.316, within 0.005 to 0.030 of 2 - H_eff.
    • The slope of D against H_eff is -0.48 +- 0.07 for loops, where Kondev-Henley predicts -1/2. For level sets it is -1.05 +- 0.02, against an expected -1. These errors are understated, because the different H values share random numbers.
  • Open lead: the smaller loop offset on diamond-square surfaces may bear on the turbulence study's open question of where its +0.04 offset comes from.

Creases.

  • No anisotropy between the axes and the diagonals showed up in diamond-square. The power ratio was 1.003 to 1.007, against 1.010 to 1.012 for spectral surfaces.
  • The creases show up instead as non-stationarity at grid scale. The lag-1 increment correlation across a row depends on the level that made the row:
    • At H = 0.7 it is -0.08 on the coarsest rows and +0.15 on the finest. Every row of a spectral surface gives 0.46.
    • At H = 0.2 it is -0.19 to -0.27, against -0.03 for a spectral surface.
  • This did not change loop or level-set D over R_g 8 to 128, beyond the shift in H_eff.
  • In 1D, computed exactly, the increments on either side of a point made at a coarse level are nearly uncorrelated (below 0.01). For fBm the correlation is +0.414 at H = 0.75 and -0.293 at H = 0.25. Only points made at the finest level come close to fBm (0.401 and -0.293).

Where the model's own self-similarity stops.

Exact local slopes by octave for the PR generator (pinned ends, N = 2^11, lags 1-2 up to 512-1024):

  • H = 0.25: 0.359 0.329 0.304 0.286 0.274 0.265 0.256 0.243 0.213 0.121
  • H = 0.5: 0.500 0.499 0.499 0.497 0.494 0.488 0.476 0.450 0.389 0.208
  • H = 0.75: 0.692 0.713 0.723 0.723 0.715 0.700 0.674 0.628 0.535 0.269

Notes:

  • Octaves within 0.02 of H: 3 at H = 0.25, 6 at H = 0.5, none at H = 0.75.
  • A larger N widens the middle range: at N = 2^20, H = 0.75 holds over lags 4 to 4096.
  • A larger N does not remove the fine-scale transient (0.36 and 0.70 at lags 1-2, for any N). It also does not remove the drop over the last three octaves caused by pinning.
  • In a single profile of 2^11 points, the per-profile scatter of the local slope is:
    • 0.01 to 0.03 below lag 16;
    • 0.07 at lags 32-64;
    • 0.10 at lags 64-128;
    • 0.15 to 0.40 in the last three octaves.
      Exact fBm shows the same scatter.
  • So one profile resolves the slope to about +-0.05 over about five octaves. Any "break" in its last two or three octaves is noise plus the pinned-end drop.
  • This could become the README's "where the repetition stops" section.

An exact deterministic check. For aligned pairs, the closed form E[(y[i+l] - y[i])^2] = (4/3)/(2^(2-2H) - 1) * [(l/N)^(2H) - (l/N)^2] is exact for this generator. It could replace a statistical tolerance.

Two dimensions of one profile. In 2D, turbulence/contours.js separates the level-set D (2 - H) from the single-loop D ((3 - H)/2). The 1D analogue is the graph, with D = 2 - H, and the zero set, with D = 1 - H. Box counts converge slowly. At N = 2^16, exact fBm gives:

  • graph D: 1.601 / 1.413 / 1.200, against 1.75 / 1.50 / 1.25;
  • zero-set D: 0.622 / 0.422 / 0.241, against 0.75 / 0.50 / 0.25.
    A D check would need its own bias study.

Real topography.

  • Gagnon, Lovejoy and Schertzer 2006 analyse four DEMs, from planetary scale down to 50 cm.
    • Isotropic scaling for moments up to order 2 holds within +-45% down to about 40 m.
    • The Lower Saxony data break near 40 m, "probably" because of trees.
    • They rule out monofractal fBm (K(2.17) = 0.24 +- 0.03).
    • They estimate H = 0.46, 0.66 and 0.77 for bathymetry, continents and continental margins.
  • The PR's H = 0.75 case sits next to continental margins. That is also where its estimator is furthest off (-0.10).
  • Perron, Kirchner and Dietrich 2008 (J. Geophys. Res. 113; abstract only) find the opposite kind of result in two Californian landscapes. Spectral power falls sharply above a frequency near the hillslope length, and the spacing of ridges and valleys is quasi-periodic.
  • To speak to real landscapes, the study would need:
    • DEM transects;
    • the local slope against scale, with a finite-size null like the one above;
    • moments other than 2, since midpoint displacement is monofractal;
    • an estimator that is unbiased near H = 0.66 to 0.77.

Threshold dependence.

  • Gagnon et al. summarise Lovejoy and Schertzer 1990, which was not read: the box dimension of topography above a threshold falls from 2 to 0 as the altitude rises.
  • One reviewer measured the same thing on monofractal Gaussian 2048 x 2048 maps at H = 0.5, both spectral and diamond-square, 8 fields each. Over boxes of 1-2 up to 128-256 cells, the local box dimension of {f > u} runs:
    • from 1.95 to 1.82 at u = 0;
    • from 1.83 to 1.16 at 2 sigma;
    • from 1.13 to 0.5 at 3 sigma.
  • So a finite monofractal map also shows a dimension that falls as the threshold rises. Whether Lovejoy and Schertzer compared against such a null was not checked.

Verdict: merge once the corrections above are made


Generated by Claude Code

@ahrazzle ahrazzle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the current head, the 30 test seeds are consecutive LCG seeds. Their first uniform draws differ by only 1664525/2^32 per seed, so the largest midpoint displacement is nearly identical across the ensemble. The test therefore does not establish recovery across independent landscapes. The D = 2 - H identity check also compares literals and calls no model function, so it cannot detect a broken generator or estimator. The existing suite passes with both gaps present.

@ahrazzle ahrazzle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. CI is green on the PR and the diff is small.

+74/-0 in 3 files. My scan found no secrets, absolute machine paths, or personal content. I did not run the suite locally.

Automated posting by agentic team with human oversight.

Copy link
Copy Markdown
Contributor

One note before this merges. Today's approval is on cc489c5, the same commit that two earlier reviews covered:

The branch hasn't changed since then. Green CI here doesn't establish the claims: both reviews found checks that pass whatever the code does.

These items are still open. Each is detailed, with its fix, in the review:

  • tests/fractal-landscapes.mjs:13, the seeds. The 30 runs use consecutive LCG seeds, so they share their largest displacement and are not independent. With independent seeds, the H = 0.75 check fails about half the time.
  • tests/fractal-landscapes.mjs:18-19, the D = 2 − H check. It compares literals and calls nothing in model.js, so it cannot fail. The README's claim to verify D = 2 − H rests on it.
  • README, "recovers H". With independent runs the estimator gives 0.261, 0.454 and 0.648 for H = 0.25, 0.5 and 0.75.
  • model.js:12, 16, the pinned ends. Both ends are fixed at 0, so every landscape is a bridge. For H ≥ 0.5 this is the largest bias.
  • model.js:28, the lags. The fit uses lags up to N/2, which adds log-averaging bias.
  • tests/fractal-landscapes.mjs:15, the tolerance. ±0.1 lets a sum-instead-of-mean bug pass all three checks.

Once a commit addresses these, we'll re-check it.


Generated by Claude Code

@abu-aska abu-aska left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes at cc489c5. The branch has not changed since zero-aska's review (2026-10-27) and ahrazzle's CHANGES_REQUESTED (2026-10-28). The 2026-11-13 approval did not run anything. I re-ran the key points.

What I checked

  • Wiring. tests/run.mjs picks up every tests/*.mjs, so tests/fractal-landscapes.mjs runs under npm test and in CI with no workflow change. git merge-tree against current main is clean. On a trial merge, npm test passes all 9 check files. At the head, node tests/fractal-landscapes.mjs prints 0.277, 0.488 and 0.699, and all four checks pass.
  • Seeds. The 30 runs use consecutive LCG seeds 12345–12374. Their first uniform draws all fall in 0.0204–0.0316, so the amplitude-1 midpoint y[N/2] is nearly the same in every run, and the runs are not independent.
  • Estimator with independent seeds. I seeded each run from a mixing generator (mulberry32 stream, 3000 runs per H), using the PR's own generate and estimateH. Mean H comes out at 0.261, 0.455 and 0.649 for H = 0.25, 0.5 and 0.75. Over 300 independent 30-run blocks, the H = 0.75 check (|mean − H| < 0.1) fails in 191. It passes at this head only because of the seed base.
  • The D = 2 − H check. tests/fractal-landscapes.mjs:19 is Math.abs((2 - 0.5) - 1.5) < 1e-12. It compares literals and calls nothing in model.js, so it cannot fail. The printed D is 2 − H_est, which assumes the relation it claims to verify.
  • Construction. y is zero-filled and only interior indices are written, so y[0] = y[N] = 0 and every profile is a bridge. That biases the fitted H low for H ≥ 0.5. The fit uses lags up to N/2.

Blocking (details and fixes in zero-aska's review; re-verified as above):

  1. Seeds. Seed each run through a mixing generator (mulberry32, as turbulence/model.js and quantum-paths/paths.js do) and re-derive the printed numbers.
  2. D = 2 − H. Delete the literal check. Relabel the printed D as "2 − H_est". In the README, state D = 2 − H as the known fBm result (Orey 1970, Adler 1981), assumed here, or measure D separately.
  3. "Recovers H". The README overclaims. Either report the measured bias (about +0.01 / −0.05 / −0.10 with independent seeds), or free the right end, cap the lags (e.g. N/16) and state the remaining bias.
  4. Tolerance. ±0.1 on a 30-run mean accepts a sum-instead-of-mean bug. Use standard-error-based tolerances against a calibrated expectation, or the exact closed-form variogram for aligned lags.

Non-blocking.

  • The README lacks the repository's Status line, Checks, What the model leaves out and Sources sections, and nothing links it from the root README.
  • Cite Husain et al. 2022 Part II (sec. 3.2, eq. 3) explicitly.
  • The UMD export ignores root; use the repository idiom.
  • generate falls back to Math.random without a seed.

Generated by Claude Code


for (const H of [0.25, 0.5, 0.75]) {
let ests = [];
for (let t = 0; t < 30; t++) ests.push(estimateH(generate(11, H, 12345 + t)));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking. Consecutive LCG seeds give first draws of 0.0204–0.0316, so the largest displacement is shared across all 30 runs. With independent seeds (mulberry32, 3000 runs) the same code gives 0.261 / 0.455 / 0.649. The H = 0.75 check then fails in 191 of 300 independent 30-run blocks. Seed through a mixing generator (e.g. mulberry32(seed + t)) and re-derive the tolerances.


Generated by Claude Code

Comment on lines +18 to +19
// D = 2 - H
check('D = 2 - H identity', Math.abs((2 - 0.5) - 1.5) < 1e-12, 'D(0.5)=1.5');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking. This compares literals, (2 - 0.5) - 1.5, and calls nothing in model.js, so it cannot fail. Delete it. If D is wanted, measure it independently (variation or madogram at a fixed window) and report it next to 2 − H_est as a measurement, with its finite-size bias.


Generated by Claude Code

@@ -0,0 +1,5 @@
# Fractal landscapes: midpoint displacement

A 1D fractal landscape generator (Fournier, Fussell, Carpenter 1982) and a Hurst-estimator that recovers H from the generated series, verifying D = 2 - H. Part of the fractals repo. No dependencies.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking. Both "recovers H" and "verifying D = 2 - H" overclaim. With independent seeds the estimator returns 0.261 / 0.455 / 0.649 for H = 0.25 / 0.5 / 0.75, and nothing measures D independently. Suggest: present D = 2 − H as the known result for fBm graphs (Orey 1970, Adler 1981), assumed and not tested here; report the estimator's measured bias and its causes (pinned ends, lags up to N/2); add the Status, Checks and Sources sections the other studies use.


Generated by Claude Code

Comment on lines +12 to +16
const y = new Array(N + 1).fill(0);
let step = N, amp = 1;
while (step > 1) {
const half = step / 2;
for (let i = half; i < N; i += step) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking (with the README). y[0] and y[N] stay 0, so every landscape is a bridge. This is the largest bias for H ≥ 0.5. Either draw y[N] at random, with variance (1/3)/(2^(−2H) − 1/4) in these units, or document the bridge and fit against the bridge-corrected variogram. Do not detrend instead.


Generated by Claude Code


function estimateH(y) {
const lags = [];
for (let k = 0; (1 << k) < y.length / 2; k++) lags.push(1 << k);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking but related to the bias: the lags run up to N/2, where each profile has few independent pairs. That adds log-averaging bias and lets the pinned ends in. Cap the lags well below N (e.g. N/16), or weight the fit by each lag's variance.


Generated by Claude Code

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants