GithubHelp home page GithubHelp logo

ohai / randomext Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 183 KB

The library extends class Random in the Ruby standard library to efficiently sample random values from various probabilistic distributions

License: BSD 2-Clause "Simplified" License

Shell 0.11% C 69.67% Ruby 30.21%
scientific-computing numerical-analysis

randomext's Introduction

randomext

The library extends class Random in the Ruby standard library.

Overview

The Random class in the Ruby standard library supports only random sampling from discrete/continuous uniform distribution.

This library provides random sampling methods from many kinds of probability distributions such as:

  • normal (Gaussian)
  • lognormal
  • Cauthy
  • levy
  • exponential
  • Laplace
  • Rayleigh
  • Weibull
  • Gumbel
  • gamma
  • beta
  • power
  • Chi-square
  • F
  • t
  • Wald (inverse Gaussian)
  • Pareto
  • logistic
  • von Mises
  • Non-Central Chi-Square
  • Non-Central t
  • Planck
  • Bernoulli
  • binomial
  • Poisson
  • geometric
  • negative binomial
  • log series
  • Zipf-Mandelbrot
  • zeta

Usage

To use this library, you need to install randomext gem:

gem install randomext

And write

require 'randomext'

in your ruby script, then you can use some additional methods in Random class.

Example

Create an sequence of random numbers from the Gaussian distribution whose mean is 0.0 and S.D. is 2.0.

require 'randomext'
rng = Random.new  # rng means Random Number Generator
random_numbers = Array.new(100){ rng.normal(0.0, 2.0) }

References

Almost all algorithms are based on: 四辻哲章, "計算機シミュレーションのための確率分布乱数生成法", プレアデス出版 (2010)

I examine numpy to select nice distributions.

URLs

Author

Ippei Obayashi [email protected]

Copyright

Copyright (c) 2012, Ippei Obayashi All rights reserved.

The software is licensed under the BSD 2-Clause License. Please see the {file:LICENSE} for more information.

randomext's People

Contributors

ohai avatar

Stargazers

 avatar

Watchers

 avatar

randomext's Issues

Example doesn't run

Hi, your example on README doesn't run, at least on my computer:

irb(main):001:0> require 'randomext'
=> true

irb(main):002:0> random_numbers = Array.new(100){ Random::DEFAULT.normal(0.0, 2.0) }
(irb):2:in `block in <main>': undefined method `normal' for Random:Class (NoMethodError)
	from (irb):2:in `initialize'
	from (irb):2:in `new'
	from (irb):2:in `<main>'
	from /usr/lib/ruby/gems/3.0.0/gems/irb-1.3.6/exe/irb:11:in `<top (required)>'
	from /usr/bin/irb:23:in `load'
	from /usr/bin/irb:23:in `<main>'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.