Skip to content

Commit 22e456f

Browse files
committed
reduce Newton model test runtime
1 parent 9dd8d55 commit 22e456f

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

models/newton.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This model infers what forces govern a simple physical scene from the scene's ob
1111

1212
In the observed scene, one particle moves at high speed towards another particle at rest. Inference is over the dynamics that produced the observed trajectory: did collision forces act between the particles, and if so, with what elasticity? The initial velocities are also uncertain. Each hypothesis is evaluated by simulating the scene forward with RK4 and softly conditioning the simulated trajectory to match the observed one at a subsampled set of points, so every MH step integrates the equations of motion anew.
1313

14-
The program runs this inference for two scenes: one where the particles truly do not interact, so the moving particle passes straight through the other (the run in the original program), and one where collision forces truly act, so the particles collide almost inelastically. In the first case the posterior concludes that no collision forces were at play, and the elasticity posterior stays at its prior; in the second it concludes that collision forces were present and recovers the true elasticity of 0.1. Expect MCMC to take on the order of ten seconds per scene.
14+
The program runs this inference for two scenes: one where the particles do not interact, so the moving particle passes through the other, and one where collision forces produce an almost inelastic collision. The first posterior favors no collision force; the second favors collision and recovers elasticity near its true value of 0.1. The short paths and modest MCMC settings keep both examples practical in the browser and in headless checks.
1515

1616
~~~~
1717
// ----- 2-D vector helpers -----
@@ -194,8 +194,8 @@ var v0 = [[0, 0], [1000, 0]];
194194
var sceneProperties = [{ mass: 2, size: 12, elastic: 0.1 },
195195
{ mass: 1, size: 12, elastic: 0.1 }];
196196
var dt = 0.001;
197-
var pathLength = 300;
198-
var numInferencePoints = 100;
197+
var pathLength = 250;
198+
var numInferencePoints = 50;
199199
200200
// ----- Observation model -----
201201
@@ -234,7 +234,7 @@ var addNoiseVL = function(A, noiseVar) {
234234
// scene, the particles' elasticity, and the initial velocities.
235235
var inferDynamics = function(observedPath) {
236236
var reducedObserved = pathSplitter(observedPath, numInferencePoints);
237-
return Infer({ method: 'MCMC', samples: 200, lag: 1, burn: 500 }, function() {
237+
return Infer({ method: 'MCMC', samples: 100, lag: 1, burn: 200 }, function() {
238238
var collision = flip(0.5);
239239
var inferredForces = collision ? [collisionF] : [nullF];
240240
var mass1 = Math.exp(0.2); // deterministic, as in the original code
@@ -292,10 +292,10 @@ This page was originally written for desktop Church (Bher/Ikarus) and could not
292292

293293
- Particle properties are records rather than association lists, and angles are computed with `Math.atan2`, which is equivalent to the original's case analysis.
294294
- The original parameterized Gaussians by variance (see its `gaussian-lnpdf`); the port keeps the variance parameterization through a helper.
295-
- The original's `noisy=` soft-equality conditions are folded into a single equivalent `factor`. As in the original's reduced comparison, the condition uses 100 subsampled path points; the original also listed a comparison over the full path.
295+
- The original's `noisy=` soft-equality conditions are folded into a single equivalent `factor`. The browser model conditions on 50 subsampled path points rather than the full path.
296296
- The original's `mh-query` returned `(list mass1 mass2)`, but both masses were the deterministic constant `(exp 0.2)`; the port returns the inferred force law and elasticity instead.
297297
- The original only ran the pass-through scene (its `true-Fl` was the null force); the port also runs the collision scene, which the original's output filenames suggest was the intended experiment.
298-
- MH settings: 500 burn-in iterations plus 200 samples per scene (the original requested 10 samples).
298+
- MH settings: 200 burn-in iterations plus 100 samples per scene (the original requested 10 samples).
299299

300300
The original Church program:
301301

0 commit comments

Comments
 (0)