Class: ExoBasic::DecayingAvg
- Inherits:
-
Object
- Object
- ExoBasic::DecayingAvg
- Includes:
- AvgTraits
- Defined in:
- lib/exobasic/stats/decaying_avg.rb
Constant Summary collapse
- DEFAULT_D =
12
Instance Attribute Summary collapse
-
#avg ⇒ Object
readonly
Returns the value of attribute avg.
-
#d ⇒ Object
Returns the value of attribute d.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(d = DEFAULT_D) ⇒ DecayingAvg
constructor
A new instance of DecayingAvg.
- #offer(x) ⇒ Object
Methods included from AvgTraits
#approx=, #count, #deep_copy, #maximum, #minimum, #offer_many
Constructor Details
#initialize(d = DEFAULT_D) ⇒ DecayingAvg
Returns a new instance of DecayingAvg.
9 10 11 12 13 |
# File 'lib/exobasic/stats/decaying_avg.rb', line 9 def initialize(d=DEFAULT_D) @d = d <= 0 ? DEFAULT_D : d @avg = 0.0 @meta = AvgMeta.new end |
Instance Attribute Details
#avg ⇒ Object (readonly)
Returns the value of attribute avg.
5 6 7 |
# File 'lib/exobasic/stats/decaying_avg.rb', line 5 def avg @avg end |
#d ⇒ Object
Returns the value of attribute d.
5 6 7 |
# File 'lib/exobasic/stats/decaying_avg.rb', line 5 def d @d end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
5 6 7 |
# File 'lib/exobasic/stats/decaying_avg.rb', line 5 def @meta end |
Instance Method Details
#==(other) ⇒ Object
26 27 28 29 30 |
# File 'lib/exobasic/stats/decaying_avg.rb', line 26 def ==(other) @d == other.d && StatsHelpers.double_equals(@avg, other.avg) && @meta == other. end |
#offer(x) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/exobasic/stats/decaying_avg.rb', line 19 def offer(x) @meta = @meta.offer(x, @avg, d) d_prime = @d.to_f @avg = x / d_prime + (d_prime - 1.0) * @avg / d_prime end |