Sha256: 4a3c64af3e1083185e74ff46ce3047b26f32e4275ee9bb3f5cedb6cae61533d1

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'fathom'))
module Fathom  
  module NumericMethods
    # def initialize(opts={})
    #   super(opts)
    # end
    
    def rand
      return nil unless vector
      distribution.rand(sd) + mean
    end
    
    def vector
      return @vector if @vector
      return nil unless values
      case values
      when Array
        @vector = GSL::Vector.ary_to_gv(values)
      when GSL::Vector
        @vector = values
      end
    end
    
    def standard_deviation
      return nil unless vector
      vector.sd
    end
    alias :std :standard_deviation
    alias :sd :standard_deviation

    def mean
      return nil unless vector
      vector.mean
    end
    
    def inverse_cdf(opts={})
      distribution.inverse_cdf(opts.merge(:mean => mean, :sd => sd))
    end
    alias :lower_bound :inverse_cdf

    def upper_bound(opts={})
      distribution.upper_bound(opts.merge(:mean => mean, :sd => sd))
    end

    def interval_values(opts={})
      distribution.interval_values(opts.merge(:mean => mean, :sd => sd))
    end
    
    def coefficient_of_variation
      return nil unless vector
      vector.sd / vector.mean
    end
    alias :cov :coefficient_of_variation
    
    def summary
      {
        :mean => mean,
        :standard_deviation => standard_deviation,
        :min => vector ? vector.min : nil,
        :max => vector ? vector.max : nil,
        :lower_bound => lower_bound,
        :upper_bound => upper_bound,
        :coefficient_of_variation => coefficient_of_variation
      }
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fathom-0.3.2 lib/fathom/node/node_extensions/numeric_methods.rb