Stores the minimum, maximum, mean, count and standard deviation for a set of values but not the values themselves.
The mean of all values
The number of items in the set
The maximum value added
The maximum value added
The mean of all values
The minimum value added
The minimum value added
Adds value
to the set of values. Returns the number of
values.
# File lib/drbdump/statistic.rb, line 38 def add value @min = value if value < @min @max = value if value > @max @count += 1 delta = value - @mean @mean += delta / @count @M_2 += delta * (value - @mean) @count end
The sample variance for all values
# File lib/drbdump/statistic.rb, line 68 def sample_variance sv = @M_2 / (@count - 1) return 0.0 if sv.nan? sv end
The standard deviation of all values
# File lib/drbdump/statistic.rb, line 77 def standard_deviation Math.sqrt sample_variance end
An array containing the number of values in the set, the mean and the standard deviation
# File lib/drbdump/statistic.rb, line 85 def to_a [@count, @min, @mean, @max, standard_deviation] end