Class: ExoBasic::DecayingAvg

Inherits:
Object
  • Object
show all
Includes:
AvgTraits
Defined in:
lib/exobasic/stats/decaying_avg.rb

Constant Summary collapse

DEFAULT_D =
12

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#avgObject (readonly)

Returns the value of attribute avg.



5
6
7
# File 'lib/exobasic/stats/decaying_avg.rb', line 5

def avg
  @avg
end

#dObject

Returns the value of attribute d.



5
6
7
# File 'lib/exobasic/stats/decaying_avg.rb', line 5

def d
  @d
end

#metaObject (readonly)

Returns the value of attribute meta.



5
6
7
# File 'lib/exobasic/stats/decaying_avg.rb', line 5

def meta
  @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.meta
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