# Release Schedule 2: Choosing Distributions

Source: https://obsvra.com/learn/simulation-101/simulation-lesson-release-schedule-2

**Uses Only Free-Tier SpiceGrinder**

### Problem statement

The release has four tasks: design, build, test and docs. In the last lesson one triangle described design. We shouldn't reach for the same shape every time: the right distribution depends on where an estimate comes from and on how that kind of work behaves when it goes wrong.

So the questions are: which distribution fits each task, and which task do we have to worry about?

### The model

Four tasks, four reasons:

- **Design** is the designer's three-point guess again: at best 5 days, most likely 8, at worst 15. A `Triangular` takes exactly those three numbers.
- **Build** is work that overruns. It can't take less than no time, and every so often it runs far past the plan. A `Lognormal` has that shape: a floor at zero and a long right tail. It's set by its typical value, a median of 16 days, and a `sigma` of 0.4 for how wild the tail is. (SpiceGrinder takes `mu`, the log of the median: ln 16 = 2.7726.)
- **Test** is another expert guess, so another `Triangular`: 3, 5 and 12 days.
- **Docs** is the one task with a history. We have the durations of the last 20 sprints, so we use them directly: an `Empirical` draws from that list at random. (In Free the 20 values are written into the model; Pro's `FlatFile` can read them from a CSV instead.)

An `Append` puts the four side by side, one column per task, and for now each task is drawn independently. Lesson 4 adds the connections between them.

```xml
<?xml version="1.0" encoding="UTF-8"?>
<dataset columns="design, build, test, docs" seed="102">
	<root node="Tasks"/>
	<nodes>
		<Triangular name="Design" min="5" mode="8" max="15"/>
		<Lognormal name="Build" mu="2.772588722239781" sigma="0.4"/>
		<Triangular name="Test" min="3" mode="5" max="12"/>
		<Empirical name="Docs" values="5 6 6 7 7 7 8 8 9 9 6 5 10 12 7 6 8 14 7 6"/>
		<Append name="Tasks">
			<input name="Design"/>
			<input name="Build"/>
			<input name="Test"/>
			<input name="Docs"/>
		</Append>
	</nodes>
</dataset>
```

Each row is one possible project: the days each of the four tasks takes. Run it a million times (about a second and a half) and look at the first rows (`samples/simulation/task-distributions.xml` in your own install, if you want to reproduce this; leave the seed at 102 and you get exactly these values):

```
grind --count 1000000 task-distributions.xml
```

```
6.399164102651392,34.09118610848373,8.334736067404226,12.0
8.32739827471821,12.550579870009901,4.127337989331635,8.0
13.944809347845812,20.33417405655924,6.212258116115994,7.0
11.99401171511139,17.14139250813068,11.644579051572022,9.0
```

### Which task carries the spread

A task's average tells you when it usually finishes. What it can do to the schedule depends on its spread, how far it wanders from that average:

| Task | Mean (days) | Spread (standard deviation) | Share of the project's variance |
|---|---|---|---|
| Design | 9.3 | 2.1 | 7% |
| Build | 17.3 | 7.2 | 80% |
| Test | 6.7 | 1.9 | 6% |
| Docs | 7.6 | 2.2 | 8% |

The last column squares the spreads (that's the variance) and compares them. For independent tasks the variances simply add up to the project's total uncertainty, so a task with 3.5 times the spread of its neighbors has about 12 times the weight. Build has 3.5 times the spread of the others, and it carries 80% of the project's uncertainty.

![Four histograms of the release tasks, drawn on the same scale, and a bar showing that Build carries 80 percent of the variance](https://obsvra.com/lesson-assets/figures/sim101-02-tasks.svg)

The [companion page](https://obsvra.com/lesson-assets/companions/sim101-02.html) lets you slide Build's `sigma` and watch its shape and its share change while the other three tasks stay exactly the same.

Two details bear noticing. Build's tail is long: the typical run is 16 days, the mean is 17.3, one run in a hundred takes more than 40.6 days, and the longest in a million took 109.5. And Docs only ever produces eight different values (5, 6, 7, 8, 9, 10, 12 and 14), because that is all its history contains. An `Empirical` can't invent a 20-day docs sprint. If you believe one could happen, the history is the limit, not the model.

### Same mean, different tails

Build's long tail raises a bigger question. If two distributions have the same average, how much does the shape of their tails matter? Insurance claims make the point sharply, because a few huge claims sit among many small ones. We'll build two claim models with exactly the same mean of 10,000: a `Lognormal` with `sigma` 1, and a `Pareto` with a shape of 1.5, the classic heavy-tailed choice.

To make the means match exactly, solve for the parameters. A Lognormal's mean is `exp(mu + sigma² / 2)`, so for a mean of 10,000 and sigma 1, `mu = ln(10,000) − 0.5 = 8.7103`. A Pareto's mean is `shape × scale / (shape − 1)`, so `scale = 10,000 × 0.5 / 1.5 = 3,333.33`.

```xml
<Lognormal name="LognormalClaim" mu="8.710340371976184" sigma="1.0"/>
<Pareto name="ParetoClaim" scale="3333.3333333333335" shape="1.5"/>
```

Four million claims each (`samples/simulation/claim-severity.xml`, seed 1002):

| | Lognormal | Pareto |
|---|---|---|
| Mean | 9,994 | 9,963 |
| 99th percentile | 62,050 | 71,771 |
| 99.9th percentile | 132,765 | 332,581 |
| Share of all loss from the biggest 1% of claims | 9.2% | 21.2% |

![The chance that a claim exceeds a given size, for a Lognormal and a Pareto with the same mean of 10,000, on logarithmic axes; the Pareto stays far higher in the tail](https://obsvra.com/lesson-assets/figures/sim101-02-tails.svg)

An average can't tell these two apart. The 99th percentiles differ by 16%, but the 99.9th percentiles differ by a factor of 2.5, and the Pareto's biggest 1% of claims make up more than a fifth of everything paid. One more warning is built into the numbers: a Pareto with a shape of 2 or less has no finite variance, so its sample average (9,963 here, against a true 10,000) settles slowly, and you can't trust a measured average of such data the way you can with the Lognormal's.

Back to the schedule: Build is the task whose tail decides the risk. Choosing a Lognormal for it was a decision about how bad the bad days can get, and it's the decision to revisit if the history says they get worse.

### Check: do the numbers match the math?

Every figure above can be computed exactly:

- Design: (5 + 8 + 15) / 3 = 9.33 for the mean, and a spread of 2.10.
- Build: the mean is 16 × e^(0.4² / 2) = 17.33, the spread is 17.33 × √(e^(0.4²) − 1) = 7.22, and the 99th percentile 40.6 is 16 × e^(2.326 × 0.4).
- Test: (3 + 5 + 12) / 3 = 6.67, spread 1.93.
- Docs: the mean and spread of the 20 listed values, 7.65 and 2.22.
- Claims: the Lognormal's 99th and 99.9th percentiles are `exp(mu + z × sigma)`, 62,112 and 133,329, with 9.2% of the loss in the top 1%. The Pareto's are `scale × 100^(1/shape)` and `scale × 1000^(1/shape)`, 71,814 and 333,333, with `0.01^(1/3)` = 21.5% of the loss in the top 1%.

Our million runs gave 9.33, 17.33, 6.67 and 7.65, spreads of 2.10, 7.22, 1.93 and 2.22, and a Build 99th percentile of 40.6. The claim percentiles land within 0.5% of theory, and the top-1% shares within 0.3 points; the Pareto's 99.9th percentile is the hardest number to pin down, because the heavy tail makes it noisy.

**What this gives you:** a distribution chosen for a reason rather than by habit, a way to see which task actually drives the uncertainty (compare the variances), and a reminder that two models with the same average can carry very different risk in their tails.

One more thing the four tasks need before they are a project: how they connect. Design comes first, Build and Test run in sequence, and Docs runs alongside them. The next lesson turns the four columns into a finish day and asks how likely a given deadline is to be missed.
