Sha256: ccb4719105ad2c221dfcbb7c26305276023bb3254eac1d3d11be4dc8c325f2d5

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

# MonteCarlo [![Build Status](https://travis-ci.org/agelber/monte_carlo.svg)](https://travis-ci.org/agelber/monte_carlo)

A utility to write quick [Monte Carlo Method](http://en.wikipedia.org/wiki/Monte_Carlo_method) experiments.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'monte_carlo'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install monte_carlo

## Usage

Every `MonteCarlo::Experiment` must have a sample method to generate random samples. The samples generated when the experiment is run will be collected into a `MonteCarlo::ExperimentResults` object after an optional computation method to turn the random sample into a meaningful value.

For example, the sample method may draw a random number between 1 and 10 and the computation method will test whether the number is greater than 5, returning `true` or `false` results.

```ruby
# Create an instance and configure it with the DSL
experiment = MonteCarlo::Experiment.new do
  times 1000000
  sample_method { rand(10) }
  computation { |sample| sample >= 5 }
end

results = experiment.run

results.probability_distribution
# => {true=>0.499443, false=>0.500557}
```

Or run it with the shorthand class method syntax:

```ruby
# Use one method for both sample and computation and run immediately
results = MonteCarlo::Experiment.run(1000000) do
  sample = rand(10)
  sample >= 5
end
``` 

## Docs

[Can be found here](http://www.rubydoc.info/gems/monte_carlo)

## Contributing

1. Fork it ( https://github.com/agelber/monte_carlo/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
monte_carlo-0.0.8 README.md
monte_carlo-0.0.7 README.md