class Quantile::Quantile

A known quantile rank invariant for {Estimator}.

@note {Quantile} is concurrency-safe.

Attributes

inaccuracy[R]
quantile[R]

Public Class Methods

new(quantile, inaccuracy) click to toggle source

Create a known quantile estimator invariant.

@param quantile [Float] The target quantile value expressed along the

interval [0, 1].  For instance, 0.5, would
generate a precomputed median value and 0.99
would provide the 99th percentile.

@param inaccuracy [Float] The target error allowance expressed along the

interval [0, 1].  For instance, 0.05 sets an
error allowance of 5 percent and 0.001 of 0.1
percent.

@return [Quantile] an initialized {Quantile} for the given targets.

# File lib/quantile/quantile.rb, line 39
def initialize(quantile, inaccuracy)
  @quantile = quantile
  @inaccuracy = inaccuracy

  @coefficient_i  = (2.0 * inaccuracy) / (1.0 - quantile)
  @coefficient_ii = 2.0 * inaccuracy / quantile
end

Public Instance Methods

<=>(other) click to toggle source

Compare the given other quantile.

@return [Fixnum] -1, 0, +1 or nil depending on whether the other quantile is less than, equal to, or greater than self. This is the basis for the tests in Comparable.

# File lib/quantile/quantile.rb, line 62
def <=>(other)
  self.quantile <=> other.quantile && self.inaccuracy <=> other.inaccuracy
end
delta(rank, n) click to toggle source
# File lib/quantile/quantile.rb, line 47
def delta(rank, n)
  if rank <= (@quantile * n).floor
    return @coefficient_i * (n - rank)
  end

  return @coefficient_ii * rank
end