Class: DRbDump::Statistic
- Inherits:
-
Object
- Object
- DRbDump::Statistic
- Defined in:
- lib/drbdump/statistic.rb
Overview
Stores the minimum, maximum, mean, count and standard deviation for a set of values but not the values themselves.
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
The number of items in the set.
-
#max ⇒ Object
(also: #maximum)
readonly
The maximum value added.
-
#mean ⇒ Object
(also: #average)
readonly
The mean of all values.
-
#min ⇒ Object
(also: #minimum)
readonly
The minimum value added.
Instance Method Summary collapse
-
#add(value) ⇒ Object
Adds
value
to the set of values. -
#initialize ⇒ Statistic
constructor
:nodoc:.
-
#sample_variance ⇒ Object
The sample variance for all values.
-
#standard_deviation ⇒ Object
The standard deviation of all values.
-
#to_a ⇒ Object
An array containing the number of values in the set, the mean and the standard deviation.
Constructor Details
#initialize ⇒ Statistic
:nodoc:
27 28 29 30 31 32 33 |
# File 'lib/drbdump/statistic.rb', line 27 def initialize # :nodoc: @M_2 = 0.0 @count = 0 @max = -Float::INFINITY @mean = 0.0 @min = Float::INFINITY end |
Instance Attribute Details
#count ⇒ Object (readonly)
The number of items in the set
10 11 12 |
# File 'lib/drbdump/statistic.rb', line 10 def count @count end |
#max ⇒ Object (readonly) Also known as: maximum
The maximum value added
15 16 17 |
# File 'lib/drbdump/statistic.rb', line 15 def max @max end |
#mean ⇒ Object (readonly) Also known as: average
The mean of all values
20 21 22 |
# File 'lib/drbdump/statistic.rb', line 20 def mean @mean end |
#min ⇒ Object (readonly) Also known as: minimum
The minimum value added
25 26 27 |
# File 'lib/drbdump/statistic.rb', line 25 def min @min end |
Instance Method Details
#add(value) ⇒ Object
Adds value
to the set of values. Returns the number of values.
38 39 40 41 42 43 44 45 46 47 48 |
# 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 |
#sample_variance ⇒ Object
The sample variance for all values
68 69 70 71 72 |
# File 'lib/drbdump/statistic.rb', line 68 def sample_variance sv = @M_2 / (@count - 1) return 0.0 if sv.nan? sv end |
#standard_deviation ⇒ Object
The standard deviation of all values
77 78 79 |
# File 'lib/drbdump/statistic.rb', line 77 def standard_deviation Math.sqrt sample_variance end |
#to_a ⇒ Object
An array containing the number of values in the set, the mean and the standard deviation
85 86 87 |
# File 'lib/drbdump/statistic.rb', line 85 def to_a [@count, @min, @mean, @max, standard_deviation] end |