class Chao92::Estimator

Estimator

Used to estimate the total number of species

A minimal usage could be:

Chao92::Estimator.run(samples) # => the estimator of the samples

Public Class Methods

new() click to toggle source
# File lib/chao92/estimator.rb, line 13
def initialize
  @samples = []
  @observed = {}
  @ff = {}
end
run(samples) click to toggle source
# File lib/chao92/estimator.rb, line 19
def self.run(samples)
  Estimator.new.sampling(samples)
end

Public Instance Methods

sampling(samples) click to toggle source
# File lib/chao92/estimator.rb, line 23
def sampling(samples)
  @samples += samples
  update()
  estimate()
  @N
end
show() click to toggle source

Show the samples

# File lib/chao92/estimator.rb, line 32
def show
  @samples
end

Private Instance Methods

estimate() click to toggle source
# File lib/chao92/estimator.rb, line 42
def estimate
  @turing_estimator = if @ff[1] 
                        1 - @ff[1].to_f / @samples.size 
                      else         
                        1      
                      end

  @N1 = @observed.size / @turing_estimator

  tmp = 0.0
  tmp = @samples.size.times do |x| 
    tmp += x * (x - 1) * @ff[x] if @ff[x]
  end

  @cv_estimator = [@N1 * tmp / (@samples.size.to_f * (@samples.size - 1).to_f - 1), 0.0].max

  @N = @N1 + @samples.size * (1 - @turing_estimator) / @turing_estimator * @cv_estimator
end
update() click to toggle source
# File lib/chao92/estimator.rb, line 37
def update
  @observed = @samples.to_hash
  @ff = @observed.to_inverse
end