Alex Gutteridge
4/13/2007 12:36:00 AM
On 13 Apr 2007, at 06:55, Libra wrote:
> Hello,
>
> I would extract some numbers according to a given probability
> distribution (at least, Normal, Exponential, Poisson and Bernoulli).
>
> Do you know if a similar library already exists in Ruby? I only
> found pseudo-random number generator.
>
> TIA
>
> Libra
If you are comfortable with R, you can use RSRuby (http://
web.kuicr.kyoto-u.ac.jp/~alexg/rsruby/) to generate numbers from any
its distribution functions. For example, extracting 10 numbers from a
normal distribution with mean 0:
[alexg@powerbook]/Users/alexg(1): irb -rubygems
irb(main):001:0> require 'rsruby'
=> true
irb(main):002:0> r = RSRuby.instance
=> #<RSRuby:0x1c1510>
irb(main):003:0> r.rnorm(10)
=> [-0.418488870801272, 3.8442920287686, -2.23915973195997,
-1.1852964455658, 0.292187794718865, -0.0538355720349994,
-0.682675725085902, -0.179593328583021, 0.617238096715829,
-0.353627801112474]
The default R stats package has the following distributions built in
and you can use any R library to add more (I couldn't see Bernoulli
in this list, but maybe it has an alternative name?):
Beta(stats) The Beta Distribution
Binomial(stats) The Binomial Distribution
Cauchy(stats) The Cauchy Distribution
Chisquare(stats) The (non-central) Chi-Squared Distribution
Exponential(stats) The Exponential Distribution
FDist(stats) The F Distribution
GammaDist(stats) The Gamma Distribution
Geometric(stats) The Geometric Distribution
Hypergeometric(stats) The Hypergeometric Distribution
Logistic(stats) The Logistic Distribution
Lognormal(stats) The Log Normal Distribution
Multinomial(stats) The Multinomial Distribution
NegBinomial(stats) The Negative Binomial Distribution
Normal(stats) The Normal Distribution
Poisson(stats) The Poisson Distribution
SignRank(stats) Distribution of the Wilcoxon Signed Rank
Statistic
TDist(stats) The Student t Distribution
Tukey(stats) The Studentized Range Distribution
Uniform(stats) The Uniform Distribution
Weibull(stats) The Weibull Distribution
Wilcoxon(stats) Distribution of the Wilcoxon Rank Sum Statistic
ecdf(stats) Empirical Cumulative Distribution Function
survreg.distributions(survival)
Parametric Survival Distributions
Alex Gutteridge
Bioinformatics Center
Kyoto University