tomz-liblinear-ruby-swig 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/linear_cv.rb ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'linear'
4
+
5
+ def do_cross_validation(prob_x, prob_y, param, nr_fold)
6
+ puts "Do cross validation for a given Linear problem."
7
+ prob_l = prob_y.size
8
+ total_correct = 0
9
+ total_error = sumv = sumy = sumvv = sumyy = sumvy = 0.0
10
+ prob = LProblem.new(prob_y, prob_x, 0)
11
+ target = cross_validation(prob, param, nr_fold)
12
+ for i in (0..prob_l-1)
13
+ if false
14
+ v = target[i]
15
+ y = prob_y[i]
16
+ sumv = sumv + v
17
+ sumy = sumy + y
18
+ sumvv = sumvv + v * v
19
+ sumyy = sumyy + y * y
20
+ sumvy = sumvy + v * y
21
+ total_error = total_error + (v-y) * (v-y)
22
+ else
23
+ v = target[i]
24
+ if v == prob_y[i]
25
+ total_correct = total_correct + 1
26
+ end
27
+ end
28
+ end
29
+
30
+ if false
31
+ puts "Cross Validation Mean squared error = #{total_error / prob_l}"
32
+ puts "Cross Validation Squared correlation coefficient = #{((prob_l * sumvy - sumv * sumy) * (prob_l * sumvy - sumv * sumy)) / ((prob_l * sumvv - sumv * sumv) * (prob_l * sumyy - sumy * sumy))}"
33
+ else
34
+ puts "Cross Validation Accuracy = #{100.0 * total_correct / prob_l}%"
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tomz-liblinear-ruby-swig
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tom Zeng
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-09 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.3
24
+ version:
25
+ description: Ruby wrapper of LIBLINEAR using SWIG
26
+ email: tom.z.zeng@gmail.com
27
+ executables: []
28
+
29
+ extensions:
30
+ - ext/extconf.rb
31
+ extra_rdoc_files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.rdoc
35
+ files:
36
+ - History.txt
37
+ - COPYING
38
+ - AUTHORS
39
+ - Manifest.txt
40
+ - README.rdoc
41
+ - Rakefile
42
+ - lib/linear.rb
43
+ - lib/linear_cv.rb
44
+ - ext/liblinear_wrap.cxx
45
+ - ext/linear.cpp
46
+ - ext/linear.h
47
+ - ext/extconf.rb
48
+ - ext/tron.h
49
+ - ext/tron.cpp
50
+ - ext/blas.h
51
+ - ext/blasp.h
52
+ - ext/dscal.c
53
+ - ext/dnrm2.c
54
+ - ext/ddot.c
55
+ - ext/daxpy.c
56
+ has_rdoc: false
57
+ homepage: http://www.tomzconsulting.com
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --main
61
+ - README.rdoc
62
+ require_paths:
63
+ - lib
64
+ - ext
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.2.0
81
+ signing_key:
82
+ specification_version: 2
83
+ summary: Ruby wrapper of LIBLINEAR using SWIG
84
+ test_files: []
85
+