ai4r 1.9 → 1.11

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 (35) hide show
  1. data/README.rdoc +8 -21
  2. data/lib/ai4r.rb +1 -0
  3. data/lib/ai4r/classifiers/classifier.rb +3 -0
  4. data/lib/ai4r/classifiers/ib1.rb +121 -0
  5. data/lib/ai4r/classifiers/naive_bayes.rb +7 -1
  6. data/lib/ai4r/classifiers/zero_r.rb +3 -3
  7. data/lib/ai4r/neural_network/backpropagation.rb +35 -2
  8. data/test/classifiers/hyperpipes_test.rb +2 -2
  9. data/test/classifiers/ib1_test.rb +78 -0
  10. data/test/classifiers/id3_test.rb +2 -2
  11. data/test/classifiers/multilayer_perceptron_test.rb +2 -2
  12. data/test/classifiers/naive_bayes_test.rb +3 -3
  13. data/test/classifiers/one_r_test.rb +1 -1
  14. data/test/classifiers/prism_test.rb +1 -1
  15. data/test/classifiers/zero_r_test.rb +12 -11
  16. data/test/clusterers/average_linkage_test.rb +1 -1
  17. data/test/clusterers/bisecting_k_means_test.rb +1 -1
  18. data/test/clusterers/centroid_linkage_test.rb +1 -1
  19. data/test/clusterers/complete_linkage_test.rb +1 -1
  20. data/test/clusterers/diana_test.rb +2 -2
  21. data/test/clusterers/k_means_test.rb +1 -1
  22. data/test/clusterers/median_linkage_test.rb +1 -1
  23. data/test/clusterers/single_linkage_test.rb +1 -1
  24. data/test/clusterers/ward_linkage_test.rb +1 -1
  25. data/test/clusterers/weighted_average_linkage_test.rb +1 -1
  26. data/test/data/data_set_test.rb +1 -1
  27. data/test/data/proximity_test.rb +2 -2
  28. data/test/data/statistics_test.rb +2 -2
  29. data/test/experiment/classifier_evaluator_test.rb +2 -2
  30. data/test/genetic_algorithm/chromosome_test.rb +1 -2
  31. data/test/genetic_algorithm/genetic_algorithm_test.rb +2 -2
  32. data/test/neural_network/backpropagation_test.rb +15 -2
  33. data/test/neural_network/hopfield_test.rb +2 -2
  34. data/test/som/som_test.rb +2 -2
  35. metadata +130 -96
@@ -20,36 +20,23 @@ http://ai4r.rubyforge.org
20
20
 
21
21
  = More Info
22
22
 
23
- * AI4R wiki: http://wiki.jadeferret.com/Category:AI4R
24
23
  * AI4R Project site: http://ai4r.rubyforge.org
25
24
 
26
25
  = Contact
27
26
 
