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.
Files changed (33) hide show
  1. data/VERSION +1 -1
  2. data/bio-band.gemspec +8 -3
  3. data/features/step_definitions/create_dataset.rb +16 -17
  4. data/features/step_definitions/weka_clustering.rb +2 -2
  5. data/features/step_definitions/weka_filters.rb +12 -9
  6. data/features/step_definitions/weka_parsers.rb +13 -13
  7. data/lib/bio-band/core/type/instances.rb +33 -14
  8. data/lib/bio-band/weka.rb +3 -1
  9. data/lib/bio-band/weka/attribute_selection/attribute_selection_utils.rb +18 -0
  10. data/lib/bio-band/weka/attribute_selection/evaluators.rb +21 -0
  11. data/lib/bio-band/weka/attribute_selection/search.rb +26 -0
  12. data/lib/bio-band/weka/classifiers/bayes/bayes.rb +74 -54
  13. data/lib/bio-band/weka/classifiers/bayes/bayes_utils.rb +43 -23
  14. data/lib/bio-band/weka/classifiers/evaluation.rb +1 -1
  15. data/lib/bio-band/weka/classifiers/functions/functions.rb +157 -2
  16. data/lib/bio-band/weka/classifiers/functions/functions_utils.rb +45 -25
  17. data/lib/bio-band/weka/classifiers/lazy/lazy.rb +69 -4
  18. data/lib/bio-band/weka/classifiers/lazy/lazy_utils.rb +48 -28
  19. data/lib/bio-band/weka/classifiers/mi/mi.rb +190 -0
  20. data/lib/bio-band/weka/classifiers/mi/mi_utils.rb +65 -0
  21. data/lib/bio-band/weka/classifiers/rules/rules.rb +190 -0
  22. data/lib/bio-band/weka/classifiers/rules/rules_utils.rb +45 -25
  23. data/lib/bio-band/weka/classifiers/trees/trees.rb +66 -0
  24. data/lib/bio-band/weka/classifiers/trees/trees_utils.rb +47 -27
  25. data/lib/bio-band/weka/clusterers/clusterers.rb +34 -0
  26. data/lib/bio-band/weka/clusterers/clusterers_utils.rb +2 -4
  27. data/lib/bio-band/weka/db/db.rb +67 -67
  28. data/lib/bio-band/weka/filters/supervised/attribute/attribute.rb +31 -1
  29. data/lib/bio-band/weka/filters/supervised/supervised_utils.rb +33 -31
  30. data/lib/bio-band/weka/filters/unsupervised/attribute/attribute.rb +12 -0
  31. data/lib/bio-band/weka/filters/unsupervised/unsupervised_utils.rb +29 -29
  32. metadata +8 -3
  33. data/lib/bio-band/weka/classifiers/rules/rules.rb +0 -32
@@ -2,7 +2,7 @@
2
2
  #to inherit the following methods (instance and class methods)
3
3
  module Bayes_utils
4
4
 
5
- java_import "weka.core.Utils"
5
+ java_import "weka.core.Utils"
6
6
 
7
7
  def init_classifier
8
8
  set_options(self.class.options) if self.class.options
@@ -10,39 +10,59 @@ module Bayes_utils
10
10
  buildClassifier(self.class.data)
11
11
  end
12
12
 
13
- #Instance methods list
13
+ def init_instance_classifier(&block)
14
+ self.instance_eval(&block)
15
+ @dataset.setClassIndex(@class_index)
16
+ build_classifier(@dataset)
17
+ end
18
+
19
+ def set_data(data)
20
+ @dataset = data
21
+ end
22
+
23
+ def set_class_index(class_index)
24
+ @class_index = class_index
25
+ end
26
+
27
+ #Instance methods list
14
28
  def self.included(base)
15
29
  base.extend(ClassMethods)
16
30
  end
17
31
 
18
32
  def set_options(options)
19
- options_inst = Utils.splitOptions(options)
20
- setOptions(options_inst)
33
+ options_inst = Utils.splitOptions(options)
34
+ setOptions(options_inst)
21
35
  end
22
36
 
23
- def list_options
24
- listOptions.each {|key| puts "#{key.synopsis} #{key.description}"}
25
- end
37
+ def list_options
38
+ listOptions.map {|key| "#{key.synopsis} #{key.description}"}.join("\n")
39
+ end
26
40
 
