Sha256: 50cdcf68fe2cb05f0a9adbc97d3f1ffb2a74fbfd3ee843a8a6fe8e5d6daae3c9

Contents?: true

Size: 733 Bytes

Versions: 3

Compression:

Stored size: 733 Bytes

Contents

module RubyStatistics
  module Distribution
    class Uniform
      attr_accessor :left, :right

      def initialize(a, b)
        self.left = a.to_r
        self.right = b.to_r
      end

      def density_function(value)
        if value >= left && value <= right
          1/(right - left)
        else
          0
        end
      end

      def cumulative_function(value)
        if value < left
          0
        elsif value >= left && value <= right
          (value - left)/(right - left)
        else
          1
        end
      end

      def mean
        (1/2.0) * ( left + right )
      end
      alias_method :median, :mean


      def variance
        (1/12.0) * ( right - left ) ** 2
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby-statistics-4.1.0 lib/ruby-statistics/distribution/uniform.rb
ruby-statistics-4.0.1 lib/ruby-statistics/distribution/uniform.rb
ruby-statistics-4.0.0 lib/ruby-statistics/distribution/uniform.rb