Sha256: 8df7d36cf3d2c6dbad03ff86fe3812c12885d41e161857890320c97b8615ab0f

Contents?: true

Size: 580 Bytes

Versions: 5

Compression:

Stored size: 580 Bytes

Contents

module Misc

  Log2Multiplier = 1.0 / Math.log(2.0)
  def self.log2(x)
    Math.log(x) * Log2Multiplier
  end

  def self.max(list)
    max = nil
    list.each do |v|
      next if v.nil?
      max = v if max.nil? or v > max
    end
    max
  end

  def self.sum(list)
    list.compact.inject(0.0){|acc,e| acc += e}
  end

  def self.mean(list)
    sum(list) / list.compact.length
  end

  def self.sd(list)
    return nil if list.length < 3
    mean = mean(list)
    Math.sqrt(list.compact.inject(0.0){|acc,e| d = e - mean; acc += d * d}) / (list.compact.length - 1)
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rbbt-util-5.11.9 lib/rbbt/util/misc/math.rb
rbbt-util-5.11.8 lib/rbbt/util/misc/math.rb
rbbt-util-5.11.7 lib/rbbt/util/misc/math.rb
rbbt-util-5.11.6 lib/rbbt/util/misc/math.rb
rbbt-util-5.11.5 lib/rbbt/util/misc/math.rb