svm_toolkit 1.1.7-java → 1.1.8-java
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.
- checksums.yaml +4 -4
- data/LICENSE.rdoc +59 -59
- data/README.rdoc +99 -103
- data/bin/svm-demo +354 -354
- data/lib/libsvm.jar +0 -0
- data/lib/svm_toolkit/evaluators.rb +169 -169
- data/lib/svm_toolkit/model.rb +122 -124
- data/lib/svm_toolkit/node.rb +17 -21
- data/lib/svm_toolkit/parameter.rb +114 -117
- data/lib/svm_toolkit/problem.rb +294 -308
- data/lib/svm_toolkit/svm.rb +219 -224
- data/lib/svm_toolkit.rb +37 -37
- metadata +26 -12
|
@@ -1,117 +1,114 @@
|
|
|
1
|
-
module SvmToolkit
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
# *
|
|
10
|
-
# *
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
# *
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
# *
|
|
17
|
-
# *
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
#
|
|
41
|
-
#
|
|
42
|
-
#
|
|
43
|
-
#
|
|
44
|
-
#
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
#
|
|
51
|
-
#
|
|
52
|
-
# * :
|
|
53
|
-
# * :
|
|
54
|
-
# * :
|
|
55
|
-
# * :
|
|
56
|
-
# * :
|
|
57
|
-
# * :
|
|
58
|
-
# * :
|
|
59
|
-
# * :
|
|
60
|
-
# * :
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
self.
|
|
67
|
-
self.
|
|
68
|
-
self.
|
|
69
|
-
self.
|
|
70
|
-
self.
|
|
71
|
-
self.
|
|
72
|
-
self.
|
|
73
|
-
self.
|
|
74
|
-
self.
|
|
75
|
-
|
|
76
|
-
self.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
end
|
|
117
|
-
|
|
1
|
+
module SvmToolkit
|
|
2
|
+
|
|
3
|
+
# Holds values determining the kernel type and training process.
|
|
4
|
+
#
|
|
5
|
+
# svm_type:: The type of SVM problem being solved.
|
|
6
|
+
# * C_SVC, the usual classification task.
|
|
7
|
+
# * NU_SVC
|
|
8
|
+
# * ONE_CLASS
|
|
9
|
+
# * EPSILON_SVR
|
|
10
|
+
# * NU_SVR
|
|
11
|
+
#
|
|
12
|
+
# kernel_type:: The type of kernel to use.
|
|
13
|
+
# * LINEAR
|
|
14
|
+
# * POLY
|
|
15
|
+
# * RBF
|
|
16
|
+
# * SIGMOID
|
|
17
|
+
# * PRECOMPUTED
|
|
18
|
+
#
|
|
19
|
+
# degree:: A parameter in polynomial kernels.
|
|
20
|
+
#
|
|
21
|
+
# gamma:: A parameter in poly/rbf/sigmoid kernels.
|
|
22
|
+
#
|
|
23
|
+
# coef0:: A parameter for poly/sigmoid kernels.
|
|
24
|
+
#
|
|
25
|
+
# cache_size:: For training, in MB.
|
|
26
|
+
#
|
|
27
|
+
# eps:: For training, stopping criterion.
|
|
28
|
+
#
|
|
29
|
+
# C:: For training with C_SVC, EPSILON_SVR, NU_SVR: the cost parameter.
|
|
30
|
+
#
|
|
31
|
+
# nr_weight:: For training with C_SVC.
|
|
32
|
+
#
|
|
33
|
+
# weight_label:: For training with C_SVC.
|
|
34
|
+
#
|
|
35
|
+
# weight:: For training with C_SVC.
|
|
36
|
+
#
|
|
37
|
+
# nu:: For training with NU_SVR, ONE_CLASS, NU_SVC.
|
|
38
|
+
#
|
|
39
|
+
# p:: For training with EPSILON_SVR.
|
|
40
|
+
#
|
|
41
|
+
# shrinking:: training, whether to use shrinking heuristics.
|
|
42
|
+
#
|
|
43
|
+
# probability:: For training, whether to use probability estimates.
|
|
44
|
+
#
|
|
45
|
+
class Parameter
|
|
46
|
+
|
|
47
|
+
# Constructor sets up values of attributes based on provided map.
|
|
48
|
+
# Valid keys with their default values:
|
|
49
|
+
# * :svm_type = Parameter::C_SVC, for the type of SVM
|
|
50
|
+
# * :kernel_type = Parameter::LINEAR, for the type of kernel
|
|
51
|
+
# * :cost = 1.0, for the cost or C parameter
|
|
52
|
+
# * :gamma = 0.0, for the gamma parameter in kernel
|
|
53
|
+
# * :degree = 1, for polynomial kernel
|
|
54
|
+
# * :coef0 = 0.0, for polynomial/sigmoid kernels
|
|
55
|
+
# * :eps = 0.001, for stopping criterion
|
|
56
|
+
# * :nr_weight = 0, for C_SVC
|
|
57
|
+
# * :nu = 0.5, used for NU_SVC, ONE_CLASS and NU_SVR. Nu must be in (0,1]
|
|
58
|
+
# * :p = 0.1, used for EPSILON_SVR
|
|
59
|
+
# * :shrinking = 1, use the shrinking heuristics
|
|
60
|
+
# * :probability = 0, use the probability estimates
|
|
61
|
+
def initialize args
|
|
62
|
+
super()
|
|
63
|
+
self.svm_type = args.fetch(:svm_type, Parameter::C_SVC)
|
|
64
|
+
self.kernel_type = args.fetch(:kernel_type, Parameter::LINEAR)
|
|
65
|
+
self.C = args.fetch(:cost, 1.0)
|
|
66
|
+
self.gamma = args.fetch(:gamma, 0.0)
|
|
67
|
+
self.degree = args.fetch(:degree, 1)
|
|
68
|
+
self.coef0 = args.fetch(:coef0, 0.0)
|
|
69
|
+
self.eps = args.fetch(:eps, 0.001)
|
|
70
|
+
self.nr_weight = args.fetch(:nr_weight, 0)
|
|
71
|
+
self.nu = args.fetch(:nu, 0.5)
|
|
72
|
+
self.p = args.fetch(:p, 0.1)
|
|
73
|
+
self.shrinking = args.fetch(:shrinking, 1)
|
|
74
|
+
self.probability = args.fetch(:probability, 0)
|
|
75
|
+
|
|
76
|
+
unless self.nu > 0.0 and self.nu <= 1.0
|
|
77
|
+
raise ArgumentError "Invalid value of nu #{self.nu}, should be in (0,1]"
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# A more readable accessor for the C parameter
|
|
82
|
+
def cost
|
|
83
|
+
self.C
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# A more readable mutator for the C parameter
|
|
87
|
+
def cost= val
|
|
88
|
+
self.C = val
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Return a list of the available kernels.
|
|
92
|
+
def self.kernels
|
|
93
|
+
[Parameter::LINEAR, Parameter::POLY, Parameter::RBF, Parameter::SIGMOID]
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Return a printable name for the given kernel.
|
|
97
|
+
def self.kernel_name kernel
|
|
98
|
+
case kernel
|
|
99
|
+
when Parameter::LINEAR
|
|
100
|
+
"Linear"
|
|
101
|
+
when Parameter::POLY
|
|
102
|
+
"Polynomial"
|
|
103
|
+
when Parameter::RBF
|
|
104
|
+
"Radial basis function"
|
|
105
|
+
when Parameter::SIGMOID
|
|
106
|
+
"Sigmoid"
|
|
107
|
+
else
|
|
108
|
+
"Unknown"
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
end
|
|
114
|
+
|