Class: SClust::Util::WeightedMovingAverage
- Inherits:
-
Object
- Object
- SClust::Util::WeightedMovingAverage
- Defined in:
- lib/sclust/util/weightedmovingaverage.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
-
#weight ⇒ Object
Returns the value of attribute weight.
Instance Method Summary collapse
- #adjust(value) ⇒ Object
-
#initialize(weight, initial_value = 0.0) ⇒ WeightedMovingAverage
constructor
A new instance of WeightedMovingAverage.
Constructor Details
#initialize(weight, initial_value = 0.0) ⇒ WeightedMovingAverage
Returns a new instance of WeightedMovingAverage.
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
#value ⇒ Object
Returns the value of attribute value.
8 9 10 |
# File 'lib/sclust/util/weightedmovingaverage.rb', line 8 def value @value end |
#weight ⇒ Object
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 |