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
@@ -7,6 +7,32 @@ module Weka
7
7
  java_import 'weka.classifiers.trees.J48'
8
8
  java_import 'weka.classifiers.trees.FT'
9
9
  java_import 'weka.classifiers.trees.RandomForest'
10
+ java_import 'weka.classifiers.trees.BFTree'
11
+ java_import 'weka.classifiers.trees.J48graft'
12
+ java_import 'weka.classifiers.trees.LADTree'
13
+ java_import 'weka.classifiers.trees.LMT'
14
+ java_import 'weka.classifiers.trees.M5P'
15
+ java_import 'weka.classifiers.trees.RandomTree'
16
+
17
+ class ADTree
18
+ include Trees_utils
19
+ class Base < ADTree
20
+ def initialize
21
+ super
22
+ init_tree
23
+ end
24
+ end
25
+ end
26
+
27
+ class BFTree
28
+ include Trees_utils
29
+ class Base < BFTree
30
+ def initialize
31
+ super
32
+ init_tree
33
+ end
34
+ end
35
+ end
10
36
 
11
37
  class FT
12
38
  include Trees_utils
@@ -28,6 +54,36 @@ module Weka
28
54
  end
29
55
  end
30
56
 
57
+ class J48graft
58
+ include Trees_utils
59
+ class Base < J48graft
60
+ def initialize
61
+ super
62
+ init_tree
63
+ end
64
+ end
65
+ end
66
+
67
+ class LMT
68
+ include Trees_utils
69
+ class Base < LMT
70
+ def initialize
71
+ super
72
+ init_tree
73
+ end
74
+ end
75
+ end
76
+
77
+ class M5P
78
+ include Trees_utils
79
+ class Base < M5P
80
+ def initialize
81
+ super
82
+ init_tree
83
+ end
84
+ end
85
+ end
86
+
31
87
  class RandomForest
32
88
  include Trees_utils
33
89
  class Base < RandomForest
@@ -38,6 +94,16 @@ module Weka
38
94
  end
39
95
  end
40
96
 
97
+ class RandomTree
98
+ include Trees_utils
99
+ class Base < RandomTree
100
+ def initialize
101
+ super
102
+ init_tree
103
+ end
104
+ end
105
+ end
106
+
41
107
  end
42
108
  end
43
109
  end
@@ -1,7 +1,7 @@
1
- #This module is used by the 'trees' classifiers from 'trees.rb'
2
- #to inherit the following methods (instance and class methods)
1
+ # This module is used by the 'trees' classifiers from 'trees.rb'
2
+ # to inherit the following methods (instance and class methods)
3
3
  module Trees_utils
4
- java_import "weka.core.Utils"
4
+ java_import "weka.core.Utils"
5
5
 
6
6
  def init_tree
7
7
  set_options(self.class.options) if self.class.options
@@ -9,39 +9,59 @@ module Trees_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.each {|key| puts "#{key.synopsis} #{key.description}"}
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
46
66
 
47
67
 
@@ -6,6 +6,19 @@ module Weka
6
6
  java_import 'weka.clusterers.SimpleKMeans'
7
7
  java_import 'weka.clusterers.FarthestFirst'
8
8
  java_import 'weka.clusterers.EM'
9
+ java_import 'weka.clusterers.XMeans'
10
+ java_import 'weka.clusterers.HierarchicalClusterer'
11
+ java_import 'weka.clusterers.Cobweb'
12
+
13
+ class Cobweb
14
+ include Clusterer_utils
15
+ class Base < Cobweb
16
+ def initialize
17
+ super
18
+ init_clusterer
19
+ end
20
+ end
21
+ end
9
22
 
10
23
  class EM
11
24
  include Clusterer_utils
@@ -17,6 +30,17 @@ module Weka
17
30
  end
18
31
  end
19
32
 
33
+ class HierarchicalClusterer
34
+ include Clusterer_utils
35
+ class Base < HierarchicalClusterer
36
+ def initialize
37
+ super
38
+ init_clusterer
39
+ end
40
+ end
41
+ end
42
+
43
+
20
44
  class SimpleKMeans
21
45
  include Clusterer_utils
22
46
  class Base < SimpleKMeans
@@ -37,5 +61,15 @@ module Weka
37
61
  end
38
62
  end
39
63
 
64
+ class XMeans
65
+ include Clusterer_utils
66
+ class Base < XMeans
67
+ def initialize
68
+ super
69
+ init_clusterer
70
+ end
71
+ end
72
+ end
73
+
40
74
  end
41
75
  end
@@ -20,9 +20,7 @@ module Clusterer_utils
20
20
  end
21
21
 
22
22
  def list_options
23
- options = ''
24
- listOptions.each {|key| options="#{options}\n#{key.synopsis} #{key.description}"}
25
- options
23
+ listOptions.map {|key| "#{key.synopsis} #{key.description}"}.join("\n")
26
24
  end
27
25
 
28
26
  def description
@@ -38,7 +36,7 @@ module Clusterer_utils
38
36
  end
