distribution 0.7.3 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +4 -6
  3. data/.yardopts +5 -0
  4. data/History.txt +3 -0
  5. data/README.md +87 -44
  6. data/benchmark/binomial_coefficient.rb +19 -23
  7. data/benchmark/binomial_coefficient/experiment.rb +33 -36
  8. data/benchmark/factorial_hash.rb +7 -8
  9. data/benchmark/factorial_method.rb +4 -6
  10. data/benchmark/odd.rb +6 -7
  11. data/benchmark/power.rb +11 -11
  12. data/bin/distribution +26 -26
  13. data/distribution.gemspec +3 -4
  14. data/lib/distribution.rb +55 -96
  15. data/lib/distribution/beta/gsl.rb +10 -5
  16. data/lib/distribution/beta/ruby.rb +3 -1
  17. data/lib/distribution/binomial/ruby.rb +5 -2
  18. data/lib/distribution/bivariatenormal.rb +4 -5
  19. data/lib/distribution/bivariatenormal/gsl.rb +2 -2
  20. data/lib/distribution/bivariatenormal/java.rb +1 -1
  21. data/lib/distribution/bivariatenormal/ruby.rb +245 -254
  22. data/lib/distribution/chisquare.rb +8 -10
  23. data/lib/distribution/chisquare/gsl.rb +24 -19
  24. data/lib/distribution/chisquare/java.rb +1 -1
  25. data/lib/distribution/chisquare/ruby.rb +25 -25
  26. data/lib/distribution/chisquare/statistics2.rb +16 -13
  27. data/lib/distribution/distributable.rb +40 -0
  28. data/lib/distribution/exponential.rb +4 -5
  29. data/lib/distribution/exponential/gsl.rb +13 -9
  30. data/lib/distribution/exponential/ruby.rb +14 -9
  31. data/lib/distribution/f.rb +1 -1
  32. data/lib/distribution/f/gsl.rb +26 -22
  33. data/lib/distribution/f/java.rb +1 -1
  34. data/lib/distribution/f/ruby.rb +16 -19
  35. data/lib/distribution/f/statistics2.rb +22 -19
  36. data/lib/distribution/gamma.rb +5 -7
  37. data/lib/distribution/gamma/gsl.rb +13 -9
  38. data/lib/distribution/gamma/java.rb +1 -1
  39. data/lib/distribution/gamma/ruby.rb +5 -11
  40. data/lib/distribution/hypergeometric.rb +5 -8
  41. data/lib/distribution/hypergeometric/gsl.rb +4 -5
  42. data/lib/distribution/hypergeometric/java.rb +1 -1
  43. data/lib/distribution/hypergeometric/ruby.rb +34 -35
  44. data/lib/distribution/logistic.rb +5 -8
  45. data/lib/distribution/logistic/ruby.rb +13 -8
  46. data/lib/distribution/lognormal.rb +5 -7
  47. data/lib/distribution/lognormal/gsl.rb +8 -6
  48. data/lib/distribution/lognormal/ruby.rb +5 -9
  49. data/lib/distribution/math_extension.rb +6 -15
  50. data/lib/distribution/math_extension/chebyshev_series.rb +281 -272
  51. data/lib/distribution/math_extension/erfc.rb +26 -29
  52. data/lib/distribution/math_extension/exponential_integral.rb +17 -17
  53. data/lib/distribution/math_extension/gammastar.rb +19 -20
  54. data/lib/distribution/math_extension/gsl_utilities.rb +12 -12
  55. data/lib/distribution/math_extension/incomplete_beta.rb +52 -61
  56. data/lib/distribution/math_extension/incomplete_gamma.rb +166 -168
  57. data/lib/distribution/math_extension/log_utilities.rb +20 -22
  58. data/lib/distribution/normal.rb +11 -13
  59. data/lib/distribution/normal/gsl.rb +13 -10
  60. data/lib/distribution/normal/java.rb +14 -13
  61. data/lib/distribution/normal/ruby.rb +68 -58
  62. data/lib/distribution/normal/statistics2.rb +5 -2
  63. data/lib/distribution/normalmultivariate.rb +64 -64
  64. data/lib/distribution/poisson.rb +11 -13
  65. data/lib/distribution/poisson/gsl.rb +7 -7
  66. data/lib/distribution/poisson/java.rb +19 -24
  67. data/lib/distribution/poisson/ruby.rb +38 -9
  68. data/lib/distribution/shorthand.rb +17 -0
  69. data/lib/distribution/t.rb +13 -15
  70. data/lib/distribution/t/gsl.rb +27 -24
  71. data/lib/distribution/t/java.rb +1 -1
  72. data/lib/distribution/t/ruby.rb +99 -100
  73. data/lib/distribution/t/statistics2.rb +19 -19
  74. data/lib/distribution/uniform.rb +26 -0
  75. data/lib/distribution/uniform/gsl.rb +36 -0
  76. data/lib/distribution/uniform/ruby.rb +91 -0
  77. data/lib/distribution/version.rb +1 -1
  78. data/lib/distribution/weibull.rb +6 -7
  79. data/lib/distribution/weibull/gsl.rb +16 -16
  80. data/lib/distribution/weibull/ruby.rb +30 -23
  81. data/spec/beta_spec.rb +45 -47
  82. data/spec/binomial_spec.rb +77 -85
  83. data/spec/bivariatenormal_spec.rb +28 -35
  84. data/spec/chisquare_spec.rb +48 -52
  85. data/spec/distribution_spec.rb +10 -10
  86. data/spec/exponential_spec.rb +44 -49
  87. data/spec/f_spec.rb +4 -4
  88. data/spec/gamma_spec.rb +50 -53
  89. data/spec/hypergeometric_spec.rb +63 -69
  90. data/spec/logistic_spec.rb +32 -37
  91. data/spec/lognormal_spec.rb +25 -31
  92. data/spec/math_extension_spec.rb +192 -210
  93. data/spec/normal_spec.rb +80 -73
  94. data/spec/poisson_spec.rb +63 -41
  95. data/spec/shorthand_spec.rb +19 -22
  96. data/spec/spec_helper.rb +8 -9
  97. data/spec/t_spec.rb +63 -77
  98. data/spec/uniform_spec.rb +154 -0
  99. data/spec/weibull_spec.rb +13 -14
  100. metadata +17 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4904710a92ef44ae987119ac6c214ea860735cd9
