require 'glm' require 'pp' require 'ruby-debug' ; Debugger.start(:post_mortem => true) Debugger.settings[:autoeval] = true require 'prepare' T = 2000 iris = load_iris y_arr = iris.map {|r| r[0]} x = iris.map {|r| r[1...-1]} x = x.map{|r| r << 1} x,y = GLM::Util.formatArrays(x, y_arr) linear = GLM::Linear.new(x, y) (1..T).each do |i| linear.sto_update est_y = linear.est(x) err = (y.zip(est_y).map{|e| (e[0]-e[1])**2}).reduce(:+)/y.row_size puts err end #end #puts ((y_est - y).map {|e| e ** 2}).reduce(:+)/y.row_size # puts "Theta: #{y_est.to_a.to_s}"