Sha256: 0f8d42e389b62b6b55e52f8747337247a9c41717c2820527285b2162ebf524b9

Contents?: true

Size: 1.34 KB

Versions: 4

Compression:

Stored size: 1.34 KB

Contents

# encoding: utf-8

module Veritas
  class Aggregate

    # The standard deviation of a sequence of numbers
    class StandardDeviation < Variance

      # Calculate the standard deviation from the accumulator
      #
      # @example
      #   standard_deviation = StandardDeviation.finalize(accumulator)
      #
      # @param [Array(Numeric, Integer, Numeric)] accumulator
      #
      # @return [Float]
      #   returned for a non-empty set
      # @return [nil]
      #   returned for an empty set
      #
      # @api public
      def self.finalize(*)
        variance = super
        Math.sqrt(variance) if variance
      end

      # Return the type returned from #call
      #
      # @return [Class<Attribute::Float>]
      #
      # @api public
      def type
        Attribute::Float
      end

      module Methods
        extend Aliasable

        inheritable_alias(:stddev => :standard_deviation)

        # Return a standard deviation aggregate function
        #
        # @example
        #   standard_deviation = attribute.standard_deviation
        #
        # @param [Attribute]
        #
        # @return [StandardDeviation]
        #
        # @api public
        def standard_deviation
          StandardDeviation.new(self)
        end

      end # module Methods
    end # class StandardDeviation
  end # class Aggregate
end # module Veritas

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
veritas-0.0.7 lib/veritas/aggregate/standard_deviation.rb
veritas-0.0.6 lib/veritas/aggregate/standard_deviation.rb
veritas-0.0.5 lib/veritas/aggregate/standard_deviation.rb
veritas-0.0.4 lib/veritas/aggregate/standard_deviation.rb