lib/postrunner/LinearPredictor.rb in postrunner-0.8.1 vs lib/postrunner/LinearPredictor.rb in postrunner-0.9.0

- old
+ new

@@ -16,24 +16,26 @@ # average of past values to predict the next value. class LinearPredictor # Create a new LinearPredictor object. # @param n [Fixnum] The number of coefficients the predictor should use. - def initialize(n, default = nil) - @values = Array.new(n, default) + def initialize(n) + @values = [] @size = n @next = nil end # Tell the predictor about the actual next value. # @param value [Float] next value def insert(value) @values << value - if @values.length > @size + if @values.length >= @size @values.shift - @next = @values.reduce(:+) / @size end + + @next = @values.reduce(:+) / @values.size + $stderr.puts "insert(#{value}) next: #{@next}" end # @return [Float] The predicted value of the next sample. def predict @next