Skip to content

Commit

Permalink
Drhuffman12/add team utils part 3 (#58)
Browse files Browse the repository at this point in the history
* drhuffman12/add_team_utils_part_3 initail prep for adding RnnSimpleManager

* drhuffman12/add_team_utils_part_3 initail prep for adding RnnSimpleManager

* drhuffman12/add_team_utils_part_3 formatting

* drhuffman12/add_team_utils_part_3 finish adding RnnSimpleManager and update tests

* drhuffman12/add_team_utils_part_3 formatting

* drhuffman12/add_team_utils_part_3 bump version from '0.1.20' to '0.1.21'
  • Loading branch information
drhuffman12 committed Feb 3, 2021
1 parent a9f5a4f commit 55e9a27
Show file tree
Hide file tree
Showing 10 changed files with 440 additions and 193 deletions.
2 changes: 1 addition & 1 deletion shard.yml
@@ -1,5 +1,5 @@
name: ai4cr
version: 0.1.20
version: 0.1.21

authors:
- Daniel Huffman <drhuffman12@yahoo.com>
Expand Down
272 changes: 95 additions & 177 deletions spec/ai4cr/neural_network/cmn/mini_net_manager_spec.cr
Expand Up @@ -21,13 +21,19 @@ Spectator.describe Ai4cr::NeuralNetwork::Cmn::MiniNetManager do

let(config_adam) {
config_default_randomized.merge(
name: "Adam", learning_rate: ancestor_adam_learning_rate_expected
name: "Adam",
learning_rate: ancestor_adam_learning_rate_expected,
momentum: Ai4cr::Data::Utils.rand_excluding,
deriv_scale: Ai4cr::Data::Utils.rand_excluding / 2.0
)
}

let(config_eve) {
config_default_randomized.merge(
name: "Eve", learning_rate: ancestor_eve_learning_rate_expected
name: "Eve",
learning_rate: ancestor_eve_learning_rate_expected,
momentum: Ai4cr::Data::Utils.rand_excluding,
deriv_scale: Ai4cr::Data::Utils.rand_excluding / 2.0
)
}

Expand All @@ -44,93 +50,93 @@ Spectator.describe Ai4cr::NeuralNetwork::Cmn::MiniNetManager do
expect(ancestor_adam.learning_rate).not_to eq(ancestor_eve.learning_rate)
end

# context "birth_id's are in the consistent order (when birthed in order" do
# it "first Adam" do
# expected_birth_counter = 0

# # Adam
# expected_birth_counter += 1
# expect(ancestor_adam.birth_id).to eq(expected_birth_counter)

# puts_debug
# puts_debug "ancestor_adam: #{ancestor_adam.to_json}"
# end

# it "first Adam then Eve" do
# expected_birth_counter = 0

# # Adam
# expected_birth_counter += 1
# expect(ancestor_adam.birth_id).to eq(expected_birth_counter)

# # Eve
# expected_birth_counter += 1
# expect(ancestor_eve.birth_id).to eq(expected_birth_counter)

# puts_debug
# puts_debug "ancestor_adam: #{ancestor_adam.to_json}"
# puts_debug
# puts_debug "ancestor_eve: #{ancestor_eve.to_json}"
# end

# it "first Adam then Eve followed by Cain" do
# expected_birth_counter = 0

# # Adam
# expected_birth_counter += 1
# expect(ancestor_adam.birth_id).to eq(expected_birth_counter)

# # Eve
# expected_birth_counter += 1
# expect(ancestor_eve.birth_id).to eq(expected_birth_counter)

# # Cain
# expected_birth_counter += 1
# child_1 = my_breed_manager.breed(ancestor_adam, ancestor_eve, delta: delta_child_1)
# child_1.name = "Cain, child of #{child_1.name} and #{ancestor_eve.name}"
# expect(child_1.birth_id).to eq(expected_birth_counter)

# puts_debug
# puts_debug "ancestor_adam: #{ancestor_adam.to_json}"
# puts_debug
# puts_debug "ancestor_eve: #{ancestor_eve.to_json}"
# puts_debug
# puts_debug "child_1: #{child_1.to_json}"
# end

# it "first Adam then Eve followed by Cain and then Abel" do
# expected_birth_counter = 0

# # Adam
# expected_birth_counter += 1
# expect(ancestor_adam.birth_id).to eq(expected_birth_counter)

# # Eve
# expected_birth_counter += 1
# expect(ancestor_eve.birth_id).to eq(expected_birth_counter)

# # Cain
# expected_birth_counter += 1
# child_1 = my_breed_manager.breed(ancestor_adam, ancestor_eve, delta: delta_child_1)
# child_1.name = "Cain, child of #{child_1.name} and #{ancestor_eve.name}"
# expect(child_1.birth_id).to eq(expected_birth_counter)

# # Abel
# expected_birth_counter += 1
# child_2 = my_breed_manager.breed(ancestor_adam, ancestor_eve, delta: delta_child_2)
# child_2.name = "Abel, child of #{child_2.name} and #{ancestor_eve.name}"
# expect(child_2.birth_id).to eq(expected_birth_counter)

# puts_debug
# puts_debug "ancestor_adam: #{ancestor_adam.to_json}"
# puts_debug
# puts_debug "ancestor_eve: #{ancestor_eve.to_json}"
# puts_debug
# puts_debug "child_1: #{child_1.to_json}"
# puts_debug
# puts_debug "child_2: #{child_2.to_json}"
# end
# end
context "birth_id's are in the consistent order (when birthed in order" do
it "first Adam" do
expected_birth_counter = 0

# Adam
expected_birth_counter += 1
expect(ancestor_adam.birth_id).to eq(expected_birth_counter)

puts_debug
puts_debug "ancestor_adam: #{ancestor_adam.to_json}"
end

it "first Adam then Eve" do
expected_birth_counter = 0

# Adam
expected_birth_counter += 1
expect(ancestor_adam.birth_id).to eq(expected_birth_counter)

# Eve
expected_birth_counter += 1
expect(ancestor_eve.birth_id).to eq(expected_birth_counter)

puts_debug
puts_debug "ancestor_adam: #{ancestor_adam.to_json}"
puts_debug
puts_debug "ancestor_eve: #{ancestor_eve.to_json}"
end

it "first Adam then Eve followed by Cain" do
expected_birth_counter = 0

# Adam
expected_birth_counter += 1
expect(ancestor_adam.birth_id).to eq(expected_birth_counter)

# Eve
expected_birth_counter += 1
expect(ancestor_eve.birth_id).to eq(expected_birth_counter)

# Cain
expected_birth_counter += 1
child_1 = my_breed_manager.breed(ancestor_adam, ancestor_eve, delta: delta_child_1)
child_1.name = "Cain, child of #{child_1.name} and #{ancestor_eve.name}"
expect(child_1.birth_id).to eq(expected_birth_counter)

puts_debug
puts_debug "ancestor_adam: #{ancestor_adam.to_json}"
puts_debug
puts_debug "ancestor_eve: #{ancestor_eve.to_json}"
puts_debug
puts_debug "child_1: #{child_1.to_json}"
end

it "first Adam then Eve followed by Cain and then Abel" do
expected_birth_counter = 0

# Adam
expected_birth_counter += 1
expect(ancestor_adam.birth_id).to eq(expected_birth_counter)

# Eve
expected_birth_counter += 1
expect(ancestor_eve.birth_id).to eq(expected_birth_counter)

# Cain
expected_birth_counter += 1
child_1 = my_breed_manager.breed(ancestor_adam, ancestor_eve, delta: delta_child_1)
child_1.name = "Cain, child of #{child_1.name} and #{ancestor_eve.name}"
expect(child_1.birth_id).to eq(expected_birth_counter)

# Abel
expected_birth_counter += 1
child_2 = my_breed_manager.breed(ancestor_adam, ancestor_eve, delta: delta_child_2)
child_2.name = "Abel, child of #{child_2.name} and #{ancestor_eve.name}"
expect(child_2.birth_id).to eq(expected_birth_counter)

puts_debug
puts_debug "ancestor_adam: #{ancestor_adam.to_json}"
puts_debug
puts_debug "ancestor_eve: #{ancestor_eve.to_json}"
puts_debug
puts_debug "child_1: #{child_1.to_json}"
puts_debug
puts_debug "child_2: #{child_2.to_json}"
end
end

describe "#mix_parts" do
context "first Adam then Eve followed by Cain" do
Expand Down Expand Up @@ -214,91 +220,3 @@ Spectator.describe Ai4cr::NeuralNetwork::Cmn::MiniNetManager do
end
end
end

# let(weights_expected_1) {
# ancestor_adam.weights.map_with_index do |sa, i|
# parent_a_part = sa
# parent_b_part = ancestor_eve.weights[i]

# vector_a_to_b = parent_b_part - parent_a_part
# parent_a_part + (delta_child_1 * vector_a_to_b)
# end
# }
# let(weights_expected_2) {
# ancestor_adam.weights.map_with_index do |sa, i|
# parent_a_part = sa
# parent_b_part = ancestor_eve.weights[i]

# vector_a_to_b = parent_b_part - parent_a_part
# parent_a_part + (delta_child_2 * vector_a_to_b)
# end
# }

# let(momentum_expected_1) {
# ancestor_adam.momentum.map_with_index do |sa, i|
# parent_a_part = sa
# parent_b_part = ancestor_eve.momentum[i]

# vector_a_to_b = parent_b_part - parent_a_part
# parent_a_part + (delta_child_1 * vector_a_to_b)
# end
# }
# let(momentum_expected_2) {
# ancestor_adam.momentum.map_with_index do |sa, i|
# parent_a_part = sa
# parent_b_part = ancestor_eve.momentum[i]

# vector_a_to_b = parent_b_part - parent_a_part
# parent_a_part + (delta_child_2 * vector_a_to_b)
# end
# }

# let(config_cain) {
# config_default_randomized.merge(
# name: "Cain", learning_rate: ancestor_adam_learning_rate_expected
# )
# }

# let(config_abel) {
# config_default_randomized.merge(
# name: "Abel", learning_rate: ancestor_adam_learning_rate_expected
# )
# }

# expect(ancestor_adam.learning_rate).to eq(ancestor_adam_learning_rate_expected)

# expected_birth_counter += 1
# expect(ancestor_eve.birth_id).to eq(expected_birth_counter)
# expect(ancestor_eve.learning_rate).to eq(ancestor_eve_learning_rate_expected)

# # cain
# child_1 = my_breed_manager.breed(ancestor_adam, ancestor_eve, delta: delta_child_1)
# child_1.name = "Cain, child of #{child_1.name} and #{ancestor_eve.name}"

# puts_debug "child_1: #{child_1.to_json}"
# expected_birth_counter += 1
# expect(child_1.birth_id).to eq(expected_birth_counter)
# expect(child_1.learning_rate).to eq(delta_child_1)

# # expect(child_1.weights).to eq(weights_expected_1)
# # expect(child_1.momentum).to eq(momentum_expected_1)

# # abel
# child_2 = my_breed_manager.breed(ancestor_adam, ancestor_eve, delta: delta_child_2)
# child_2.name = "Abel, child of #{child_2.name} and #{ancestor_eve.name}"

# puts_debug "child_2: #{child_2.to_json}"
# expected_birth_counter += 1
# expect(child_2.birth_id).to eq(expected_birth_counter)
# expect(child_2.learning_rate).to eq(delta_child_2)

# # expect(child_2.weights).to eq(weights_expected_2)
# # expect(child_2.momentum).to eq(momentum_expected_2)

# puts_debug
# puts_debug "Now, in order or youngest to oldest:"
# [ancestor_adam, ancestor_eve, child_1, child_2].sort_by do |person|
# (- person.birth_id)
# end.each do |person|
# puts_debug "person: #{person.to_json}"
# end

0 comments on commit 55e9a27

Please sign in to comment.