brainz 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +21 -0
- data/Gemfile +4 -0
- data/LICENSE +3 -1
- data/README.md +70 -0
- data/Rakefile +5 -11
- data/brainz.gemspec +15 -30
- data/examples/and.rb +1 -1
- data/examples/multi_layer_xor.rb +1 -2
- data/examples/sign.rb +1 -1
- data/examples/xor.rb +2 -2
- data/lib/brainz.rb +12 -9
- data/lib/brainz/algorithms.rb +4 -0
- data/lib/brainz/{backpropagation.rb → algorithms/backpropagation.rb} +0 -0
- data/lib/brainz/brainz.rb +2 -6
- data/lib/brainz/network.rb +1 -2
- data/lib/brainz/version.rb +2 -2
- data/spec/{array_spec.rb → ext/array_spec.rb} +2 -2
- data/spec/fixtures/.gitkeep +0 -0
- data/spec/{brainz_spec.rb → lib/brainz_spec.rb} +1 -35
- data/spec/lib/loader_spec.rb +42 -0
- data/spec/lib/neuron_spec.rb +19 -0
- data/spec/spec_helper.rb +3 -3
- metadata +28 -37
- data/Manifest +0 -25
- data/README.rdoc +0 -20
- data/spec/loader_spec.rb +0 -31
- data/spec/neuron_spec.rb +0 -18
- data/spec/temp/brainz.b +0 -0
data/.gitignore
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
.idea
|
19
|
+
.DS_Store
|
20
|
+
.rbenv-version
|
21
|
+
.rspec
|
data/Gemfile
ADDED
data/LICENSE
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
Copyright (c) 2012 Vilius Luneckas
|
2
2
|
|
3
|
+
MIT License
|
4
|
+
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
6
|
a copy of this software and associated documentation files (the
|
5
7
|
"Software"), to deal in the Software without restriction, including
|
@@ -17,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Brainz
|
2
|
+
|
3
|
+
Artificial Neural Network Library written in Ruby.
|
4
|
+
|
5
|
+
## Supported training algorithms
|
6
|
+
|
7
|
+
* Backpropagation
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'brainz'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install brainz
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### Simple example, logical AND operation
|
26
|
+
|
27
|
+
require 'brainz'
|
28
|
+
|
29
|
+
brainz = Brainz::Brainz.new
|
30
|
+
|
31
|
+
brainz.teach do |iteration, error|
|
32
|
+
that(1, 1).is(1)
|
33
|
+
that(1, 0).is(0)
|
34
|
+
that(0, 1).is(0)
|
35
|
+
that(0, 0).is(0)
|
36
|
+
p "error_rate = #{'%.3f' % error || 0 } after #{iteration} iterations" if iteration % 10 == 0
|
37
|
+
end
|
38
|
+
|
39
|
+
puts "0 and 0 = #{brainz.guess(a: 0, b: 0)}"
|
40
|
+
puts "0 and 1 = #{brainz.guess(a: 0, b: 1)}"
|
41
|
+
puts "1 and 1 = #{brainz.guess(a: 1, b: 1)}"
|
42
|
+
puts "1 and 0 = #{brainz.guess(a: 1, b: 0)}"
|
43
|
+
|
44
|
+
### Advanced usage, ligical XOR operation
|
45
|
+
|
46
|
+
require 'brainz'
|
47
|
+
|
48
|
+
brainz = Brainz::Brainz.new
|
49
|
+
|
50
|
+
# specify number of hidden layers
|
51
|
+
# 3 hidden layers with 4, 7 and 3 neurons
|
52
|
+
brainz.num_hidden = [4, 7, 3]
|
53
|
+
|
54
|
+
# tune learning parameters: learning_rate, momentum, wanted_error (mse)
|
55
|
+
brainz.teach(learning_rate: 0.2, momentum: 0.05, wanted_error: 0.01) do |iteration, error|
|
56
|
+
that(1, 1).is(0)
|
57
|
+
that(1, 0).is(1)
|
58
|
+
that(0, 1).is(1)
|
59
|
+
that(0, 0).is(0)
|
60
|
+
end
|
61
|
+
|
62
|
+
puts "Learning took #{brainz.last_iterations}, error: #{brainz.error}, time: #{brainz.learning_time} s."
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
1. Fork it
|
67
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
68
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
69
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
70
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
@@ -1,13 +1,7 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require "rspec/core/rake_task"
|
2
4
|
|
3
|
-
|
4
|
-
require 'echoe'
|
5
|
-
require './lib/brainz/version.rb'
|
5
|
+
RSpec::Core::RakeTask.new
|
6
6
|
|
7
|
-
|
8
|
-
gem.description = "Simple artificial intelligence"
|
9
|
-
gem.url = "https://github.com/ViliusLuneckas/brainz/"
|
10
|
-
gem.email = "vilius.luneckas@gmail.com"
|
11
|
-
gem.author = "Vilius Luneckas"
|
12
|
-
gem.development_dependencies = ['rspec', 'mocha']
|
13
|
-
end
|
7
|
+
task :default => :spec
|
data/brainz.gemspec
CHANGED
@@ -1,35 +1,20 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/brainz/version', __FILE__)
|
2
3
|
|
3
|
-
Gem::Specification.new do |
|
4
|
-
|
5
|
-
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Vilius Luneckas"]
|
6
|
+
gem.email = ["vilius.luneckas@gmail.com"]
|
7
|
+
gem.description = %q{Artificial Neural Network library written in Ruby}
|
8
|
+
gem.summary = %q{Artificial Neural Network library written in Ruby}
|
9
|
+
gem.homepage = "https://github.com/ViliusLuneckas/brainz/"
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Brainz", "--main", "README.rdoc"]
|
16
|
-
s.require_paths = ["lib"]
|
17
|
-
s.rubyforge_project = "brainz"
|
18
|
-
s.rubygems_version = "1.8.19"
|
19
|
-
s.summary = "Simple artificial intelligence"
|
20
|
-
|
21
|
-
if s.respond_to? :specification_version then
|
22
|
-
s.specification_version = 3
|
23
|
-
|
24
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
25
|
-
s.add_development_dependency(%q<rspec>, [">= 0"])
|
26
|
-
s.add_development_dependency(%q<mocha>, [">= 0"])
|
27
|
-
else
|
28
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
29
|
-
s.add_dependency(%q<mocha>, [">= 0"])
|
30
|
-
end
|
31
|
-
else
|
32
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
33
|
-
s.add_dependency(%q<mocha>, [">= 0"])
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "brainz"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Brainz::VERSION
|
17
|
+
%w(rspec mocha).each do |gem_name|
|
18
|
+
gem.add_development_dependency gem_name
|
34
19
|
end
|
35
20
|
end
|
data/examples/and.rb
CHANGED
data/examples/multi_layer_xor.rb
CHANGED
data/examples/sign.rb
CHANGED
data/examples/xor.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'brainz'
|
2
2
|
|
3
3
|
# XOR problem
|
4
4
|
|
@@ -11,4 +11,4 @@ brainz.teach(learning_rate: 0.2, momentum: 0.01, wanted_error: 0.01, max_iterati
|
|
11
11
|
that(0, 0).is(0)
|
12
12
|
end
|
13
13
|
|
14
|
-
p "Learning took #{brainz.last_iterations}, error: #{brainz.error}, time: #{brainz.learning_time} s."
|
14
|
+
p "Learning took #{brainz.last_iterations}, error: #{brainz.error}, time: #{brainz.learning_time} s."
|
data/lib/brainz.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
-
|
1
|
+
require "brainz/version"
|
2
|
+
require "ext/array"
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
module Brainz
|
5
|
+
require "brainz/algorithms"
|
6
|
+
require "brainz/algorithms/backpropagation"
|
7
|
+
require "brainz/synapse"
|
8
|
+
require "brainz/neuron"
|
9
|
+
require "brainz/layer"
|
10
|
+
require "brainz/network"
|
11
|
+
require "brainz/brainz"
|
12
|
+
require "brainz/loader"
|
13
|
+
end
|
File without changes
|
data/lib/brainz/brainz.rb
CHANGED
@@ -139,9 +139,5 @@ end
|
|
139
139
|
|
140
140
|
|
141
141
|
def self.method_missing(meth = nil, *args, &block)
|
142
|
-
|
143
|
-
|
144
|
-
else
|
145
|
-
raise NoMethodError
|
146
|
-
end
|
147
|
-
end
|
142
|
+
meth == :that ? Brainz::Brainz.current.send(meth, *args) : super
|
143
|
+
end
|
data/lib/brainz/network.rb
CHANGED
data/lib/brainz/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Brainz
|
2
|
-
VERSION = '0.1.
|
3
|
-
end
|
2
|
+
VERSION = '0.1.3'
|
3
|
+
end
|
File without changes
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Brainz::Brainz do
|
4
4
|
subject { Brainz::Brainz.new }
|
@@ -79,40 +79,6 @@ describe Brainz::Brainz do
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
|
83
|
-
describe "#update" do
|
84
|
-
|
85
|
-
before do
|
86
|
-
pending
|
87
|
-
subject.stubs(num_hidden: 2, num_output: 1)
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should return subject" do
|
91
|
-
subject.update([]).should == subject
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should create weight matrices" do
|
95
|
-
Kernel.stubs(rand: 0)
|
96
|
-
expect {
|
97
|
-
expect {
|
98
|
-
subject.update([1.0, 1.0])
|
99
|
-
}.to change { subject.input_weights }.from(nil).to([[-0.2, -0.2], [-0.2, -0.2], [-0.2, -0.2]])
|
100
|
-
}.to change { subject.output_weights }.from(nil).to([[-2], [-2]])
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should create input weights matrix size of input and hidden" do
|
104
|
-
matrix = subject.update([0, 1, 0]).input_weights
|
105
|
-
matrix.size.should == 4
|
106
|
-
matrix[0].size.should == 2
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should create output weights matrix size of hidden and output" do
|
110
|
-
matrix = subject.update([0, 1, 0]).output_weights
|
111
|
-
matrix.size.should == 2
|
112
|
-
matrix[0].size.should == 1
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
82
|
describe "xor" do
|
117
83
|
it "should learn xor" do
|
118
84
|
subject.teach do
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
describe "loader" do
|
5
|
+
let(:file_path) { File.expand_path('spec/fixtures/brainz.b') }
|
6
|
+
|
7
|
+
subject { Brainz::Brainz.new }
|
8
|
+
|
9
|
+
before do
|
10
|
+
FileUtils.rm_rf(file_path)
|
11
|
+
|
12
|
+
subject.teach do
|
13
|
+
subject.that(a: 1, b: 1).is(0)
|
14
|
+
subject.that(1, 0).is(1)
|
15
|
+
subject.that(0, 1).is(1)
|
16
|
+
subject.that(0, 0).is(0)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
after do
|
21
|
+
FileUtils.rm_rf(file_path)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should work after load" do
|
25
|
+
results_before_saving = []
|
26
|
+
results_before_saving << subject.explain(a: 0, b: 0).first.round
|
27
|
+
results_before_saving << subject.explain(a: 0, b: 1).first.round
|
28
|
+
results_before_saving << subject.explain(a: 1, b: 1).first.round
|
29
|
+
results_before_saving << subject.explain(a: 1, b: 0).first.round
|
30
|
+
|
31
|
+
subject.save(file_path)
|
32
|
+
loaded_brainz = Brainz::Brainz.load(file_path)
|
33
|
+
|
34
|
+
results_after_load = []
|
35
|
+
results_after_load << subject.explain(a: 0, b: 0).first.round
|
36
|
+
results_after_load << subject.explain(a: 0, b: 1).first.round
|
37
|
+
results_after_load << subject.explain(a: 1, b: 1).first.round
|
38
|
+
results_after_load << subject.explain(a: 1, b: 0).first.round
|
39
|
+
|
40
|
+
results_before_saving.should == results_after_load
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require '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
|
+
end
|
9
|
+
|
10
|
+
subject { @brainz.network.input.neurons.first }
|
11
|
+
|
12
|
+
it "should return learning rate of brainz" do
|
13
|
+
subject.learning_rate.should == 1.66
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return momentum of brainz" do
|
17
|
+
subject.momentum.should == 0.123
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 0.1.3
|
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-
|
12
|
+
date: 2012-11-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -43,26 +43,17 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
-
description:
|
47
|
-
email:
|
46
|
+
description: Artificial Neural Network library written in Ruby
|
47
|
+
email:
|
48
|
+
- vilius.luneckas@gmail.com
|
48
49
|
executables: []
|
49
50
|
extensions: []
|
50
|
-
extra_rdoc_files:
|
51
|
-
- LICENSE
|
52
|
-
- README.rdoc
|
53
|
-
- lib/brainz.rb
|
54
|
-
- lib/brainz/backpropagation.rb
|
55
|
-
- lib/brainz/brainz.rb
|
56
|
-
- lib/brainz/layer.rb
|
57
|
-
- lib/brainz/loader.rb
|
58
|
-
- lib/brainz/network.rb
|
59
|
-
- lib/brainz/neuron.rb
|
60
|
-
- lib/brainz/synapse.rb
|
61
|
-
- lib/brainz/version.rb
|
62
|
-
- lib/ext/array.rb
|
51
|
+
extra_rdoc_files: []
|
63
52
|
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
64
55
|
- LICENSE
|
65
|
-
- README.
|
56
|
+
- README.md
|
66
57
|
- Rakefile
|
67
58
|
- brainz.gemspec
|
68
59
|
- examples/and.rb
|
@@ -70,7 +61,8 @@ files:
|
|
70
61
|
- examples/sign.rb
|
71
62
|
- examples/xor.rb
|
72
63
|
- lib/brainz.rb
|
73
|
-
- lib/brainz/
|
64
|
+
- lib/brainz/algorithms.rb
|
65
|
+
- lib/brainz/algorithms/backpropagation.rb
|
74
66
|
- lib/brainz/brainz.rb
|
75
67
|
- lib/brainz/layer.rb
|
76
68
|
- lib/brainz/loader.rb
|
@@ -79,23 +71,16 @@ files:
|
|
79
71
|
- lib/brainz/synapse.rb
|
80
72
|
- lib/brainz/version.rb
|
81
73
|
- lib/ext/array.rb
|
82
|
-
- spec/array_spec.rb
|
83
|
-
- spec/
|
84
|
-
- spec/
|
85
|
-
- spec/
|
74
|
+
- spec/ext/array_spec.rb
|
75
|
+
- spec/fixtures/.gitkeep
|
76
|
+
- spec/lib/brainz_spec.rb
|
77
|
+
- spec/lib/loader_spec.rb
|
78
|
+
- spec/lib/neuron_spec.rb
|
86
79
|
- spec/spec_helper.rb
|
87
|
-
- spec/temp/brainz.b
|
88
|
-
- Manifest
|
89
80
|
homepage: https://github.com/ViliusLuneckas/brainz/
|
90
81
|
licenses: []
|
91
82
|
post_install_message:
|
92
|
-
rdoc_options:
|
93
|
-
- --line-numbers
|
94
|
-
- --inline-source
|
95
|
-
- --title
|
96
|
-
- Brainz
|
97
|
-
- --main
|
98
|
-
- README.rdoc
|
83
|
+
rdoc_options: []
|
99
84
|
require_paths:
|
100
85
|
- lib
|
101
86
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -109,11 +94,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
94
|
requirements:
|
110
95
|
- - ! '>='
|
111
96
|
- !ruby/object:Gem::Version
|
112
|
-
version: '
|
97
|
+
version: '0'
|
113
98
|
requirements: []
|
114
|
-
rubyforge_project:
|
115
|
-
rubygems_version: 1.8.
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.8.23
|
116
101
|
signing_key:
|
117
102
|
specification_version: 3
|
118
|
-
summary:
|
119
|
-
test_files:
|
103
|
+
summary: Artificial Neural Network library written in Ruby
|
104
|
+
test_files:
|
105
|
+
- spec/ext/array_spec.rb
|
106
|
+
- spec/fixtures/.gitkeep
|
107
|
+
- spec/lib/brainz_spec.rb
|
108
|
+
- spec/lib/loader_spec.rb
|
109
|
+
- spec/lib/neuron_spec.rb
|
110
|
+
- spec/spec_helper.rb
|
data/Manifest
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
LICENSE
|
2
|
-
README.rdoc
|
3
|
-
Rakefile
|
4
|
-
brainz.gemspec
|
5
|
-
examples/and.rb
|
6
|
-
examples/multi_layer_xor.rb
|
7
|
-
examples/sign.rb
|
8
|
-
examples/xor.rb
|
9
|
-
lib/brainz.rb
|
10
|
-
lib/brainz/backpropagation.rb
|
11
|
-
lib/brainz/brainz.rb
|
12
|
-
lib/brainz/layer.rb
|
13
|
-
lib/brainz/loader.rb
|
14
|
-
lib/brainz/network.rb
|
15
|
-
lib/brainz/neuron.rb
|
16
|
-
lib/brainz/synapse.rb
|
17
|
-
lib/brainz/version.rb
|
18
|
-
lib/ext/array.rb
|
19
|
-
spec/array_spec.rb
|
20
|
-
spec/brainz_spec.rb
|
21
|
-
spec/loader_spec.rb
|
22
|
-
spec/neuron_spec.rb
|
23
|
-
spec/spec_helper.rb
|
24
|
-
spec/temp/brainz.b
|
25
|
-
Manifest
|
data/README.rdoc
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
= brainz
|
2
|
-
|
3
|
-
Artificial Neural Network Library for Ruby programming language.
|
4
|
-
|
5
|
-
== Supported algorithms
|
6
|
-
* Backpropagation
|
7
|
-
|
8
|
-
== Contributing to brainz
|
9
|
-
|
10
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
11
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
12
|
-
* Fork the project
|
13
|
-
* Start a feature/bugfix branch
|
14
|
-
* Commit and push until you are happy with your contribution
|
15
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
16
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
17
|
-
|
18
|
-
== Copyright
|
19
|
-
|
20
|
-
Copyright (c) 2011 Vilius Luneckas. See LICENSE for further details.
|
data/spec/loader_spec.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require_relative '../spec/spec_helper'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
describe "loader" do
|
5
|
-
describe "xor" do
|
6
|
-
subject { Brainz::Brainz.new }
|
7
|
-
|
8
|
-
it "should work after load" do
|
9
|
-
subject.teach do
|
10
|
-
subject.that(a: 1, b: 1).is(0)
|
11
|
-
subject.that(1, 0).is(1)
|
12
|
-
subject.that(0, 1).is(1)
|
13
|
-
subject.that(0, 0).is(0)
|
14
|
-
end
|
15
|
-
|
16
|
-
subject.explain(a: 0, b: 0).first.round.should == 0
|
17
|
-
subject.explain(a: 0, b: 1).first.round.should == 1
|
18
|
-
subject.explain(a: 1, b: 1).first.round.should == 0
|
19
|
-
subject.explain(a: 1, b: 0).first.round.should == 1
|
20
|
-
|
21
|
-
subject.save(File.expand_path('.', 'temp/brainz.b'))
|
22
|
-
|
23
|
-
|
24
|
-
old_brainz = Brainz::Brainz.load(File.expand_path('.', 'temp/brainz.b'))
|
25
|
-
old_brainz.explain(a: 0, b: 0).first.round.should == 0
|
26
|
-
old_brainz.explain(a: 0, b: 1).first.round.should == 1
|
27
|
-
old_brainz.explain(a: 1, b: 1).first.round.should == 0
|
28
|
-
old_brainz.explain(a: 1, b: 0).first.round.should == 1
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
data/spec/neuron_spec.rb
DELETED
@@ -1,18 +0,0 @@
|
|
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
|
data/spec/temp/brainz.b
DELETED
Binary file
|