Sha256: 617ba0c6258d9790c77dbeb399eee22826d9a4e5b077dc95ee10d38fe338e531
Contents?: true
Size: 616 Bytes
Versions: 5
Compression:
Stored size: 616 Bytes
Contents
class Palette module Statistics begin require "enumerable/statistics" def self.mean(enum) enum.mean end def self.stdev(enum, population: false) enum.stdev(population: population) end rescue LoadError def self.mean(enum) xs = enum.to_a xs.sum / xs.length.to_f end def self.stdev(enum, population: false) xs = enum.to_a n = xs.length mean = xs.sum.to_f / n ddof = population ? 0 : 1 var = xs.map {|x| (x - mean)**2 }.sum / (n - ddof) Math.sqrt(var) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems