Sha256: ee7e5066731e500005ea25b5b4b12f292eb75b3b403009e935bfa5457c9913f7
Contents?: true
Size: 1.11 KB
Versions: 1
Compression:
Stored size: 1.11 KB
Contents
require 'test/unit' require 'glm' require 'pp' require 'ruby-debug' Debugger.start(:post_mortem => true) Debugger.settings[:autoeval] = true class GLMTest < Test::Unit::TestCase def test_glm_logit_truth assert_equal "Sanity is for the weak!", GLM::Logit.truth end #Helper method def load_iris ifile = File.open( File.join("data","iris.data")) iris = ((ifile.readlines.map {|l| fields = l.chomp.split(pattern=",") fields }).select {|fields| fields[4] != "Iris-virginica" && fields != []}).map {|fields| fields[4] = (fields[4] == "Iris-setosa") ? 1 : 0 fields.map{|f| f.to_f}} assert_equal 100, iris.length ifile.close return iris end def test_linear iris = load_iris y = 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) x = GLM::Util.aa_to_gsl_matrix(x) y = GSL::Vector.alloc(y) linear = GLM::Linear.new(x, y) theta, y_est = linear.ne_est(x) assert ((y_est - y).map {|e| e ** 2}).norm < 0.1 end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
glm-0.0.2 | test/test_glm.rb |