ruby-numo / numo-gsl

GSL interface for Ruby/Numo::NArray
GNU General Public License v3.0
20 stars 8 forks source link

GSL::Ran negative_binomial method not found #6

Closed kojix2 closed 6 years ago

kojix2 commented 6 years ago

Hello!

I attempted to use Numo :: GSL :: Ran.negative_binomial. First, I searched for a yard document. But I can not find the method. Next, I searched source code . I think it seems to be implemented here. https://github.com/ruby-numo/numo-gsl/blob/d91e93c0f4e0d224aef490f854cca9c66dc4fadc/ext/numo/gsl/ran/func_2.3.rb#L1404

sample code

require 'numo/gsl'
a = Numo::GSL::Rng::Rand.new
p (a.methods - Object.methods).sort

output:

[:bernoulli, :beta, :binomial, :bivariate_gaussian, :cauchy, :chisq, :dir_2d, 
:dir_2d_trig_method, :dir_3d, :dirichlet, :exponential, :exppow, :fdist, :flat, 
:gamma, :gamma_knuth, :gaussian, :gaussian_ratio_method, :gaussian_tail, 
:gaussian_ziggurat, :geometric, :get, :gumbel1, :gumbel2, :hypergeometric, 
:landau, :laplace, :levy, :logarithmic, :logistic, :lognormal, :max, :memcpy, 
:min, :multinomial, :pareto, :pascal, :poisson, :rayleigh, :rayleigh_tail, :set, 
:size, :tdist, :ugaussian, :ugaussian_ratio_method, :ugaussian_tail, :uniform, 
:uniform_int, :uniform_pos, :weibull]

negative_binomial is not here. Are there any hints?

system:

masa16 commented 6 years ago

fixed in https://github.com/ruby-numo/numo-gsl/commit/d859ace4a1ff9841cd78081f089d80a018fef61c

kojix2 commented 6 years ago

Thank you very much!

require 'numo/gsl'
require 'numo/gnuplot'
require 'histogram/array'

g = Numo::GSL::Rng::Mt19937.new
data = g.negative_binomial(0.5,3.5,10000).to_a
bins, freq = data.histogram(20)
bins.map!{|b| b.round(2).to_s}

Numo.gnuplot do
  set term: 'png font "IPA Mincho"'
  set out: "out.png"
  set title:"負の二項分布"
  set style:[:fill, :solid, {border:-1}]
  set xtics:["rotate by": -45]
  plot bins, freq, u:"2:xtic(1)", w: :boxes, lc:{rgb:"orange"}, t:"p=0.3, n=3.5"
end

out