distribution 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.travis.yml +12 -0
- data/Gemfile +5 -0
- data/LICENCE.md +26 -0
- data/Manifest.txt +5 -1
- data/{README.txt → README.md} +75 -70
- data/Rakefile +11 -9
- data/bin/distribution +1 -1
- data/distribution.gemspec +20 -0
- data/lib/distribution.rb +2 -2
- data/lib/distribution/beta/ruby.rb +34 -0
- data/lib/distribution/exponential/ruby.rb +5 -4
- data/lib/distribution/normal/ruby.rb +3 -3
- data/lib/distribution/t/ruby.rb +2 -2
- data/lib/distribution/version.rb +3 -0
- data/lib/distribution/weibull.rb +11 -0
- data/lib/distribution/weibull/gsl.rb +21 -0
- data/lib/distribution/weibull/ruby.rb +27 -0
- data/spec/distribution_spec.rb +1 -1
- data/spec/exponential_spec.rb +15 -1
- data/spec/weibull_spec.rb +18 -0
- metadata +59 -135
- data.tar.gz.sig +0 -3
- data/.autotest +0 -23
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 10da9cb77a0a56fd768b3b512e3c80c64b7a865d
|
4
|
+
data.tar.gz: 86646fd4edf1880ed627b50e37f035dabf960317
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 46f20bc037e47b6a1eea5f90a081c72d2b280912d36df4275d1f0b60163653f791a7f61fdbba95b2734d6dc36fe678103f85c10e2cc35ecb4620b911e6ec5858
|
7
|
+
data.tar.gz: a169f7a086666cbc8fb609d025d0aa20dd8c9a8cca70313d9b8555479e7a78beceab3889afa52391978b91a78cf92bf864e92cc3740168d4ee582cf139b46245
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- "1.8.7"
|
4
|
+
- "1.9.2"
|
5
|
+
- "1.9.3"
|
6
|
+
- jruby-18mode # JRuby in 1.8 mode
|
7
|
+
- jruby-19mode # JRuby in 1.9 mode
|
8
|
+
- rbx-18mode
|
9
|
+
- rbx-19mode
|
10
|
+
# uncomment this line if your project needs to run something other than `rake`:
|
11
|
+
# script: bundle exec rspec spec
|
12
|
+
|
data/Gemfile
ADDED
data/LICENCE.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
## LICENSE:
|
2
|
+
|
3
|
+
Copyright (c) 2011-2012, Claudio Bustos
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
8
|
+
* Redistributions of source code must retain the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
10
|
+
* Redistributions in binary form must reproduce the above copyright
|
11
|
+
notice, this list of conditions and the following disclaimer in the
|
12
|
+
documentation and/or other materials provided with the distribution.
|
13
|
+
* Neither the name of the copyright holder nor the
|
14
|
+
names of its contributors may be used to endorse or promote products
|
15
|
+
derived from this software without specific prior written permission.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
18
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20
|
+
DISCLAIMED. IN NO EVENT SHALL Claudio Bustos BE LIABLE FOR ANY
|
21
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
22
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
23
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
24
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/Manifest.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
Gemfile
|
2
2
|
History.txt
|
3
3
|
Manifest.txt
|
4
4
|
README.txt
|
@@ -80,6 +80,9 @@ lib/distribution/t/gsl.rb
|
|
80
80
|
lib/distribution/t/java.rb
|
81
81
|
lib/distribution/t/ruby.rb
|
82
82
|
lib/distribution/t/statistics2.rb
|
83
|
+
lib/distribution/weibull.rb
|
84
|
+
lib/distribution/weibull/gsl.rb
|
85
|
+
lib/distribution/weibull/ruby.rb
|
83
86
|
spec/beta_spec.rb
|
84
87
|
spec/binomial_spec.rb
|
85
88
|
spec/bivariatenormal_spec.rb
|
@@ -98,4 +101,5 @@ spec/shorthand_spec.rb
|
|
98
101
|
spec/spec.opts
|
99
102
|
spec/spec_helper.rb
|
100
103
|
spec/t_spec.rb
|
104
|
+
spec/weibull_spec.rb
|
101
105
|
vendor/java/commons-math-2.2.jar
|
data/{README.txt → README.md}
RENAMED
@@ -1,100 +1,105 @@
|
|
1
|
-
|
1
|
+
# [Distribution](https://github.com/clbustos/distribution) Quick Start
|
2
2
|
|
3
|
-
|
3
|
+
```
|
4
|
+
git clone https://github.com/sciruby/distribution
|
5
|
+
```
|
4
6
|
|
5
|
-
|
7
|
+
## Description:
|
6
8
|
|
7
9
|
Statistical Distributions library. Includes Normal univariate and bivariate, T, F, Chi Square, Binomial, Hypergeometric, Exponential, Poisson, Beta, LogNormal and Gamma.
|
8
10
|
|
9
11
|
Uses Ruby by default and C (statistics2/GSL) or Java extensions where available.
|
10
12
|
|
11
|
-
Includes code from statistics2 on Normal, T, F and Chi Square ruby code [http://blade.nagaokaut.ac.jp/~sinara/ruby/math/statistics2]
|
13
|
+
Includes code from statistics2 on Normal, T, F and Chi Square ruby code [http://blade.nagaokaut.ac.jp/~sinara/ruby/math/statistics2]
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
* Very fast ruby 1.8.7/1.9.+ implementation, with improved method to calculate factorials and others common functions
|
16
|
-
* All methods tested on several ranges. See spec/
|
17
|
-
* On Jruby and Rubinius, BivariateNormal returns incorrect pdf
|
18
|
-
|
19
|
-
== API structure
|
20
|
-
|
21
|
-
Distribution::<name>.(cdf|pdf|p_value|rng)
|
22
|
-
|
23
|
-
On discrete distributions, exact Ruby implementations of pdf, cdf and p_value could be provided, using
|
24
|
-
|
25
|
-
Distribution::<name>.exact_(cdf|pdf|p_value)
|
26
|
-
|
27
|
-
module Distribution::Shorthand provides (you guess?) shortands method to call all methods
|
28
|
-
|
29
|
-
<Distribution shortname>_(cdf|pdf|p|r)
|
30
|
-
|
31
|
-
On discrete distributions, exact cdf, pdf and p_value are
|
32
|
-
|
33
|
-
<Distribution shortname>_(ecdf|epdf|ep)
|
34
|
-
|
35
|
-
Shortnames for distributions:
|
36
|
-
|
37
|
-
* Normal: norm
|
38
|
-
* Bivariate Normal: bnor
|
39
|
-
* T: tdist
|
40
|
-
* F: fdist
|
41
|
-
* Chi Square: chisq
|
42
|
-
* Binomial: bino
|
43
|
-
* Hypergeometric: hypg
|
44
|
-
* Exponential: expo
|
45
|
-
* Poisson: pois
|
46
|
-
* Beta: beta
|
47
|
-
* Gamma: gamma
|
48
|
-
* LogNormal: lognormal
|
49
|
-
|
50
|
-
For example
|
51
|
-
|
52
|
-
Distribution::T.cdf
|
53
|
-
|
54
|
-
could be called after including Distribution::Shorthand
|
55
|
-
|
56
|
-
tdist_cdf
|
57
|
-
|
58
|
-
|
59
|
-
== SYNOPSIS:
|
60
|
-
# Returns Gaussian PDF for x
|
15
|
+
## Synopsis:
|
16
|
+
* Returns Gaussian PDF for x
|
61
17
|
pdf=Distribution::Normal.pdf(x)
|
62
|
-
|
18
|
+
* Returns Gaussian CDF for x
|
63
19
|
cdf=Distribution::Normal.cdf(x)
|
64
|
-
|
65
|
-
pv
|
66
|
-
|
67
|
-
|
20
|
+
* Returns inverse CDF (or p-value) for x
|
21
|
+
pv=Distribution::Normal.p_value(x)
|
22
|
+
|
23
|
+
## System Requirements:
|
68
24
|
|
69
|
-
|
25
|
+
To increase (notably!) the speed, please install
|
70
26
|
|
71
27
|
* Ruby 1.8-1.9: gsl (prefered) or statistics2
|
72
28
|
* Java: Not yet implemented
|
73
29
|
|
74
|
-
|
75
|
-
|
30
|
+
## User Installation:
|
31
|
+
```
|
76
32
|
gem install distribution
|
77
|
-
|
33
|
+
```
|
78
34
|
To speep up
|
79
|
-
|
35
|
+
```
|
80
36
|
gem install gsl
|
81
37
|
gem install statistics
|
82
|
-
|
83
|
-
== DEVELOPERS:
|
38
|
+
```
|
84
39
|
|
85
|
-
|
40
|
+
## Developers:
|
86
41
|
|
42
|
+
After checking out the source, run:
|
43
|
+
```
|
87
44
|
$ rake newb
|
88
|
-
|
45
|
+
```
|
89
46
|
This task will install any missing dependencies, run the tests/specs,
|
90
47
|
and generate the RDoc.
|
91
48
|
|
92
49
|
If you want to provide a new distribution, /lib/distribution run
|
93
|
-
|
50
|
+
```
|
94
51
|
$ distribution --new your_distribution
|
95
|
-
|
52
|
+
```
|
96
53
|
This should create the main distribution file, the directory with ruby and gsl engines and the rspec on /spec directory.
|
97
54
|
|
98
|
-
|
55
|
+
### API Structure
|
56
|
+
|
57
|
+
Distribution::<name>.(cdf|pdf|p_value|rng)
|
58
|
+
|
59
|
+
On discrete distributions, exact Ruby implementations of pdf, cdf and p_value could be provided, using
|
60
|
+
```
|
61
|
+
Distribution::<name>.exact_(cdf|pdf|p_value)
|
62
|
+
```
|
63
|
+
module Distribution::Shorthand provides (you guess?) shortands method to call all methods
|
64
|
+
```
|
65
|
+
<Distribution shortname>_(cdf|pdf|p|r)
|
66
|
+
```
|
67
|
+
On discrete distributions, exact cdf, pdf and p_value are
|
68
|
+
```
|
69
|
+
<Distribution shortname>_(ecdf|epdf|ep)
|
70
|
+
```
|
71
|
+
Shortnames for distributions:
|
72
|
+
|
73
|
+
* Normal: norm
|
74
|
+
* Bivariate Normal: bnor
|
75
|
+
* T: tdist
|
76
|
+
* F: fdist
|
77
|
+
* Chi Square: chisq
|
78
|
+
* Binomial: bino
|
79
|
+
* Hypergeometric: hypg
|
80
|
+
* Exponential: expo
|
81
|
+
* Poisson: pois
|
82
|
+
* Beta: beta
|
83
|
+
* Gamma: gamma
|
84
|
+
* LogNormal: lognormal
|
85
|
+
|
86
|
+
### API Structure Example
|
87
|
+
|
88
|
+
```
|
89
|
+
Distribution::T.cdf
|
90
|
+
```
|
91
|
+
could be called after including Distribution::Shorthand
|
92
|
+
```
|
93
|
+
tdist_cdf
|
94
|
+
```
|
95
|
+
|
96
|
+
## Features
|
97
|
+
|
98
|
+
* Very fast ruby 1.8.7/1.9.+ implementation, with improved method to calculate factorials and others common functions
|
99
|
+
* All methods tested on several ranges. See spec/
|
100
|
+
|
101
|
+
## Issues
|
102
|
+
|
103
|
+
* On Jruby and Rubinius, BivariateNormal returns incorrect pdf
|
99
104
|
|
100
|
-
|
105
|
+
For current issues see the [issue tracker pages](https://github.com/clbustos/distribution/issues)
|
data/Rakefile
CHANGED
@@ -1,26 +1,28 @@
|
|
1
1
|
# -*- ruby -*-
|
2
2
|
$:.unshift(File.expand_path(File.dirname(__FILE__)+"/lib/"))
|
3
3
|
require 'rubygems'
|
4
|
-
require 'hoe'
|
4
|
+
#require 'hoe'
|
5
5
|
require 'distribution'
|
6
|
-
require 'rubyforge'
|
7
6
|
# Hoe.plugin :compiler
|
8
7
|
# Hoe.plugin :gem_prelude_sucks
|
9
|
-
Hoe.plugin :git
|
8
|
+
# Hoe.plugin :git
|
10
9
|
# Hoe.plugin :inline
|
11
10
|
# Hoe.plugin :racc
|
12
|
-
Hoe.plugin :rubyforge
|
11
|
+
# Hoe.plugin :rubyforge
|
13
12
|
|
14
|
-
Hoe.spec 'distribution' do
|
15
|
-
self.developer('Claudio Bustos', 'clbustos_at_gmail.com')
|
16
|
-
self.version=Distribution::VERSION
|
17
|
-
self.extra_dev_deps << ["rspec",">=2.0"] << ["rubyforge",">=0"]
|
13
|
+
#Hoe.spec 'distribution' do
|
14
|
+
# self.developer('Claudio Bustos', 'clbustos_at_gmail.com')
|
15
|
+
# self.version=Distribution::VERSION
|
16
|
+
# self.extra_dev_deps << ["rspec",">=2.0"] << ["rubyforge",">=0"]
|
18
17
|
|
19
|
-
end
|
18
|
+
#end
|
20
19
|
# git log --pretty=format:"*%s[%cn]" v0.5.0..HEAD >> History.txt
|
21
20
|
desc "Open an irb session preloaded with distribution"
|
22
21
|
task :console do
|
23
22
|
sh "irb -rubygems -I lib -r distribution.rb"
|
24
23
|
end
|
25
24
|
|
25
|
+
require 'bundler'
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
26
28
|
# vim: syntax=ruby
|
data/bin/distribution
CHANGED
@@ -36,7 +36,7 @@ ARGV.each do |distribution|
|
|
36
36
|
basename=distribution.downcase
|
37
37
|
raise "You should be inside distribution lib directory" unless File.exists? "../distribution.rb"
|
38
38
|
raise "Distribution already created" if File.exists? basename+".rb"
|
39
|
-
main=ERB.new(File.read(gem_base+"/data/template/distribution.erb")
|
39
|
+
main=ERB.new(File.read(gem_base+"/data/template/distribution.erb"))
|
40
40
|
ruby=ERB.new(File.read(gem_base+"/data/template/distribution/ruby.erb"))
|
41
41
|
gsl=ERB.new(File.read(gem_base+"/data/template/distribution/gsl.erb"))
|
42
42
|
spec=ERB.new(File.read(gem_base+"/data/template/spec.erb"))
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/distribution/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "distribution"
|
6
|
+
s.version = Distribution::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ['Claudio Bustos']
|
9
|
+
s.email = []
|
10
|
+
s.homepage = "http://rubygems.org/gems/foodie"
|
11
|
+
s.summary = "Distribution"
|
12
|
+
s.description = "Distribution"
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
16
|
+
s.add_development_dependency "rspec"
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
19
|
+
s.require_path = 'lib'
|
20
|
+
end
|
data/lib/distribution.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# = distribution.rb -
|
2
2
|
# Distribution - Statistical Distributions package for Ruby
|
3
3
|
#
|
4
|
-
# Copyright (C) 2011 Claudio Bustos
|
4
|
+
# Copyright (C) 2011-2014 Claudio Bustos
|
5
5
|
#
|
6
6
|
# This program is free software; you can redistribute it and/or
|
7
7
|
# modify it under the terms of the GNU General Public License
|
@@ -50,7 +50,6 @@ require 'distribution/math_extension'
|
|
50
50
|
# Distribution::Normal.p_value(0.95)
|
51
51
|
# => 1.64485364660836
|
52
52
|
module Distribution
|
53
|
-
VERSION="0.7.0"
|
54
53
|
module Shorthand
|
55
54
|
EQUIVALENCES={:p_value=>:p, :cdf=>:cdf, :pdf=>:pdf, :rng=>:r, :exact_pdf=>:epdf, :exact_cdf=>:ecdf, :exact_p_value=>:ep}
|
56
55
|
def self.add_shortcut(sh,m, &block)
|
@@ -156,6 +155,7 @@ module Distribution
|
|
156
155
|
require 'distribution/poisson'
|
157
156
|
require 'distribution/logistic'
|
158
157
|
require 'distribution/lognormal'
|
158
|
+
require 'distribution/weibull'
|
159
159
|
|
160
160
|
if has_java?
|
161
161
|
init_java()
|
@@ -35,6 +35,40 @@ module Distribution
|
|
35
35
|
Math::IncompleteBeta.axpy(1.0, 0.0, a,b,x)
|
36
36
|
end
|
37
37
|
|
38
|
+
# Inverse of the beta distribution function
|
39
|
+
def p_value(p,a,b, rmin=0, rmax=1)
|
40
|
+
raise "a <= 0" if a <= 0
|
41
|
+
raise "b <= 0" if b <= 0
|
42
|
+
raise "rmin == rmax" if rmin == rmax
|
43
|
+
raise "p <= 0" if p <= 0
|
44
|
+
raise "p > 1" if p > 1
|
45
|
+
|
46
|
+
precision=8.88e-016
|
47
|
+
max_iterations=256
|
48
|
+
|
49
|
+
ga = 0
|
50
|
+
gb = 2
|
51
|
+
|
52
|
+
i = 1
|
53
|
+
while ((gb - ga) > precision) && (i < max_iterations)
|
54
|
+
guess = (ga + gb) / 2.0
|
55
|
+
result = cdf(guess, a, b)
|
56
|
+
|
57
|
+
if (result == p) || (result == 0)
|
58
|
+
gb = ga
|
59
|
+
elsif result > p
|
60
|
+
gb = guess
|
61
|
+
else
|
62
|
+
ga = guess
|
63
|
+
end
|
64
|
+
|
65
|
+
raise 'No value' if i == max_iterations
|
66
|
+
|
67
|
+
i+=1
|
68
|
+
end
|
69
|
+
|
70
|
+
rmin + guess * (rmax - rmin)
|
71
|
+
end
|
38
72
|
|
39
73
|
end
|
40
74
|
end
|
@@ -2,10 +2,11 @@ module Distribution
|
|
2
2
|
module Exponential
|
3
3
|
module Ruby_
|
4
4
|
class << self
|
5
|
-
def rng(l)
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
def rng(l, opts = {})
|
6
|
+
rng = opts[:random] || Random
|
7
|
+
lambda {p_value(rng.rand,l)}
|
8
|
+
end
|
9
|
+
def pdf(x,l)
|
9
10
|
return 0 if x<0
|
10
11
|
l*Math.exp(-l*x)
|
11
12
|
end
|
data/lib/distribution/t/ruby.rb
CHANGED
@@ -67,7 +67,7 @@ module Distribution
|
|
67
67
|
def pt(q, n)
|
68
68
|
q = q.to_f
|
69
69
|
if(q < 1.0e-5 || q > 1.0 || n < 1)
|
70
|
-
$stderr.printf("Error :
|
70
|
+
$stderr.printf("Error : Illegal parameter in pt()!\n")
|
71
71
|
return 0.0
|
72
72
|
end
|
73
73
|
|
@@ -108,4 +108,4 @@ module Distribution
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
end
|
111
|
-
end
|
111
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Distribution
|
2
|
+
module Weibull
|
3
|
+
module GSL_
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def pdf(x, k, lam)
|
7
|
+
GSL::Ran.weibull_pdf(x, lam, k)
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def cdf(x, k, lam)
|
12
|
+
GSL::Cdf.weibull_P(x, lam, k)
|
13
|
+
end
|
14
|
+
|
15
|
+
def p_value(y, k, lam)
|
16
|
+
GSL::Cdf.weibull_Pinv(y, lam, k)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Distribution
|
2
|
+
module Weibull
|
3
|
+
module Ruby_
|
4
|
+
class << self
|
5
|
+
def pdf(x, k, lam)
|
6
|
+
return 0.0 if x < 0.0
|
7
|
+
return ((k.to_f/lam.to_f)*(x.to_f/lam.to_f)**(k-1.0))*Math.exp(-(x.to_f/lam.to_f)**k)
|
8
|
+
end
|
9
|
+
|
10
|
+
#Returns the integral of the Weibull distribution from [-Inf to x]
|
11
|
+
|
12
|
+
def cdf(x, k, lam)
|
13
|
+
return 0.0 if x < 0.0
|
14
|
+
return 1.0-Math.exp(-(x.to_f/lam.to_f)**k)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns the P-value of weibull
|
18
|
+
|
19
|
+
def p_value(y, k, lam)
|
20
|
+
return 1.0 if y > 1.0
|
21
|
+
return 0.0 if y < 0.0
|
22
|
+
return -lam*(Math.log(1.0-y))**(1.0/k)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/distribution_spec.rb
CHANGED
data/spec/exponential_spec.rb
CHANGED
@@ -76,5 +76,19 @@ describe Distribution::Exponential do
|
|
76
76
|
#
|
77
77
|
# end
|
78
78
|
# end
|
79
|
-
|
79
|
+
describe "rng" do
|
80
|
+
it "should default to Kernel#rand if no :random is given" do
|
81
|
+
Random.stub(:rand)
|
82
|
+
Random.should_receive(:rand).and_return(0.5)
|
83
|
+
rng = Distribution::Exponential.rng 1.0
|
84
|
+
rng.call()
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should use a given rng if one is passed during construction" do
|
88
|
+
random = double("random")
|
89
|
+
random.should_receive(:rand).and_return(0.5)
|
90
|
+
rng = Distribution::Exponential::rng 1.0, :random => random
|
91
|
+
rng.call()
|
92
|
+
end
|
93
|
+
end
|
80
94
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
|
2
|
+
|
3
|
+
include ExampleWithGSL
|
4
|
+
|
5
|
+
describe Distribution::Weibull do
|
6
|
+
|
7
|
+
#shared_examples for "Weibull engine" do
|
8
|
+
it "should return correct pdf" do
|
9
|
+
Distribution::Weibull::pdf(2, 1, 1).should be_within(1e-3).of(0.13533)
|
10
|
+
end
|
11
|
+
it "should return correct cdf" do
|
12
|
+
Distribution::Weibull::cdf(2, 1, 1).should be_within(1e-3).of(0.86466)
|
13
|
+
end
|
14
|
+
it "should return correct p-value" do
|
15
|
+
Distribution::Weibull::p_value(0.86466, 1, 1).should be_within(1e-3).of(2.0)
|
16
|
+
end
|
17
|
+
#end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,126 +1,57 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: distribution
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 7
|
9
|
-
- 0
|
10
|
-
version: 0.7.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.1
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Claudio Bustos
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
|
-
cert_chain:
|
17
|
-
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALf8JVMGqE7m5kYb+PNN
|
24
|
-
neZv2pcXV5fQCi6xkyG8bi2/SIFy/LyxuvLzEeOxBeaz1Be93bayIUquOIqw3dyw
|
25
|
-
/KXWa31FxuNuvAm6CN8fyeRYX/ou4cw3OIUUnIvB7RMNIu4wbgeM6htV/QEsNLrv
|
26
|
-
at1/mh9JpqawPrcjIOVMj4BIp67vmzJCaUf+S/H2uYtSO09F+YQE3tv85TPeRmqU
|
27
|
-
yjyXyTc/oJiw1cXskUL8UtMWZmrwNLHXuZWWIMzkjiz3UNdhJr/t5ROk8S2WPznl
|
28
|
-
0bMy/PMIlAbqWolRn1zl2VFJ3TaXScbqImY8Wf4g62b/1ZSUlGrtnLNsCYXrWiso
|
29
|
-
UPUCAwEAAaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFGu9
|
30
|
-
rrJ1H64qRmNNu3Jj/Qjvh0u5MA0GCSqGSIb3DQEBBQUAA4IBAQCV0Unka5isrhZk
|
31
|
-
GjqSDqY/6hF+G2pbFcbWUpjmC8NWtAxeC+7NGV3ljd0e1SLfoyBj4gnFtFmY8qX4
|
32
|
-
K02tgSZM0eDV8TpgFpWXzK6LzHvoanuahHLZEtk/+Z885lFene+nHadkem1n9iAB
|
33
|
-
cs96JO9/JfFyuXM27wFAwmfHCmJfPF09R4VvGHRAvb8MGzSVgk2i06OJTqkBTwvv
|
34
|
-
JHJdoyw3+8bw9RJ+jLaNoQ+xu+1pQdS2bb3m7xjZpufml/m8zFCtjYM/7qgkKR8z
|
35
|
-
/ZZt8lCiKfFArppRrZayE2FVsps4X6WwBdrKTMZ0CKSXTRctbEj1BAZ67eoTvBBt
|
36
|
-
rpP0jjs0
|
37
|
-
-----END CERTIFICATE-----
|
38
|
-
|
39
|
-
date: 2011-11-30 00:00:00 -03:00
|
40
|
-
default_executable:
|
41
|
-
dependencies:
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: rubyforge
|
44
|
-
prerelease: false
|
45
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
46
|
-
none: false
|
47
|
-
requirements:
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
48
17
|
- - ">="
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
|
51
|
-
segments:
|
52
|
-
- 2
|
53
|
-
- 0
|
54
|
-
- 4
|
55
|
-
version: 2.0.4
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0
|
56
20
|
type: :development
|
57
|
-
version_requirements: *id001
|
58
|
-
- !ruby/object:Gem::Dependency
|
59
|
-
name: rspec
|
60
21
|
prerelease: false
|
61
|
-
|
62
|
-
|
63
|
-
requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
64
24
|
- - ">="
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
type: :development
|
72
|
-
version_requirements: *id002
|
73
|
-
- !ruby/object:Gem::Dependency
|
74
|
-
name: rubyforge
|
75
|
-
prerelease: false
|
76
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
77
|
-
none: false
|
78
|
-
requirements:
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
79
31
|
- - ">="
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
|
82
|
-
segments:
|
83
|
-
- 0
|
84
|
-
version: "0"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
85
34
|
type: :development
|
86
|
-
version_requirements: *id003
|
87
|
-
- !ruby/object:Gem::Dependency
|
88
|
-
name: hoe
|
89
35
|
prerelease: false
|
90
|
-
|
91
|
-
|
92
|
-
requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
93
38
|
- - ">="
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
- 0
|
100
|
-
version: 2.8.0
|
101
|
-
type: :development
|
102
|
-
version_requirements: *id004
|
103
|
-
description: |-
|
104
|
-
Statistical Distributions library. Includes Normal univariate and bivariate, T, F, Chi Square, Binomial, Hypergeometric, Exponential, Poisson, Beta, LogNormal and Gamma.
|
105
|
-
|
106
|
-
Uses Ruby by default and C (statistics2/GSL) or Java extensions where available.
|
107
|
-
|
108
|
-
Includes code from statistics2 on Normal, T, F and Chi Square ruby code [http://blade.nagaokaut.ac.jp/~sinara/ruby/math/statistics2]
|
109
|
-
email:
|
110
|
-
- clbustos_at_gmail.com
|
111
|
-
executables:
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Distribution
|
42
|
+
email: []
|
43
|
+
executables:
|
112
44
|
- distribution
|
113
45
|
extensions: []
|
114
|
-
|
115
|
-
|
116
|
-
-
|
117
|
-
-
|
118
|
-
-
|
119
|
-
files:
|
120
|
-
- .autotest
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".travis.yml"
|
50
|
+
- Gemfile
|
121
51
|
- History.txt
|
52
|
+
- LICENCE.md
|
122
53
|
- Manifest.txt
|
123
|
-
- README.
|
54
|
+
- README.md
|
124
55
|
- Rakefile
|
125
56
|
- benchmark/binomial_coefficient.rb
|
126
57
|
- benchmark/binomial_coefficient/binomial_coefficient.ds
|
@@ -135,6 +66,7 @@ files:
|
|
135
66
|
- data/template/distribution/gsl.erb
|
136
67
|
- data/template/distribution/ruby.erb
|
137
68
|
- data/template/spec.erb
|
69
|
+
- distribution.gemspec
|
138
70
|
- lib/distribution.rb
|
139
71
|
- lib/distribution/beta.rb
|
140
72
|
- lib/distribution/beta/gsl.rb
|
@@ -199,6 +131,10 @@ files:
|
|
199
131
|
- lib/distribution/t/java.rb
|
200
132
|
- lib/distribution/t/ruby.rb
|
201
133
|
- lib/distribution/t/statistics2.rb
|
134
|
+
- lib/distribution/version.rb
|
135
|
+
- lib/distribution/weibull.rb
|
136
|
+
- lib/distribution/weibull/gsl.rb
|
137
|
+
- lib/distribution/weibull/ruby.rb
|
202
138
|
- spec/beta_spec.rb
|
203
139
|
- spec/binomial_spec.rb
|
204
140
|
- spec/bivariatenormal_spec.rb
|
@@ -217,41 +153,29 @@ files:
|
|
217
153
|
- spec/spec.opts
|
218
154
|
- spec/spec_helper.rb
|
219
155
|
- spec/t_spec.rb
|
156
|
+
- spec/weibull_spec.rb
|
220
157
|
- vendor/java/commons-math-2.2.jar
|
221
|
-
|
222
|
-
homepage: https://github.com/clbustos/distribution
|
158
|
+
homepage: http://rubygems.org/gems/foodie
|
223
159
|
licenses: []
|
224
|
-
|
160
|
+
metadata: {}
|
225
161
|
post_install_message:
|
226
|
-
rdoc_options:
|
227
|
-
|
228
|
-
- README.txt
|
229
|
-
require_paths:
|
162
|
+
rdoc_options: []
|
163
|
+
require_paths:
|
230
164
|
- lib
|
231
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
232
|
-
|
233
|
-
requirements:
|
165
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
234
167
|
- - ">="
|
235
|
-
- !ruby/object:Gem::Version
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
version: "0"
|
240
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
241
|
-
none: false
|
242
|
-
requirements:
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
243
172
|
- - ">="
|
244
|
-
- !ruby/object:Gem::Version
|
245
|
-
|
246
|
-
segments:
|
247
|
-
- 0
|
248
|
-
version: "0"
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: 1.3.6
|
249
175
|
requirements: []
|
250
|
-
|
251
|
-
|
252
|
-
rubygems_version: 1.3.7
|
176
|
+
rubyforge_project:
|
177
|
+
rubygems_version: 2.2.2
|
253
178
|
signing_key:
|
254
|
-
specification_version:
|
255
|
-
summary:
|
179
|
+
specification_version: 4
|
180
|
+
summary: Distribution
|
256
181
|
test_files: []
|
257
|
-
|
data.tar.gz.sig
DELETED
data/.autotest
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# -*- ruby -*-
|
2
|
-
|
3
|
-
require 'autotest/restart'
|
4
|
-
|
5
|
-
# Autotest.add_hook :initialize do |at|
|
6
|
-
# at.extra_files << "../some/external/dependency.rb"
|
7
|
-
#
|
8
|
-
# at.libs << ":../some/external"
|
9
|
-
#
|
10
|
-
# at.add_exception 'vendor'
|
11
|
-
#
|
12
|
-
# at.add_mapping(/dependency.rb/) do |f, _|
|
13
|
-
# at.files_matching(/test_.*rb$/)
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# %w(TestA TestB).each do |klass|
|
17
|
-
# at.extra_class_map[klass] = "test/test_misc.rb"
|
18
|
-
# end
|
19
|
-
# end
|
20
|
-
|
21
|
-
# Autotest.add_hook :run_command do |at|
|
22
|
-
# system "rake build"
|
23
|
-
# end
|
metadata.gz.sig
DELETED
Binary file
|