Module: Ritsudo::Result::Helper

Included in:
Uncompletable
Defined in:
lib/ritsudo/result/helper.rb

Class Method Summary collapse

Class Method Details

.mean(values) ⇒ Object



11
12
13
14
# File 'lib/ritsudo/result/helper.rb', line 11

def self.mean(values)
  sum = values.sum(0.0)
  mean = sum / values.size
end

.remove_outliters(values, stdev_multiple) ⇒ Object



4
5
6
7
8
9
# File 'lib/ritsudo/result/helper.rb', line 4

def self.remove_outliters(values, stdev_multiple)
  stdev = standard_deviation(values)
  mean = mean(values)
  range = (mean - (stdev * stdev_multiple))..(mean + (stdev * stdev_multiple))
  values.select { |v| range.cover?(v) }
end

.standard_deviation(values) ⇒ Object



21
22
23
# File 'lib/ritsudo/result/helper.rb', line 21

def self.standard_deviation(values)
  Math.sqrt(variance(values))
end

.variance(values) ⇒ Object



16
17
18
19
# File 'lib/ritsudo/result/helper.rb', line 16

def self.variance(values)
  total = values.inject(0) { |sum, v| sum + ((v - mean(values)) ** 2) }
  total.to_f / (values.size - 1)
end