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
@@ -2,17 +2,19 @@ module Distribution
2
2
  module LogNormal
3
3
  module GSL_
4
4
  class << self
5
- def pdf(x,u,s)
6
- GSL::Ran::lognormal_pdf(x.to_f, u.to_f, s.to_f)
5
+ def pdf(x, u, s)
6
+ GSL::Ran.lognormal_pdf(x.to_f, u.to_f, s.to_f)
7
7
  end
8
8
 
9
- def p_value(pr,u,s)
10
- GSL::Cdf::lognormal_Pinv(pr.to_f, u.to_f, s.to_f)
9
+ def cdf(x, u, s)
10
+ GSL::Cdf.lognormal_P(x.to_f, u.to_f, s.to_f)
11
11
  end
12
12
 
13
- def cdf(x,u,s)
14
- GSL::Cdf::lognormal_P(x.to_f, u.to_f, s.to_f)
13
+ def quantile(pr, u, s)
14
+ GSL::Cdf.lognormal_Pinv(pr.to_f, u.to_f, s.to_f)
15
15
  end
16
+
17
+ alias_method :p_value, :quantile
16
18
  end
17
19
  end
18
20
  end
@@ -2,17 +2,13 @@ module Distribution
2
2
  module LogNormal
3
3
  module Ruby_
4
4
  class << self
5
-
6
- def pdf(x,u,s)
7
- raise "x should be > 0 " if x < 0
8
- (1.0/(x*s*Math.sqrt(2*Math::PI)))*Math.exp(-((Math.log(x)-u)**2 / (2*s**2)))
5
+ def pdf(x, u, s)
6
+ fail 'x should be > 0 ' if x < 0
7
+ (1.0 / (x * s * Math.sqrt(2 * Math::PI))) * Math.exp(-((Math.log(x) - u)**2 / (2 * s**2)))
9
8
  end
10
9
 
11
- #def p_value(pr,u,s)
12
- #end
13
-
14
- def cdf(x,u,s)
15
- Distribution::Normal.cdf((Math.log(x)-u) / s)
10
+ def cdf(x, u, s)
11
+ Distribution::Normal.cdf((Math.log(x) - u) / s)
16
12
  end
17
13
  end
18
14
  end
@@ -14,16 +14,13 @@ require 'distribution/math_extension/incomplete_beta'
14
14
  require 'distribution/math_extension/log_utilities'
15
15
 
16
16
  module Distribution
17
-
18
17
  # Useful additions to Math
19
18
  module MathExtension
20
-
21
19
  # Factorization based on Prime Swing algorithm, by Luschny (the king of factorial numbers analysis :P )
22
20
  # == Reference
23
21
  # * The Homepage of Factorial Algorithms. (C) Peter Luschny, 2000-2010
24
22
  # == URL: http://www.luschny.de/math/factorial/csharp/FactorialPrimeSwing.cs.html
25
23
  class SwingFactorial
