Class: SClust::Util::WeightedMovingAverage

Inherits:
Object
  • Object
show all
Defined in:
lib/sclust/util/weightedmovingaverage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(weight, initial_value = 0.0) ⇒ WeightedMovingAverage

Returns a new instance of WeightedMovingAverage.

Raises:

  • (Exception)


11
12
13
14
15
16
17
18
# File 'lib/sclust/util/weightedmovingaverage.rb', line 11

def initialize(weight, initial_value = 0.0)
    
    raise Exception.new("Weight was #{weight} but must be between 0.0 and 1.0.") if ( weight > 1 or weight < 0)
    
    @weight = weight
    @weight_compliment = 1.0-weight
    @value  = initial_value
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



8
9
10
# File 'lib/sclust/util/weightedmovingaverage.rb', line 8

def value
  @value
end

#weightObject

Returns the value of attribute weight.



8
9
10
# File 'lib/sclust/util/weightedmovingaverage.rb', line 8

def weight
  @weight
end

Instance Method Details

#adjust(value) ⇒ Object



20
21
22
# File 'lib/sclust/util/weightedmovingaverage.rb', line 20

def adjust(value)
    @value = ( @weight_compliment*@value ) + ( @weight * value )
end