class DRbDump::Statistic

Stores the minimum, maximum, mean, count and standard deviation for a set of values but not the values themselves.

Attributes

average[R]

The mean of all values

count[R]

The number of items in the set

max[R]

The maximum value added

maximum[R]

The maximum value added

mean[R]

The mean of all values

min[R]

The minimum value added

minimum[R]

The minimum value added

Public Instance Methods

add(value) click to toggle source

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
sample_variance() click to toggle source

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
standard_deviation() click to toggle source

The standard deviation of all values

# File lib/drbdump/statistic.rb, line 77
def standard_deviation
  Math.sqrt sample_variance
end
to_a() click to toggle source

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