Module: FeldtRuby::Normalization

Included in:
Array
Defined in:
lib/feldtruby/statistics/normalization.rb

Overview

The normalization methods assumes the existence of basic statistics on the class it they are included in:

z_normalize: require mean and stdev

Instance Method Summary collapse

Instance Method Details

#min_max_normalizeObject



16
17
18
19
20
21
# File 'lib/feldtruby/statistics/normalization.rb', line 16

def min_max_normalize
  return [] if self.length == 0
  min = self.min.to_f
  range = self.max - min
  self.map {|e| (e-min)/range}
end

#normalize(&transform) ⇒ Object



7
8
9
# File 'lib/feldtruby/statistics/normalization.rb', line 7

def normalize(&transform)
  self.map {|v| transform.call(v)}
end

#z_normalizeObject



11
12
13
14
# File 'lib/feldtruby/statistics/normalization.rb', line 11

def z_normalize
  mean, stdev = self.mean, self.sd
  self.map {|e| (e-mean)/stdev}
end