bio-band 0.1.2 → 0.1.3
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/VERSION +1 -1
- data/bio-band.gemspec +8 -3
- data/features/step_definitions/create_dataset.rb +16 -17
- data/features/step_definitions/weka_clustering.rb +2 -2
- data/features/step_definitions/weka_filters.rb +12 -9
- data/features/step_definitions/weka_parsers.rb +13 -13
- data/lib/bio-band/core/type/instances.rb +33 -14
- data/lib/bio-band/weka.rb +3 -1
- data/lib/bio-band/weka/attribute_selection/attribute_selection_utils.rb +18 -0
- data/lib/bio-band/weka/attribute_selection/evaluators.rb +21 -0
- data/lib/bio-band/weka/attribute_selection/search.rb +26 -0
- data/lib/bio-band/weka/classifiers/bayes/bayes.rb +74 -54
- data/lib/bio-band/weka/classifiers/bayes/bayes_utils.rb +43 -23
- data/lib/bio-band/weka/classifiers/evaluation.rb +1 -1
- data/lib/bio-band/weka/classifiers/functions/functions.rb +157 -2
- data/lib/bio-band/weka/classifiers/functions/functions_utils.rb +45 -25
- data/lib/bio-band/weka/classifiers/lazy/lazy.rb +69 -4
- data/lib/bio-band/weka/classifiers/lazy/lazy_utils.rb +48 -28
- data/lib/bio-band/weka/classifiers/mi/mi.rb +190 -0
- data/lib/bio-band/weka/classifiers/mi/mi_utils.rb +65 -0
- data/lib/bio-band/weka/classifiers/rules/rules.rb +190 -0
- data/lib/bio-band/weka/classifiers/rules/rules_utils.rb +45 -25
- data/lib/bio-band/weka/classifiers/trees/trees.rb +66 -0
- data/lib/bio-band/weka/classifiers/trees/trees_utils.rb +47 -27
- data/lib/bio-band/weka/clusterers/clusterers.rb +34 -0
- data/lib/bio-band/weka/clusterers/clusterers_utils.rb +2 -4
- data/lib/bio-band/weka/db/db.rb +67 -67
- data/lib/bio-band/weka/filters/supervised/attribute/attribute.rb +31 -1
- data/lib/bio-band/weka/filters/supervised/supervised_utils.rb +33 -31
- data/lib/bio-band/weka/filters/unsupervised/attribute/attribute.rb +12 -0
- data/lib/bio-band/weka/filters/unsupervised/unsupervised_utils.rb +29 -29
- metadata +8 -3
- data/lib/bio-band/weka/classifiers/rules/rules.rb +0 -32
@@ -0,0 +1,190 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
require 'mi_utils'
|
3
|
+
|
4
|
+
module Weka
|
5
|
+
module Classifier
|
6
|
+
module Mi
|
7
|
+
java_import 'weka.classifiers.mi.CitationKNN'
|
8
|
+
java_import 'weka.classifiers.mi.MDD'
|
9
|
+
java_import 'weka.classifiers.mi.MIBoost'
|
10
|
+
java_import 'weka.classifiers.mi.MIDD'
|
11
|
+
java_import 'weka.classifiers.mi.MIEMDD'
|
12
|
+
java_import 'weka.classifiers.mi.MILR'
|
13
|
+
java_import 'weka.classifiers.mi.MINND'
|
14
|
+
java_import 'weka.classifiers.mi.MIOptimalBall'
|
15
|
+
java_import 'weka.classifiers.mi.MISMO'
|
16
|
+
java_import 'weka.classifiers.mi.MISVM'
|
17
|
+
java_import 'weka.classifiers.mi.MIWrapper'
|
18
|
+
java_import 'weka.classifiers.mi.SimpleMI'
|
19
|
+
|
20
|
+
class CitationKNN
|
21
|
+
include Mi_utils
|
22
|
+
class Base < CitationKNN
|
23
|
+
def initialize(&block)
|
24
|
+
super
|
25
|
+
if block_given?
|
26
|
+
init_instance_classifier(&block)
|
27
|
+
else
|
28
|
+
init_classifier
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class MIEMDD
|
35
|
+
include Mi_utils
|
36
|
+
class Base < MIEMDD
|
37
|
+
def initialize(&block)
|
38
|
+
super
|
39
|
+
if block_given?
|
40
|
+
init_instance_classifier(&block)
|
41
|
+
else
|
42
|
+
init_classifier
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class MILR
|
49
|
+
include Mi_utils
|
50
|
+
class Base < MILR
|
51
|
+
def initialize(&block)
|
52
|
+
super
|
53
|
+
if block_given?
|
54
|
+
init_instance_classifier(&block)
|
55
|
+
else
|
56
|
+
init_classifier
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class MINND
|
63
|
+
include Mi_utils
|
64
|
+
class Base < MINND
|
65
|
+
def initialize(&block)
|
66
|
+
super
|
67
|
+
if block_given?
|
68
|
+
init_instance_classifier(&block)
|
69
|
+
else
|
70
|
+
init_classifier
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class MIOptimalBall
|
77
|
+
include Mi_utils
|
78
|
+
class Base < MIOptimalBall
|
79
|
+
def initialize(&block)
|
80
|
+
super
|
81
|
+
if block_given?
|
82
|
+
init_instance_classifier(&block)
|
83
|
+
else
|
84
|
+
init_classifier
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
class MISMO
|
91
|
+
include Mi_utils
|
92
|
+
class Base < MISMO
|
93
|
+
def initialize(&block)
|
94
|
+
super
|
95
|
+
if block_given?
|
96
|
+
init_instance_classifier(&block)
|
97
|
+
else
|
98
|
+
init_classifier
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
class MISVM
|
105
|
+
include Mi_utils
|
106
|
+
class Base < MISVM
|
107
|
+
def initialize(&block)
|
108
|
+
super
|
109
|
+
if block_given?
|
110
|
+
init_instance_classifier(&block)
|
111
|
+
else
|
112
|
+
init_classifier
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
class MIWrapper
|
119
|
+
include Mi_utils
|
120
|
+
class Base < MIWrapper
|
121
|
+
def initialize(&block)
|
122
|
+
super
|
123
|
+
if block_given?
|
124
|
+
init_instance_classifier(&block)
|
125
|
+
else
|
126
|
+
init_classifier
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
class MDD
|
133
|
+
include Mi_utils
|
134
|
+
class Base < MDD
|
135
|
+
def initialize(&block)
|
136
|
+
super
|
137
|
+
if block_given?
|
138
|
+
init_instance_classifier(&block)
|
139
|
+
else
|
140
|
+
init_classifier
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
class MIBoost
|
147
|
+
include Mi_utils
|
148
|
+
class Base < MIBoost
|
149
|
+
def initialize(&block)
|
150
|
+
super
|
151
|
+
if block_given?
|
152
|
+
init_instance_classifier(&block)
|
153
|
+
else
|
154
|
+
init_classifier
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
class MIDD
|
161
|
+
include Mi_utils
|
162
|
+
class Base < MIDD
|
163
|
+
def initialize(&block)
|
164
|
+
super
|
165
|
+
if block_given?
|
166
|
+
init_instance_classifier(&block)
|
167
|
+
else
|
168
|
+
init_classifier
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
class SimpleMI
|
175
|
+
include Mi_utils
|
176
|
+
class Base < SimpleMI
|
177
|
+
def initialize(&block)
|
178
|
+
super
|
179
|
+
if block_given?
|
180
|
+
init_instance_classifier(&block)
|
181
|
+
else
|
182
|
+
init_classifier
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#This module is used by the 'mi' classifiers from 'mi.rb'
|
2
|
+
#to inherit the following methods (instance and class methods)
|
3
|
+
module Mi_utils
|
4
|
+
java_import "weka.core.Utils"
|
5
|
+
|
6
|
+
def init_mi
|
7
|
+
set_options(self.class.options) if self.class.options
|
8
|
+
self.class.data.setClassIndex(self.class.class_index) if self.class.class_index
|
9
|
+
buildClassifier(self.class.data)
|
10
|
+
end
|
11
|
+
|
12
|
+
#Instance methods list
|
13
|
+
def self.included(base)
|
14
|
+
base.extend(ClassMethods)
|
15
|
+
end
|
16
|
+
|
17
|
+
def init_instance_classifier(&block)
|
18
|
+
self.instance_eval(&block)
|
19
|
+
@dataset.setClassIndex(@class_index)
|
20
|
+
build_classifier(@dataset)
|
21
|
+
end
|
22
|
+
|
23
|
+
def set_data(data)
|
24
|
+
@dataset = data
|
25
|
+
end
|
26
|
+
|
27
|
+
def set_class_index(class_index)
|
28
|
+
@class_index = class_index
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_options(options)
|
32
|
+
options_inst = Utils.splitOptions(options)
|
33
|
+
setOptions(options_inst)
|
34
|
+
end
|
35
|
+
|
36
|
+
def list_options
|
37
|
+
listOptions.each {|key| puts "#{key.synopsis} #{key.description}"}
|
38
|
+
end
|
39
|
+
|
40
|
+
def description
|
41
|
+
puts globalInfo
|
42
|
+
end
|
43
|
+
|
44
|
+
def cross_validate(fold)
|
45
|
+
eval = Weka::Classifier::Evaluation.new self.class.data
|
46
|
+
eval.crossValidateModel(self.class.ancestors[2].new, self.class.data, fold.to_java(:int), Random.new(1))
|
47
|
+
eval.summary
|
48
|
+
end
|
49
|
+
|
50
|
+
#Class methods module
|
51
|
+
module ClassMethods
|
52
|
+
|
53
|
+
def self.classifier_attr_accessor(*args)
|
54
|
+
args.each do |arg|
|
55
|
+
#Here's the getter
|
56
|
+
self.class_eval("def #{arg};@#{arg};end")
|
57
|
+
#Here's the setter
|
58
|
+
self.class_eval("def set_#{arg}(val);@#{arg}=val;end")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
classifier_attr_accessor :options,:data,:class_index
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
require 'rules_utils'
|
3
|
+
|
4
|
+
module Weka
|
5
|
+
module Classifier
|
6
|
+
module Rules
|
7
|
+
java_import "weka.classifiers.rules.DecisionTable"
|
8
|
+
java_import "weka.classifiers.rules.DTNB"
|
9
|
+
java_import "weka.classifiers.rules.JRip"
|
10
|
+
java_import "weka.classifiers.rules.M5Rules"
|
11
|
+
java_import "weka.classifiers.rules.NNge"
|
12
|
+
java_import "weka.classifiers.rules.OneR"
|
13
|
+
java_import "weka.classifiers.rules.PART"
|
14
|
+
java_import "weka.classifiers.rules.Prism"
|
15
|
+
java_import "weka.classifiers.rules.Ridor"
|
16
|
+
java_import "weka.classifiers.rules.Rule"
|
17
|
+
java_import "weka.classifiers.rules.RuleStats"
|
18
|
+
java_import "weka.classifiers.rules.ZeroR"
|
19
|
+
|
20
|
+
class DecisionTable
|
21
|
+
include Rules_utils
|
22
|
+
class Base < DecisionTable
|
23
|
+
def initialize(&block)
|
24
|
+
super
|
25
|
+
if block_given?
|
26
|
+
init_instance_classifier(&block)
|
27
|
+
else
|
28
|
+
init_classifier
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class DTNB
|
35
|
+
include Rules_utils
|
36
|
+
class Base < DTNB
|
37
|
+
def initialize(&block)
|
38
|
+
super
|
39
|
+
if block_given?
|
40
|
+
init_instance_classifier(&block)
|
41
|
+
else
|
42
|
+
init_classifier
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class JRip
|
49
|
+
include Rules_utils
|
50
|
+
class Base < JRip
|
51
|
+
def initialize(&block)
|
52
|
+
super
|
53
|
+
if block_given?
|
54
|
+
init_instance_classifier(&block)
|
55
|
+
else
|
56
|
+
init_classifier
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class M5Rules
|
63
|
+
include Rules_utils
|
64
|
+
class Base < M5Rules
|
65
|
+
def initialize(&block)
|
66
|
+
super
|
67
|
+
if block_given?
|
68
|
+
init_instance_classifier(&block)
|
69
|
+
else
|
70
|
+
init_classifier
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class NNge
|
77
|
+
include Rules_utils
|
78
|
+
class Base < NNge
|
79
|
+
def initialize(&block)
|
80
|
+
super
|
81
|
+
if block_given?
|
82
|
+
init_instance_classifier(&block)
|
83
|
+
else
|
84
|
+
init_classifier
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
class OneR
|
91
|
+
include Rules_utils
|
92
|
+
class Base < OneR
|
93
|
+
def initialize(&block)
|
94
|
+
super
|
95
|
+
if block_given?
|
96
|
+
init_instance_classifier(&block)
|
97
|
+
else
|
98
|
+
init_classifier
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
class PART
|
105
|
+
include Rules_utils
|
106
|
+
class Base < PART
|
107
|
+
def initialize(&block)
|
108
|
+
super
|
109
|
+
if block_given?
|
110
|
+
init_instance_classifier(&block)
|
111
|
+
else
|
112
|
+
init_classifier
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
class Prism
|
119
|
+
include Rules_utils
|
120
|
+
class Base < Prism
|
121
|
+
def initialize(&block)
|
122
|
+
super
|
123
|
+
if block_given?
|
124
|
+
init_instance_classifier(&block)
|
125
|
+
else
|
126
|
+
init_classifier
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
class Ridor
|
133
|
+
include Rules_utils
|
134
|
+
class Base < Ridor
|
135
|
+
def initialize(&block)
|
136
|
+
super
|
137
|
+
if block_given?
|
138
|
+
init_instance_classifier(&block)
|
139
|
+
else
|
140
|
+
init_classifier
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
class Rule
|
147
|
+
include Rules_utils
|
148
|
+
class Base < Rule
|
149
|
+
def initialize(&block)
|
150
|
+
super
|
151
|
+
if block_given?
|
152
|
+
init_instance_classifier(&block)
|
153
|
+
else
|
154
|
+
init_classifier
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
class RuleStats
|
161
|
+
include Rules_utils
|
162
|
+
class Base < RuleStats
|
163
|
+
def initialize(&block)
|
164
|
+
super
|
165
|
+
if block_given?
|
166
|
+
init_instance_classifier(&block)
|
167
|
+
else
|
168
|
+
init_classifier
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
class ZeroR
|
175
|
+
include Rules_utils
|
176
|
+
class Base < ZeroR
|
177
|
+
def initialize(&block)
|
178
|
+
super
|
179
|
+
if block_given?
|
180
|
+
init_instance_classifier(&block)
|
181
|
+
else
|
182
|
+
init_classifier
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#This module is used by the 'rules' classifiers from 'rules.rb'
|
2
2
|
#to inherit the following methods (instance and class methods)
|
3
3
|
module Rules_utils
|
4
|
-
|
4
|
+
java_import "weka.core.Utils"
|
5
5
|
|
6
6
|
def init_rules
|
7
7
|
set_options(self.class.options) if self.class.options
|
@@ -9,37 +9,57 @@ module Rules_utils
|
|
9
9
|
buildClassifier(self.class.data)
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
#Instance methods list
|
13
13
|
def self.included(base)
|
14
14
|
base.extend(ClassMethods)
|
15
15
|
end
|
16
16
|
|
17
|
+
def init_instance_classifier(&block)
|
18
|
+
self.instance_eval(&block)
|
19
|
+
@dataset.setClassIndex(@class_index)
|
20
|
+
build_classifier(@dataset)
|
21
|
+
end
|
22
|
+
|
23
|
+
def set_data(data)
|
24
|
+
@dataset = data
|
25
|
+
end
|
26
|
+
|
27
|
+
def set_class_index(class_index)
|
28
|
+
@class_index = class_index
|
29
|
+
end
|
30
|
+
|
17
31
|
def set_options(options)
|
18
|
-
|
19
|
-
|
32
|
+
options_inst = Utils.splitOptions(options)
|
33
|
+
setOptions(options_inst)
|
20
34
|
end
|
21
35
|
|
22
|
-
|
23
|
-
|
24
|
-
|
36
|
+
def list_options
|
37
|
+
listOptions.map {|key| "#{key.synopsis} #{key.description}"}.join("\n")
|
38
|
+
end
|
25
39
|
|
26
|
-
|
40
|
+
def description
|
27
41
|
puts globalInfo
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
end
|
43
|
+
|
44
|
+
def cross_validate(fold)
|
45
|
+
eval = Weka::Classifier::Evaluation.new self.class.data
|
46
|
+
eval.crossValidateModel(self.class.ancestors[2].new, self.class.data, fold.to_java(:int), Random.new(1))
|
47
|
+
eval.summary
|
48
|
+
end
|
49
|
+
|
50
|
+
#Class methods module
|
51
|
+
module ClassMethods
|
52
|
+
|
53
|
+
def self.classifier_attr_accessor(*args)
|
54
|
+
args.each do |arg|
|
55
|
+
#Here's the getter
|
56
|
+
self.class_eval("def #{arg};@#{arg};end")
|
57
|
+
#Here's the setter
|
58
|
+
self.class_eval("def set_#{arg}(val);@#{arg}=val;end")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
classifier_attr_accessor :options,:data,:class_index
|
63
|
+
|
64
|
+
end
|
45
65
|
end
|