Class: Silicium::Regression::PolynomialRegressionByGradientDescent

Inherits:
Object
  • Object
show all
Defined in:
lib/regression.rb

Overview

Finds parameters as array [1..n] for polynom of n-th degree

Class Method Summary collapse

Class Method Details

.generate_function(given_plot, n = 5, alpha = 0.001, epsilon = 0.000001) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/regression.rb', line 52

def self.generate_function(given_plot, n = 5, alpha = 0.001, epsilon = 0.000001)
  scaling = n > 3
  if scaling
      plot, avg_x, div = feature_scaled_plot(given_plot, n)
  else
      (plot = given_plot)
  end
  array = Array.new(n + 1, 1)
  m = plot.length.to_f
  bias = old_bias = 0.5

  array = calculate([bias, epsilon, array, alpha, plot, old_bias, m])

  return array.map! {|x| x * div + avg_x } if scaling
  array
end