39
37
 
40
38
  # 'data' is an Instances class object
41
- def validate
39
+ def evaluate
42
40
  eval = ClusterEvaluation.new
43
41
  eval.setClusterer(self)
44
42
  eval.evaluateClusterer(self.class.data)
@@ -1,74 +1,74 @@
1
1
  require 'java'
2
2
 
3
3
  module Weka
4
- module Db
5
- java_import 'weka.core.Instances'
6
- java_import 'weka.core.converters.DatabaseLoader'
7
- java_import 'weka.core.converters.DatabaseSaver'
4
+ module Db
5
+ java_import 'weka.core.Instances'
6
+ java_import 'weka.core.converters.DatabaseLoader'
7
+ java_import 'weka.core.converters.DatabaseSaver'
8
8
 
9
- # Query data from a MySQL database
10
- # * *Args* :
11
- # - +db_url+ -> The database URL
12
- # - +user+ -> User name
13
- # - +psw+ -> Password
14
- # - +quey+ -> A query to submit
15
- def Db.query_mysql(db_url,user,psw,query)
16
- open([[Dir.home],["DatabaseUtils.props"]].join("/"),'w') do |out|
17
- open(File.join(File.dirname(File.expand_path(__FILE__)), 'DatabaseUtils_mysql'),'r') do |f|
18
- f.each_line do |line|
19
- out.write line
20
- end
21
- end
22
- end
23
- loader = DatabaseLoader.new
24
- loader.setSource(db_url,user,psw)
25
- loader.setQuery(query)
26
- data = loader.getDataSet
27
- return data
28
- end
9
+ # Query data from a MySQL database
10
+ # * *Args* :
11
+ # - +db_url+ -> The database URL
12
+ # - +user+ -> User name
13
+ # - +psw+ -> Password
14
+ # - +quey+ -> A query to submit
15
+ def Db.query_mysql(db_url,user,psw,query)
16
+ open([[Dir.home],["DatabaseUtils.props"]].join("/"),'w') do |out|
17
+ open(File.join(File.dirname(File.expand_path(__FILE__)), 'DatabaseUtils_mysql'),'r') do |f|
18
+ f.each_line do |line|
19
+ out.write line
20
+ end
21
+ end
22
+ end
23
+ loader = DatabaseLoader.new
24
+ loader.setSource(db_url,user,psw)
25
+ loader.setQuery(query)
26
+ data = loader.getDataSet
27
+ return data
28
+ end
29
29
 
30
- # Query data from a PostgreSQL database
31
- # * *Args* :
32
- # - +db_url+ -> The database URL
33
- # - +user+ -> User name
34
- # - +psw+ -> Password
35
- # - +quey+ -> A query to submit
36
- def Db.query_postgresql(db_url,user,psw,query)
37
- open([[Dir.home],["DatabaseUtils.props"]].join("/"),'w') do |out|
38
- open(File.join(File.dirname(File.expand_path(__FILE__)), 'DatabaseUtils_postgresql'),'r') do |f|
39
- f.each_line do |line|
40
- out.write line
41
- end
42
- end
43
- end
44
- loader = DatabaseLoader.new
45
- loader.setSource(db_url,user,psw)
46
- loader.setQuery(query)
47
- data = loader.getDataSet
48
- return data
49
- end
30
+ # Query data from a PostgreSQL database
31
+ # * *Args* :
32
+ # - +db_url+ -> The database URL
33
+ # - +user+ -> User name
34
+ # - +psw+ -> Password
35
+ # - +quey+ -> A query to submit
36
+ def Db.query_postgresql(db_url,user,psw,query)
37
+ open([[Dir.home],["DatabaseUtils.props"]].join("/"),'w') do |out|
38
+ open(File.join(File.dirname(File.expand_path(__FILE__)), 'DatabaseUtils_postgresql'),'r') do |f|
39
+ f.each_line do |line|
40
+ out.write line
41
+ end
42
+ end
43
+ end
44
+ loader = DatabaseLoader.new
45
+ loader.setSource(db_url,user,psw)
46
+ loader.setQuery(query)
47
+ data = loader.getDataSet
48
+ return data
49
+ end
50
50
 
