class PostRunner::LinearPredictor
For now we use a trivial adaptive linear predictor that just uses the average of past values to predict the next value.
Public Class Methods
new(n)
click to toggle source
Create a new LinearPredictor
object. @param n [Fixnum] The number of coefficients the predictor should use.
# File lib/postrunner/LinearPredictor.rb, line 21 def initialize(n) @values = [] @size = n @next = nil end
Public Instance Methods
insert(value)
click to toggle source
Tell the predictor about the actual next value. @param value [Float] next value
# 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()
click to toggle source
@return [Float] The predicted value of the next sample.
# File lib/postrunner/LinearPredictor.rb, line 41 def predict @next end