distribution 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10da9cb77a0a56fd768b3b512e3c80c64b7a865d
4
- data.tar.gz: 86646fd4edf1880ed627b50e37f035dabf960317
3
+ metadata.gz: 5ad89b4b418c98eadf4c2a4ed5c9cba5b63bb22d
4
+ data.tar.gz: 52f3687e89e6ba1e76a13f8ff551a664efe21854
5
5
  SHA512:
6
- metadata.gz: 46f20bc037e47b6a1eea5f90a081c72d2b280912d36df4275d1f0b60163653f791a7f61fdbba95b2734d6dc36fe678103f85c10e2cc35ecb4620b911e6ec5858
7
- data.tar.gz: a169f7a086666cbc8fb609d025d0aa20dd8c9a8cca70313d9b8555479e7a78beceab3889afa52391978b91a78cf92bf864e92cc3740168d4ee582cf139b46245
6
+ metadata.gz: 0163e569b86ac34b5beec82d883371482fa39a78c59705fd4236f41567f4fa1785ab7c35cdb08c3e1f9b0a7694d0787e190aad0898ba768185a6a88d72dc58fe
7
+ data.tar.gz: ad23f9bae7be679a5324b4b37dedabbc8d7702b360a602c4b24df92d210892143c7d8f3b9dcec677dadebddf08d18df2d3d24e2d42dcfe997446973656987e64
@@ -1,12 +1,15 @@
1
1
  language: ruby
2
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
3
+ - 1.9.3
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
7
+ # - jruby-19mode # JRuby in 1.9 mode -> Problems with bigint
8
+ # - rbx-19mode
12
9
 
10
+ script:
11
+ bundle exec rake
12
+
13
+ before_install:
14
+ - sudo apt-get update -qq
15
+ - sudo apt-get install -y libgsl0-dev
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
- # A sample Gemfile
2
1
  source "https://rubygems.org"
3
- gem "rspec"
4
- gem "rb-gsl"
2
+ gem "rb-gsl", :platforms=>[:ruby,:mswin]
5
3
  gemspec
@@ -1,12 +1,15 @@
1
- === 0.7.0 / 2011-11-30
1
+ === 0.7.2 / 2015-04-03
2
+ * Formatting files according to the community's best practices.
3
+ * Other minor improvements in gemspec, Rakefile, etc.
2
4
 
5
+ === 0.7.0 / 2011-11-30
3
6
  + Basic log-normal distribution support, with pdf and cdf for ruby [dennyabraham and clbustos]
4
- * Matthew Peterson add Java support for Poisson and Normal distributions.
7
+ * Matthew Peterson add Java support for Poisson and Normal distributions.
5
8
  * Updated Logistic, Normal spec. Added LogNormal spec [clbustos]
6
9
  * Updated template for new distributions
7
10
 
8
11
  === 0.6.0 / 2011-09-23
9
- * Incomplete Beta functions on math renamed to Regularized beta, because MathExtension::IncompleteBeta calculates regularized beta function, not Incomplete Beta.
12
+ * Incomplete Beta functions on math renamed to Regularized beta, because MathExtension::IncompleteBeta calculates regularized beta function, not Incomplete Beta.
10
13
  * Corrected documention on F distribution and added comments on gamma and beta[Claudio Bustos]
11
14
  * Moved ported methods from GSL to lib/math_extension. Updated spec for gamma and beta distributions[Claudio Bustos]
12
15
  * Added beta distribution functions. p_value does not seem to work yet.[John Woods]
@@ -20,15 +23,15 @@
20
23
  === 0.5.0 / 2011-05-03
21
24
 
22
25
  * Exception raises on calculation of T's cdf with ruby engine. For now, stick to gsl implementation
23
- * Added logistic distribution.
24
- * Raises an error on binomial if k>n.
26
+ * Added logistic distribution.
27
+ * Raises an error on binomial if k>n.
25
28
  * New rng for exponential distribution, based on F^-1 [clbustos]
26
29
  * Added power benchmark
27
30
 
28
31
  === 0.4.0 / 2011-02-01
29
32
 
30
33
  * Poisson and exponential distributions implemented. Implementation of inverse cdf for poisson is not perfect, yet.
31
- * +distribution+ executable can create template files for new distributions.
34
+ * +distribution+ executable can create template files for new distributions.
32
35
  * MathExtension should work fine with Ruby 1.8. Fixed shadowed variable on MathExtension.naive_factorial
