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