ruby-band 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/.travis.yml +3 -0
  2. data/Gemfile +30 -0
  3. data/Gemfile.lock +119 -0
  4. data/Jarfile +9 -0
  5. data/Jarfile.lock +10 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +321 -0
  8. data/README.rdoc +70 -0
  9. data/Rakefile +66 -0
  10. data/VERSION +1 -0
  11. data/band_server/client.rb +35 -0
  12. data/band_server/client_alt.rb +35 -0
  13. data/band_server/first_dataset.csv +15 -0
  14. data/band_server/second_dataset.csv +15 -0
  15. data/band_server/simple_server.rb +90 -0
  16. data/band_server/third_dataset.csv +15 -0
  17. data/band_server/uploads/first_dataset.csv +15 -0
  18. data/band_server/uploads/second_dataset.csv +15 -0
  19. data/band_server/uploads/third_dataset.csv +15 -0
  20. data/bin/ruby-band +83 -0
  21. data/ext/mkrf_conf.rb +74 -0
  22. data/features/create_dataset.feature +12 -0
  23. data/features/step_definitions/create_dataset.rb +39 -0
  24. data/features/step_definitions/weka_classifiers.rb +43 -0
  25. data/features/step_definitions/weka_clustering.rb +34 -0
  26. data/features/step_definitions/weka_filters.rb +32 -0
  27. data/features/step_definitions/weka_parsers.rb +46 -0
  28. data/features/step_definitions/weka_pipeline.rb +41 -0
  29. data/features/support/env.rb +3 -0
  30. data/features/weka_classifiers.feature +16 -0
  31. data/features/weka_clustering.feature +15 -0
  32. data/features/weka_filters.feature +12 -0
  33. data/features/weka_parsers.feature +18 -0
  34. data/features/weka_pipeline.feature +14 -0
  35. data/lib/ruby-band.rb +12 -0
  36. data/lib/ruby-band/apache.rb +2 -0
  37. data/lib/ruby-band/apache/stat/correlation.rb +42 -0
  38. data/lib/ruby-band/apache/stat/inference.rb +151 -0
  39. data/lib/ruby-band/apache/stat/regression.rb +22 -0
  40. data/lib/ruby-band/core.rb +6 -0
  41. data/lib/ruby-band/core/parser/parser.rb +27 -0
  42. data/lib/ruby-band/core/type/apache_matrices.rb +35 -0
  43. data/lib/ruby-band/core/type/attribute.rb +53 -0
  44. data/lib/ruby-band/core/type/instance.rb +10 -0
  45. data/lib/ruby-band/core/type/instances.rb +361 -0
  46. data/lib/ruby-band/core/type/utils.rb +31 -0
  47. data/lib/ruby-band/weka.rb +14 -0
  48. data/lib/ruby-band/weka/attribute_selection/attribute_selection_utils.rb +20 -0
  49. data/lib/ruby-band/weka/attribute_selection/evaluators.rb +58 -0
  50. data/lib/ruby-band/weka/attribute_selection/search.rb +52 -0
  51. data/lib/ruby-band/weka/classifiers/bayes/bayes.rb +86 -0
  52. data/lib/ruby-band/weka/classifiers/bayes/bayes_utils.rb +82 -0
  53. data/lib/ruby-band/weka/classifiers/evaluation.rb +13 -0
  54. data/lib/ruby-band/weka/classifiers/functions/functions.rb +177 -0
  55. data/lib/ruby-band/weka/classifiers/functions/functions_utils.rb +78 -0
  56. data/lib/ruby-band/weka/classifiers/lazy/lazy.rb +86 -0
  57. data/lib/ruby-band/weka/classifiers/lazy/lazy_utils.rb +83 -0
  58. data/lib/ruby-band/weka/classifiers/mi/mi.rb +191 -0
  59. data/lib/ruby-band/weka/classifiers/mi/mi_utils.rb +80 -0
  60. data/lib/ruby-band/weka/classifiers/rules/rules.rb +190 -0
  61. data/lib/ruby-band/weka/classifiers/rules/rules_utils.rb +81 -0
  62. data/lib/ruby-band/weka/classifiers/trees/trees.rb +110 -0
  63. data/lib/ruby-band/weka/classifiers/trees/trees_utils.rb +85 -0
  64. data/lib/ruby-band/weka/clusterers/clusterers.rb +99 -0
  65. data/lib/ruby-band/weka/clusterers/clusterers_utils.rb +86 -0
  66. data/lib/ruby-band/weka/db/DatabaseUtils_mysql +280 -0
  67. data/lib/ruby-band/weka/db/DatabaseUtils_postgresql +594 -0
  68. data/lib/ruby-band/weka/db/db.rb +74 -0
  69. data/lib/ruby-band/weka/filters/supervised/attribute/attribute.rb +55 -0
  70. data/lib/ruby-band/weka/filters/supervised/instance/instance.rb +17 -0
  71. data/lib/ruby-band/weka/filters/supervised/supervised_utils.rb +38 -0
  72. data/lib/ruby-band/weka/filters/unsupervised/attribute/attribute.rb +90 -0
  73. data/lib/ruby-band/weka/filters/unsupervised/instance/instance.rb +48 -0
  74. data/lib/ruby-band/weka/filters/unsupervised/unsupervised_utils.rb +38 -0
  75. data/resources/ReutersGrain-test.arff +611 -0
  76. data/resources/ReutersGrain-train.arff +1561 -0
  77. data/resources/weather.csv +15 -0
  78. data/resources/weather.numeric.arff +23 -0
  79. data/ruby-band.gemspec +178 -0
  80. data/spec/ruby-band_spec.rb +7 -0
  81. data/spec/spec_helper.rb +12 -0
  82. data/test/helper.rb +18 -0
  83. data/test/test_apacheCorrelation.rb +22 -0
  84. data/test/test_apacheInference.rb +46 -0
  85. data/test/test_ruby-band.rb +9 -0
  86. metadata +426 -0
