Class: Quantile::Quantile
- Inherits:
-
Object
- Object
- Quantile::Quantile
- Includes:
- Comparable
- Defined in:
- lib/quantile/quantile.rb
Overview
Instance Attribute Summary collapse
-
#inaccuracy ⇒ Object
readonly
Returns the value of attribute inaccuracy.
-
#quantile ⇒ Object
readonly
Returns the value of attribute quantile.
Instance Method Summary collapse
-
#<=>(other) ⇒ Fixnum
Compare the given other quantile.
- #delta(rank, n) ⇒ Object
-
#initialize(quantile, inaccuracy) ⇒ Quantile
constructor
Create a known quantile estimator invariant.
Constructor Details
#initialize(quantile, inaccuracy) ⇒ Quantile
Create a known quantile estimator invariant.
39 40 41 42 43 44 45 |
# 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 |
Instance Attribute Details
#inaccuracy ⇒ Object (readonly)
Returns the value of attribute inaccuracy.
24 25 26 |
# File 'lib/quantile/quantile.rb', line 24 def inaccuracy @inaccuracy end |
#quantile ⇒ Object (readonly)
Returns the value of attribute quantile.
23 24 25 |
# File 'lib/quantile/quantile.rb', line 23 def quantile @quantile end |
Instance Method Details
#<=>(other) ⇒ Fixnum
Compare the given other quantile.
is less than, equal to, or greater than self. This is the basis for the tests in Comparable.
62 63 64 |
# File 'lib/quantile/quantile.rb', line 62 def <=>(other) self.quantile <=> other.quantile && self.inaccuracy <=> other.inaccuracy end |
#delta(rank, n) ⇒ Object
47 48 49 50 51 52 53 |
# 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 |