27
- def description
28
- puts globalInfo
29
- end
41
+ def description
42
+ globalInfo
43
+ end
30
44
 
31
- #Class methods module
32
- module ClassMethods
33
-
34
- def self.classifier_attr_accessor(*args)
35
- args.each do |arg|
36
- #Here's the getter
37
- self.class_eval("def #{arg};@#{arg};end")
38
- #Here's the setter
39
- self.class_eval("def set_#{arg}(val);@#{arg}=val;end")
40
- end
41
- end
45
+ def cross_validate(fold)
46
+ eval = Weka::Classifier::Evaluation.new self.class.data
47
+ eval.crossValidateModel(self.class.ancestors[2].new, self.class.data, fold.to_java(:int), Random.new(1))
48
+ eval.summary
49
+ end
42
50
 
43
- classifier_attr_accessor :options,:data,:class_index
51
+ #Class methods module
52
+ module ClassMethods
53
+
54
+ def self.classifier_attr_accessor(*args)
55
+ args.each do |arg|
56
+ #Here's the getter
57
+ self.class_eval("def #{arg};@#{arg};end")
58
+ #Here's the setter
59
+ self.class_eval("def set_#{arg}(val);@#{arg}=val;end")
60
+ end
61
+ end
44
62
 
45
- end
63
+ classifier_attr_accessor :options,:data,:class_index
64
+
65
+ end
46
66
  end
47
67
 
48
68
 
@@ -5,7 +5,7 @@ module Weka
5
5
 
6
6
  class Evaluation
7
7
  def summary
8
- puts toSummaryString
8
+ toSummaryString
9
9
  end
10
10
  end
11
11
 
@@ -5,13 +5,168 @@ module Weka
5
5
  module Classifier
6
6
  module Functions
7
7
  java_import 'weka.classifiers.functions.LinearRegression'
8
+ java_import 'weka.classifiers.functions.PLSClassifier'
9
+ java_import 'weka.classifiers.functions.RBFNetwork'
10
+ java_import 'weka.classifiers.functions.GaussianProcesses'
11
+ java_import 'weka.classifiers.functions.LeastMedSq'
12
+ java_import 'weka.classifiers.functions.LibSVM'
13
+ java_import 'weka.classifiers.functions.SMO'
14
+ java_import 'weka.classifiers.functions.SMOreg'
15
+ java_import 'weka.classifiers.functions.SPegasos'
16
+ java_import 'weka.classifiers.functions.VotedPerceptron'
17
+ java_import 'weka.classifiers.functions.Winnow'
18
+
19
+
20
+ class LeastMedSq
21
+ include Functions_utils
22
+ class Base < LeastMedSq
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 LibSVM
35
+ include Functions_utils
36
+ class Base < LibSVM
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
8
47
 
9
48
  class LinearRegression
10
49
  include Functions_utils
11
50
  class Base < LinearRegression
12
- def initialize
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 PLSClassifier
63
+ include Functions_utils
64
+ class Base < PLSClassifier
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 RBFNetwork
77
+ include Functions_utils
78
+ class Base < RBFNetwork
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 SMO
91
+ include Functions_utils
92
+ class Base < SMO
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 SMOreg
105
+ include Functions_utils
106
+ class Base < SMOreg
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 SPegasos
119
+ include Functions_utils
120
+ class Base < SPegasos
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 GaussianProcesses
133
+ include Functions_utils
134
+ class Base < GaussianProcesses
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 VotedPerceptron
147
+ include Functions_utils
148
+ class Base < VotedPerceptron
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 Winnow
161
+ include Functions_utils
162
+ class Base < Winnow
163
+ def initialize(&block)
13
164
  super
14
- init_function
165
+ if block_given?
166
+ init_instance_classifier(&block)
167
+ else
168
+ init_classifier
169
+ end
15
170
  end
16
171
  end
17
172
  end
@@ -1,7 +1,7 @@
1
1
  #This module is used by the 'functions' classifiers from 'functions.rb'
2
2
  #to inherit the following methods (instance and class methods)
3
3
  module Functions_utils
4
- java_import "weka.core.Utils"
4
+ java_import "weka.core.Utils"
5
5
 
6
6
  def init_function
7
7
  set_options(self.class.options) if self.class.options
@@ -9,37 +9,57 @@ module Functions_utils
9
9
  buildClassifier(self.class.data)
10
10
  end
11
11
 
