brainz 0.1.1 → 0.1.2

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/Manifest CHANGED
@@ -3,6 +3,7 @@ README.rdoc
3
3
  Rakefile
4
4
  brainz.gemspec
5
5
  examples/and.rb
6
+ examples/multi_layer_xor.rb
6
7
  examples/sign.rb
7
8
  examples/xor.rb
8
9
  lib/brainz.rb
@@ -18,6 +19,7 @@ lib/ext/array.rb
18
19
  spec/array_spec.rb
19
20
  spec/brainz_spec.rb
20
21
  spec/loader_spec.rb
22
+ spec/neuron_spec.rb
21
23
  spec/spec_helper.rb
22
24
  spec/temp/brainz.b
23
25
  Manifest
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "brainz"
5
- s.version = "0.1.1"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Vilius Luneckas"]
9
- s.date = "2012-03-20"
9
+ s.date = "2012-03-26"
10
10
  s.description = "Simple artificial intelligence"
11
11
  s.email = "vilius.luneckas@gmail.com"
12
12
  s.extra_rdoc_files = ["LICENSE", "README.rdoc", "lib/brainz.rb", "lib/brainz/backpropagation.rb", "lib/brainz/brainz.rb", "lib/brainz/layer.rb", "lib/brainz/loader.rb", "lib/brainz/network.rb", "lib/brainz/neuron.rb", "lib/brainz/synapse.rb", "lib/brainz/version.rb", "lib/ext/array.rb"]
13
- s.files = ["LICENSE", "README.rdoc", "Rakefile", "brainz.gemspec", "examples/and.rb", "examples/sign.rb", "examples/xor.rb", "lib/brainz.rb", "lib/brainz/backpropagation.rb", "lib/brainz/brainz.rb", "lib/brainz/layer.rb", "lib/brainz/loader.rb", "lib/brainz/network.rb", "lib/brainz/neuron.rb", "lib/brainz/synapse.rb", "lib/brainz/version.rb", "lib/ext/array.rb", "spec/array_spec.rb", "spec/brainz_spec.rb", "spec/loader_spec.rb", "spec/spec_helper.rb", "spec/temp/brainz.b", "Manifest"]
13
+ s.files = ["LICENSE", "README.rdoc", "Rakefile", "brainz.gemspec", "examples/and.rb", "examples/multi_layer_xor.rb", "examples/sign.rb", "examples/xor.rb", "lib/brainz.rb", "lib/brainz/backpropagation.rb", "lib/brainz/brainz.rb", "lib/brainz/layer.rb", "lib/brainz/loader.rb", "lib/brainz/network.rb", "lib/brainz/neuron.rb", "lib/brainz/synapse.rb", "lib/brainz/version.rb", "lib/ext/array.rb", "spec/array_spec.rb", "spec/brainz_spec.rb", "spec/loader_spec.rb", "spec/neuron_spec.rb", "spec/spec_helper.rb", "spec/temp/brainz.b", "Manifest"]
14
14
  s.homepage = "https://github.com/ViliusLuneckas/brainz/"
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Brainz", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
@@ -0,0 +1,14 @@
1
+ require_relative '../lib/brainz'
2
+
3
+
4
+ brainz = Brainz::Brainz.new
5
+
6
+ brainz.num_hidden = [4, 7, 3]
7
+
8
+ brainz.teach(learning_rate: 0.2, momentum: 0.05, wanted_error: 0.01) do |iteration, error|
9
+ that(a: 1, b: 1).is(0)
10
+ that(1, 0).is(1)
11
+ that(0, 1).is(1)
12
+ that(0, 0).is(0)
13
+ end
14
+ p "Learning took #{brainz.last_iterations}, error: #{brainz.error}, time: #{brainz.learning_time} s."
@@ -2,9 +2,7 @@ module Brainz
2
2
  module Algorithms
3
3
  module Backpropagation
4
4
  def update(input)
5
- @network ||= ::Brainz::Network.new(
6
- @num_input, [num_hidden, @num_output * 2], @num_output, momentum: momentum, learning_rate: learning_rate
7
- )
5
+ initialize_network unless @network
8
6
  @network.update(input)
9
7
  self
10
8
  end
@@ -12,6 +10,12 @@ module Brainz
12
10
  def fix_weights(targets)
13
11
  @network.fix_weights(targets)
14
12
  end
13
+
14
+ def initialize_network
15
+ @network ||= ::Brainz::Network.new(
16
+ num_input, num_hidden, num_output, momentum: momentum, learning_rate: learning_rate
17
+ )
18
+ end
15
19
  end
16
20
  end
17
21
  end
@@ -22,7 +22,7 @@ module Brainz
22
22
  end
23
23
 
24
24
  def num_hidden
25
- @num_hidden || (num_input + num_output) * 2 / 3
25
+ @num_hidden || [(num_input + num_output) * 2 / 3]
26
26
  end
27
27
 
28
28
  def learning_cycle
@@ -1,3 +1,3 @@
1
1
  module Brainz
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -47,9 +47,9 @@ describe Brainz::Brainz do
47
47
  end
48
48
 
49
49
  describe "#num_hidden" do
50
- it "should return 7" do
50
+ it "should return [7]" do
51
51
  subject.stubs(num_input: 5, num_output: 6)
52
- subject.num_hidden.should == 7
52
+ subject.num_hidden.should == [7]
53
53
  end
54
54
  end
55
55
 
@@ -0,0 +1,18 @@
1
+ require_relative '../spec/spec_helper'
2
+
3
+ describe Brainz::Neuron do
4
+ before do
5
+ brainz = Brainz::Brainz.new
6
+ brainz.stubs(num_input: 2, num_output: 2, learning_rate: 1.66, momentum: 0.123)
7
+ brainz.initialize_network
8
+ @neuron = brainz.network.input.neurons.first
9
+ end
10
+
11
+ it "should get learning rate from brainz" do
12
+ @neuron.learning_rate.should == 1.66
13
+ end
14
+
15
+ it "should get momentum from brainz" do
16
+ @neuron.momentum.should == 0.123
17
+ end
18
+ end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brainz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-20 00:00:00.000000000 Z
12
+ date: 2012-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -66,6 +66,7 @@ files:
66
66
  - Rakefile
67
67
  - brainz.gemspec
68
68
  - examples/and.rb
69
+ - examples/multi_layer_xor.rb
69
70
  - examples/sign.rb
70
71
  - examples/xor.rb
71
72
  - lib/brainz.rb
@@ -81,6 +82,7 @@ files:
81
82
  - spec/array_spec.rb
82
83
  - spec/brainz_spec.rb
83
84
  - spec/loader_spec.rb
85
+ - spec/neuron_spec.rb
84
86
  - spec/spec_helper.rb
85
87
  - spec/temp/brainz.b
86
88
  - Manifest