Skip to content

Instantly share code, notes, and snippets.

@awostenberg
Created September 3, 2020 16:58
Show Gist options
  • Save awostenberg/f7a4779d366ee028574e5e7ac6f0208a to your computer and use it in GitHub Desktop.
Save awostenberg/f7a4779d366ee028574e5e7ac6f0208a to your computer and use it in GitHub Desktop.
Montecarlo simulation of likely points delivered over five sprint planning horizon given recent velocities
//Montecarlo simulation of likely points delivered this planning increment (5 sprints)
let copperV = [14;13;19;10;15]
let nRuns = 10_000
/// given velocity history and number of sprints in a PI, simulate the PI nRuns times
let sims velocityHistory nRuns nSprints =
let vHistory = velocityHistory |> Seq.toArray;
let rnd = System.Random();
let simPi = [for _ in 1..nRuns ->
[for _ in 1..nSprints -> vHistory.[rnd.Next(0,vHistory.Length-1)]] |> List.reduce (+)]
let histogram = simPi |> Seq.countBy id |> Seq.sort |> Seq.toArray
histogram
/// probability distribution
let pDistribution h =
let nEvents = h |> Seq.sumBy snd
h |> Seq.map (fun (item,count) -> item,( float count / float (nEvents)))
let stars n = String.replicate n "*"
//let histogram = sims copperV nRuns 4
printfn "probability distribution for %d simulated PI runs given historical sprint velocities %A" nRuns copperV
sims copperV nRuns 4 |> pDistribution |>
Seq.iter (fun (item,p) -> printfn "%2d %f | %s" item p (stars (int (p * 400.0))))
/// confidence of delivering at least N points?
let cum histogram nPoints =
let nEvents = histogram |> Seq.sumBy snd
histogram |>
Seq.map (fun (item,count) -> item,( float count / float (nEvents))) |>
Seq.filter (fun (item,count) -> item >= nPoints) |>
Seq.s`\mBy snd
`
/// the confidence of delivering N points for each in item in probability distribution
let cumulativeProbability p =
pDistribution p |> Seq.map (fun (item,_) -> item,cum p item) |> Seq.sortDescending
let runAndReport historicalVelocities nRuns =
let pConfidence = cumulativeProbability (sims historicalVelocities nRuns 4)
printfn "PI delivery confidence for velocities from %d simulated PI runs given historical sprint velocities %A" nRuns historicalVelocities
printfn "Points\tProbability"
pConfidence |> Seq.iter (fun (item,p) -> printfn "%2d\t%f | %s" item p (stars (int (p * 100.0) )))
runAndReport copperV 10_000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment