Sha256: eeac5a371277e18c01deba703588f1e5e556e95f4441cb1335c6d8ab88e31eca

Contents?: true

Size: 1.13 KB

Versions: 15

Compression:

Stored size: 1.13 KB

Contents

#!/usr/bin/env ruby -w
# encoding: UTF-8
#
# = LinearPredictor.rb -- PostRunner - Manage the data from your Garmin sport devices.
#
# Copyright (c) 2015 by Chris Schlaeger <cs@taskjuggler.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#

module PostRunner

  # For now we use a trivial adaptive linear predictor that just uses the
  # 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)
      @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
        @values.shift
        @next = @values.reduce(:+) / @size
      end
    end

    # @return [Float] The predicted value of the next sample.
    def predict
      @next
    end

  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
postrunner-0.8.1 lib/postrunner/LinearPredictor.rb
postrunner-0.8.0 lib/postrunner/LinearPredictor.rb
postrunner-0.7.5 lib/postrunner/LinearPredictor.rb
postrunner-0.7.4 lib/postrunner/LinearPredictor.rb
postrunner-0.7.3 lib/postrunner/LinearPredictor.rb
postrunner-0.7.2 lib/postrunner/LinearPredictor.rb
postrunner-0.7.1 lib/postrunner/LinearPredictor.rb
postrunner-0.7.0 lib/postrunner/LinearPredictor.rb
postrunner-0.6.0 lib/postrunner/LinearPredictor.rb
postrunner-0.5.0 lib/postrunner/LinearPredictor.rb
postrunner-0.4.0 lib/postrunner/LinearPredictor.rb
postrunner-0.3.0 lib/postrunner/LinearPredictor.rb
postrunner-0.2.1 lib/postrunner/LinearPredictor.rb
postrunner-0.2.0 lib/postrunner/LinearPredictor.rb
postrunner-0.1.0 lib/postrunner/LinearPredictor.rb