Skip to content
Open
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
5 changes: 5 additions & 0 deletions fractal-landscapes/README.md
Original file line number Diff line number Diff line change
@@ -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


Run: node tests/fractal-landscapes.mjs
47 changes: 47 additions & 0 deletions fractal-landscapes/model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Fractal landscapes via 1D midpoint displacement (Fournier-Fussell-Carpenter 1982).
* Hurst parameter H in (0,1): smaller H = rougher. Fractal dimension D = 2 - H.
* No dependencies. Loads in Node (require) and browser (window.FL).
*/
(function (root) {
'use strict';

function generate(n, H, seed) {
// deterministic-ish via simple LCG if seed given
let rng = seed == null ? Math.random : (() => { let s = seed >>> 0; return () => { s = (s * 1664525 + 1013904223) >>> 0; return s / 0x100000000; }; })();
const N = 1 << n;
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) {
Comment on lines +12 to +16

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

const mid = (y[i - half] + y[i + half]) / 2;
y[i] = mid + (rng() * 2 - 1) * amp;
}
step = half;
amp *= Math.pow(0.5, H);
}
return y;
}

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

const pts = lags.map(lag => {
let s = 0, n = 0;
for (let i = 0; i + lag < y.length; i++) { const d = y[i + lag] - y[i]; s += d * d; n++; }
return { lag, v: s / n };
});
const xs = pts.map(p => Math.log(p.lag));
const ys = pts.map(p => Math.log(p.v));
const n = xs.length;
const mx = xs.reduce((a, b) => a + b, 0) / n;
const my = ys.reduce((a, b) => a + b, 0) / n;
let num = 0, den = 0;
for (let i = 0; i < n; i++) { num += (xs[i] - mx) * (ys[i] - my); den += (xs[i] - mx) ** 2; }
return num / den / 2;
}

const api = { generate, estimateH };
if (typeof module !== 'undefined' && module.exports) module.exports = api;
if (typeof window !== 'undefined') window.FL = api;
})(typeof globalThis !== 'undefined' ? globalThis : this);
22 changes: 22 additions & 0 deletions tests/fractal-landscapes.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const { generate, estimateH } = require('../fractal-landscapes/model.js');

let fails = 0;
function check(name, ok, detail) {
console.log(`${ok ? 'PASS' : 'FAIL'} ${name}\n ${detail}`);
if (!ok) fails++;
}

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

const mean = ests.reduce((a, b) => a + b, 0) / ests.length;
check(`H=${H}: estimated H within 0.1`, Math.abs(mean - H) < 0.1, `estimated ${mean.toFixed(3)} (D=${(2-mean).toFixed(3)})`);
}

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

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


if (fails) { console.log(`\n${fails} check(s) failed`); process.exit(1); }
else console.log('\nall checks pass');
Loading