26
-
27
24
  SmallOddSwing = [1, 1, 1, 3, 3, 15, 5, 35, 35, 315, 63, 693, 231, 3003,
28
25
  429, 6435, 6435, 109_395, 12_155, 230_945, 46_189,
29
26
  969_969, 88_179, 2_028_117, 676_039, 16_900_975,
@@ -76,9 +73,7 @@ module Distribution
76
73
  _p = 1
77
74
 
78
75
  while (q = (q / prime).truncate) > 0
79
- if q.odd?
80
- _p *= prime
81
- end
76
+ _p *= prime if q.odd?
82
77
  end
83
78
  if _p > 1
84
79
  @prime_list[count] = _p
@@ -119,7 +114,6 @@ module Distribution
119
114
  # == Reference
120
115
  # * http://www.luschny.de/math/factorial/approx/SimpleCases.html
121
116
  module ApproxFactorial
122
-
123
117
  class << self
124
118
  def stieltjes_ln_factorial(z)
125
119
  a0 = 1.quo(12); a1 = 1.quo(30); a2 = 53.quo(210); a3 = 195.quo(371)
@@ -147,9 +141,7 @@ module Distribution
147
141
  y = x
148
142
  _p = 1
149
143
 
150
- while y < 8
151
- _p *= y; y += 1
152
- end
144
+ _p *= y; y += 1 while y < 8
153
145
 
154
146
  lr = stieltjes_ln_factorial(y)
155
147
  r = Math.exp(lr)
@@ -219,7 +211,6 @@ module Distribution
219
211
  end
220
212
  end
221
213
 
222
-
223
214
  # Incomplete beta function: B(x;a,b)
224
215
  # +a+ and +b+ are parameters and +x+ is
225
216
  # integration upper limit.
@@ -330,8 +321,8 @@ end
330
321
  module CMath # :nodoc:
331
322
  include Distribution::MathExtension
332
323
  module_function :factorial, :beta, :loggamma, :unnormalized_incomplete_gamma,
333
- :incomplete_gamma, :gammp, :gammq, :erfc_e, :binomial_coefficient,
334
- :binomial_coefficient_gamma, :incomplete_beta, :exact_regularized_beta,
335
- :regularized_beta, :permutations, :rising_factorial, :fast_factorial,
336
- :combinations, :logbeta, :lbeta
324
+ :incomplete_gamma, :gammp, :gammq, :erfc_e, :binomial_coefficient,
325
+ :binomial_coefficient_gamma, :incomplete_beta, :exact_regularized_beta,
326
+ :regularized_beta, :permutations, :rising_factorial, :fast_factorial,
327
+ :combinations, :logbeta, :lbeta
337
328
  end
@@ -5,352 +5,352 @@ module Distribution
5
5
  module MathExtension
6
6
  # Adapted from GSL-1.9.
7
7
  class ChebyshevSeries
8
- DATA = {:lopx => [ 2.16647910664395270521272590407,
9
- -0.28565398551049742084877469679,
10
- 0.01517767255690553732382488171,
11
- -0.00200215904941415466274422081,
12
- 0.00019211375164056698287947962,
13
- -0.00002553258886105542567601400,
14
- 2.9004512660400621301999384544e-06,
15
- -3.8873813517057343800270917900e-07,
16
- 4.7743678729400456026672697926e-08,
17
- -6.4501969776090319441714445454e-09,
18
- 8.2751976628812389601561347296e-10,
19
- -1.1260499376492049411710290413e-10,
20
- 1.4844576692270934446023686322e-11,
21
- -2.0328515972462118942821556033e-12,
22
- 2.7291231220549214896095654769e-13,
23
- -3.7581977830387938294437434651e-14,
24
- 5.1107345870861673561462339876e-15,
25
- -7.0722150011433276578323272272e-16,
26
- 9.7089758328248469219003866867e-17,
27
- -1.3492637457521938883731579510e-17,
28
- 1.8657327910677296608121390705e-18 ],
29
- :lopxmx => [ -1.12100231323744103373737274541,
30
- 0.19553462773379386241549597019,
31
- -0.01467470453808083971825344956,
32
- 0.00166678250474365477643629067,
33
- -0.00018543356147700369785746902,
34
- 0.00002280154021771635036301071,
35
- -2.8031253116633521699214134172e-06,
36
- 3.5936568872522162983669541401e-07,
37
- -4.6241857041062060284381167925e-08,
38
- 6.0822637459403991012451054971e-09,
39
- -8.0339824424815790302621320732e-10,
40
- 1.0751718277499375044851551587e-10,
41
- -1.4445310914224613448759230882e-11,
42
- 1.9573912180610336168921438426e-12,
43
- -2.6614436796793061741564104510e-13,
44
- 3.6402634315269586532158344584e-14,
45
- -4.9937495922755006545809120531e-15,
46
- 6.8802890218846809524646902703e-16,
47
- -9.5034129794804273611403251480e-17,
48
- 1.3170135013050997157326965813e-17],
49
- :gstar_a => [ 2.16786447866463034423060819465,
50
- -0.05533249018745584258035832802,
51
- 0.01800392431460719960888319748,
52
- -0.00580919269468937714480019814,
53
- 0.00186523689488400339978881560,
54
- -0.00059746524113955531852595159,
55
- 0.00019125169907783353925426722,
56
- -0.00006124996546944685735909697,
57
- 0.00001963889633130842586440945,
58
- -6.3067741254637180272515795142e-06,
59
- 2.0288698405861392526872789863e-06,
60
- -6.5384896660838465981983750582e-07,
61
- 2.1108698058908865476480734911e-07,
62
- -6.8260714912274941677892994580e-08,
63
- 2.2108560875880560555583978510e-08,
64
- -7.1710331930255456643627187187e-09,
65
- 2.3290892983985406754602564745e-09,
66
- -7.5740371598505586754890405359e-10,
67
- 2.4658267222594334398525312084e-10,
68
- -8.0362243171659883803428749516e-11,
69
- 2.6215616826341594653521346229e-11,
70
- -8.5596155025948750540420068109e-12,
71
- 2.7970831499487963614315315444e-12,
72
- -9.1471771211886202805502562414e-13,
73
- 2.9934720198063397094916415927e-13,
74
- -9.8026575909753445931073620469e-14,
75
- 3.2116773667767153777571410671e-14,
76
- -1.0518035333878147029650507254e-14,
77
- 3.4144405720185253938994854173e-15,
78
- -1.0115153943081187052322643819e-15 ],
79
- :gstar_b => [ 0.0057502277273114339831606096782,
80
- 0.0004496689534965685038254147807,
81
- -0.0001672763153188717308905047405,
82
- 0.0000615137014913154794776670946,
83
- -0.0000223726551711525016380862195,
84
- 8.0507405356647954540694800545e-06,
85
- -2.8671077107583395569766746448e-06,
86
- 1.0106727053742747568362254106e-06,
87
- -3.5265558477595061262310873482e-07,
88
- 1.2179216046419401193247254591e-07,
89
- -4.1619640180795366971160162267e-08,
90
- 1.4066283500795206892487241294e-08,
91
- -4.6982570380537099016106141654e-09,
92
- 1.5491248664620612686423108936e-09,
93
- -5.0340936319394885789686867772e-10,
94
- 1.6084448673736032249959475006e-10,
95
- -5.0349733196835456497619787559e-11,
96
- 1.5357154939762136997591808461e-11,
97
- -4.5233809655775649997667176224e-12,
98
- 1.2664429179254447281068538964e-12,
99
- -3.2648287937449326771785041692e-13,
100
- 7.1528272726086133795579071407e-14,
101
- -9.4831735252566034505739531258e-15,
102
- -2.3124001991413207293120906691e-15,
103
- 2.8406613277170391482590129474e-15,
104
- -1.7245370321618816421281770927e-15,
105
- 8.6507923128671112154695006592e-16,
106
- -3.9506563665427555895391869919e-16,
107
- 1.6779342132074761078792361165e-16,
108
- -6.0483153034414765129837716260e-17 ],
109
- :e11 => [ -16.11346165557149402600,
110
- 7.79407277874268027690,
8
+ DATA = { lopx: [2.16647910664395270521272590407,
9
+ -0.28565398551049742084877469679,
10
+ 0.01517767255690553732382488171,
11
+ -0.00200215904941415466274422081,
12
+ 0.00019211375164056698287947962,
13
+ -0.00002553258886105542567601400,
14
+ 2.9004512660400621301999384544e-06,
15
+ -3.8873813517057343800270917900e-07,
16
+ 4.7743678729400456026672697926e-08,
17
+ -6.4501969776090319441714445454e-09,
18
+ 8.2751976628812389601561347296e-10,
19
+ -1.1260499376492049411710290413e-10,
20
+ 1.4844576692270934446023686322e-11,
21
+ -2.0328515972462118942821556033e-12,
22
+ 2.7291231220549214896095654769e-13,
23
+ -3.7581977830387938294437434651e-14,
24
+ 5.1107345870861673561462339876e-15,
25
+ -7.0722150011433276578323272272e-16,
26
+ 9.7089758328248469219003866867e-17,
27
+ -1.3492637457521938883731579510e-17,
28
+ 1.8657327910677296608121390705e-18],
29
+ lopxmx: [-1.12100231323744103373737274541,
30
+ 0.19553462773379386241549597019,
31
+ -0.01467470453808083971825344956,
32
+ 0.00166678250474365477643629067,
33
+ -0.00018543356147700369785746902,
34
+ 0.00002280154021771635036301071,
35
+ -2.8031253116633521699214134172e-06,
36
+ 3.5936568872522162983669541401e-07,
37
+ -4.6241857041062060284381167925e-08,
38
+ 6.0822637459403991012451054971e-09,
39
+ -8.0339824424815790302621320732e-10,
40
+ 1.0751718277499375044851551587e-10,
41
+ -1.4445310914224613448759230882e-11,
42
+ 1.9573912180610336168921438426e-12,
43
+ -2.6614436796793061741564104510e-13,
44
+ 3.6402634315269586532158344584e-14,
45
+ -4.9937495922755006545809120531e-15,
46
+ 6.8802890218846809524646902703e-16,
47
+ -9.5034129794804273611403251480e-17,
48
+ 1.3170135013050997157326965813e-17],
49
+ gstar_a: [2.16786447866463034423060819465,
50
+ -0.05533249018745584258035832802,
51
+ 0.01800392431460719960888319748,
52
+ -0.00580919269468937714480019814,
53
+ 0.00186523689488400339978881560,
54
+ -0.00059746524113955531852595159,
55
+ 0.00019125169907783353925426722,
56
+ -0.00006124996546944685735909697,
57
+ 0.00001963889633130842586440945,
58
+ -6.3067741254637180272515795142e-06,
59
+ 2.0288698405861392526872789863e-06,
60
+ -6.5384896660838465981983750582e-07,
61
+ 2.1108698058908865476480734911e-07,
62
+ -6.8260714912274941677892994580e-08,
63
+ 2.2108560875880560555583978510e-08,
64
+ -7.1710331930255456643627187187e-09,
65
+ 2.3290892983985406754602564745e-09,
66
+ -7.5740371598505586754890405359e-10,
67
+ 2.4658267222594334398525312084e-10,
68
+ -8.0362243171659883803428749516e-11,
69
+ 2.6215616826341594653521346229e-11,
70
+ -8.5596155025948750540420068109e-12,
71
+ 2.7970831499487963614315315444e-12,
72
+ -9.1471771211886202805502562414e-13,
73
+ 2.9934720198063397094916415927e-13,
74
+ -9.8026575909753445931073620469e-14,
75
+ 3.2116773667767153777571410671e-14,
76
+ -1.0518035333878147029650507254e-14,
77
+ 3.4144405720185253938994854173e-15,
78
+ -1.0115153943081187052322643819e-15],
79
+ gstar_b: [0.0057502277273114339831606096782,
80
+ 0.0004496689534965685038254147807,
81
+ -0.0001672763153188717308905047405,
82
+ 0.0000615137014913154794776670946,
83
+ -0.0000223726551711525016380862195,
84
+ 8.0507405356647954540694800545e-06,
85
+ -2.8671077107583395569766746448e-06,
86
+ 1.0106727053742747568362254106e-06,
87
+ -3.5265558477595061262310873482e-07,
88
+ 1.2179216046419401193247254591e-07,
89
+ -4.1619640180795366971160162267e-08,
90
+ 1.4066283500795206892487241294e-08,
91
+ -4.6982570380537099016106141654e-09,
92
+ 1.5491248664620612686423108936e-09,
93
+ -5.0340936319394885789686867772e-10,
94
+ 1.6084448673736032249959475006e-10,
95
+ -5.0349733196835456497619787559e-11,
96
+ 1.5357154939762136997591808461e-11,
97
+ -4.5233809655775649997667176224e-12,
98
+ 1.2664429179254447281068538964e-12,
99
+ -3.2648287937449326771785041692e-13,
100
+ 7.1528272726086133795579071407e-14,
101
+ -9.4831735252566034505739531258e-15,
102
+ -2.3124001991413207293120906691e-15,
103
+ 2.8406613277170391482590129474e-15,
104
+ -1.7245370321618816421281770927e-15,
105
+ 8.6507923128671112154695006592e-16,
106
+ -3.9506563665427555895391869919e-16,
107
+ 1.6779342132074761078792361165e-16,
108
+ -6.0483153034414765129837716260e-17],
109
+ e11: [-16.11346165557149402600,
110
+ 7.79407277874268027690,
111
111
  -1.95540581886314195070,
112
- 0.37337293866277945612,
112
+ 0.37337293866277945612,
113
113
  -0.05692503191092901938,
114
- 0.00721107776966009185,
114
+ 0.00721107776966009185,
115
115
  -0.00078104901449841593,
116
- 0.00007388093356262168,
116
+ 0.00007388093356262168,
117
117
  -0.00000620286187580820,
118
- 0.00000046816002303176,
118
+ 0.00000046816002303176,
119
119
  -0.00000003209288853329,
120
- 0.00000000201519974874,
120
+ 0.00000000201519974874,
121
121
  -0.00000000011673686816,
122
- 0.00000000000627627066,
122
+ 0.00000000000627627066,
123
123
  -0.00000000000031481541,
124
- 0.00000000000001479904,
124
+ 0.00000000000001479904,
125
125
  -0.00000000000000065457,
126
- 0.00000000000000002733,
126
+ 0.00000000000000002733,
127
127
  -0.00000000000000000108],
128
- :e12 => [ -0.03739021479220279500,
129
- 0.04272398606220957700,
130
- -0.13031820798497005440,
131
- 0.01441912402469889073,
132
- -0.00134617078051068022,
133
- 0.00010731029253063780,
134
- -0.00000742999951611943,
135
- 0.00000045377325690753,
136
- -0.00000002476417211390,
137
- 0.00000000122076581374,
138
- -0.00000000005485141480,
139
- 0.00000000000226362142,
140
- -0.00000000000008635897,
141
- 0.00000000000000306291,
142
- -0.00000000000000010148,
143
- 0.00000000000000000315 ],
144
- :ae11 => [ 0.121503239716065790,
128
+ e12: [-0.03739021479220279500,
129
+ 0.04272398606220957700,
130
+ -0.13031820798497005440,
131
+ 0.01441912402469889073,
132
+ -0.00134617078051068022,
133
+ 0.00010731029253063780,
134
+ -0.00000742999951611943,
135
+ 0.00000045377325690753,
136
+ -0.00000002476417211390,
137
+ 0.00000000122076581374,
138
+ -0.00000000005485141480,
139
+ 0.00000000000226362142,
140
+ -0.00000000000008635897,
141
+ 0.00000000000000306291,
142
+ -0.00000000000000010148,
143
+ 0.00000000000000000315],
144
+ ae11: [0.121503239716065790,
145
145
  -0.065088778513550150,
146
- 0.004897651357459670,
146
+ 0.004897651357459670,
147
147
  -0.000649237843027216,
148
- 0.000093840434587471,
149
- 0.000000420236380882,
148
+ 0.000093840434587471,
149
+ 0.000000420236380882,
150
150
  -0.000008113374735904,
151
- 0.000002804247688663,
152
- 0.000000056487164441,
151
+ 0.000002804247688663,
152
+ 0.000000056487164441,
153
153
  -0.000000344809174450,
154
- 0.000000058209273578,
155
- 0.000000038711426349,
154
+ 0.000000058209273578,
155
+ 0.000000038711426349,
156
156
  -0.000000012453235014,
157
157
  -0.000000005118504888,
158
- 0.000000002148771527,
159
- 0.000000000868459898,
158
+ 0.000000002148771527,
159
+ 0.000000000868459898,
160
160
  -0.000000000343650105,
161
161
  -0.000000000179796603,
162
- 0.000000000047442060,
163
- 0.000000000040423282,
162
+ 0.000000000047442060,
163
+ 0.000000000040423282,
164
164
  -0.000000000003543928,
165
165
  -0.000000000008853444,
166
166
  -0.000000000000960151,
167
- 0.000000000001692921,
168
- 0.000000000000607990,
167
+ 0.000000000001692921,
168
+ 0.000000000000607990,
169
169
  -0.000000000000224338,
170
170
  -0.000000000000200327,
171
171
  -0.000000000000006246,
172
- 0.000000000000045571,
173
- 0.000000000000016383,
172
+ 0.000000000000045571,
173
+ 0.000000000000016383,
174
174
  -0.000000000000005561,
175
175
  -0.000000000000006074,
176
176
  -0.000000000000000862,
177
- 0.000000000000001223,
178
- 0.000000000000000716,
177
+ 0.000000000000001223,
178
+ 0.000000000000000716,
179
179
  -0.000000000000000024,
180
180
  -0.000000000000000201,
181
181
  -0.000000000000000082,
182
- 0.000000000000000017],
183
- :ae12 => [ 0.582417495134726740,
182
+ 0.000000000000000017],
183
+ ae12: [0.582417495134726740,
184
184
  -0.158348850905782750,
185
185
  -0.006764275590323141,
186
- 0.005125843950185725,
187
- 0.000435232492169391,
186
+ 0.005125843950185725,
187
+ 0.000435232492169391,
188
188
  -0.000143613366305483,
189
189
  -0.000041801320556301,
190
190
  -0.000002713395758640,
191
- 0.000001151381913647,
192
- 0.000000420650022012,
193
- 0.000000066581901391,
194
- 0.000000000662143777,
191
+ 0.000001151381913647,
192
+ 0.000000420650022012,
193
+ 0.000000066581901391,
194
+ 0.000000000662143777,
195
195
  -0.000000002844104870,
196
196
  -0.000000000940724197,
197
197
  -0.000000000177476602,
198
198
  -0.000000000015830222,
199
- 0.000000000002905732,
200
- 0.000000000001769356,
201
- 0.000000000000492735,
202
- 0.000000000000093709,
203
- 0.000000000000010707,
199
+ 0.000000000002905732,
200
+ 0.000000000001769356,
201
+ 0.000000000000492735,
202
+ 0.000000000000093709,
203
+ 0.000000000000010707,
204
204
  -0.000000000000000537,
205
205
  -0.000000000000000716,
206
206
  -0.000000000000000244,
207
207
  -0.000000000000000058],
208
- :ae13 => [ -0.605773246640603460,
208
+ ae13: [-0.605773246640603460,
209
209
  -0.112535243483660900,
210
- 0.013432266247902779,
210
+ 0.013432266247902779,
211
211
  -0.001926845187381145,
212
- 0.000309118337720603,
212
+ 0.000309118337720603,
213
213
  -0.000053564132129618,
214
- 0.000009827812880247,
214
+ 0.000009827812880247,
215
215
  -0.000001885368984916,
216
- 0.000000374943193568,
216
+ 0.000000374943193568,
217
217
  -0.000000076823455870,
218
- 0.000000016143270567,
218
+ 0.000000016143270567,
219
219
  -0.000000003466802211,
220
- 0.000000000758754209,
220
+ 0.000000000758754209,
221
221
  -0.000000000168864333,
222
- 0.000000000038145706,
222
+ 0.000000000038145706,
223
223
  -0.000000000008733026,
224
- 0.000000000002023672,
224
+ 0.000000000002023672,
225
225
  -0.000000000000474132,
226
- 0.000000000000112211,
226
+ 0.000000000000112211,
227
227
  -0.000000000000026804,
228
- 0.000000000000006457,
228
+ 0.000000000000006457,
229
229
  -0.000000000000001568,
230
- 0.000000000000000383,
230
+ 0.000000000000000383,
231
231
  -0.000000000000000094,
232
- 0.000000000000000023],
233
- :ae14 => [ -0.18929180007530170,
232
+ 0.000000000000000023],
233
+ ae14: [-0.18929180007530170,
234
234
  -0.08648117855259871,
235
- 0.00722410154374659,
235
+ 0.00722410154374659,
236
236
  -0.00080975594575573,
237
- 0.00010999134432661,
237
+ 0.00010999134432661,
238
238
  -0.00001717332998937,
239
- 0.00000298562751447,
239
+ 0.00000298562751447,
240
240
  -0.00000056596491457,
241
- 0.00000011526808397,
241
+ 0.00000011526808397,
242
242
  -0.00000002495030440,
243
- 0.00000000569232420,
243
+ 0.00000000569232420,
244
244
  -0.00000000135995766,
245
- 0.00000000033846628,
245
+ 0.00000000033846628,
246
246
  -0.00000000008737853,
247
- 0.00000000002331588,
247
+ 0.00000000002331588,
248
248
  -0.00000000000641148,
249
- 0.00000000000181224,
249
+ 0.00000000000181224,
250
250
  -0.00000000000052538,
251
- 0.00000000000015592,
251
+ 0.00000000000015592,
252
252
  -0.00000000000004729,
253
- 0.00000000000001463,
253
+ 0.00000000000001463,
254
254
  -0.00000000000000461,
255
- 0.00000000000000148,
255
+ 0.00000000000000148,
256
256
  -0.00000000000000048,
257
- 0.00000000000000016,
257
+ 0.00000000000000016,
258
258
  -0.00000000000000005],
259
- :erfc_xlt1 => [ 1.06073416421769980345174155056,
259
+ erfc_xlt1: [1.06073416421769980345174155056,
260
260
  -0.42582445804381043569204735291,
261
- 0.04955262679620434040357683080,
262
- 0.00449293488768382749558001242,
261
+ 0.04955262679620434040357683080,
262
+ 0.00449293488768382749558001242,
263
263
  -0.00129194104658496953494224761,
264
264
  -0.00001836389292149396270416979,
265
- 0.00002211114704099526291538556,
265
+ 0.00002211114704099526291538556,
266
266
  -5.23337485234257134673693179020e-7,
267
267
  -2.78184788833537885382530989578e-7,
268
- 1.41158092748813114560316684249e-8,
269
- 2.72571296330561699984539141865e-9,
268
+ 1.41158092748813114560316684249e-8,
269
+ 2.72571296330561699984539141865e-9,
270
270
  -2.06343904872070629406401492476e-10,
271
271
  -2.14273991996785367924201401812e-11,
272
- 2.22990255539358204580285098119e-12,
273
- 1.36250074650698280575807934155e-13,
272
+ 2.22990255539358204580285098119e-12,
273
+ 1.36250074650698280575807934155e-13,
274
274
  -1.95144010922293091898995913038e-14,
275
275
  -6.85627169231704599442806370690e-16,
276
- 1.44506492869699938239521607493e-16,
277
- 2.45935306460536488037576200030e-18,
278
- -9.29599561220523396007359328540e-19 ],
279
- :erfc_x15 => [ 0.44045832024338111077637466616,
280
- -0.143958836762168335790826895326,
276
+ 1.44506492869699938239521607493e-16,
277
+ 2.45935306460536488037576200030e-18,
278
+ -9.29599561220523396007359328540e-19],
279
+ erfc_x15: [0.44045832024338111077637466616,
280
+ -0.143958836762168335790826895326,
281
281
  0.044786499817939267247056666937,
282
- -0.013343124200271211203618353102,
282
+ -0.013343124200271211203618353102,
283
283
  0.003824682739750469767692372556,
284
- -0.001058699227195126547306482530,
284
+ -0.001058699227195126547306482530,
285
285
  0.000283859419210073742736310108,
286
- -0.000073906170662206760483959432,
286
+ -0.000073906170662206760483959432,
287
287
  0.000018725312521489179015872934,
288
- -4.62530981164919445131297264430e-6,
288
+ -4.62530981164919445131297264430e-6,
289
289
  1.11558657244432857487884006422e-6,
290
- -2.63098662650834130067808832725e-7,
290
+ -2.63098662650834130067808832725e-7,
291
291
  6.07462122724551777372119408710e-8,
292
- -1.37460865539865444777251011793e-8,
292
+ -1.37460865539865444777251011793e-8,
293
293
  3.05157051905475145520096717210e-9,
294
- -6.65174789720310713757307724790e-10,
294
+ -6.65174789720310713757307724790e-10,
295
295
  1.42483346273207784489792999706e-10,
296
- -3.00141127395323902092018744545e-11,
296
+ -3.00141127395323902092018744545e-11,
297
297
  6.22171792645348091472914001250e-12,
298
- -1.26994639225668496876152836555e-12,
298
+ -1.26994639225668496876152836555e-12,
299
299
  2.55385883033257575402681845385e-13,
300
- -5.06258237507038698392265499770e-14,
300
+ -5.06258237507038698392265499770e-14,
301
301
  9.89705409478327321641264227110e-15,
302
- -1.90685978789192181051961024995e-15,
303
- 3.50826648032737849245113757340e-16 ],
304
- :erfc_x510 => [ 1.11684990123545698684297865808,
305
- 0.003736240359381998520654927536,
306
- -0.000916623948045470238763619870,
307
- 0.000199094325044940833965078819,
308
- -0.000040276384918650072591781859,
309
- 7.76515264697061049477127605790e-6,
310
- -1.44464794206689070402099225301e-6,
311
- 2.61311930343463958393485241947e-7,
312
- -4.61833026634844152345304095560e-8,
313
- 8.00253111512943601598732144340e-9,
314
- -1.36291114862793031395712122089e-9,
315
- 2.28570483090160869607683087722e-10,
316
- -3.78022521563251805044056974560e-11,
317
- 6.17253683874528285729910462130e-12,
318
- -9.96019290955316888445830597430e-13,
319
- 1.58953143706980770269506726000e-13,
320
- -2.51045971047162509999527428316e-14,
321
- 3.92607828989125810013581287560e-15,
322
- -6.07970619384160374392535453420e-16,
323
- 9.12600607264794717315507477670e-17 ],
324
- :sin => [ -0.3295190160663511504173,
302
+ -1.90685978789192181051961024995e-15,
303
+ 3.50826648032737849245113757340e-16],
304
+ erfc_x510: [1.11684990123545698684297865808,
305
+ 0.003736240359381998520654927536,
306
+ -0.000916623948045470238763619870,
307
+ 0.000199094325044940833965078819,
308
+ -0.000040276384918650072591781859,
309
+ 7.76515264697061049477127605790e-6,
310
+ -1.44464794206689070402099225301e-6,
311
+ 2.61311930343463958393485241947e-7,
312
+ -4.61833026634844152345304095560e-8,
313
+ 8.00253111512943601598732144340e-9,
314
+ -1.36291114862793031395712122089e-9,
315
+ 2.28570483090160869607683087722e-10,
316
+ -3.78022521563251805044056974560e-11,
317
+ 6.17253683874528285729910462130e-12,
318
+ -9.96019290955316888445830597430e-13,
319
+ 1.58953143706980770269506726000e-13,
320
+ -2.51045971047162509999527428316e-14,
321
+ 3.92607828989125810013581287560e-15,
322
+ -6.07970619384160374392535453420e-16,
323
+ 9.12600607264794717315507477670e-17],
324
+ sin: [-0.3295190160663511504173,
325
325
  0.0025374284671667991990,
326
326
  0.0006261928782647355874,
327
- -4.6495547521854042157541e-06,
328
- -5.6917531549379706526677e-07,
327
+ -4.6495547521854042157541e-06,
328
+ -5.6917531549379706526677e-07,
329
329
  3.7283335140973803627866e-09,
330
330
  3.0267376484747473727186e-10,
331
- -1.7400875016436622322022e-12,
332
- -1.0554678305790849834462e-13,
331
+ -1.7400875016436622322022e-12,
332
+ -1.0554678305790849834462e-13,
333
333
  5.3701981409132410797062e-16,
334
334
  2.5984137983099020336115e-17,
335
- -1.1821555255364833468288e-19],
335
+ -1.1821555255364833468288e-19]
336
336
  }
337
337
 
338
- PARAMS = {
339
- :lopx => [20, -1, 1, 10],
340
- :lopxmx => [19, -1, 1, 9],
341
- :gstar_a => [29, -1, 1, 17],
342
- :gstar_b => [29, -1, 1, 18],
343
- :e11 => [18, -1, 1, 13],
344
- :e12 => [15, -1, 1, 10],
345
- :ae11 => [38, -1, 1, 20],
346
- :ae12 => [24, -1, 1, 15],
347
- :ae13 => [24, -1, 1, 15],
348
- :ae14 => [25, -1, 1, 13],
349
- :erfc_xlt1 => [19, -1, 1, 12],
350
- :erfc_x15 => [24, -1, 1, 16],
351
- :erfc_x510 => [19, -1, 1, 12],
352
- :sin => [11, -1, 1, 11]
353
- }
338
+ PARAMS = {
339
+ lopx: [20, -1, 1, 10],
340
+ lopxmx: [19, -1, 1, 9],
341
+ gstar_a: [29, -1, 1, 17],
342
+ gstar_b: [29, -1, 1, 18],
343
+ e11: [18, -1, 1, 13],
344
+ e12: [15, -1, 1, 10],
345
+ ae11: [38, -1, 1, 20],
346
+ ae12: [24, -1, 1, 15],
347
+ ae13: [24, -1, 1, 15],
348
+ ae14: [25, -1, 1, 13],
349
+ erfc_xlt1: [19, -1, 1, 12],
350
+ erfc_x15: [24, -1, 1, 16],
351
+ erfc_x510: [19, -1, 1, 12],
352
+ sin: [11, -1, 1, 11]
353
+ }
354
354
 
355
355
  def initialize(coefficients, expansion_order, lower_interval_point, upper_interval_point, single_precision_order)
356
356
  @c = coefficients.is_a?(Symbol) ? DATA[coefficients] : coefficients
@@ -359,53 +359,62 @@ module Distribution
359
359
  @upper_interval_point = upper_interval_point
360
360
  @single_precision_order = single_precision_order
361
361
  end
362
- #double * c; /* coefficients */
363
- #int order; /* order of expansion */
364
- #double a; /* lower interval point */
365
- #double b; /* upper interval point */
366
- #int order_sp; /* effective single precision order */
362
+ # double * c; /* coefficients */
363
+ # int order; /* order of expansion */
364
+ # double a; /* lower interval point */
365
+ # double b; /* upper interval point */
366
+ # int order_sp; /* effective single precision order */
367
367
 
368
368
  attr_reader :lower_interval_point, :upper_interval_point, :single_precision_order, :order, :c
369
- def a; @lower_interval_point; end
370
- def b; @upper_interval_point; end
371
- def order_sp; @single_precision_order; end
372
- def coefficients(idx); @c[idx]; end
369
+ def a
370
+ @lower_interval_point
371
+ end
372
+
373
+ def b
374
+ @upper_interval_point
375
+ end
376
+
377
+ def order_sp
378
+ @single_precision_order
379
+ end
380
+
381
+ def coefficients(idx)
382
+ @c[idx]
383
+ end
373
384
 
374
385
  class << self
375
386
  # cheb_eval_e in specfunc/cheb_eval.c (gsl-1.9)
376
- def evaluate series, x, with_error = false
387
+ def evaluate(series, x, with_error = false)
377
388
  cs = Math.const_get "#{series.to_s.upcase}_CS"
378
- raise(ArgumentError, "Unrecognized series #{series.to_s}") if cs.nil?
389
+ fail(ArgumentError, "Unrecognized series #{series}") if cs.nil?
379
390
 
380
391
  d = 0.0
381
392
  dd = 0.0
382
- y = (2*x - cs.a - cs.b).quo(cs.b - cs.a)
383
- y2 = 2*y
393
+ y = (2 * x - cs.a - cs.b).quo(cs.b - cs.a)
394
+ y2 = 2 * y
384
395
 
385
396
  e = 0.0
386
397
 
387
398
  cs.order.downto(1) do |j|
388
399
  temp = d
389
- d = y2*d - dd + cs.c[j]
390
- e += (y2*temp).abs + dd.abs + cs.c[j].abs
400
+ d = y2 * d - dd + cs.c[j]
401
+ e += (y2 * temp).abs + dd.abs + cs.c[j].abs
391
402
  dd = temp
392
403
  end
393
404
 
394
405
  begin
395
406
  temp = d
396
- d = y*d - dd + 0.5 * cs.c[0]
397
- e += (y*temp).abs + dd.abs + 0.5*cs.c[0].abs
407
+ d = y * d - dd + 0.5 * cs.c[0]
408
+ e += (y * temp).abs + dd.abs + 0.5 * cs.c[0].abs
398
409
  end
399
410
 
400
- with_error ? [d, Float::EPSILON*e + (cs.c[cs.order])] : d
411
+ with_error ? [d, Float::EPSILON * e + (cs.c[cs.order])] : d
401
412
  end
402
413
  end
403
-
404
414
  end
405
415
 
406
416
  ChebyshevSeries::DATA.keys.each do |series|
407
417
  Math.const_set "#{series.to_s.upcase}_CS", ChebyshevSeries.new(series, *(ChebyshevSeries::PARAMS[series]))
408
418
  end
409
-
410
419
  end
411
- end
420
+ end