From 156aa39a2232ebf82f33d431cc3598dd7b70f8f6 Mon Sep 17 00:00:00 2001 From: MLopez-Ibanez <2620021+MLopez-Ibanez@users.noreply.github.com> Date: Wed, 11 Nov 2026 19:54:26 +0000 Subject: [PATCH] Make Monte Carlo regressions independent of the RNG Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- hvapprox/1p16d.exp | 2 +- hvapprox/1p16d.test | 4 +++- hvapprox/DTLZLinearShape.8d.front.60pts.10.exp | 2 +- hvapprox/DTLZLinearShape.8d.front.60pts.10.test | 4 +++- hvapprox/DTLZLinearShape.9d.front.60pts.10.exp | 2 +- hvapprox/DTLZLinearShape.9d.front.60pts.10.test | 4 +++- hvapprox/check_mc.exp | 5 +++++ hvapprox/check_mc.py | 15 +++++++++++++++ hvapprox/check_mc.test | 10 ++++++++++ hvapprox/ran.10pts.9d.10.exp | 2 +- hvapprox/ran.10pts.9d.10.test | 4 +++- 11 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 hvapprox/check_mc.exp create mode 100644 hvapprox/check_mc.py create mode 100644 hvapprox/check_mc.test diff --git a/hvapprox/1p16d.exp b/hvapprox/1p16d.exp index 9a247b4..684ed1c 100644 --- a/hvapprox/1p16d.exp +++ b/hvapprox/1p16d.exp @@ -1,3 +1,3 @@ -3.06...e-05 +Monte Carlo estimate within tolerance 3.05...e-05 3.03...e-05 diff --git a/hvapprox/1p16d.test b/hvapprox/1p16d.test index b16981b..3b2d2bb 100644 --- a/hvapprox/1p16d.test +++ b/hvapprox/1p16d.test @@ -1,3 +1,5 @@ -${PROGRAM} -r "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1" --method=1 --nsamples 100000 --seed=42 < ./${TESTNAME}.inp +set -o pipefail +# The exact hypervolume is 0.5^15; allow for Monte Carlo sampling error. +${PROGRAM} -r "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1" --method=1 --nsamples 100000 --seed=42 < ./${TESTNAME}.inp | python3 check_mc.py 0.000030517578125 0.015 || echo "Monte Carlo pipeline failed" ${PROGRAM} -r "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1" --method=2 --nsamples 100000 < ./${TESTNAME}.inp ${PROGRAM} -r "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1" --method=3 --nsamples 100000 < ./${TESTNAME}.inp diff --git a/hvapprox/DTLZLinearShape.8d.front.60pts.10.exp b/hvapprox/DTLZLinearShape.8d.front.60pts.10.exp index 306d853..c75faa3 100644 --- a/hvapprox/DTLZLinearShape.8d.front.60pts.10.exp +++ b/hvapprox/DTLZLinearShape.8d.front.60pts.10.exp @@ -1,3 +1,3 @@ -0.99341123409... +Monte Carlo estimate within tolerance 0.98996193911... 0.99032079022... diff --git a/hvapprox/DTLZLinearShape.8d.front.60pts.10.test b/hvapprox/DTLZLinearShape.8d.front.60pts.10.test index 1fce8fb..927da8a 100644 --- a/hvapprox/DTLZLinearShape.8d.front.60pts.10.test +++ b/hvapprox/DTLZLinearShape.8d.front.60pts.10.test @@ -1,3 +1,5 @@ -${PROGRAM} -r "1 1 1 1 1 1 1 1" --method=1 --nsamples 100000 --seed=42 --union < ../data/${TESTNAME} +set -o pipefail +# Compare the stochastic method against the low-discrepancy estimate. +${PROGRAM} -r "1 1 1 1 1 1 1 1" --method=1 --nsamples 100000 --seed=42 --union < ../data/${TESTNAME} | python3 check_mc.py 0.99032079022485 0.015 || echo "Monte Carlo pipeline failed" ${PROGRAM} -r "1 1 1 1 1 1 1 1" --method=2 --nsamples 100000 --union < ../data/${TESTNAME} ${PROGRAM} -r "1 1 1 1 1 1 1 1" --method=3 --nsamples 100000 --union < ../data/${TESTNAME} diff --git a/hvapprox/DTLZLinearShape.9d.front.60pts.10.exp b/hvapprox/DTLZLinearShape.9d.front.60pts.10.exp index ffca1df..3042d5e 100644 --- a/hvapprox/DTLZLinearShape.9d.front.60pts.10.exp +++ b/hvapprox/DTLZLinearShape.9d.front.60pts.10.exp @@ -1,3 +1,3 @@ -0.99131734089... +Monte Carlo estimate within tolerance 0.99348088822... 0.98924472303... diff --git a/hvapprox/DTLZLinearShape.9d.front.60pts.10.test b/hvapprox/DTLZLinearShape.9d.front.60pts.10.test index 0ee499e..1f0c8fb 100644 --- a/hvapprox/DTLZLinearShape.9d.front.60pts.10.test +++ b/hvapprox/DTLZLinearShape.9d.front.60pts.10.test @@ -1,3 +1,5 @@ -${PROGRAM} -r "1 1 1 1 1 1 1 1 1" --method=1 --nsamples 100000 --seed=42 --union < ../data/${TESTNAME} +set -o pipefail +# Compare the stochastic method against the low-discrepancy estimate. +${PROGRAM} -r "1 1 1 1 1 1 1 1 1" --method=1 --nsamples 100000 --seed=42 --union < ../data/${TESTNAME} | python3 check_mc.py 0.989244723035221 0.015 || echo "Monte Carlo pipeline failed" ${PROGRAM} -r "1 1 1 1 1 1 1 1 1" --method=2 --nsamples 100000 --union < ../data/${TESTNAME} ${PROGRAM} -r "1 1 1 1 1 1 1 1 1" --method=3 --nsamples 100000 --union < ../data/${TESTNAME} diff --git a/hvapprox/check_mc.exp b/hvapprox/check_mc.exp new file mode 100644 index 0000000..40689bd --- /dev/null +++ b/hvapprox/check_mc.exp @@ -0,0 +1,5 @@ +Monte Carlo estimate within tolerance +Monte Carlo estimate within tolerance +invalid estimate rejected +invalid estimate rejected +invalid estimate rejected diff --git a/hvapprox/check_mc.py b/hvapprox/check_mc.py new file mode 100644 index 0000000..6fada24 --- /dev/null +++ b/hvapprox/check_mc.py @@ -0,0 +1,15 @@ +import math +import sys + +reference = float(sys.argv[1]) +tolerance = float(sys.argv[2]) +estimate = float(sys.stdin.read()) + +if not math.isfinite(estimate) or abs(estimate - reference) > tolerance * abs( + reference +): + sys.exit( + f"Monte Carlo estimate {estimate} is not within {tolerance:.1%} of {reference}" + ) + +print("Monte Carlo estimate within tolerance") diff --git a/hvapprox/check_mc.test b/hvapprox/check_mc.test new file mode 100644 index 0000000..5146eff --- /dev/null +++ b/hvapprox/check_mc.test @@ -0,0 +1,10 @@ +set -o pipefail +printf '100\n' | python3 check_mc.py 100 0.015 +printf '101.5\n' | python3 check_mc.py 100 0.015 +for estimate in 101.51 98.49 nan; do + if printf '%s\n' "$estimate" | python3 check_mc.py 100 0.015 > /dev/null 2>&1; then + echo "invalid estimate accepted: $estimate" + else + echo "invalid estimate rejected" + fi +done diff --git a/hvapprox/ran.10pts.9d.10.exp b/hvapprox/ran.10pts.9d.10.exp index 058f746..7a89754 100644 --- a/hvapprox/ran.10pts.9d.10.exp +++ b/hvapprox/ran.10pts.9d.10.exp @@ -1,3 +1,3 @@ -116387804.47... +Monte Carlo estimate within tolerance 116701329.23... 116309924.78... diff --git a/hvapprox/ran.10pts.9d.10.test b/hvapprox/ran.10pts.9d.10.test index a3bc07a..f6cc844 100644 --- a/hvapprox/ran.10pts.9d.10.test +++ b/hvapprox/ran.10pts.9d.10.test @@ -1,3 +1,5 @@ -${PROGRAM} -r "10 10 10 10 10 10 10 10 10" --method=1 --nsamples 100000 --seed=42 --union < ../data/${TESTNAME} +set -o pipefail +# Compare the stochastic method against the low-discrepancy estimate. +${PROGRAM} -r "10 10 10 10 10 10 10 10 10" --method=1 --nsamples 100000 --seed=42 --union < ../data/${TESTNAME} | python3 check_mc.py 116309924.781825 0.015 || echo "Monte Carlo pipeline failed" ${PROGRAM} -r "10 10 10 10 10 10 10 10 10" --method=2 --nsamples 100000 --union < ../data/${TESTNAME} ${PROGRAM} -r "10 10 10 10 10 10 10 10 10" --method=3 --nsamples 100000 --union < ../data/${TESTNAME}