28
- If you have questions or constructive comments about this project,
29
- please post them in the forum (http://forum.jadeferret.com/viewforum.php?f=3).
30
- I get an email notification when you post, and I do my best to answer as soon as possible.
31
-
32
- If you do not want to make it public, send it to me: Sergio Fierens, email address: (sergio (at) jadeferret (dot) com). But please, try to post them in the forum. I get tons of emails and it would be great to make them public to help everyone.
33
-
34
- = Roadmap
35
-
36
- AI4R is an active project. If you are interested about what we are working on,
37
- checkout the development roadmap: http://wiki.jadeferret.com/AI4R_RoadMap
27
+ If you have questions or constructive comments about this project send it to me:
28
+ {Sergio Fierens}[https://github.com/SergioFierens], email address: (sergio (at) gmail (dot) com).
38
29
 
39
30
  = Contributors
40
31
 
41
- * Thomas Kern (SOM implementation and examples)
42
- * Sergio Fierens
32
+ This project was created and is maintained by {Sergio Fierens}[https://github.com/SergioFierens].
33
+ There are other (great and absolutely cool) people who have donated time and code to make this project better, including:
43
34
 
44
- = Disclaimer
35
+ * {Thomas Kern}[https://github.com/thomaskern]
36
+ * {Luis Parravicini}[https://github.com/luisparravicini]
37
+ * {Kevin Menard}[https://github.com/nirvdrum]
45
38
 
46
- In plain english:
47
-
48
- This project was created by Sergio Fierens, but the AI algorithms were created by other
49
- people who are actually much more clever than Sergio. He does his best implementing
50
- them, but he cannot warranty that these implementations are accurate.
51
-
52
- In legalese:
39
+ = Disclaimer
53
40
 
54
41
  This software is provided "as is" and without any express or implied warranties,
55
42
  including, without limitation, the implied warranties of merchantibility and
@@ -23,6 +23,7 @@ require File.dirname(__FILE__) + "/ai4r/classifiers/one_r"
23
23
  require File.dirname(__FILE__) + "/ai4r/classifiers/zero_r"
24
24
  require File.dirname(__FILE__) + "/ai4r/classifiers/hyperpipes"
25
25
  require File.dirname(__FILE__) + "/ai4r/classifiers/naive_bayes"
26
+ require File.dirname(__FILE__) + "/ai4r/classifiers/ib1"
26
27
  # Neural networks
27
28
  require File.dirname(__FILE__) + "/ai4r/neural_network/backpropagation"
28
29
  require File.dirname(__FILE__) + "/ai4r/neural_network/hopfield"
@@ -50,6 +50,9 @@ module Ai4r
50
50
  # eval classifier.get_rules
51
51
  # puts marketing_target
52
52
  # # => 'Y'
53
+ #
54
+ # Note, however, that not all classifiers are able to produce rules.
55
+ # This method is not implemented in such classifiers.
53
56
  def get_rules
54
57
  raise NotImplementedError
55
58
  end
@@ -0,0 +1,121 @@
1
+ # Author:: Sergio Fierens (Implementation only)
2
+ # License:: MPL 1.1
3
+ # Project:: ai4r
4
+ # Url:: http://ai4r.rubyforge.org/
5
+ #
6
+ # You can redistribute it and/or modify it under the terms of
7
+ # the Mozilla Public License version 1.1 as published by the
8
+ # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
+
10
+ require 'set'
11
+ require File.dirname(__FILE__) + '/../data/data_set'
12
+ require File.dirname(__FILE__) + '/../classifiers/classifier'
13
+
14
+ module Ai4r
15
+ module Classifiers
16
+
17
+ # = Introduction
18
+ #
19
+ # IB1 algorithm implementation.
20
+ # IB1 is the simplest instance-based learning (IBL) algorithm.
21
+ #
22
+ # D. Aha, D. Kibler (1991). Instance-based learning algorithms.
23
+ # Machine Learning. 6:37-66.
24
+ #
25
+ # IBI is identical to the nearest neighbor algorithm except that
26
+ # it normalizes its attributes' ranges, processes instances
27
+ # incrementally, and has a simple policy for tolerating missing values
28
+ class IB1 < Classifier
29
+
30
+ attr_reader :data_set
31
+
32
+ # Build a new IB1 classifier. You must provide a DataSet instance
33
+ # as parameter. The last attribute of each item is considered as
34
+ # the item class.
35
+ def build(data_set)
36
+ data_set.check_not_empty
37
+ @data_set = data_set
38
+ @min_values = Array.new(data_set.data_labels.length)
39
+ @max_values = Array.new(data_set.data_labels.length)
40
+ data_set.data_items.each { |data_item| update_min_max(data_item[0...-1]) }
41
+ return self
42
+ end
43
+
44
+ # You can evaluate new data, predicting its class.
45
+ # e.g.
46
+ # classifier.eval(['New York', '<30', 'F']) # => 'Y'
47
+ def eval(data)
48
+ update_min_max(data)
49
+ min_distance = 1.0/0
50
+ klass = nil
51
+ @data_set.data_items.each do |train_item|
52
+ d = distance(data, train_item)
53
+ if d < min_distance
54
+ min_distance = d
55
+ klass = train_item.last
56
+ end
57
+ end
58
+ return klass
59
+ end
60
+
61
+ protected
62
+
63
+ # We keep in the state the min and max value of each attribute,
64
+ # to provide normalized distances between to values of a numeric attribute
65
+ def update_min_max(atts)
66
+ atts.each_with_index do |att, i|
67
+ if att && att.is_a?(Numeric)
68
+ @min_values[i] = att if @min_values[i].nil? || @min_values[i] > att
69
+ @max_values[i] = att if @max_values[i].nil? || @max_values[i] < att
70
+ end
71
+ end
72
+ end
73
+
74
+ # Normalized distance between 2 instances
75
+ #
76
+ #
77
+ # Returns sum of
78
+ # * squared difference between normalized numeric att values
79
+ # * 1 for nominal atts which differs or one is missing
80
+ # * 1 if both atts are missing
81
+ # * normalized numeric att value if other att value is missing and > 0.5
82
+ # * 1.0-normalized numeric att value if other att value is missing and < 0.5
83
+ def distance(a, b)
84
+ d = 0
85
+ a.each_with_index do |att_a, i|
86
+ att_b = b[i]
87
+ if att_a.nil?
88
+ if att_b.is_a? Numeric
89
+ diff = norm(att_b, i)
90
+ diff = 1.0 - diff if diff < 0.5
91
+ else
92
+ diff = 1
93
+ end
94
+ elsif att_a.is_a? Numeric
95
+ if att_b.is_a? Numeric
96
+ diff = norm(att_a, i) - norm(att_b, i);
97
+ else
98
+ diff = norm(att_a, i)
99
+ diff = 1.0 - diff if diff < 0.5
100
+ end
101
+ elsif att_a != att_b
102
+ diff = 1
103
+ else
104
+ diff = 0
105
+ end
106
+ d += diff * diff
107
+ end
108
+ return d
109
+ end
110
+
111
+ # Returns normalized value att
112
+ #
113
+ # index is the index of the attribute in the instance.
114
+ def norm(att, index)
115
+ return 0 if @min_values[index].nil?
116
+ return 1.0*(att - @min_values[index]) / (@max_values[index] -@min_values[index]);
117
+ end
118
+
119
+ end
120
+ end
121
+ end
@@ -54,6 +54,7 @@ module Ai4r
54
54
  # build data
55
55
  # b.eval(["Red", "SUV", "Domestic"])
56
56
  #
57
+
57
58
  class NaiveBayes < Classifier
58
59
 
59
60
  parameters_info :m => "Default value is set to 0. It may be set to a value greater than " +
@@ -150,7 +151,7 @@ module Ai4r
150
151
 
151
152
  # returns the name of the class when the index is found
152
153
  def index_to_klass(index)
153
- @klass_index.has_value?(index) ? @klass_index.index(index) : nil
154
+ @klass_index.has_value?(index) ? @klass_index.key(index) : nil
154
155
  end
155
156
 
156
157
  # initializes @values and @klass_index; maps a certain value to a uniq index
@@ -257,3 +258,8 @@ module Ai4r
257
258
  end
258
259
  end
259
260
  end
261
+
262
+ # Monkeypatch to support both ruby 1.8 and 1.9 (key vs index method)
263
+ class Hash
264
+ alias_method(:key, :index) unless method_defined?(:key)
265
+ end
@@ -30,13 +30,13 @@ module Ai4r
30
30
  def build(data_set)
31
31
  data_set.check_not_empty
32
32
  @data_set = data_set
33
- frequence = {}
33
+ frequencies = {}
34
34
  max_freq = 0
35
35
  @class_value = nil
36
36
  @data_set.data_items.each do |example|
37
37
  class_value = example.last
38
- class_frequency = frequence[class_value]
39
- class_frequency = (class_frequency) ? class_frequency+1 : 1
38
+ frequencies[class_value] = frequencies[class_value].nil? ? 1 : frequencies[class_value] + 1
39
+ class_frequency = frequencies[class_value]
40
40
  if max_freq < class_frequency
41
41
  max_freq = class_frequency
42
42
  @class_value = class_value
@@ -100,7 +100,7 @@ module Ai4r
100
100
  :momentum => "By default 0.1. Set this parameter to 0 to disable "+
101
101
  "momentum."
102
102
 
103
- attr_accessor :structure, :weights, :activation_nodes
103
+ attr_accessor :structure, :weights, :activation_nodes, :last_changes
104
104
 
105
105
  # Creates a new network specifying the its architecture.
106
106
  # E.g.
@@ -158,9 +158,42 @@ module Ai4r
158
158
  init_last_changes
159
159
  return self
160
160
  end
161
-
161
+
162
162
  protected
163
163
 
164
+ # Custom serialization. It used to fail trying to serialize because
165
+ # it uses lambda functions internally, and they cannot be serialized.
166
+ # Now it does not fail, but if you customize the values of
167
+ # * initial_weight_function
168
+ # * propagation_function
169
+ # * derivative_propagation_function
170
+ # you must restore their values manually after loading the instance.
171
+ def marshal_dump
172
+ [
173
+ @structure,
174
+ @disable_bias,
175
+ @learning_rate,
176
+ @momentum,
177
+ @weights,
178
+ @last_changes,
179
+ @activation_nodes
180
+ ]
181
+ end
182
+
183
+ def marshal_load(ary)
184
+ @structure,
185
+ @disable_bias,
186
+ @learning_rate,
187
+ @momentum,
188
+ @weights,
189
+ @last_changes,
190
+ @activation_nodes = ary
191
+ @initial_weight_function = lambda { |n, i, j| ((rand 2000)/1000.0) - 1}
192
+ @propagation_function = lambda { |x| 1/(1+Math.exp(-1*(x))) } #lambda { |x| Math.tanh(x) }
193
+ @derivative_propagation_function = lambda { |y| y*(1-y) } #lambda { |y| 1.0 - y**2 }
194
+ end
195
+
196
+
164
197
  # Propagate error backwards
165
198
  def backpropagate(expected_output_values)
166
199
  check_output_dimension(expected_output_values.length)
@@ -7,7 +7,7 @@
7
7
  # the Mozilla Public License version 1.1 as published by the
8
8
  # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
9
 
10
- require File.dirname(__FILE__) + '/../../lib/ai4r/classifiers/hyperpipes'
10
+ require 'ai4r/classifiers/hyperpipes'
11
11
  require 'test/unit'
12
12
 
13
13
  class Ai4r::Classifiers::Hyperpipes
@@ -81,4 +81,4 @@ class HyperpipesTest < Test::Unit::TestCase
81
81
  end
82
82
  end
83
83
 
84
-
84
+
@@ -0,0 +1,78 @@
1
+ # Author:: Sergio Fierens
2
+ # License:: MPL 1.1
3
+ # Project:: ai4r
4
+ # Url:: http://ai4r.rubyforge.org/
5
+ #
6
+ # You can redistribute it and/or modify it under the terms of
7
+ # the Mozilla Public License version 1.1 as published by the
8
+ # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
+
10
+ require 'ai4r/classifiers/ib1'
11
+ require 'test/unit'
12
+
13
+ class Ai4r::Classifiers::IB1
14
+ attr_accessor :data_set, :min_values, :max_values
15
+ end
16
+
17
+ include Ai4r::Classifiers
18
+ include Ai4r::Data
19
+
20
+ class IB1Test < Test::Unit::TestCase
21
+
22
+ @@data_labels = [ 'city', 'age', 'gender', 'marketing_target' ]
23
+
24
+ @@data_items = [['New York', 25, 'M', 'Y'],
25
+ ['New York', 23, 'M', 'Y'],
26
+ ['New York', 18, 'M', 'Y'],
27
+ ['Chicago', 43, 'M', 'Y'],
28
+ ['New York', 34, 'F', 'N'],
29
+ ['Chicago', 33, 'F', 'Y'],
30
+ ['New York', 31, 'F', 'N'],
31
+ ['Chicago', 55, 'M', 'N'],
32
+ ['New York', 58, 'F', 'N'],
33
+ ['New York', 59, 'M', 'N'],
34
+ ['Chicago', 71, 'M', 'N'],
35
+ ['New York', 60, 'F', 'N'],
36
+ ['Chicago', 85, 'F', 'Y']
37
+ ]
38
+
39
+
40
+ def setup
41
+ IB1.send(:public, *IB1.protected_instance_methods)
42
+ @data_set = DataSet.new(:data_items => @@data_items, :data_labels => @@data_labels)
43
+ @classifier = IB1.new.build(@data_set)
44
+ end
45
+
46
+ def test_build
47
+ assert_raise(ArgumentError) { IB1.new.build(DataSet.new) }
48
+ assert @classifier.data_set
49
+ assert_equal [nil, 18, nil, nil], @classifier.min_values
50
+ assert_equal [nil, 85, nil, nil], @classifier.max_values
51
+ end
52
+
53
+ def test_norm
54
+ assert_equal(0,@classifier.norm('Chicago', 0))
55
+ assert_in_delta(0.5522,@classifier.norm(55, 1),0.0001)
56
+ assert_equal(0,@classifier.norm('F', 0))
57
+ end
58
+
59
+ def test_distance
60
+ item = ['Chicago', 55, 'M', 'N']
61
+ assert_equal(0, @classifier.distance(['Chicago', 55, 'M'], item))
62
+ assert_equal(1, @classifier.distance([nil, 55, 'M'], item))
63
+ assert_equal(1, @classifier.distance(['New York', 55, 'M'], item))
64
+ assert_in_delta(0.2728, @classifier.distance(['Chicago', 20, 'M'], item), 0.0001)
65
+ end
66
+
67
+ def test_eval
68
+ classifier = IB1.new.build(@data_set)
69
+ assert classifier
70
+ assert_equal('N', classifier.eval(['Chicago', 55, 'M']))
71
+ assert_equal('N', classifier.eval(['New York', 35, 'F']))
72
+ assert_equal('Y', classifier.eval(['New York', 25, 'M']))
73
+ assert_equal('Y', classifier.eval(['Chicago', 85, 'F']))
74
+ end
75
+
76
+ end
77
+
78
+
@@ -12,7 +12,7 @@
12
12
  # the Mozilla Public License version 1.1 as published by the
13
13
  # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
14
14
 
15
- require File.dirname(__FILE__) + '/../../lib/ai4r/classifiers/id3'
15
+ require 'ai4r/classifiers/id3'
16
16
  require 'test/unit'
17
17
 
18
18
  DATA_LABELS = [ 'city', 'age_range', 'gender', 'marketing_target' ]
@@ -205,4 +205,4 @@ class ID3Test < Test::Unit::TestCase
205
205
  end
206
206
  end
207
207
 
208
-
208
+
@@ -1,6 +1,6 @@
1
1
  require 'test/unit'
2
- require File.dirname(__FILE__) + '/../../lib/ai4r/classifiers/multilayer_perceptron'
3
- require File.dirname(__FILE__) + '/../../lib/ai4r/data/data_set'
2
+ require 'ai4r/classifiers/multilayer_perceptron'
3
+ require 'ai4r/data/data_set'
4
4
 
5
5
  # Make all accessors and methods public
6
6
  class Ai4r::Classifiers::MultilayerPerceptron
@@ -1,5 +1,5 @@
1
- require File.dirname(__FILE__) + '/../../lib/ai4r/classifiers/naive_bayes'
2
- require File.dirname(__FILE__) + '/../../lib/ai4r/data/data_set'
1
+ require 'ai4r/classifiers/naive_bayes'
2
+ require 'ai4r/data/data_set'
3
3
  require 'test/unit'
4
4
 
5
5
  include Ai4r::Classifiers
@@ -40,4 +40,4 @@ class NaiveBayesTest < Test::Unit::TestCase
40
40
  assert_in_delta 0.58, map["No"], 0.1
41
41
  end
42
42
 
43
- end
43
+ end
@@ -1,5 +1,5 @@
1
1
  require 'test/unit'
2
- require File.dirname(__FILE__) + '/../../lib/ai4r/classifiers/one_r'
2
+ require 'ai4r/classifiers/one_r'
3
3
 
4
4
  class OneRTest < Test::Unit::TestCase
5
5
 
@@ -1,5 +1,5 @@
1
1
  require 'test/unit'
2
- require File.dirname(__FILE__) + '/../../lib/ai4r/classifiers/prism'
2
+ require 'ai4r/classifiers/prism'
3
3
 
4
4
 
5
5
  class PrismTest < Test::Unit::TestCase
@@ -1,20 +1,21 @@
1
1
  require 'test/unit'
2
- require File.dirname(__FILE__) + '/../../lib/ai4r/classifiers/zero_r'
3
- require File.dirname(__FILE__) + '/../../lib/ai4r/data/data_set'
2
+ require 'ai4r/classifiers/zero_r'
3
+ require 'ai4r/data/data_set'
4
4
 
5
5
  class ZeroRTest < Test::Unit::TestCase
6
6
 
7
7
  include Ai4r::Classifiers
8
8
  include Ai4r::Data
9
-
10
- @@data_examples = [ ['New York', '<30', 'M', 'Y'],
11
- ['Chicago', '<30', 'M', 'Y'],
12
- ['New York', '<30', 'M', 'Y'],
13
- ['New York', '[30-50)', 'F', 'N'],
14
- ['Chicago', '[30-50)', 'F', 'Y'],
15
- ['New York', '[30-50)', 'F', 'N'],
16
- ['Chicago', '[50-80]', 'M', 'N'],
17
- ]
9
+
10
+ @@data_examples = [
11
+ ['New York', '[30-50)', 'F', 'N'],
12
+ ['New York', '<30', 'M', 'Y'],
13
+ ['Chicago', '<30', 'M', 'Y'],
14
+ ['New York', '<30', 'M', 'Y'],
15
+ ['Chicago', '[30-50)', 'F', 'Y'],
16
+ ['New York', '[30-50)', 'F', 'N'],
17
+ ['Chicago', '[50-80]', 'M', 'N'],
18
+ ]
18
19
 
19
20
  @@data_labels = [ 'city', 'age_range', 'gender', 'marketing_target' ]
20
21
 
@@ -8,7 +8,7 @@
8
8
  # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
9
 
10
10
  require 'test/unit'
11
- require File.dirname(__FILE__) + '/../../lib/ai4r/clusterers/average_linkage'
11
+ require 'ai4r/clusterers/average_linkage'
12
12
 
13
13
  class Ai4r::Clusterers::AverageLinkage < Ai4r::Clusterers::SingleLinkage
14
14
  attr_accessor :data_set, :number_of_clusters, :clusters, :distance_matrix
@@ -8,7 +8,7 @@
8
8
  # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
9
 
10
10
  require 'test/unit'
11
- require File.dirname(__FILE__) + '/../../lib/ai4r/clusterers/bisecting_k_means'
11
+ require 'ai4r/clusterers/bisecting_k_means'
12
12
 
13
13
  class BisectingKMeansTest < Test::Unit::TestCase
14
14
 
@@ -8,7 +8,7 @@
8
8
  # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
9
 
10
10
  require 'test/unit'
11
- require File.dirname(__FILE__) + '/../../lib/ai4r/clusterers/centroid_linkage'
11
+ require 'ai4r/clusterers/centroid_linkage'
12
12
 
13
13
  class Ai4r::Clusterers::CentroidLinkage
14
14
  attr_accessor :data_set, :number_of_clusters, :clusters, :distance_matrix, :index_clusters
@@ -8,7 +8,7 @@
8
8
  # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
9
 
10
10
  require 'test/unit'
11
- require File.dirname(__FILE__) + '/../../lib/ai4r/clusterers/complete_linkage'
11
+ require 'ai4r/clusterers/complete_linkage'
12
12
 
13
13
  class Ai4r::Clusterers::CompleteLinkage
14
14
  attr_accessor :data_set, :number_of_clusters, :clusters, :distance_matrix
@@ -8,7 +8,7 @@
8
8
  # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
9
 
10
10
  require 'test/unit'
11
- require File.dirname(__FILE__) + '/../../lib/ai4r/clusterers/diana'
11
+ require 'ai4r/clusterers/diana'
12
12
 
13
13
  class Ai4r::Clusterers::Diana
14
14
  attr_accessor :data_set, :number_of_clusters, :clusters
@@ -66,4 +66,4 @@ class DianaTest < Test::Unit::TestCase
66
66
  max_distance_difference(data_set_a, data_set_b)
67
67
  end
68
68
 
69
- end
69
+ end
@@ -8,7 +8,7 @@
8
8
  # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
9
 
10
10
  require 'test/unit'
11
- require File.dirname(__FILE__) + '/../../lib/ai4r/clusterers/k_means'
11
+ require 'ai4r/clusterers/k_means'
12
12
 
13
13
  class KMeansTest < Test::Unit::TestCase
14
14
 
@@ -8,7 +8,7 @@
8
8
  # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
9
 
10
10
  require 'test/unit'
11
- require File.dirname(__FILE__) + '/../../lib/ai4r/clusterers/median_linkage'
11
+ require 'ai4r/clusterers/median_linkage'
12
12
 
13
13
  class Ai4r::Clusterers::MedianLinkage
14
14
  attr_accessor :data_set, :number_of_clusters, :clusters, :distance_matrix, :index_clusters
@@ -8,7 +8,7 @@
8
8
  # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
9
 
10
10
  require 'test/unit'
11
- require File.dirname(__FILE__) + '/../../lib/ai4r/clusterers/single_linkage'
11
+ require 'ai4r/clusterers/single_linkage'
12
12
 
13
13
  class Ai4r::Clusterers::SingleLinkage
14
14
  attr_accessor :data_set, :number_of_clusters, :clusters, :distance_matrix
@@ -8,7 +8,7 @@
8
8
  # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
9
 
10
10
  require 'test/unit'
11
- require File.dirname(__FILE__) + '/../../lib/ai4r/clusterers/ward_linkage'
11
+ require 'ai4r/clusterers/ward_linkage'
12
12
 
13
13
  class Ai4r::Clusterers::WardLinkage
14
14
  attr_accessor :data_set, :number_of_clusters, :clusters, :distance_matrix, :index_clusters
@@ -8,7 +8,7 @@
8
8
  # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
9
 
10
10
  require 'test/unit'
11
- require File.dirname(__FILE__) + '/../../lib/ai4r/clusterers/weighted_average_linkage'
11
+ require 'ai4r/clusterers/weighted_average_linkage'
12
12
 
13
13
  class Ai4r::Clusterers::WeightedAverageLinkage
14
14
  attr_accessor :data_set, :number_of_clusters, :clusters, :distance_matrix, :index_clusters
@@ -8,7 +8,7 @@
8
8
  # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
9
 
10
10
  require 'test/unit'
11
- require File.dirname(__FILE__) + '/../../lib/ai4r/data/data_set'
11
+ require 'ai4r/data/data_set'
12
12
 
13
13
  module Ai4r
14
14
  module Data
@@ -8,7 +8,7 @@
8
8
  # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
9
 
10
10
  require 'test/unit'
11
- require File.dirname(__FILE__) + '/../../lib/ai4r/data/proximity'
11
+ require 'ai4r/data/proximity'
12
12
 
13
13
  module Ai4r
14
14
  module Data
@@ -78,4 +78,4 @@ module Ai4r
78
78
 
79
79
  end
80
80
  end
81
- end
81
+ end
@@ -8,7 +8,7 @@
8
8
  # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
9
 
10
10
  require 'test/unit'
11
- require File.dirname(__FILE__) + '/../../lib/ai4r/data/statistics'
11
+ require 'ai4r/data/statistics'
12
12
 
13
13
  module Ai4r
14
14
  module Data
@@ -62,4 +62,4 @@ module Ai4r
62
62
 
63
63
  end
64
64
  end
65
- end
65
+ end
@@ -8,8 +8,8 @@
8
8
  # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
9
 
10
10
  require 'test/unit'
11
- require File.dirname(__FILE__) + '/../../lib/ai4r/experiment/classifier_evaluator'
12
- require File.dirname(__FILE__) + '/../../lib/ai4r/classifiers/classifier'
11
+ require 'ai4r/experiment/classifier_evaluator'
12
+ require 'ai4r/classifiers/classifier'
13
13
 
14
14
  class MockClassifier < Ai4r::Classifiers::Classifier
15
15
 
@@ -8,8 +8,7 @@
8
8
  # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
9
 
10
10
 
11
- require File.dirname(__FILE__) + '/../../lib/ai4r/genetic_algorithm/genetic_algorithm'
12
-
11
+ require 'ai4r/genetic_algorithm/genetic_algorithm'
13
12
  require 'test/unit'
14
13
 
15
14
  module Ai4r
@@ -7,7 +7,7 @@
7
7
  # the Mozilla Public License version 1.1 as published by the
8
8
  # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
9
9
 
10
- require File.dirname(__FILE__) + '/../../lib/ai4r/genetic_algorithm/genetic_algorithm'
10
+ require 'ai4r/genetic_algorithm/genetic_algorithm'
11
11
  require 'test/unit'
12
12
 
13
13
  module Ai4r
@@ -78,4 +78,4 @@ module Ai4r
78
78
 
79
79
  end
80
80
 
81
- end
81
+ end
@@ -15,7 +15,7 @@
15
15
  #
16
16
 
17
17
 
18
- require File.dirname(__FILE__) + '/../../lib/ai4r/neural_network/backpropagation'
18
+ require 'ai4r/neural_network/backpropagation'
19
19
  require 'test/unit'
20
20
 
21
21
  Ai4r::NeuralNetwork::Backpropagation.send(:public, *Ai4r::NeuralNetwork::Backpropagation.protected_instance_methods)
@@ -62,8 +62,21 @@ module Ai4r
62
62
  assert y.length == 7
63
63
  end
64
64
 
65
+ def test_dump
66
+ net = Backpropagation.new([3, 2]).init_network
67
+ s = Marshal.dump(net)
68
+ x = Marshal.load(s)
69
+ assert_equal net.structure, x.structure
70
+ assert_equal net.disable_bias, x.disable_bias
71
+ assert_equal net.learning_rate, x.learning_rate
72
+ assert_equal net.momentum, x.momentum
73
+ assert_equal net.weights, x.weights
74
+ assert_equal net.last_changes, x.last_changes
75
+ assert_equal net.activation_nodes, x.activation_nodes
76
+ end
77
+
65
78
  end
66
79
 
67
80
  end
68
81
 
69
- end
82
+ end
@@ -9,7 +9,7 @@
9
9
  # the Mozilla Public License version 1.1 as published by the
10
10
  # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
11
11
 
12
- require File.dirname(__FILE__) + '/../../lib/ai4r'
12
+ require 'ai4r'
13
13
  require 'test/unit'
14
14
 
15
15
  Ai4r::NeuralNetwork::Hopfield.send(:public, *Ai4r::NeuralNetwork::Hopfield.protected_instance_methods)
@@ -69,4 +69,4 @@ module Ai4r
69
69
 
70
70
  end
71
71
  end
72
- end
72
+ end
@@ -10,7 +10,7 @@
10
10
  # the Mozilla Public License version 1.1 as published by the
11
11
  # Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
12
12
 
13
- require File.dirname(__FILE__) + '/../../lib/ai4r/som/som'
13
+ require 'ai4r/som/som'
14
14
  require 'test/unit'
15
15
 
16
16
  module Ai4r
@@ -94,4 +94,4 @@ module Ai4r
94
94
 
95
95
  end
96
96
 
97
- end
97
+ end
metadata CHANGED
@@ -1,131 +1,165 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: ai4r
5
3
  version: !ruby/object:Gem::Version
6
- version: "1.9"
7
- date: 2009-07-01 00:00:00 +01:00
8
- summary: Ruby implementations of algorithms covering several Artificial intelligence fields, including Genetic algorithms, Neural Networks, machine learning, and clustering.
9
- require_paths:
10
- - lib
11
- email: sergio@jadeferret.com
12
- homepage: http://ai4r.rubyforge.org
13
- rubyforge_project: ai4r
14
- description:
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 11
9
+ version: "1.11"
25
10
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
11
  authors:
30
12
  - Sergio Fierens
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-02-28 00:00:00 Z
18
+ dependencies: []
19
+
20
+ description:
21
+ email: sergio.fierens@gmail.com
22
+ executables: []
23
+
24
+ extensions: []
25
+
26
+ extra_rdoc_files:
27
+ - README.rdoc
31
28
  files:
32
- - examples/classifiers
33
- - examples/classifiers/id3_data.csv
29
+ - examples/som/som_multi_node_example.rb
30
+ - examples/som/som_single_example.rb
31
+ - examples/som/som_data.rb
32
+ - examples/neural_network/patterns_with_noise.rb
33
+ - examples/neural_network/patterns_with_base_noise.rb
34
+ - examples/neural_network/training_patterns.rb
35
+ - examples/neural_network/xor_example.rb
36
+ - examples/neural_network/backpropagation_example.rb
34
37
  - examples/classifiers/id3_example.rb
35
- - examples/classifiers/naive_bayes_data.csv
36
38
  - examples/classifiers/naive_bayes_example.rb
39
+ - examples/classifiers/id3_data.csv
40
+ - examples/classifiers/naive_bayes_data.csv
37
41
  - examples/classifiers/results.txt
38
- - examples/clusterers
39
- - examples/genetic_algorithm
40
- - examples/genetic_algorithm/genetic_algorithm_example.rb
41
42
  - examples/genetic_algorithm/travel_cost.csv
42
- - examples/neural_network
43
- - examples/neural_network/backpropagation_example.rb
44
- - examples/neural_network/patterns_with_base_noise.rb
45
- - examples/neural_network/patterns_with_noise.rb
46
- - examples/neural_network/training_patterns.rb
47
- - examples/neural_network/xor_example.rb
48
- - examples/som
49
- - examples/som/som_data.rb
50
- - examples/som/som_multi_node_example.rb
51
- - examples/som/som_single_example.rb
52
- - lib/ai4r
53
- - lib/ai4r/classifiers
54
- - lib/ai4r/classifiers/classifier.rb
55
- - lib/ai4r/classifiers/hyperpipes.rb
56
- - lib/ai4r/classifiers/id3.rb
57
- - lib/ai4r/classifiers/multilayer_perceptron.rb
58
- - lib/ai4r/classifiers/naive_bayes.rb
59
- - lib/ai4r/classifiers/one_r.rb
60
- - lib/ai4r/classifiers/prism.rb
61
- - lib/ai4r/classifiers/zero_r.rb
62
- - lib/ai4r/clusterers
63
- - lib/ai4r/clusterers/average_linkage.rb
64
- - lib/ai4r/clusterers/bisecting_k_means.rb
65
- - lib/ai4r/clusterers/centroid_linkage.rb
43
+ - examples/genetic_algorithm/genetic_algorithm_example.rb
44
+ - lib/ai4r.rb
45
+ - lib/ai4r/som/layer.rb
46
+ - lib/ai4r/som/node.rb
47
+ - lib/ai4r/som/som.rb
48
+ - lib/ai4r/som/two_phase_layer.rb
49
+ - lib/ai4r/clusterers/median_linkage.rb
66
50
  - lib/ai4r/clusterers/clusterer.rb
67
- - lib/ai4r/clusterers/complete_linkage.rb
68
- - lib/ai4r/clusterers/diana.rb
69
51
  - lib/ai4r/clusterers/k_means.rb
70
- - lib/ai4r/clusterers/median_linkage.rb
71
52
  - lib/ai4r/clusterers/single_linkage.rb
72
- - lib/ai4r/clusterers/ward_linkage.rb
53
+ - lib/ai4r/clusterers/diana.rb
73
54
  - lib/ai4r/clusterers/weighted_average_linkage.rb
74
- - lib/ai4r/data
55
+ - lib/ai4r/clusterers/centroid_linkage.rb
56
+ - lib/ai4r/clusterers/complete_linkage.rb
57
+ - lib/ai4r/clusterers/average_linkage.rb
58
+ - lib/ai4r/clusterers/bisecting_k_means.rb
59
+ - lib/ai4r/clusterers/ward_linkage.rb
60
+ - lib/ai4r/data/statistics.rb
75
61
  - lib/ai4r/data/data_set.rb
76
62
  - lib/ai4r/data/parameterizable.rb
77
63
  - lib/ai4r/data/proximity.rb
78
- - lib/ai4r/data/statistics.rb
79
- - lib/ai4r/experiment
80
- - lib/ai4r/experiment/classifier_evaluator.rb
81
- - lib/ai4r/genetic_algorithm
82
- - lib/ai4r/genetic_algorithm/genetic_algorithm.rb
83
- - lib/ai4r/neural_network
84
64
  - lib/ai4r/neural_network/backpropagation.rb
85
65
  - lib/ai4r/neural_network/hopfield.rb
86
- - lib/ai4r/som
87
- - lib/ai4r/som/layer.rb
88
- - lib/ai4r/som/node.rb
89
- - lib/ai4r/som/som.rb
90
- - lib/ai4r/som/two_phase_layer.rb
91
- - lib/ai4r.rb
66
+ - lib/ai4r/classifiers/one_r.rb
67
+ - lib/ai4r/classifiers/multilayer_perceptron.rb
68
+ - lib/ai4r/classifiers/classifier.rb
69
+ - lib/ai4r/classifiers/ib1.rb
70
+ - lib/ai4r/classifiers/prism.rb
71
+ - lib/ai4r/classifiers/zero_r.rb
72
+ - lib/ai4r/classifiers/id3.rb
73
+ - lib/ai4r/classifiers/naive_bayes.rb
74
+ - lib/ai4r/classifiers/hyperpipes.rb
75
+ - lib/ai4r/experiment/classifier_evaluator.rb
76
+ - lib/ai4r/genetic_algorithm/genetic_algorithm.rb
92
77
  - README.rdoc
93
- test_files:
94
- - test/classifiers/hyperpipes_test.rb
95
- - test/classifiers/id3_test.rb
96
- - test/classifiers/multilayer_perceptron_test.rb
97
- - test/classifiers/naive_bayes_test.rb
98
- - test/classifiers/one_r_test.rb
99
- - test/classifiers/prism_test.rb
100
- - test/classifiers/zero_r_test.rb
78
+ - test/som/som_test.rb
79
+ - test/clusterers/ward_linkage_test.rb
80
+ - test/clusterers/median_linkage_test.rb
81
+ - test/clusterers/diana_test.rb
101
82
  - test/clusterers/average_linkage_test.rb
102
- - test/clusterers/bisecting_k_means_test.rb
103
83
  - test/clusterers/centroid_linkage_test.rb
104
84
  - test/clusterers/complete_linkage_test.rb
105
- - test/clusterers/diana_test.rb
106
- - test/clusterers/k_means_test.rb
107
- - test/clusterers/median_linkage_test.rb
108
85
  - test/clusterers/single_linkage_test.rb
109
- - test/clusterers/ward_linkage_test.rb
86
+ - test/clusterers/bisecting_k_means_test.rb
87
+ - test/clusterers/k_means_test.rb
110
88
  - test/clusterers/weighted_average_linkage_test.rb
111
- - test/data/data_set_test.rb
112
89
  - test/data/proximity_test.rb
113
90
  - test/data/statistics_test.rb
91
+ - test/data/data_set_test.rb
92
+ - test/neural_network/backpropagation_test.rb
93
+ - test/neural_network/hopfield_test.rb
94
+ - test/classifiers/one_r_test.rb
95
+ - test/classifiers/multilayer_perceptron_test.rb
96
+ - test/classifiers/hyperpipes_test.rb
97
+ - test/classifiers/ib1_test.rb
98
+ - test/classifiers/zero_r_test.rb
99
+ - test/classifiers/naive_bayes_test.rb
100
+ - test/classifiers/id3_test.rb
101
+ - test/classifiers/prism_test.rb
114
102
  - test/experiment/classifier_evaluator_test.rb
115
103
  - test/genetic_algorithm/chromosome_test.rb
116
104
  - test/genetic_algorithm/genetic_algorithm_test.rb
117
- - test/neural_network/backpropagation_test.rb
118
- - test/neural_network/hopfield_test.rb
119
- - test/som/som_test.rb
120
- rdoc_options: []
121
-
122
- extra_rdoc_files:
123
- - README.rdoc
124
- executables: []
105
+ homepage: http://ai4r.rubyforge.org
106
+ licenses: []
125
107
 
126
- extensions: []
108
+ post_install_message:
109
+ rdoc_options: []
127
110
 
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ hash: 3
128
+ segments:
129
+ - 0
130
+ version: "0"
128
131
  requirements: []
129
132
 
130
- dependencies: []
131
-
133
+ rubyforge_project: ai4r
134
+ rubygems_version: 1.7.2
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: Ruby implementations of algorithms covering several Artificial intelligence fields, including Genetic algorithms, Neural Networks, machine learning, and clustering.
138
+ test_files:
139
+ - test/som/som_test.rb
140
+ - test/clusterers/ward_linkage_test.rb
141
+ - test/clusterers/median_linkage_test.rb
142
+ - test/clusterers/diana_test.rb
143
+ - test/clusterers/average_linkage_test.rb
144
+ - test/clusterers/centroid_linkage_test.rb
145
+ - test/clusterers/complete_linkage_test.rb
146
+ - test/clusterers/single_linkage_test.rb
147
+ - test/clusterers/bisecting_k_means_test.rb
148
+ - test/clusterers/k_means_test.rb
149
+ - test/clusterers/weighted_average_linkage_test.rb
150
+ - test/data/proximity_test.rb
151
+ - test/data/statistics_test.rb
152
+ - test/data/data_set_test.rb
153
+ - test/neural_network/backpropagation_test.rb
154
+ - test/neural_network/hopfield_test.rb
155
+ - test/classifiers/one_r_test.rb
156
+ - test/classifiers/multilayer_perceptron_test.rb
157
+ - test/classifiers/hyperpipes_test.rb
158
+ - test/classifiers/ib1_test.rb
159
+ - test/classifiers/zero_r_test.rb
160
+ - test/classifiers/naive_bayes_test.rb
161
+ - test/classifiers/id3_test.rb
162
+ - test/classifiers/prism_test.rb
163
+ - test/experiment/classifier_evaluator_test.rb
164
+ - test/genetic_algorithm/chromosome_test.rb
165
+ - test/genetic_algorithm/genetic_algorithm_test.rb