Sha256: de96f38f4f69d4508f52780767ec718e0c4cb758ca5bd5859e55f8add7912879

Contents?: true

Size: 789 Bytes

Versions: 2

Compression:

Stored size: 789 Bytes

Contents

module MovingAvg
  class Evaluator
    class << self
      def error_sum(training_items:, teacher_items:, window_size:, strategy:)
        errors = self.errors(
          training_items: training_items,
          teacher_items: teacher_items,
          window_size: window_size,
          strategy: strategy,
        )
        errors.
          select { |x| !x.nan? }.
          reduce(0) { |x, y| x + y }
      end

      def errors(training_items:, teacher_items:, window_size:, strategy:)
        trained = MovingAvg::Helper.build_with_sliding(
          items: training_items,
          window_size: window_size,
          strategy: strategy,
        )
        trained.zip(teacher_items).map { |trained, teacher|
          (trained - teacher).abs
        }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
moving_avg-0.2.2 lib/moving_avg/evaluator.rb
moving_avg-0.2.1 lib/moving_avg/evaluator.rb