Class: FeldtRuby::MinMaxMeanPerPositionArchive
- Inherits:
-
PositionBasedValueArchive
- Object
- ValueArchive
- PositionBasedValueArchive
- FeldtRuby::MinMaxMeanPerPositionArchive
- 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
-
#maxs ⇒ Object
readonly
Returns the value of attribute maxs.
-
#mins ⇒ Object
readonly
Returns the value of attribute mins.
Attributes inherited from ValueArchive
Instance Method Summary collapse
-
#initialize ⇒ MinMaxMeanPerPositionArchive
constructor
A new instance of MinMaxMeanPerPositionArchive.
-
#max_for_position(index) ⇒ Object
Return the maximum value we have seen so far in position index.
-
#mean_for_position(index) ⇒ Object
Return the maximum value we have seen so far in position index.
- #means ⇒ Object
-
#min_for_position(index) ⇒ Object
Return the minimum value we have seen so far in position index.
- #update(values) ⇒ Object
- #update_statistic_per_position(currentStatistics, values, &updateStatistic) ⇒ Object
Constructor Details
#initialize ⇒ MinMaxMeanPerPositionArchive
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
#maxs ⇒ Object (readonly)
Returns the value of attribute maxs.
29 30 31 |
# File 'lib/feldtruby/statistics/array_archive.rb', line 29 def maxs @maxs end |
#mins ⇒ Object (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 |
#means ⇒ Object
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 |