Algorithmcore
Morris method
Also called elementary effects method.
Screens many inputs cheaply by averaging one-at-a-time differences along random trajectories, ranking inputs by their mean and spread.
- Time
- O(r d F + r d^2) worst
- Space
- O(r d) extra
- Where
- F = the cost of one model run; d = the number of inputs; r = the number of trajectories
- Model
- Real RAM
- Properties
- randomizednot exactnot iterativerandomized
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Max D. Morris, Francesca Campolongo, Jessica Cariboni, Andrea Saltelli, 1991
The Morris method screens a model with many inputs for the few that matter, at a cost that grows only linearly with the number of inputs. It moves through the input space along random trajectories, changing one input at a time by a fixed step, and records the change of the output divided by the step: an elementary effect, a coarse finite difference. Each trajectory gives one elementary effect of each input with runs. Over trajectories, the mean of the absolute effects ranks the inputs by overall influence, and their standard deviation shows nonlinearity or interactions. The method gives a ranking, not a share of the variance like the Sobol indices, and it is usually run first, to decide which inputs deserve a costly variance-based study.
In plain words
Your model has fifty knobs, and each run takes an hour. You want to know which knobs are worth a closer look.
Start at a random setting. Turn one knob by a fixed amount and see how much the output moves. Then turn a second knob from there, then a third, until each knob has moved once. That walk costs one run per knob, plus one. Repeat the walk from a few random starting points. A knob whose turns always move the output a lot is important. A knob whose effect changes much from walk to walk has a curved effect or works together with other knobs. A knob that never moves the output can be left fixed.
The problem
The input is a model with inputs, each scaled to , and a budget of model runs. The output is, for each input , three screening measures of its elementary effects
where is the unit vector of input . The inputs take values on a grid of levels with even, and the step is , half the grid plus half a cell. The measures are the mean , the mean of the absolute values and the standard deviation of over the grid points where both and are on the grid. An input with large is important; a large means that its effect depends on where it is measured.
The algorithm
MORRIS(f, d, r, p)- 1
for t = 1..r do ▷ one trajectory per pass - 2
x*_k ← uniform on {0, 1/(p-1), ..., 1 - Δ} for k = 1..d, Δ = p / (2(p - 1)) - 3
u_k ← up or down with probability 1/2 for k = 1..d; start x_k ← x*_k if up, x*_k + Δ if down - 4
π ← a uniformly random order of 1..d - 5
for each input k in the order π: x_k ← x_k + Δ if up, x_k - Δ if down; record the point - 6
y_0..y_d ← f at the d + 1 points of the trajectory - 7
for the j-th move, of input k = π_j: EE_k ← (y_j - y_(j-1)) / (signed step of input k) - 8
μ_i, μ*_i, σ_i ← mean, mean of absolute values and standard deviation of the r effects of input i - 9
return μ, μ*, σ and the run count r(d + 1)
Lines L2 to L5 build one trajectory: a start point and moves, each of one input, by , so that consecutive points differ in exactly one input. The base values of line L2 keep every point on the grid. Line L6 is the only step that runs the model. In line L7, the move of input changes only , so the difference of the two outputs, divided by the signed step, is an elementary effect of input at a grid point. Line L8 uses the divisor for .
Example
By hand. Let with , so the grid is and . The exact effects are and , so over the grid and . One trajectory with , both directions up and the order :
| point | move | effect | |||
|---|---|---|---|---|---|
| 0 | 0 | 1/3 | 0 | start | |
| 1 | 2/3 | 1/3 | 8/9 | by | |
| 2 | 2/3 | 1 | 4/3 | by |
Three runs give one effect of each input. at , and at . Different trajectories meet different values of and , so and are positive: each effect depends on the other input, which is the interaction .
The Ishigami function. With on , scaled to the unit cube, and , the grid measures over all 32 grid pairs of each input are:
| input | spread of | ||||
|---|---|---|---|---|---|
| 7.7041 | 7.7041 | 6.2488 | 0.3139 | 0.5576 | |
| 0 | 7.875 | 7.875 | 0.4424 | 0.4424 | |
| 0 | 6.2488 | 8.8371 | 0 | 0.2437 |
A run with trajectories (40 runs) and random.Random(1991) gives , a measurement. The method finds that all three inputs matter, and with and a large spread acts through an interaction or a sign change, which is right. But ranks above , while the total indices rank first: is a screening measure, not a variance share.
Correctness
The claim is that each elementary effect of input in line L7 is a uniform random draw from the list of all grid differences of input , so that and are unbiased for the grid means and , is unbiased for the grid variance, and all three converge as . The key step is the point before the move of input : its other inputs have either moved or not, depending on the random order, but in both cases a fair coin decides whether they sit at or , which makes each of them uniform on the whole grid. This uses that is even, so that is a whole number of grid cells. The full proof is in the proof file. There is no theorem that orders the inputs like the total Sobol indices; that is an empirical finding of Campolongo, Cariboni and Saltelli.
Proof: Each Morris elementary effect is a uniform draw from the grid differences, so mu and mu* are unbiasedfull
We assume exact arithmetic and exact random numbers. The inputs are scaled to the unit cube. The grid has levels with even, and the step is , which is grid cells. Let , the levels with . For input , the grid differences are the numbers
There are of them. The method estimates the grid means and , and the spread of the . These are the screening measures of Morris (for and ) and of Campolongo, Cariboni and Saltelli (for ).
One trajectory draws, independently, base values uniform on (line L2), fair coins for the direction up or down (line L3) and a uniform random order of the inputs (line L4). The start point has the components if is up and if not. Line L5 moves the inputs in the order , each once, by if is up and by if not.
Lemma 1 (the trajectory stays on the grid). Every point of the trajectory is in , consecutive points differ in one component by , and each component moves exactly once.
Proof. Component takes only the two values and , which are in because . It starts at one of them and moves once, to the other one.
Lemma 2 (one elementary effect is a grid difference). The elementary effect of input in line L7 is , where is the point before the move of with its component set to .
Proof. If is up, the move goes from to , and the effect is . If not, the move goes from to , and the effect is .
Lemma 3 (the lower point is uniform). The point of Lemma 2 is uniform on the set (with in component ).
Proof. Condition on the order . Component of is , uniform on . For , let if moves before and if not; given , is fixed. Component of is if exactly one of " is down" and "" holds, and if not. So it is , where is the coin flipped when . A flipped fair coin is a fair coin, so the are independent fair coins, independent of the . Now is uniform on and , so is uniform on . The components are independent, so is uniform on the product set. This holds for every , so it holds without the condition.
Theorem (unbiased screening measures). With independent trajectories, the outputs of line L8 satisfy and , and (with the divisor ) is unbiased for the variance of the over the grid. As , all three converge almost surely.
Proof. By Lemmas 2 and 3, the effect of input on one trajectory is with uniform on its set, so it is a uniform draw from the list of grid differences. The trajectories are independent, so the effects of input are independent draws. The sample mean, the mean of the absolute values and the sample variance of independent draws are unbiased for the mean, the mean absolute value and the variance of the list. The list is finite, so the strong law of large numbers applies.
The effects of different inputs on one trajectory are dependent, because they share points. The theorem is about each input alone. The run count is : one start point and one point per move.
Corollary (a linear model). If , then for every , so , and for every .
Corollary (an input that the model ignores). If does not depend on , every effect of input is zero, so exactly.
What is not proved. The measures are defined by the grid and the step ; they are not the Sobol indices, and there is no theorem that orders the inputs in the same way. The theorem says that the estimates converge to the grid measures; how many trajectories are enough for a stable ranking is a rule of thumb, not a result. For odd , the step is grid cells, which is not a whole number, so the moves leave the grid and Lemma 3 fails; the code rejects odd .
Complexity
Each trajectory makes runs, so the method makes runs, time for a run cost . Recording the points of length costs per trajectory in the real RAM model, or if each point is stored as one change from the last. The effects take space; line L8 is . A variance-based study with the Saltelli sampling scheme needs runs with usually in the hundreds or more, while is usually between 10 and 50, so screening is cheaper by a factor of about .
Properties
- Linear cost in d. One trajectory gives one effect of every input with runs.
- Global, not local. The step is about half the range, and the start points cover the grid, so the effects sample the whole input space, unlike a derivative at one nominal point.
- Exact for linear models. If is linear, every effect of input is its coefficient, and .
- Qualitative. The measures rank the inputs and flag nonlinearity or interaction; they do not split the variance and have no standard error in the original method.
- Robust to sign changes with mu.* Effects of opposite signs cancel in but not in .
Variants and improvements
- Mu star. Campolongo, Cariboni and Saltelli (2007) use instead of , because can be near zero for an important input whose effect changes sign, as and of the Ishigami example show.
- Spread-out trajectories. Generate many candidate trajectories and keep the with the largest distances between them, for a better coverage of the input space at the same cost.
- Radial designs. Move each input from one common base point to a second random point, one input at a time; this shares the base run and is the screening analogue of the column swap in the Saltelli scheme.
- Groups of inputs. For very many inputs, move groups together, and screen the inputs of an important group in a second round.
- Small steps. As , the effects become derivatives, and the mean of their squares is a derivative-based global sensitivity measure, which bounds the total Sobol index for some input laws.
When to use it
Use the Morris method when the model has many inputs, from tens to hundreds, runs are expensive, and the first question is which inputs can be fixed. Follow it with the Saltelli sampling scheme or the Fourier amplitude sensitivity test on the inputs that pass, if quantitative indices are needed. Use active subspaces when gradients are available and important directions may be combinations of inputs rather than single inputs. A local finite difference at one nominal point costs the same runs but says nothing about the rest of the input space.
Pitfalls
- An odd number of levels. With odd, is not a whole number of cells, and line L5 leaves the grid; with the base values of line L2 the effects are no longer uniform on the grid. Use even, often .
- Ranking by mu. Using only in line L8 hides inputs whose effects change sign: for the Ishigami function although carries 44 percent of the variance. Rank by and look at .
- Reading mu star as a variance share. ranks above for the Ishigami function, although . Use the ranking to discard inputs, not to compare close ones.
- A fixed number of trajectories as a guarantee. between 10 and 50 is a rule of thumb. Check that the ranking is stable when grows; with in the example, against the grid value 7.7.
- Unscaled inputs. The effects in line L7 are per unit of the scaled input. If the inputs are not mapped to through their ranges or quantiles, inputs with large units get small effects.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/morris-method/. The authors are listed in prov/2Q63VY.jsonl.
"""The Morris method of elementary effects (Morris 1991), with mu* of Campolongo, Cariboni and Saltelli 2007.
The inputs are scaled to the unit cube [0, 1]^d and take values on a grid of
p levels {0, 1/(p-1), ..., 1}, with p even. The step is Delta = p / (2 (p - 1)).
One trajectory has d + 1 points. It starts at a random grid point, and each
next point moves one coordinate by +Delta or -Delta, each coordinate once, in
a random order. The elementary effect of input i on the trajectory is
EE_i = (f(x after the move of i) - f(x before)) / (signed step of i).
With r trajectories, the method returns for each input the mean mu, the mean
of the absolute values mu*, and the standard deviation sigma of its r
elementary effects, at r (d + 1) model runs. These are screening measures,
not estimates with an error bound.
"""
import math
import random
from typing import Callable, Sequence
Model = Callable[[Sequence[float]], float]
def trajectory(d: int, p: int, rng: random.Random) -> tuple[list[list[float]], list[int]]:
"""One Morris trajectory: the d + 1 points and the order in which the coordinates move."""
if p % 2 or p < 2:
raise ValueError("p must be even and at least 2")
delta = p / (2 * (p - 1))
# base values x*_i in {0, 1/(p-1), ..., 1 - Delta}, so that x*_i + Delta is on the grid
base = [rng.randrange(p // 2) / (p - 1) for _ in range(d)] # @line L2
up = [rng.random() < 0.5 for _ in range(d)] # @line L3
x = [base[i] if up[i] else base[i] + delta for i in range(d)]
order = list(range(d))
rng.shuffle(order) # @line L4
points = [list(x)]
for i in order: # @line L5
x[i] = x[i] + delta if up[i] else x[i] - delta
points.append(list(x))
return points, order
def morris(f: Model, d: int, r: int, p: int, rng: random.Random) -> dict:
"""mu, mu* and sigma of the elementary effects of each input from r trajectories."""
effects: list[list[float]] = [[] for _ in range(d)]
runs = 0
for _ in range(r): # @line L1
points, order = trajectory(d, p, rng)
y = [f(pt) for pt in points] # @line L6
runs += len(points)
for k, i in enumerate(order): # @line L7
step = points[k + 1][i] - points[k][i]
effects[i].append((y[k + 1] - y[k]) / step)
mu = [sum(e) / r for e in effects] # @line L8
mu_star = [sum(abs(v) for v in e) / r for e in effects]
sigma = [math.sqrt(sum((v - m) ** 2 for v in e) / (r - 1)) if r > 1 else 0.0 for e, m in zip(effects, mu)]
return {"mu": mu, "mu_star": mu_star, "sigma": sigma, "effects": effects, "runs": runs} # @line L9
def grid_effects(f: Model, d: int, p: int, i: int) -> list[float]:
"""All elementary effects of input i over the full grid: pairs x, x + Delta e_i with both on the grid.
For p even, each elementary effect of a random trajectory is a uniform draw from this list.
"""
delta = p / (2 * (p - 1))
levels = [k / (p - 1) for k in range(p)]
low = [v for v in levels if v + delta <= 1 + 1e-12]
out = []
idx = [0] * d
sizes = [len(low) if k == i else p for k in range(d)]
while True:
x = [low[idx[k]] if k == i else levels[idx[k]] for k in range(d)]
xp = list(x)
xp[i] += delta
out.append((f(xp) - f(x)) / delta)
k = 0
while k < d:
idx[k] += 1
if idx[k] < sizes[k]:
break
idx[k] = 0
k += 1
if k == d:
return out
test_morris_method.py 68 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/morris-method/. The authors are listed in prov/2Q63VY.jsonl.
import math
import random
import pytest
from morris_method import grid_effects, morris, trajectory
def ishigami_unit(u):
x = [-math.pi + 2 * math.pi * v for v in u]
return math.sin(x[0]) + 7 * math.sin(x[1]) ** 2 + 0.1 * x[2] ** 4 * math.sin(x[0])
def test_trajectory_moves_each_coordinate_once_on_the_grid():
rng = random.Random(4)
p, d = 6, 5
delta = p / (2 * (p - 1))
for _ in range(50):
points, order = trajectory(d, p, rng)
assert len(points) == d + 1 and sorted(order) == list(range(d))
for k, i in enumerate(order):
diff = [b - a for a, b in zip(points[k], points[k + 1])]
assert all(abs(diff[j]) < 1e-12 for j in range(d) if j != i)
assert abs(abs(diff[i]) - delta) < 1e-12
for pt in points:
for v in pt:
assert -1e-12 <= v <= 1 + 1e-12
assert abs(v * (p - 1) - round(v * (p - 1))) < 1e-9
def test_hand_example():
# f = x1 + x1 x2 with p = 4: EE_1 = 1 + x2 and EE_2 = x1
f = lambda x: x[0] + x[0] * x[1] # noqa: E731
e1 = grid_effects(f, 2, 4, 0)
e2 = grid_effects(f, 2, 4, 1)
assert abs(sum(e1) / len(e1) - 1.5) < 1e-12
assert abs(sum(e2) / len(e2) - 0.5) < 1e-12
def test_linear_model_gives_the_coefficients_with_zero_spread():
c = [2.0, -1.0, 0.5, 0.0]
f = lambda x: sum(ci * xi for ci, xi in zip(c, x)) # noqa: E731
res = morris(f, 4, 12, 4, random.Random(7))
assert res["runs"] == 12 * 5
for i in range(4):
assert abs(res["mu"][i] - c[i]) < 1e-12
assert abs(res["mu_star"][i] - abs(c[i])) < 1e-12
assert res["sigma"][i] < 1e-12
def test_mu_star_matches_the_grid_enumeration():
# each elementary effect of a random trajectory is a uniform draw from the grid list
rng = random.Random(1991)
r = 1500
res = morris(ishigami_unit, 3, r, 4, rng)
for i in range(3):
grid = [abs(v) for v in grid_effects(ishigami_unit, 3, 4, i)]
exact = sum(grid) / len(grid)
spread = math.sqrt(sum((v - exact) ** 2 for v in grid) / len(grid))
assert abs(res["mu_star"][i] - exact) < 4 * spread / math.sqrt(r) + 1e-12
assert abs(sum(abs(v) for v in grid_effects(ishigami_unit, 3, 4, 1)) / 32 - 7.875) < 1e-12
def test_odd_number_of_levels_is_rejected():
with pytest.raises(ValueError):
trajectory(3, 5, random.Random(0))
History
Morris proposed the method in 1991 in Technometrics, as factorial sampling plans for preliminary computational experiments, with random one-at-a-time trajectories on a grid and the measures and . Campolongo, Cariboni and Saltelli introduced and the choice of trajectories with a large spread in 2007, and found that is a good proxy of the total Sobol index in their tests. The method is the standard screening tool in the sensitivity analysis primer of Saltelli and coauthors (2008).
References
- Max D. Morris, Factorial sampling plans for preliminary computational experiments, Technometrics 33(2), 1991, 161-174, the elementary effects, the grid of p levels with the step p/(2(p - 1)), the random trajectories and the measures mu and sigma
- Francesca Campolongo, Jessica Cariboni and Andrea Saltelli, An effective screening design for sensitivity analysis of large models, Environmental Modelling and Software 22(10), 2007, 1509-1518, the measure mu*, its use as a proxy of the total index, and the choice of trajectories with a large spread
- Andrea Saltelli, Marco Ratto, Terry Andres, Francesca Campolongo, Jessica Cariboni, Debora Gatelli, Michaela Saisana and Stefano Tarantola, Global Sensitivity Analysis, The Primer, Wiley, 2008, Chapter 3 (the elementary effects method)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 2Q63VY Edit this page History Report an error Markdown