4
- data.tar.gz: 8a6381d47062634afade73cafbcd093603db985b
2
+ SHA256:
3
+ metadata.gz: b3c0292d160b0f59129c73e352855422d7f1d35cbc8eac916419a7146c5ee4eb
4
+ data.tar.gz: 63f7693122a361948ad79f60e26d5ab060fe69982477cf96e0eb7815dcf29d29
5
5
  SHA512:
6
- metadata.gz: 9142471e941e7a2a44ecc727c698fc18bf46da46964e0f49ea2e80ebd829284a1b53284ceaed4135d7ac9ade786e04a4bc155d9e3bb104151925f1d88b6ec9f8
7
- data.tar.gz: 2f019d5d7388e7af9c0d7d4e93f02eacdd06ac302bc5d7f72172e8fa6df00fc5c23fbe99a035f87989ad2cb692da523eaa1127338e3f673da84b3e006a0a69b3
6
+ metadata.gz: aa9d6ccb96e181214325ad90a1bba142bb46b2b23c2826c314ece10e55de139e613999a63e0477ea9ba595158a4544fa9758ff6f0ea4eff04ac2c2a568502e67
7
+ data.tar.gz: 5730f217be13735748570c0b45d56c3a04dc6f0dffeee39b97addb64e4eadd6a03d3d731f25a99903a9624a999be58308116b494e46342ef0ecd9b36293a4f1a
@@ -1,11 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
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
3
+ - 2.5
4
+ - 2.6
5
+ - 2.7
9
6
 
