Class: FeldtRuby::MinMaxMeanPerPositionArchive

Inherits:
PositionBasedValueArchive show all
Defined in:
lib/feldtruby/statistics/array_archive.rb

Overview

A MinMaxAveragePerPositionArchive keeps the min, max and average values for each position in the supplied arrays. It can thus be used for min-max-normalization of values in each position.

Instance Attribute Summary collapse

Attributes inherited from ValueArchive

#count

Instance Method Summary collapse

Constructor Details

#initializeMinMaxMeanPerPositionArchive

Returns a new instance of MinMaxMeanPerPositionArchive.



31
32
33
34
# File 'lib/feldtruby/statistics/array_archive.rb', line 31

def initialize
  super
  @mins, @maxs, @sums = [], [], []
end

Instance Attribute Details

#maxsObject (readonly)

Returns the value of attribute maxs.



29
30
31
# File 'lib/feldtruby/statistics/array_archive.rb', line 29

def maxs
  @maxs
end

#minsObject (readonly)

Returns the value of attribute mins.



29
30
31
# File 'lib/feldtruby/statistics/array_archive.rb', line 29

def mins
  @mins
end

Instance Method Details

#max_for_position(index) ⇒ Object

Return the maximum value we have seen so far in position index.



52
53
54
# File 'lib/feldtruby/statistics/array_archive.rb', line 52

def max_for_position(index)
  @maxs[index]
end

#mean_for_position(index) ⇒ Object

Return the maximum value we have seen so far in position index.



57
58
59
# File 'lib/feldtruby/statistics/array_archive.rb', line 57

def mean_for_position(index)
  (@sums[index] / @count.to_f) if @sums[index]
end

#meansObject



61
62
63
# File 'lib/feldtruby/statistics/array_archive.rb', line 61

def means
  @sums.map {|v| v/@count.to_f}
end

#min_for_position(index) ⇒ Object

Return the minimum value we have seen so far in position index.



47
48
49
# File 'lib/feldtruby/statistics/array_archive.rb', line 47

def min_for_position(index)
  @mins[index]
end

#update(values) ⇒ Object



35
36
37
38
39
40
# File 'lib/feldtruby/statistics/array_archive.rb', line 35

def update(values)
  super
  @mins = update_statistic_per_position(@mins, values) {|newold| newold.compact.min}
  @maxs = update_statistic_per_position(@maxs, values) {|newold| newold.compact.max}
  @sums = update_statistic_per_position(@sums, values) {|newold| newold.compact.sum}
end

#update_statistic_per_position(currentStatistics, values, &updateStatistic) ⇒ Object



42
43
44
# File 'lib/feldtruby/statistics/array_archive.rb', line 42

def update_statistic_per_position(currentStatistics, values, &updateStatistic)
  values.zip(currentStatistics).map {|newold| updateStatistic.call(newold)}
end