Class: PostRunner::LinearPredictor
- Inherits:
-
Object
- Object
- PostRunner::LinearPredictor
- Defined in:
- lib/postrunner/LinearPredictor.rb
Overview
For now we use a trivial adaptive linear predictor that just uses the average of past values to predict the next value.
Instance Method Summary collapse
-
#initialize(n) ⇒ LinearPredictor
constructor
Create a new LinearPredictor object.
-
#insert(value) ⇒ Object
Tell the predictor about the actual next value.
-
#predict ⇒ Float
The predicted value of the next sample.
Constructor Details
#initialize(n) ⇒ LinearPredictor
Create a new LinearPredictor object.
21 22 23 24 25 |
# File 'lib/postrunner/LinearPredictor.rb', line 21 def initialize(n) @values = [] @size = n @next = nil end |
Instance Method Details
#insert(value) ⇒ Object
Tell the predictor about the actual next value.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/postrunner/LinearPredictor.rb', line 29 def insert(value) @values << value if @values.length >= @size @values.shift end @next = @values.reduce(:+) / @values.size $stderr.puts "insert(#{value}) next: #{@next}" end |
#predict ⇒ Float
Returns The predicted value of the next sample.
41 42 43 |
# File 'lib/postrunner/LinearPredictor.rb', line 41 def predict @next end |