10
7
  script:
11
8
  bundle exec rake
@@ -13,3 +10,4 @@ script:
13
10
  before_install:
14
11
  - sudo apt-get update -qq
15
12
  - sudo apt-get install -y libgsl0-dev
13
+ - gem update && gem install bundler
@@ -0,0 +1,5 @@
1
+ --title "Distribution"
2
+ --markup markdown
3
+ lib/**/*.rb
4
+ README.md History.txt
5
+
@@ -1,3 +1,6 @@
1
+ === 0.7.4 / 2018-04-11
2
+ * Removed reference to deprecated Fixnum class.
3
+
1
4
  === 0.7.3 / 2015-05-28
2
5
  * Fixed F::Ruby_.p_value.
3
6
 
data/README.md CHANGED
@@ -3,76 +3,99 @@
3
3
  [![Build Status](https://travis-ci.org/SciRuby/distribution.svg?branch=master)](https://travis-ci.org/SciRuby/distribution)
4
4
  [![Code Climate](https://codeclimate.com/github/SciRuby/distribution/badges/gpa.svg)](https://codeclimate.com/github/SciRuby/distribution)
5
5
 
6
+ Distribution is a gem with several probabilistic distributions. Pure Ruby is used by default, C (GSL) or Java extensions are used if available. Some facts:
7
+
8
+ - Very fast ruby 1.9.3+ implementation, with improved method to calculate factorials and other common functions.
9
+ - All methods tested on several ranges. See `spec/`.
10
+ - Code for normal, Student's t and chi square is lifted from the [statistics2 gem](https://rubygems.org/gems/statistics2). Originally at [this site](http://blade.nagaokaut.ac.jp/~sinara/ruby/math/statistics2).
11
+ - The code for some functions and RNGs was lifted from Julia's [Rmath-julia](https://github.com/JuliaLang/Rmath-julia), a patched version of R's standalone math library.
12
+
13
+ The following table lists the available distributions and the methods available for each one. If a field is marked with an *x*, that distribution doesn't have that method implemented.
14
+
15
+ | Distribution | PDF | CDF | Quantile | RNG | Mean | Mode | Variance | Skewness | Kurtosis | Entropy |
16
+ | :--------------- | :-: | :-: | :------: | :-: | :--: | :--: | :------: | :------: | :------: | :-----: |
17
+ | Uniform | | | | | x | x | x | x | x | x |
18
+ | Normal | | | | | x | x | x | x | x | x |
19
+ | Lognormal | | | x | x | x | x | x | x | x | x |
20
+ | Bivariate Normal | | | x | x | x | x | x | x | x | x |
21
+ | Exponential | | | | | x | x | x | x | x | x |
22
+ | Logistic | | | | | x | x | x | x | x | x |
23
+ | Student's T | | | | x | x | x | x | x | x | x |
24
+ | Chi Square | | | | | x | x | x | x | x | x |
25
+ | Fisher-Snedecor | | | | x | x | x | x | x | x | x |
26
+ | Beta | | | | x | x | x | x | x | x | x |
27
+ | Gamma | | | x | x | x | x | x | x | x | x |
28
+ | Weibull | | | | x | x | x | x | x | x | x |
29
+ | Binomial | | | | x | x | x | x | x | x | x |
30
+ | Poisson | | | | | x | x | x | x | x | x |
31
+ | Hypergeometric | | | | x | x | x | x | x | x | x |
32
+
6
33
  ## Installation
7
34
 
8
35
  ```
9
36
  $ gem install distribution
10
37
  ```
11
38
 
12
- If you have GSL installed and want to speed things up, install `rb-gsl`:
39
+ You can install GSL for better performance:
40
+
41
+ * For Mac OS X: `brew install gsl`
42
+ * For Ubuntu / Debian: `sudo apt-get install libgsl0-dev`
43
+
44
+ After successfully installing the library:
13
45
 
14
46
  ```bash
15
47
  $ gem install rb-gsl
16
48
  ```
17
49
 
18
- ## Description
19
-
20
- Statistical Distributions library. Includes Normal univariate and bivariate, T, F, Chi Square, Binomial, Hypergeometric, Exponential, Poisson, Beta, LogNormal and Gamma.
21
-
22
- Uses Ruby by default and C (statistics2/GSL) or Java extensions where available.
23
-
24
- Includes code from statistics2 on Normal, T, F and Chi Square ruby code [http://blade.nagaokaut.ac.jp/~sinara/ruby/math/statistics2]
25
-
26
- ## Synopsis
27
-
28
- * Returns Gaussian PDF for x
29
-
30
- ```
31
- pdf=Distribution::Normal.pdf(x)
32
- ```
50
+ ## Examples
33
51
 
34
- * Returns Gaussian CDF for x
52
+ You can find automatically generated documentation on [RubyDoc](http://www.rubydoc.info/github/sciruby/distribution/master).
35
53
 
36
54
  ```
37
- cdf=Distribution::Normal.cdf(x)
38
- ```
55
+ # Returns Gaussian PDF for x.
56
+ pdf = Distribution::Normal.pdf(x)
39
57
 
40
- * Returns inverse CDF (or p-value) for x
58
+ # Returns Gaussian CDF for x.
59
+ cdf = Distribution::Normal.cdf(x)
41
60
 
42
- ```
43
- pv=Distribution::Normal.p_value(x)
44
- ```
61
+ # Returns inverse CDF (or p-value) for x.
62
+ pv = Distribution::Normal.p_value(x)
45
63
 
46
- ## Developers
64
+ # API.
47
65
 
48
- ```
49
- $ git clone https://github.com/SciRuby/distribution.git
50
- ```
66
+ # You would normally use the following
67
+ p = Distribution::T.cdf(x)
51
68
 
52
- If you want to provide a new distribution, run `lib/distribution`:
69
+ # to get the cumulative probability of `x`. However, you can also:
53
70
 
54
- ```
55
- $ distribution --new your_distribution
71
+ include Distribution::Shorthand
72
+ tdist_cdf(x)
56
73
  ```
57
74
 
58
- This should create the main distribution file, the directory with Ruby and GSL engines and specs on the spec/ directory.
59
-
60
75
  ## API Structure
61
76
 
62
- Distribution::<name>.(cdf|pdf|p_value|rng)
77
+ ```ruby
78
+ Distribution::<name>.(cdf|pdf|p_value|rng)
79
+ ```
63
80
 
64
81
  On discrete distributions, exact Ruby implementations of pdf, cdf and p_value could be provided, using
82
+
65
83
  ```
66
84
  Distribution::<name>.exact_(cdf|pdf|p_value)
67
85
  ```
86
+
68
87
  module Distribution::Shorthand provides (you guess?) shortands method to call all methods
88
+
69
89
  ```
70
90
  <Distribution shortname>_(cdf|pdf|p|r)
71
91
  ```
92
+
72
93
  On discrete distributions, exact cdf, pdf and p_value are
94
+
73
95
  ```
74
96
  <Distribution shortname>_(ecdf|epdf|ep)
75
97
  ```
98
+
76
99
  Shortnames for distributions:
77
100
 
78
101
  * Normal: norm
@@ -87,26 +110,46 @@ Shortnames for distributions:
87
110
  * Beta: beta
88
111
  * Gamma: gamma
89
112
  * LogNormal: lognormal
113
+ * Uniform: unif
90
114
 
91
- ### API Structure Example
115
+ ## Roadmap
92
116
 
93
- ```
94
- Distribution::T.cdf
95
- ```
117
+ This gem wasn't updated for a long time before I started working on it, so there are a lot of work to do. The first priority is cleaning the interface and removing cruft whenever possible. After that, I want to implement more distributions and make sure that each one has a RNG.
96
118
 
97
- could be called after including Distribution::Shorthand
119
+ ### Short-term
98
120
 
99
- ```
100
- tdist_cdf
101
- ```
121
+ - Define a minimal interface for continuous and discrete distributions (e.g. mean, variance, mode, skewness, kurtosis, pdf, cdf, quantile, cquantile).
122
+ - Implement `Distribution::Uniform` with the default Ruby `Random`.
123
+ - Clean up the implementation of normal distribution. Implement the necessary functions.
124
+ - The same for Student's t, chi square, Fisher-Snedecor, beta, gamma, lognormal, logistic.
125
+ - The same for discrete distributions: binomial, hypergeometric, bernoulli (still missing), etc.
126
+
127
+ ### Medium-term
102
128
 
103
- ## Features
129
+ - Implement [DSFMT](http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/) for the uniform random generator.
130
+ - Cauchy distribution.
104
131
 
105
- * Very fast ruby 1.8.7/1.9.+ implementation, with improved method to calculate factorials and others common functions
106
- * All methods tested on several ranges. See spec/
132
+ ### Long-term
133
+
134
+ - Implementing everything in the distributions x functions table above.
107
135
 
108
136
  ## Issues
109
137
 
110
138
  * On JRuby and Rubinius, BivariateNormal returns incorrect pdf
111
139
 
112
140
  For current issues see the [issue tracker pages](https://github.com/sciruby/distribution/issues).
141
+
142
+ ## OMG! I want to help!
143
+
144
+ Everyone is welcome to help! Please, test these distributions with your own use
145
+ cases and give a shout on the issue tracker if you find a problem or something
146
+ is strange or hard to use. Documentation pull requests are totally welcome.
147
+ More generally, any ideas or suggestions are welcome -- even by private e-mail.
148
+
149
+ If you want to provide a new distribution, run `lib/distribution`:
150
+
151
+ ```
152
+ $ distribution --new your_distribution
153
+ ```
154
+
155
+ This should create the main distribution file, the directory with Ruby and GSL engines and specs on the spec/ directory.
@@ -1,56 +1,52 @@
1
- $:.unshift(File.expand_path(File.dirname(__FILE__)+"/../lib"))
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
2
2
  require 'distribution'
3
3
  require 'bench_press'
4
4
 
5
5
  extend BenchPress
6
6
 
7
-
8
-
9
- samples=10.times.map {|i| 2**(i+1)}
7
+ samples = 10.times.map { |i| 2**(i + 1) }
10
8
 
11
9
  name 'binomial coefficient: multiplicative, factorial and optimized factorial methods'
12
10
  author 'Claudio Bustos'
13
11
  date '2011-01-27'
14
- summary "Exact calculation of Binomial Coefficient could be obtained using multiplicative, pure factorial or optimized factorial algorithm (failing + factorial).
12
+ summary "Exact calculation of Binomial Coefficient could be obtained using multiplicative, pure factorial or optimized factorial algorithm (failing + factorial).
15
13
  Which one is faster?
16
14
 
17
- Lower k is the best for all
15
+ Lower k is the best for all
18
16
  k=n/2 is the worst case.
19
17
 
20
18
  The factorial method uses the fastest Swing Prime Algorithm."
21
19
 
22
- reps 10 #number of repetitions
23
-
24
- x=100
25
-
26
- n=100
27
- k=50
20
+ reps 10 # number of repetitions
28
21
 
22
+ x = 100
29
23
 
24
+ n = 100
25
+ k = 50
30
26
 
31
- measure "Multiplicative" do
27
+ measure 'Multiplicative' do
32
28
  samples.each do |n|
33
- [5,n/2].each do |k|
34
- k=[k,n-k].min
35
- (1..k).inject(1) {|ac, i| (ac*(n-k+i).quo(i))}
29
+ [5, n / 2].each do |k|
30
+ k = [k, n - k].min
31
+ (1..k).inject(1) { |ac, i| (ac * (n - k + i).quo(i)) }
36
32
  end
37
33
  end
38
34
  end
39
35
 
40
- measure "Pure Factorial" do
36
+ measure 'Pure Factorial' do
41
37
  samples.each do |n|
42
- [5,n/2].each do |k|
43
- k=[k,n-k].min
38
+ [5, n / 2].each do |k|
39
+ k = [k, n - k].min
44
40
  Math.factorial(n).quo(Math.factorial(k) * Math.factorial(n - k))
45
41
  end
46
42
  end
47
43
  end
48
44
 
49
- measure "Failing factorial + factorial" do
45
+ measure 'Failing factorial + factorial' do
50
46
  samples.each do |n|
51
- [5,n/2].each do |k|
52
- k=[k,n-k].min
53
- (((n-k+1)..n).inject(1) {|ac,v| ac * v}).quo(Math.factorial(k))
47
+ [5, n / 2].each do |k|
48
+ k = [k, n - k].min
49
+ (((n - k + 1)..n).inject(1) { |ac, v| ac * v }).quo(Math.factorial(k))
54
50
  end
55
51
  end
56
52
  end
@@ -1,54 +1,51 @@
1
1
  # This test create a database to adjust the best algorithm
2
2
  # to use on correlation matrix
3
- $:.unshift(File.expand_path(File.dirname(__FILE__)+"/../../lib"))
3
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../../lib'))
4
4
  require 'distribution'
5
5
  require 'statsample'
6
6
  require 'benchmark'
7
7
 
8
- if !File.exists?("binomial_coefficient.ds") or File.mtime(__FILE__) > File.mtime("binomial_coefficient.ds")
9
- reps=100 #number of repetitions
10
- ns={
11
- 5=> [1,3],
12
- 10=> [1,3,5],
13
- 50=> [1,3,5,10,25],
14
- 100=> [1,3,5,10,25,50],
15
- 500=> [1,3,5,10,25,50,100,250],
16
- 1000=> [1,3,5,10,25,50,100,250,500],
17
- 5000=> [1,3,5,10,25,50,100,250,500,1000,2500],
18
- 10000=>[1,3,5,10,25,50,100,250,500,1000,2500,5000]
19
- }
20
-
21
- rs=Statsample::Dataset.new(%w{n k mixed_factorial multiplicative})
22
-
23
- ns.each do |n,ks|
24
- ks.each do |k|
25
-
26
- time_factorial= Benchmark.realtime do
27
- reps.times {
28
- (((n-k+1)..n).inject(1) {|ac,v| ac * v}).quo(Math.factorial(k))
8
+ if !File.exist?('binomial_coefficient.ds') or File.mtime(__FILE__) > File.mtime('binomial_coefficient.ds')
9
+ reps = 100 # number of repetitions
10
+ ns = {
11
+ 5 => [1, 3],
12
+ 10 => [1, 3, 5],
13
+ 50 => [1, 3, 5, 10, 25],
14
+ 100 => [1, 3, 5, 10, 25, 50],
15
+ 500 => [1, 3, 5, 10, 25, 50, 100, 250],
16
+ 1000 => [1, 3, 5, 10, 25, 50, 100, 250, 500],
17
+ 5000 => [1, 3, 5, 10, 25, 50, 100, 250, 500, 1000, 2500],
18
+ 10_000 => [1, 3, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000]
19
+ }
20
+
21
+ rs = Statsample::Dataset.new(%w(n k mixed_factorial multiplicative))
22
+
23
+ ns.each do |n, ks|
24
+ ks.each do |k|
25
+ time_factorial = Benchmark.realtime do
26
+ reps.times {
27
+ (((n - k + 1)..n).inject(1) { |ac, v| ac * v }).quo(Math.factorial(k))
29
28
  }
30
29
  end
31
-
32
- time_multiplicative= Benchmark.realtime do
33
- reps.times {
34
- (1..k).inject(1) {|ac, i| (ac*(n-k+i).quo(i))}
30
+
31
+ time_multiplicative = Benchmark.realtime do
32
+ reps.times {
33
+ (1..k).inject(1) { |ac, i| (ac * (n - k + i).quo(i)) }
35
34
  }
36
35
  end
37
-
36
+
38
37
  puts "n:#{n}, k:#{k} -> factorial:%0.3f | multiplicative: %0.3f " % [time_factorial, time_multiplicative]
39
-
40
- rs.add_case({'n'=>n,'k'=>k,'mixed_factorial'=>time_factorial, 'multiplicative'=>time_multiplicative})
38
+
39
+ rs.add_case('n' => n, 'k' => k, 'mixed_factorial' => time_factorial, 'multiplicative' => time_multiplicative)
41
40
  end
42
41
  end
43
-
42
+
44
43
  else
45
- rs=Statsample.load("binomial_coefficient.ds")
44
+ rs = Statsample.load('binomial_coefficient.ds')
46
45
  end
47
46
 
48
-
49
- rs.fields.each {|f| rs[f].type=:scale}
50
-
47
+ rs.fields.each { |f| rs[f].type = :scale }
51
48
 
52
49
  rs.update_valid_data
53
- rs.save("binomial_coefficient.ds")
54
- Statsample::Excel.write(rs,"binomial_coefficient.xls")
50
+ rs.save('binomial_coefficient.ds')
51
+ Statsample::Excel.write(rs, 'binomial_coefficient.xls')
@@ -1,4 +1,4 @@
1
- $:.unshift(File.expand_path(File.dirname(__FILE__)+"/../lib"))
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
2
2
  require 'bench_press'
3
3
  require 'distribution'
4
4
  extend BenchPress
@@ -8,17 +8,16 @@ author 'Claudio Bustos'
8
8
  date '2011-01-31'
9
9
  summary "
10
10
  Is better create a lookup table for factorial or just calculate it?
11
- Distribution::MathExtension::SwingFactorial has a lookup table
11
+ Distribution::MathExtension::SwingFactorial has a lookup table
12
12
  for factorials n<20
13
13
  "
14
14
 
15
- reps 1000 #number of repetitions
15
+ reps 1000 # number of repetitions
16
16
 
17
- measure "Lookup" do
18
- Math.factorial(19)
17
+ measure 'Lookup' do
18
+ Math.factorial(19)
19
19
  end
20
20
 
21
- measure "calculate" do
22
- Distribution::MathExtension::SwingFactorial.naive_factorial(19)
21
+ measure 'calculate' do
22
+ Distribution::MathExtension::SwingFactorial.naive_factorial(19)
23
23
  end
24
-
@@ -1,4 +1,4 @@
1
- $:.unshift(File.dirname(__FILE__)+"/../lib")
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
2
2
  require 'distribution'
3
3
  require 'bench_press'
4
4
 
@@ -10,19 +10,17 @@ date '2011-01-27'
10
10
  summary "
11
11
  Factorization requires a lot of processing, so approximation method could be required. But for greats value, bigdecimal are required and things start to get harder.
12
12
  * Approximation (fast_factorial): Luschny f.3
13
- * Exact (factorial): Luschny Swing Prime
13
+ * Exact (factorial): Luschny Swing Prime
14
14
  "
15
15
 
16
- reps 10 #number of repetitions
16
+ reps 10 # number of repetitions
17
17
 
18
- x=200
18
+ x = 200
19
19
 
20
20
  measure "Math.factorial(#{x})" do
21
21
  Math.factorial(x)
22
22
  end
23
23
 
24
24
  measure "Math.fast_factorial(#{x})" do
25
-
26
25
  Math.fast_factorial(x)
27
26
  end
28
-