33
36
  * Added factorial lookup table for n<20.
34
37
  * Added exact cdf for Binomial
@@ -39,19 +42,19 @@
39
42
 
40
43
  * Included support for binomial distribution. p_value is not accurate
41
44
  * Included alias for ruby exact methods on discrete distributions, when they are available
42
- * Works on Jruby and Ruby 1.8.7
45
+ * Works on Jruby and Ruby 1.8.7
43
46
  * Binomial coefficient optimized. Falling factorial method with Swing Prime on factorial provides a 10x improvement over naive version.
44
47
  * Working on binomial coefficient using gamma. The same problem as using Sterling: faster than exact version, but when it requires BigDecimal, is 2-3x slower
45
48
  * Deleted Fixnum extension on Hypergeometric
46
49
 
47
50
  === 0.2.0 / 2011-01-27
48
- * Shorthands for F and T are 'fdist' and 'tdist' now, to avoid confussions
51
+ * Shorthands for F and T are 'fdist' and 'tdist' now, to avoid confussions
49
52
  * Added Hypergeometric distribution with pdf, cdf, p_value. The Ruby version uses a very slow factorial process, but also has pdf_with_stirling if you don't care about accuracy at all. This latter method needs to be improved, actually, in terms of which choose function it calls for the numerator and denominator. Once that's done, it can replace the slower pdf function. [John Woods]
50
- * Spec for cdf and p_value of Hypergeometric
53
+ * Spec for cdf and p_value of Hypergeometric
51
54
  * New cdf and p_value on Hypergeometric[clbustos]
52
55
  * Hypergeometric#pdf returns 0 on max(0,n+m-t)<=k<=min(m,n)
53
56
  * Improved factorial calculation, using Luschny algorithms
54
57
 
55
58
  === 0.1.0 / 2011-01-26
56
59
 
