-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor and add cmn and mini_net parts * crystal tool format * code cleanup * add Ai4cr::NeuralNetwork::Cmn::ConnectedNetSet::Sequencial, add error_distance_history tracking to Ai4cr::NeuralNetwork::Backpropagation, add training comparisons * version bump from 0.1.8 to 0.1.9
- Loading branch information
1 parent
fc5e17a
commit 080c5e8
Showing
24 changed files
with
2,565 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,26 @@ | ||
name: ai4cr | ||
version: 0.1.8 | ||
version: 0.1.9 | ||
|
||
authors: | ||
- Daniel Huffman <drhuffman12@yahoo.com> | ||
|
||
crystal: 0.33.0 | ||
|
||
license: MIT | ||
|
||
development_dependencies: | ||
ameba: | ||
github: crystal-ameba/ameba | ||
version: ~> 0.11.0 | ||
|
||
ascii_bar_charter: | ||
github: drhuffman12/ascii_bar_charter | ||
branch: master | ||
|
||
# aasm: | ||
# github: veelenga/aasm.cr | ||
# # version: 0.11.0 | ||
# # github: drhuffman12/aasm.cr | ||
# branch: master | ||
# # version: 0.1.1 | ||
# # # https://github.com/veelenga/aasm.cr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
spec/ai4cr/neural_network/cmn/connected_net_set/sequencial_spec.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
require "./../../../../spec_helper" | ||
|
||
describe Ai4cr::NeuralNetwork::Cmn::ConnectedNetSet::Sequencial do | ||
describe "when given two nets with structure of [3, 4] and [4, 2]" do | ||
# before_each do | ||
# structure = [3, 2] | ||
# net = Ai4cr::NeuralNetwork::Backpropagation.new([3, 2]) | ||
inputs = [0.1, 0.2, 0.3] | ||
|
||
hard_coded_weights0 = [ | ||
[-0.4, 0.9, -0.4, -0.7], | ||
[0.1, 0.8, 0.9, -0.0], | ||
[-0.7, -0.3, -0.6, -0.7], | ||
[1.0, 0.2, 0.6, -0.5] | ||
] | ||
hard_coded_weights1 = [ | ||
[-0.4, 0.8], | ||
[-1.0, -0.3], | ||
[-0.6, 0.6], | ||
[0.2, -0.3], | ||
[1.0, -0.1] | ||
] | ||
|
||
puts "hard_coded_weights0: #{hard_coded_weights0.each { |a| puts a.join("\t") }}" | ||
puts "hard_coded_weights1: #{hard_coded_weights1.each { |a| puts a.join("\t") }}" | ||
|
||
expected_outputs_guessed_before = [0.0, 0.0] | ||
expected_outputs_guessed_after = [0.454759979898907, 0.635915600435646] | ||
|
||
it "the 'outputs_guessed' start as zeros" do | ||
|
||
net0 = Ai4cr::NeuralNetwork::Cmn::MiniNet::Exp.new(height: 3, width: 4) | ||
net1 = Ai4cr::NeuralNetwork::Cmn::MiniNet::Exp.new(height: 4, width: 2) | ||
cns = Ai4cr::NeuralNetwork::Cmn::ConnectedNetSet::Sequencial(Ai4cr::NeuralNetwork::Cmn::MiniNet::Exp).new([net0, net1]) | ||
|
||
puts "net0.weights: #{net0.weights.map { |a| a.map { |b| b.round(1) } }}" | ||
puts "net1.weights: #{net1.weights.map { |a| a.map { |b| b.round(1) } }}" | ||
|
||
net0.init_network | ||
net0.learning_rate = 0.25 | ||
net0.momentum = 0.1 | ||
net0.weights = hard_coded_weights0.clone | ||
# puts "\nnet0 (BEFORE): #{net0.to_json}\n" | ||
|
||
|
||
net1.init_network | ||
net1.learning_rate = 0.25 | ||
net1.momentum = 0.1 | ||
net1.weights = hard_coded_weights1.clone | ||
# puts "\nnet1 (BEFORE): #{net1.to_json}\n" | ||
|
||
puts "\ncns (BEFORE): #{cns.to_json}\n" | ||
|
||
|
||
outputs_guessed_before = net1.outputs_guessed.clone | ||
|
||
assert_equality_of_nested_list outputs_guessed_before, expected_outputs_guessed_before | ||
end | ||
|
||
it "the 'outputs_guessed' start are updated as expected" do | ||
net0 = Ai4cr::NeuralNetwork::Cmn::MiniNet::Exp.new(height: 3, width: 4) | ||
net1 = Ai4cr::NeuralNetwork::Cmn::MiniNet::Exp.new(height: 4, width: 2) | ||
cns = Ai4cr::NeuralNetwork::Cmn::ConnectedNetSet::Sequencial(Ai4cr::NeuralNetwork::Cmn::MiniNet::Exp).new([net0, net1]) | ||
|
||
puts "net0.weights: #{net0.weights.map { |a| a.map { |b| b.round(1) } }}" | ||
puts "net1.weights: #{net1.weights.map { |a| a.map { |b| b.round(1) } }}" | ||
|
||
net0.init_network | ||
net0.learning_rate = 0.25 | ||
net0.momentum = 0.1 | ||
net0.weights = hard_coded_weights0.clone | ||
# puts "\nnet0 (BEFORE): #{net0.to_json}\n" | ||
|
||
|
||
net1.init_network | ||
net1.learning_rate = 0.25 | ||
net1.momentum = 0.1 | ||
net1.weights = hard_coded_weights1.clone | ||
# puts "\nnet1 (BEFORE): #{net1.to_json}\n" | ||
|
||
puts "\ncns (BEFORE): #{cns.to_json}\n" | ||
|
||
outputs_guessed_before = cns.net_set.last.outputs_guessed.clone | ||
|
||
cns.eval(inputs) | ||
outputs_guessed_after = cns.net_set.last.outputs_guessed.clone | ||
puts "\ncns (AFTER): #{cns.to_json}\n" | ||
|
||
assert_approximate_equality_of_nested_list outputs_guessed_after, expected_outputs_guessed_after | ||
end | ||
|
||
end | ||
end |
Oops, something went wrong.