Sha256: d8f0607e5affe82125821d684f3f199de3eabd6aacc5d435ea83ea15e15e1ad9

Contents?: true

Size: 628 Bytes

Versions: 2

Compression:

Stored size: 628 Bytes

Contents

module Uranai
  class FittingParameter
    attr_reader :params
    alias :values :params

    def initialize(params)
      @params = params
    end

    def predict(input_data)
      check(input_data) do
        params
          .zip(input_data.insert(0, 1))
          .map { |n1,n2| n1 * n2 }
          .reduce(:+)
      end
    end

    private

    def check(data)
      raise "input data must be Array" unless data.kind_of?(Array)
      raise "input data size must be equal to feature size (#{feature_size})" if data.length != feature_size
      yield
    end

    def feature_size
      params.length - 1
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
uranai-0.1.1 lib/uranai/fitting_parameter.rb
uranai-0.1.0 lib/uranai/fitting_parameter.rb