Sha256: 63acc0030461d8e890f76c89502434bc473478c2ac8e86f339618e1d433d0346
Contents?: true
Size: 1.84 KB
Versions: 1
Compression:
Stored size: 1.84 KB
Contents
# encoding: utf-8 module Axiom class Aggregate # The mean of a sequence of numbers class Mean < Aggregate DEFAULT = [0, nil].freeze # 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, Numeric)] # # @api public 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 : Rational(value)] end # 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 def self.finalize(accumulator) accumulator.last end # Return the type returned from #call # # @example # type = Axiom::Aggregate::Mean.type # => Axiom::Types::Float # # @return [Class<Types::Float>] # # @api public def self.type Types::Float end module Methods extend Aliasable inheritable_alias( average: :mean, avg: :mean ) # Return a mean aggregate function # # @example # mean = attribute.mean # # @param [Attribute] # # @return [Mean] # # @api public def mean Mean.new(self) end end # module Methods end # class Mean end # class Aggregate end # module Axiom
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
axiom-0.1.1 | lib/axiom/aggregate/mean.rb |