12
- #Instance methods list
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
- options_inst = Utils.splitOptions(options)
19
- setOptions(options_inst)
32
+ options_inst = Utils.splitOptions(options)
33
+ setOptions(options_inst)
20
34
  end
21
35
 
22
- def list_options
23
- listOptions.each {|key| puts "#{key.synopsis} #{key.description}"}
24
- end
36
+ def list_options
37
+ listOptions.map {|key| "#{key.synopsis} #{key.description}"}.join("\n")
38
+ end
25
39
 
26
- def description
40
+ def description
27
41
  puts globalInfo
28
- end
29
-
30
- #Class methods module
31
- module ClassMethods
32
-
33
- def self.classifier_attr_accessor(*args)
34
- args.each do |arg|
35
- #Here's the getter
36
- self.class_eval("def #{arg};@#{arg};end")
37
- #Here's the setter
38
- self.class_eval("def set_#{arg}(val);@#{arg}=val;end")
39
- end
40
- end
41
-
42
- classifier_attr_accessor :options,:data,:class_index
43
-
44
- end
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
@@ -6,16 +6,81 @@ module Weka
6
6
  module Lazy
7
7
 
8
8
  java_import 'weka.classifiers.lazy.KStar'
9
+ java_import 'weka.classifiers.lazy.LWL'
10
+ java_import 'weka.classifiers.lazy.LBR'
11
+ java_import 'weka.classifiers.lazy.IB1'
12
+ java_import 'weka.classifiers.lazy.IBk'
9
13
 
10
14
  class KStar
11
15
  include Lazy_utils
12
16
  class Base < KStar
13
- def initialize
14
- super
15
- init_lazy
16
- end
17
+ def initialize(&block)
18
+ super
19
+ if block_given?
20
+ init_instance_classifier(&block)
21
+ else
22
+ init_classifier
23
+ end
24
+ end
17
25
  end
18
26
  end
27
+
28
+ class LWL
29
+ include Lazy_utils
30
+ class Base < LWL
31
+ def initialize(&block)
32
+ super
33
+ if block_given?
34
+ init_instance_classifier(&block)
35
+ else
36
+ init_classifier
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ class LBR
43
+ include Lazy_utils
44
+ class Base < LBR
45
+ def initialize(&block)
46
+ super
47
+ if block_given?
48
+ init_instance_classifier(&block)
49
+ else
50
+ init_classifier
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ class IB1
57
+ include Lazy_utils
58
+ class Base < IB1
59
+ def initialize(&block)
60
+ super
61
+ if block_given?
62
+ init_instance_classifier(&block)
63
+ else
64
+ init_classifier
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ class IBk
71
+ include Lazy_utils
72
+ class Base < IBk
73
+ def initialize(&block)
74
+ super
75
+ if block_given?
76
+ init_instance_classifier(&block)
77
+ else
78
+ init_classifier
79
+ end
80
+ end
81
+ end
82
+ end
83
+
19
84
  end
20
85
  end
21
86
  end
@@ -1,45 +1,65 @@
1
1
  #This module is used by the 'lazy' classifiers from 'lazy.rb'
2
2
  #to inherit the following methods (instance and class methods)
3
3
  module Lazy_utils
4
- java_import "weka.core.Utils"
4
+ java_import "weka.core.Utils"
5
5
 
6
6
  def init_lazy
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)
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
10
  end
11
11
 
12
- #Instance methods list
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
- options_inst = Utils.splitOptions(options)
19
- setOptions(options_inst)
32
+ options_inst = Utils.splitOptions(options)
33
+ setOptions(options_inst)
20
34
  end
21
35
 
22
- def list_options
23
- listOptions.each {|key| puts "#{key.synopsis} #{key.description}"}
24
- end
36
+ def list_options
37
+ listOptions.map {|key| "#{key.synopsis} #{key.description}"}.join("\n")
38
+ end
25
39
 
26
- def description
40
+ def description
27
41
  puts globalInfo
28
- end
29
-
30
- #Class methods module
31
- module ClassMethods
32
-
33
- def self.classifier_attr_accessor(*args)
34
- args.each do |arg|
35
- #Here's the getter
36
- self.class_eval("def #{arg};@#{arg};end")
37
- #Here's the setter
38
- self.class_eval("def set_#{arg}(val);@#{arg}=val;end")
39
- end
40
- end
41
-
42
- classifier_attr_accessor :options,:data,:class_index
43
-
44
- end
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