Sha256: 1bdb69c68776f8d61a4324d739f3292a4c3bc8902d94958f9a3507d05018b2fd

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

# MonteCarlo

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

Each experiment conatins:
- `times`: the number of sample to create (defaults to 10,000)
- `sample_method`: the method with which to generate a sample each iteration
- `computation`: an optional coputation method to run on each sample to obtain a result

For example;

```ruby
# Create an experiment with an optional number of times
experiment = MonteCarlo::Experiment.new(100000)

# Set your smaple method
experiment.sample_method = -> { rand }

# Set your optional computation method
experiment.computation = -> (sample) { sample > 0.5 }

# Run your experiment and get your results
results = experiment.run
```

Alternatively, you can write your sample and computation method as one with the shorthand block syntax:

```ruby
results = MonteCarlo::Experiment.run(100000) { rand > 0.5 }
```

The experiment returns a `MonteCarlo::ExperimentResults` object which contains an array of `MonteCarlo::Results` as well as some other handy methods.

Each `MonteCarlo::Result` contains:
- `index`: the index of the sample
- `value`: the final value returned from sampling, after computation
- `sample_value`: the value returned from the sample method, before computation

If no computation method was given, `value` and `sample_value` will be the same.

## 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

1 entries across 1 versions & 1 rubygems

Version Path
monte_carlo-0.0.1 README.md