Module: Simulation
- Included in:
- Monte::Commands::Carlo
- Defined in:
- lib/monte/simulation.rb
Overview
The code to run n monte carlo simulations args is a hash that must contain the following: :backlog :split_factor :runs :low :high
Constant Summary collapse
- PERCENTILES =
[0.05, 0.15, 0.3, 0.5, 0.7, 0.85, 0.95].freeze
Instance Method Summary collapse
- #percentiles(options) ⇒ Object
- #run_simulations(options) ⇒ Object
- #simulate(backlog, throughput, result = 0) ⇒ Object
Instance Method Details
#percentiles(options) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/monte/simulation.rb', line 13 def percentiles() results = run_simulations().sort PERCENTILES.map do |percentile| index = [:runs] * (percentile - 1) results[index] end end |
#run_simulations(options) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/monte/simulation.rb', line 21 def run_simulations() estimated_backlog = [:backlog] * [:split] Array.new([:runs]) do |_| [:start] + simulate( estimated_backlog, [:throughput] ) * 7 end end |
#simulate(backlog, throughput, result = 0) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/monte/simulation.rb', line 31 def simulate(backlog, throughput, result = 0) return result if backlog <= 0 simulate( backlog - throughput.sample, throughput, result + 1 ) end |