51
- # Save an Instances class object to a Mysql database
52
- # * *Args* :
53
- # - +db_url+ -> The database URL
54
- # - +user+ -> User name
55
- # - +psw+ -> Password
56
- # - +data+ -> An Instances class object
57
- # - +table+ -> The destination table in the database
58
- def Db.save_to_mysql(db_url,user,psw,data,table)
59
- open([[Dir.home],["DatabaseUtils.props"]].join("/"),'w') do |out|
60
- open(File.join(File.dirname(File.expand_path(__FILE__)), 'DatabaseUtils_mysql'),'r') do |f|
61
- f.each_line do |line|
62
- out.write line
63
- end
64
- end
65
- end
66
- saver = DatabaseSaver.new
67
- saver.setDestination(db_url,user,psw)
68
- saver.setTableName(table)
69
- saver.setRelationForTableName(false)
70
- saver.setInstances(data)
71
- saver.writeBatch
72
- end
73
- end
51
+ # Save an Instances class object to a Mysql database
52
+ # * *Args* :
53
+ # - +db_url+ -> The database URL
54
+ # - +user+ -> User name
55
+ # - +psw+ -> Password
56
+ # - +data+ -> An Instances class object
57
+ # - +table+ -> The destination table in the database
58
+ def Db.save_to_mysql(db_url,user,psw,data,table)
59
+ open([[Dir.home],["DatabaseUtils.props"]].join("/"),'w') do |out|
60
+ open(File.join(File.dirname(File.expand_path(__FILE__)), 'DatabaseUtils_mysql'),'r') do |f|
61
+ f.each_line do |line|
62
+ out.write line
63
+ end
64
+ end
65
+ end
66
+ saver = DatabaseSaver.new
67
+ saver.setDestination(db_url,user,psw)
68
+ saver.setTableName(table)
69
+ saver.setRelationForTableName(false)
70
+ saver.setInstances(data)
71
+ saver.writeBatch
72
+ end
73
+ end
74
74
  end
@@ -8,16 +8,46 @@ module Weka
8
8
  module Attribute
9
9
  java_import "weka.core.Utils"
10
10
  java_import "weka.filters.Filter"
11
+
12
+ java_import "weka.filters.supervised.attribute.AddClassification"
13
+ java_import "weka.filters.supervised.attribute.ClassOrder"
11
14
  java_import "weka.filters.supervised.attribute.AttributeSelection"
15
+ java_import "weka.filters.supervised.attribute.NominalToBinary"
16
+ java_import "weka.filters.supervised.attribute.PLSFilter"
12
17
  java_import "weka.filters.supervised.attribute.Discretize"
13
18
 
19
+ class AddClassification
20
+ include Supervised_Util
21
+ end
22
+
14
23
  class AttributeSelection
15
24
  include Supervised_Util
16
- end
25
+ java_alias :evaluator, :setEvaluator, [Java::Weka.attributeSelection.ASEvaluation]
26
+ java_alias :search, :setSearch, [Java::Weka.attributeSelection.ASSearch]
27
+ end
28
+
29
+ class ClassOrder
30
+ include Supervised_Util
31
+ end
17
32
 
18
33
  class Discretize
19
34
  include Supervised_Util
20
35
  end
36
+
37
+ class NominalToBinary
38
+ include Supervised_Util
39
+ end
40
+
41
+ class PLSFilter
42
+ include Supervised_Util
43
+ end
44
+
45
+ Weka::Filter::Supervised::Attribute::AttributeSelection.__persistent__ = true
46
+ Weka::Filter::Supervised::Attribute::Discretize.__persistent__ = true
47
+ Weka::Filter::Supervised::Attribute::AddClassification.__persistent__ = true
48
+ Weka::Filter::Supervised::Attribute::ClassOrder.__persistent__ = true
49
+ Weka::Filter::Supervised::Attribute::NominalToBinary.__persistent__ = true
50
+ Weka::Filter::Supervised::Attribute::PLSFilter.__persistent__ = true
21
51
 
22
52
  end
23
53
  end
@@ -1,32 +1,34 @@
1
1
  module Supervised_Util
2
- java_import "weka.core.Utils"
3
- java_import "weka.filters.Filter"
4
-
5
- #Instance methods list
6
- def filter_options
7
- begin
8
- listOptions.each {|key| puts "#{key.synopsis} #{key.description}"}
9
- rescue
10
- puts "Sorry, list option is available for this filter"
11
- end
12
- end
13
-
14
- def set_filter_options(options_string)
15
- options = Utils.splitOptions(options_string)
16
- setOptions(options)
17
- end
18
-
19
- def set_data(instances)
20
- setInputFormat(instances)
21
- @input = instances
22
- end
23
-
24
- def description
25
- begin; puts globalInfo; rescue; NoMethodError; puts "Sorry, no description available for this filter"; end
26
- end
27
-
28
- def use
29
- Filter.useFilter(@input,self)
30
- end
31
-
32
- end
2
+ java_import "weka.core.Utils"
3
+ java_import "weka.filters.Filter"
4
+
5
+ #Instance methods list
6
+ def options_list
7
+ listOptions.map {|key| "#{key.synopsis} #{key.description}"}.join("\n")
8
+ end
9
+
10
+ def filter_options(options_string)
11
+ options = Utils.splitOptions(options_string)
12
+ setOptions(options)
13
+ end
14
+
15
+ def data(instances)
16
+ setInputFormat(instances)
17
+ @input = instances
18
+ end
19
+
20
+ def description
21
+ globalInfo
22
+ end
23
+
24
+ def use
25
+ Filter.useFilter(@input,self)
26
+ end
27
+
28
+ def set(&block)
29
+ self.instance_eval(&block)
30
+ end
31
+
32
+ end
33
+
34
+