class Axiom::Aggregate::Mean

The mean of a sequence of numbers

Constants

DEFAULT

Public Class Methods

call(accumulator, value) click to toggle source

Return the count and mean for a sequence of numbers

@example

count, mean = Mean.call([count, mean], value)

@param [Array(Integer, Numeric)] accumulator

@param [Numeric] value

@return [Array(Integer, Rational)]

@api public

# File lib/axiom/aggregate/mean.rb, line 23
def self.call(accumulator, value)
  return accumulator if value.nil?
  count, mean = accumulator
  count       = Count.call(count, value)
  [count, mean ? Rational(value - mean, count) + mean : value.to_r]
end
finalize(accumulator) click to toggle source

Extract the mean from the accumulator

@example

mean = Mean.finalize(accumulator)

@param [Array(Integer, Numeric)] accumulator

@return [Float]

returned for a non-empty set

@return [nil]

returned for an empty set

@api public

# File lib/axiom/aggregate/mean.rb, line 43
def self.finalize(accumulator)
  mean = accumulator.last
  mean.to_f if mean
end
type() click to toggle source

Return the type returned from call

@example

type = Axiom::Aggregate::Mean.type  # => Axiom::Types::Float

@return [Class<Types::Float>]

@api public

# File lib/axiom/aggregate/mean.rb, line 56
def self.type
  Types::Float
end