57
- * Basic set (pdf, cdf, p_value) for Normal, Chi Square, F and T distributions
60
+ * Basic set (pdf, cdf, p_value) for Normal, Chi Square, F and T distributions
data/README.md CHANGED
@@ -1,10 +1,21 @@
1
- # [Distribution](https://github.com/clbustos/distribution) Quick Start
1
+ # [Distribution](https://github.com/sciruby/distribution)
2
+
3
+ [![Build Status](https://travis-ci.org/SciRuby/distribution.svg?branch=master)](https://travis-ci.org/SciRuby/distribution)
4
+ [![Code Climate](https://codeclimate.com/github/SciRuby/distribution/badges/gpa.svg)](https://codeclimate.com/github/SciRuby/distribution)
5
+
6
+ ## Installation
2
7
 
3
8
  ```
4
- git clone https://github.com/sciruby/distribution
9
+ $ gem install distribution
5
10
  ```
6
11
 
7
- ## Description:
12
+ If you have GSL installed and want to speed things up, install `rb-gsl`:
13
+
14
+ ```bash
15
+ $ gem install rb-gsl
16
+ ```
17
+
18
+ ## Description
8
19
 
9
20
  Statistical Distributions library. Includes Normal univariate and bivariate, T, F, Chi Square, Binomial, Hypergeometric, Exponential, Poisson, Beta, LogNormal and Gamma.
10
21
 
@@ -12,47 +23,41 @@ Uses Ruby by default and C (statistics2/GSL) or Java extensions where available.
12
23
 
13
24
  Includes code from statistics2 on Normal, T, F and Chi Square ruby code [http://blade.nagaokaut.ac.jp/~sinara/ruby/math/statistics2]
14
25
 
15
- ## Synopsis:
16
- * Returns Gaussian PDF for x
17
- pdf=Distribution::Normal.pdf(x)
18
- * Returns Gaussian CDF for x
19
- cdf=Distribution::Normal.cdf(x)
20
- * Returns inverse CDF (or p-value) for x
21
- pv=Distribution::Normal.p_value(x)
26
+ ## Synopsis
22
27
 
23
- ## System Requirements:
28
+ * Returns Gaussian PDF for x
24
29
 
25
- To increase (notably!) the speed, please install
30
+ ```
31
+ pdf=Distribution::Normal.pdf(x)
32
+ ```
26
33
 
27
- * Ruby 1.8-1.9: gsl (prefered) or statistics2
28
- * Java: Not yet implemented
34
+ * Returns Gaussian CDF for x
29
35
 
30
- ## User Installation:
31
36
  ```
32
- gem install distribution
37
+ cdf=Distribution::Normal.cdf(x)
33
38
  ```
34
- To speep up
39
+
40
+ * Returns inverse CDF (or p-value) for x
41
+
35
42
  ```
36
- gem install gsl
37
- gem install statistics
43
+ pv=Distribution::Normal.p_value(x)
38
44
  ```
39
45
 
40
- ## Developers:
46
+ ## Developers
41
47
 
42
- After checking out the source, run:
43
48
  ```
44
- $ rake newb
49
+ $ git clone https://github.com/SciRuby/distribution.git
45
50
  ```
46
- This task will install any missing dependencies, run the tests/specs,
47
- and generate the RDoc.
48
51
 
49
- If you want to provide a new distribution, /lib/distribution run
52
+ If you want to provide a new distribution, run `lib/distribution`:
53
+
50
54
  ```
51
- $ distribution --new your_distribution
55
+ $ distribution --new your_distribution
52
56
  ```
53
- This should create the main distribution file, the directory with ruby and gsl engines and the rspec on /spec directory.
54
57
 
55
- ### API Structure
58
+ This should create the main distribution file, the directory with Ruby and GSL engines and specs on the spec/ directory.
59
+
60
+ ## API Structure
56
61
 
57
62
  Distribution::<name>.(cdf|pdf|p_value|rng)
58
63
 
@@ -88,7 +93,9 @@ Shortnames for distributions:
88
93
  ```
89
94
  Distribution::T.cdf
90
95
  ```
96
+
91
97
  could be called after including Distribution::Shorthand
98
+
92
99
  ```
93
100
  tdist_cdf
94
101
  ```
@@ -100,6 +107,6 @@ could be called after including Distribution::Shorthand
100
107
 
101
108
  ## Issues
102
109
 
103
- * On Jruby and Rubinius, BivariateNormal returns incorrect pdf
110
+ * On JRuby and Rubinius, BivariateNormal returns incorrect pdf
104
111
 
105
- For current issues see the [issue tracker pages](https://github.com/clbustos/distribution/issues)
112
+ For current issues see the [issue tracker pages](https://github.com/sciruby/distribution/issues).
data/Rakefile CHANGED
@@ -1,28 +1,22 @@
1
- # -*- ruby -*-
2
- $:.unshift(File.expand_path(File.dirname(__FILE__)+"/lib/"))
3
- require 'rubygems'
4
- #require 'hoe'
5
- require 'distribution'
6
- # Hoe.plugin :compiler
7
- # Hoe.plugin :gem_prelude_sucks
8
- # Hoe.plugin :git
9
- # Hoe.plugin :inline
10
- # Hoe.plugin :racc
11
- # Hoe.plugin :rubyforge
1
+ require 'bundler'
2
+ require 'bundler/gem_tasks'
3
+ require 'rake'
4
+ require 'rspec/core/rake_task'
12
5
 
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"]
6
+ # Setup the necessary gems, specified in the gemspec.
7
+ begin
8
+ Bundler.setup(:default, :development)
9
+ rescue Bundler::BundlerError => e
10
+ $stderr.puts e.message
11
+ $stderr.puts "Run `bundle install` to install missing gems"
12
+ exit e.status_code
13
+ end
17
14
 
18
- #end
19
- # git log --pretty=format:"*%s[%cn]" v0.5.0..HEAD >> History.txt
20
15
  desc "Open an irb session preloaded with distribution"
21
16
  task :console do
22
17
  sh "irb -rubygems -I lib -r distribution.rb"
23
18
  end
24
19
 
25
- require 'bundler'
26
- Bundler::GemHelper.install_tasks
20
+ RSpec::Core::RakeTask.new(:spec)
27
21
 
28
- # vim: syntax=ruby
22
+ task :default => :spec
@@ -1,20 +1,26 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path("../lib/distribution/version", __FILE__)
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+
3
+ require 'date'
4
+ require 'distribution/version'
3
5
 
4
6
  Gem::Specification.new do |s|
5
7
  s.name = "distribution"
6
8
  s.version = Distribution::VERSION
7
- s.platform = Gem::Platform::RUBY
9
+ s.date = Date.today.to_s
10
+ s.homepage = "https://github.com/sciruby/distribution"
11
+
8
12
  s.authors = ['Claudio Bustos']
9
- s.email = []
10
- s.homepage = "http://rubygems.org/gems/foodie"
13
+ s.email = ['clbustos@gmail.com']
14
+
15
+ s.platform = Gem::Platform::RUBY
11
16
  s.summary = "Distribution"
12
17
  s.description = "Distribution"
13
18
 
14
- s.required_rubygems_version = ">= 1.3.6"
15
- s.add_development_dependency "bundler", ">= 1.0.0"
16
- s.add_development_dependency "rspec"
17
19
  s.files = `git ls-files`.split("\n")
18
20
  s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
19
21
  s.require_path = 'lib'
22
+
23
+ s.add_development_dependency 'bundler'
24
+ s.add_development_dependency 'rake'
25
+ s.add_development_dependency "rspec", '~> 3.2'
20
26
  end
@@ -1,6 +1,6 @@
1
- # = distribution.rb -
1
+ # = distribution.rb -
2
2
  # Distribution - Statistical Distributions package for Ruby
3
- #
3
+ #
4
4
  # Copyright (C) 2011-2014 Claudio Bustos
5
5
  #
6
6
  # This program is free software; you can redistribute it and/or
@@ -18,62 +18,54 @@
18
18
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
19
  #
20
20
  # == Other Sources
21
- #
22
- # * Code of several Ruby engines came from statistics2.rb,
21
+ #
22
+ # * Code of several Ruby engines came from statistics2.rb,
23
23
  # created by Shin-ichiro HARA(sinara@blade.nagaokaut.ac.jp).
24
24
  # Retrieve from http://blade.nagaokaut.ac.jp/~sinara/ruby/math/statistics2/
25
25
  # * Code of Beta and Gamma distribution came from GSL project.
26
26
  # Ported by John O. Woods
27
27
  # Specific notices will be placed where there are appropiate
28
- #
29
- if !respond_to? :define_singleton_method
30
- class Module
31
- public :define_method
32
- end
33
-
34
- class Object
35
- def define_singleton_method(name,&block)
36
- sc=class <<self;self;end
37
- sc.define_method(name,&block)
38
- end
39
- end
40
- end
41
- require 'distribution/math_extension'
28
+ #
42
29
 
30
+ require 'distribution/math_extension'
31
+ require 'distribution/version'
43
32
 
44
33
  # Several distributions modules to calculate pdf, cdf, inverse cdf and generate
45
34
  # pseudo-random numbers for several statistical distributions
46
- #
35
+ #
47
36
  # == Usage:
48
37
  # Distribution::Normal.cdf(1.96)
49
38
  # => 0.97500210485178
50
39
  # Distribution::Normal.p_value(0.95)
51
40
  # => 1.64485364660836
52
41
  module Distribution
42
+
43
+ SQ2PI = Math.sqrt(2 * Math::PI)
44
+
53
45
  module Shorthand
54
- EQUIVALENCES={:p_value=>:p, :cdf=>:cdf, :pdf=>:pdf, :rng=>:r, :exact_pdf=>:epdf, :exact_cdf=>:ecdf, :exact_p_value=>:ep}
55
- def self.add_shortcut(sh,m, &block)
56
- if EQUIVALENCES.include? m.to_sym
57
- sh_name=sh+"_#{m}"
58
- define_method(sh_name,&block)
59
- sh_name=sh+"_#{EQUIVALENCES[m.to_sym]}"
60
- define_method(sh_name,&block)
61
-
46
+ EQUIVALENCES = { p_value: :p, cdf: :cdf, pdf: :pdf, rng: :r,
47
+ exact_pdf: :epdf, exact_cdf: :ecdf, exact_p_value: :ep }
48
+
49
+ def self.add_shortcut(shortcut, method, &block)
50
+ if EQUIVALENCES.include? method.to_sym
51
+ name = shortcut + "_#{method}"
52
+ define_method(name, &block)
53
+
54
+ name = shortcut + "_#{EQUIVALENCES[method.to_sym]}"
55
+ define_method(name, &block)
56
+
62
57
  end
63
58
  end
64
59
  end
65
-
66
-
67
- SQ2PI = Math.sqrt(2 * Math::PI)
68
60
 
69
61
  # Create a method 'has_<library>' on Module
70
62
  # which require a library and return true or false
71
- # according to success of failure
63
+ # according to success of failure
72
64
  def self.create_has_library(library) #:nodoc:
73
65
  define_singleton_method("has_#{library}?") do
74
- cv="@@#{library}"
75
- if !class_variable_defined? cv
76
- begin
66
+ cv = "@@#{library}"
67
+ unless class_variable_defined? cv
68
+ begin
77
69
  require library.to_s
78
70
  class_variable_set(cv, true)
79
71
  rescue LoadError
@@ -83,24 +75,26 @@ module Distribution
83
75
  class_variable_get(cv)
84
76
  end
85
77
  end
86
- # Retrieves the libraries used to calculate
78
+
79
+ # Retrieves the libraries used to calculate
87
80
  # distributions
88
81
  def self.libraries_order
89
- order=[:Ruby_]
82
+ order = [:Ruby_]
90
83
  order.unshift(:Statistics2_) if has_statistics2?
91
84
  order.unshift(:GSL_) if has_gsl?
92
85
  order.unshift(:Java_) if has_java?
93
86
  order
94
87
  end
88
+
95
89
  create_has_library :gsl
96
90
  create_has_library :statistics2
97
91
  create_has_library :java
98
-
92
+
99
93
  # Magic module
100
94
  module Distributable #:nodoc:
101
- # Create methods for each module and add methods to
102
- # Distribution::Shorthand.
103
- #
95
+ # Create methods for each module and add methods to
96
+ # Distribution::Shorthand.
97
+ #
104
98
  # Traverse Distribution.libraries_order adding
105
99
  # methods availables for each engine module on
106
100
  # the current library
@@ -108,41 +102,40 @@ module Distribution
108
102
  # Kids: Metaprogramming trickery! Don't do at work.
109
103
  # This section was created between a very long reunion
110
104
  # and a 456 Km. travel
111
- def create_distribution_methods()
105
+ def create_distribution_methods
112
106
  Distribution.libraries_order.each do |l_name|
113
- if const_defined? l_name
114
- l =const_get(l_name)
115
- # Add methods from engine to base base, if not yet included
116
- l.singleton_methods.each do |m|
117
- if !singleton_methods.include? m
118
- define_method(m) do |*args|
119
- l.send(m,*args)
120
- end
121
- # Add method to Distribution::Shorthand
122
- sh=const_get(:SHORTHAND)
123
- Distribution::Shorthand.add_shortcut(sh,m) do |*args|
124
- l.send(m,*args)
107
+ if const_defined? l_name
108
+ l = const_get(l_name)
109
+ # Add methods from engine to base base, if not yet included
110
+ l.singleton_methods.each do |m|
111
+ unless singleton_methods.include? m
112
+ define_method(m) do |*args|
113
+ l.send(m, *args)
114
+ end
115
+ # Add method to Distribution::Shorthand
116
+ sh = const_get(:SHORTHAND)
117
+ Distribution::Shorthand.add_shortcut(sh, m) do |*args|
118
+ l.send(m, *args)
119
+ end
120
+
121
+ module_function m
125
122
  end
126
-
127
- module_function m
128
123
  end
129
- end
124
+ end
130
125
  end
131
-
132
- end
133
- # create alias for common methods
134
- alias_method :inverse_cdf, :p_value if singleton_methods.include? :p_value
126
+ # create alias for common methods
127
+ alias_method :inverse_cdf, :p_value if singleton_methods.include? :p_value
135
128
  end
136
-
137
129
  end
138
- def self.init_java()
139
- $:.unshift(File.dirname(__FILE__)+"/../vendor/java")
130
+
131
+ def self.init_java
132
+ $LOAD_PATH.unshift File.expand_path('../../vendor/java', __FILE__)
140
133
  require 'commons-math-2.2.jar'
141
134
  java_import 'org.apache.commons.math.distribution.NormalDistributionImpl'
142
135
  java_import 'org.apache.commons.math.distribution.PoissonDistributionImpl'
143
-
144
136
  end
145
- require 'distribution/normal'
137
+
138
+ require 'distribution/normal'
146
139
  require 'distribution/chisquare'
147
140
  require 'distribution/gamma'
148
141
  require 'distribution/beta'
@@ -156,11 +149,8 @@ module Distribution
156
149
  require 'distribution/logistic'
157
150
  require 'distribution/lognormal'
158
151
  require 'distribution/weibull'
159
-
152
+
160
153
  if has_java?
161
- init_java()
154
+ init_java
162
155
  end
163
156
  end
164
-
165
-
166
-