@@ -0,0 +1,78 @@
1
+ #This module is used by the 'functions' classifiers from 'functions.rb'
2
+ #to inherit the following methods (instance and class methods)
3
+ module Functions_utils
4
+ java_import "weka.core.Utils"
5
+
6
+ def init_function
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
+ #Set instance data for the instance classifier
24
+ def set_data(data)
25
+ @dataset = data
26
+ end
27
+
28
+ #Set a class index for the input dataset
29
+ def set_class_index(class_index)
30
+ @class_index = class_index
31
+ end
32
+
33
+ def set_options(options)
34
+ options_inst = Utils.splitOptions(options)
35
+ setOptions(options_inst)
36
+ end
37
+
38
+ #List available options
39
+ def list_options
40
+ listOptions.map {|key| "#{key.synopsis} #{key.description}"}.join("\n")
41
+ end
42
+
43
+ #Return a description from the Weka Javadoc for the selected classifier
44
+ def description
45
+ puts globalInfo
46
+ end
47
+
48
+ # perform crossvalidation on a trained classifier
49
+ #ARGV:
50
+ #fold -> 'int' value
51
+ def cross_validate(fold)
52
+ if self.class.data
53
+ eval = Weka::Classifier::Evaluation.new self.class.data
54
+ eval.crossValidateModel(self.class.ancestors[2].new, self.class.data, fold.to_java(:int), Random.new(1))
55
+ eval.summary
56
+ else
57
+ eval = Weka::Classifier::Evaluation.new @dataset
58
+ eval.crossValidateModel(self.class.ancestors[1].new, @dataset, fold.to_java(:int), Random.new(1))
59
+ eval.summary
60
+ end
61
+ end
62
+
63
+ #Class methods module
64
+ module ClassMethods
65
+
66
+ def self.classifier_attr_accessor(*args)
67
+ args.each do |arg|
68
+ #Here's the getter
69
+ self.class_eval("def #{arg};@#{arg};end")
70
+ #Here's the setter
71
+ self.class_eval("def set_#{arg}(val);@#{arg}=val;end")
72
+ end
73
+ end
74
+
75
+ classifier_attr_accessor :options,:data,:class_index
76
+
77
+ end
78
+ end
@@ -0,0 +1,86 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'lazy_utils'
3
+
4
+ module Weka
5
+ module Classifier
6
+ module Lazy
7
+
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'
13
+
14
+ class KStar
15
+ include Lazy_utils
16
+ class Base < KStar
17
+ def initialize(&block)
18
+ super
19
+ if block_given?
20
+ init_instance_classifier(&block)
21
+ else
22
+ init_classifier
23
+ end
24
+ end
25
+ end
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
+
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,83 @@
1
+ #This module is used by the 'lazy' classifiers from 'lazy.rb'
2
+ #to inherit the following methods (instance and class methods)
3
+ module Lazy_utils
4
+ java_import "weka.core.Utils"
5
+
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)
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
+ #Set data for instance classifier
24
+ #ARGV
25
+ # data -> an Instances object
26
+ def set_data(data)
27
+ @dataset = data
28
+ end
29
+
30
+ #Set a class index for the input dataset
31
+ def set_class_index(class_index)
32
+ @class_index = class_index
33
+ end
34
+
35
+ #Set options for the selected classfier
36
+ #ARGS:
37
+ #options -> a String, i.e. "-K"
38
+ def set_options(options)
39
+ options_inst = Utils.splitOptions(options)
40
+ setOptions(options_inst)
41
+ end
42
+
43
+ #List available options
44
+ def list_options
45
+ listOptions.map {|key| "#{key.synopsis} #{key.description}"}.join("\n")
46
+ end
47
+
48
+ #Return a description from the Weka JavaDoc for the selected classifier
49
+ def description
50
+ puts globalInfo
51
+ end
52
+
53
+ # perform crossvalidation on a trained classifier
54
+ #ARGV:
55
+ #fold -> 'int' value
56
+ def cross_validate(fold)
57
+ if self.class.data
58
+ eval = Weka::Classifier::Evaluation.new self.class.data
59
+ eval.crossValidateModel(self.class.ancestors[2].new, self.class.data, fold.to_java(:int), Random.new(1))
60
+ eval.summary
61
+ else
62
+ eval = Weka::Classifier::Evaluation.new @dataset
63
+ eval.crossValidateModel(self.class.ancestors[1].new, @dataset, fold.to_java(:int), Random.new(1))
64
+ eval.summary
65
+ end
66
+ end
67
+
68
+ #Class methods module
69
+ module ClassMethods
70
+
71
+ def self.classifier_attr_accessor(*args)
72
+ args.each do |arg|
73
+ #Here's the getter
74
+ self.class_eval("def #{arg};@#{arg};end")
75
+ #Here's the setter
76
+ self.class_eval("def set_#{arg}(val);@#{arg}=val;end")
77
+ end
78
+ end
79
+
80
+ classifier_attr_accessor :options,:data,:class_index
81
+
82
+ end
83
+ end
@@ -0,0 +1,191 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'mi_utils'
3
+
4
+ module Weka
5
+ module Classifier
6
+ module Mi
7
+ #This module contains classifiers from the 'weka.classifiers.mi' package
8
+ java_import 'weka.classifiers.mi.CitationKNN'
9
+ java_import 'weka.classifiers.mi.MDD'
10
+ java_import 'weka.classifiers.mi.MIBoost'
11
+ java_import 'weka.classifiers.mi.MIDD'
12
+ java_import 'weka.classifiers.mi.MIEMDD'
13
+ java_import 'weka.classifiers.mi.MILR'
14
+ java_import 'weka.classifiers.mi.MINND'
15
+ java_import 'weka.classifiers.mi.MIOptimalBall'
16
+ java_import 'weka.classifiers.mi.MISMO'
17
+ java_import 'weka.classifiers.mi.MISVM'
18
+ java_import 'weka.classifiers.mi.MIWrapper'
19
+ java_import 'weka.classifiers.mi.SimpleMI'
20
+
21
+ class CitationKNN
22
+ include Mi_utils
23
+ class Base < CitationKNN
24
+ def initialize(&block)
25
+ super
26
+ if block_given?
27
+ init_instance_classifier(&block)
28
+ else
29
+ init_classifier
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ class MIEMDD
36
+ include Mi_utils
37
+ class Base < MIEMDD
38
+ def initialize(&block)
39
+ super
40
+ if block_given?
41
+ init_instance_classifier(&block)
42
+ else
43
+ init_classifier
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ class MILR
50
+ include Mi_utils
51
+ class Base < MILR
52
+ def initialize(&block)
53
+ super
54
+ if block_given?
55
+ init_instance_classifier(&block)
56
+ else
57
+ init_classifier
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ class MINND
64
+ include Mi_utils
65
+ class Base < MINND
66
+ def initialize(&block)
67
+ super
68
+ if block_given?
69
+ init_instance_classifier(&block)
70
+ else
71
+ init_classifier
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ class MIOptimalBall
78
+ include Mi_utils
79
+ class Base < MIOptimalBall
80
+ def initialize(&block)
81
+ super
82
+ if block_given?
83
+ init_instance_classifier(&block)
84
+ else
85
+ init_classifier
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ class MISMO
92
+ include Mi_utils
93
+ class Base < MISMO
94
+ def initialize(&block)
95
+ super
96
+ if block_given?
97
+ init_instance_classifier(&block)
98
+ else
99
+ init_classifier
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ class MISVM
106
+ include Mi_utils
107
+ class Base < MISVM
108
+ def initialize(&block)
109
+ super
110
+ if block_given?
111
+ init_instance_classifier(&block)
112
+ else
113
+ init_classifier
114
+ end
115
+ end
116
+ end
117
+ end
118
+
119
+ class MIWrapper
120
+ include Mi_utils
121
+ class Base < MIWrapper
122
+ def initialize(&block)
123
+ super
124
+ if block_given?
125
+ init_instance_classifier(&block)
126
+ else
127
+ init_classifier
128
+ end
129
+ end
130
+ end
131
+ end
132
+
133
+ class MDD
134
+ include Mi_utils
135
+ class Base < MDD
136
+ def initialize(&block)
137
+ super
138
+ if block_given?
139
+ init_instance_classifier(&block)
140
+ else
141
+ init_classifier
142
+ end
143
+ end
144
+ end
145
+ end
146
+
147
+ class MIBoost
148
+ include Mi_utils
149
+ class Base < MIBoost
150
+ def initialize(&block)
151
+ super
152
+ if block_given?
153
+ init_instance_classifier(&block)
154
+ else
155
+ init_classifier
156
+ end
157
+ end
158
+ end
159
+ end
160
+
161
+ class MIDD
162
+ include Mi_utils
163
+ class Base < MIDD
164
+ def initialize(&block)
165
+ super
166
+ if block_given?
167
+ init_instance_classifier(&block)
168
+ else
169
+ init_classifier
170
+ end
171
+ end
172
+ end
173
+ end
174
+
175
+ class SimpleMI
176
+ include Mi_utils
177
+ class Base < SimpleMI
178
+ def initialize(&block)
179
+ super
180
+ if block_given?
181
+ init_instance_classifier(&block)
182
+ else
183
+ init_classifier
184
+ end
185
+ end
186
+ end
187
+ end
188
+
189
+ end
190
+ end
191
+ end
@@ -0,0 +1,80 @@
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
+ #Set input data for the selected classifier
24
+ #ARGV:
25
+ #data -> an Instances class object
26
+ def set_data(data)
27
+ @dataset = data
28
+ end
29
+
30
+ #Set class index for the input dataset
31
+ def set_class_index(class_index)
32
+ @class_index = class_index
33
+ end
34
+
35
+ def set_options(options)
36
+ options_inst = Utils.splitOptions(options)
37
+ setOptions(options_inst)
38
+ end
39
+
40
+ #List options for the selected classifier
41
+ def list_options
42
+ listOptions.each {|key| puts "#{key.synopsis} #{key.description}"}
43
+ end
44
+
45
+ #Return a short description for the current classifier
46
+ def description
47
+ puts globalInfo
48
+ end
49
+
50
+ # perform crossvalidation on a trained classifier
51
+ #ARGV:
52
+ #fold -> 'int' value
53
+ def cross_validate(fold)
54
+ if self.class.data
55
+ eval = Weka::Classifier::Evaluation.new self.class.data
56
+ eval.crossValidateModel(self.class.ancestors[2].new, self.class.data, fold.to_java(:int), Random.new(1))
57
+ eval.summary
58
+ else
59
+ eval = Weka::Classifier::Evaluation.new @dataset
60
+ eval.crossValidateModel(self.class.ancestors[1].new, @dataset, fold.to_java(:int), Random.new(1))
61
+ eval.summary
62
+ end
63
+ end
64
+
65
+ #Class methods module
66
+ module ClassMethods
67
+
68
+ def self.classifier_attr_accessor(*args)
69
+ args.each do |arg|
70
+ #Here's the getter
71
+ self.class_eval("def #{arg};@#{arg};end")
72
+ #Here's the setter
73
+ self.class_eval("def set_#{arg}(val);@#{arg}=val;end")
74
+ end
75
+ end
76
+
77
+ classifier_attr_accessor :options,:data,:class_index
78
+
79
+ end
80
+ end