Class: StatisticalMethods::Computer

Inherits:
Object
  • Object
show all
Defined in:
lib/statistical_methods/computer.rb

Overview

Calculation class

Instance Method Summary collapse

Constructor Details

#initializeComputer

Returns a new instance of Computer.



4
5
6
7
8
# File 'lib/statistical_methods/computer.rb', line 4

def initialize
  @average = StatisticalMethods::SummaryStatistic::Location::Average
  @median = StatisticalMethods::SummaryStatistic::Location::Median
  @mode = StatisticalMethods::SummaryStatistic::Location::Mode
end

Instance Method Details

#geometric_mean(array) ⇒ Object



46
47
48
# File 'lib/statistical_methods/computer.rb', line 46

def geometric_mean(array)
  @average.new(array).geometric_mean
end

#harmonic_mean(array) ⇒ Object



42
43
44
# File 'lib/statistical_methods/computer.rb', line 42

def harmonic_mean(array)
  @average.new(array).harmonic_mean
end

#leader(array) ⇒ Object



63
64
65
# File 'lib/statistical_methods/computer.rb', line 63

def leader(array)
  Leader.new(array).find
end

#max(array) ⇒ Object



22
23
24
# File 'lib/statistical_methods/computer.rb', line 22

def max(array)
  array.max
end

#mean(array) ⇒ Object



14
15
16
# File 'lib/statistical_methods/computer.rb', line 14

def mean(array)
  @average.new(array).arithmetic_mean
end

#median(array) ⇒ Object



38
39
40
# File 'lib/statistical_methods/computer.rb', line 38

def median(array)
  @median.new(array).find
end

#min(array) ⇒ Object



18
19
20
# File 'lib/statistical_methods/computer.rb', line 18

def min(array)
  array.min
end

#mode(array) ⇒ Object



51
52
53
# File 'lib/statistical_methods/computer.rb', line 51

def mode(array)
  @mode.new(array).find
end

#power_mean(array, exponent) ⇒ Object



59
60
61
# File 'lib/statistical_methods/computer.rb', line 59

def power_mean(array, exponent)
  @average.new(array).power_mean(exponent)
end

#quadratic_mean(array) ⇒ Object



55
56
57
# File 'lib/statistical_methods/computer.rb', line 55

def quadratic_mean(array)
  @average.new(array).quadratic_mean
end

#standard_deviation(array) ⇒ Object



33
34
35
# File 'lib/statistical_methods/computer.rb', line 33

def standard_deviation(array)
  Math.sqrt(variance array)
end

#sum(array) ⇒ Object



10
11
12
# File 'lib/statistical_methods/computer.rb', line 10

def sum(array)
  array.addition
end

#variance(array) ⇒ Object



27
28
29
30
# File 'lib/statistical_methods/computer.rb', line 27

def variance(array)
  arithmetic_mean = mean(array)
  mean(array.map { |value| (arithmetic_mean - value)**2 })
end