Skip to content

Commit

Permalink
update README based on 0.1.9 mods, formatting, bump version to 0.1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
drhuffman12 committed Feb 17, 2020
1 parent 080c5e8 commit d4587dc
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 68 deletions.
96 changes: 52 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,51 +44,59 @@ assert_approximate_equality_of_nested_list net.weights, net2.weights, 0.00000000

## Roadmap

- [ ] Add RNN

- [ ] Port from `ai4r`:
- [ ] classifiers
- [ ] classifier.rb
- [ ] hyperpipes.rb
- [ ] ib1.rb
- [ ] id3.rb
- [ ] multilayer_perceptron.rb
- [ ] naive_bayes.rb
- [ ] one_r.rb
- [ ] prism.rb
- [ ] simple_linear_regression.rb
- [ ] votes.rb
- [ ] zero_r.rb
- [ ] clusterers
- [ ] average_linkage.rb
- [ ] bisecting_k_means.rb
- [ ] centroid_linkage.rb
- [ ] clusterer.rb
- [ ] complete_linkage.rb
- [ ] diana.rb
- [ ] k_means.rb
- [ ] median_linkage.rb
- [ ] single_linkage.rb
- [ ] ward_linkage_hierarchical.rb
- [ ] ward_linkage.rb
- [ ] weighted_average_linkage.rb
- [ ] data
- [ ] data_set.rb
- [ ] parameterizable.rb
- [ ] proximity.rb
- [ ] statistics.rb
- [ ] experiment
- [ ] classifier_evaluator.rb
- [ ] genetic_algorithm
- [ ] genetic_algorithm.rb
- [ ] neural_network
- [x] Generate an error history plot using `AsciiBarCharter` and `error_distance_history` , e.g.:
```
plot: '▇▊▂_▅▅▅_▅_▅▅▅▅_▅▅__▅_▅____▅___'
```
(Run `crystal spec spec_examples` to see more error history plot examples. NOTE: These run short training sessions, so some tests are likely to fail some of the time.)

- [ ] Add Cmn ("Connectable Mini Networks") (WIP)

- [ ] Add RNN

- [ ] Port from `ai4r`:
- [ ] classifiers
- [ ] classifier.rb
- [ ] hyperpipes.rb
- [ ] ib1.rb
- [ ] id3.rb
- [ ] multilayer_perceptron.rb
- [ ] naive_bayes.rb
- [ ] one_r.rb
- [ ] prism.rb
- [ ] simple_linear_regression.rb
- [ ] votes.rb
- [ ] zero_r.rb
- [ ] clusterers
- [ ] average_linkage.rb
- [ ] bisecting_k_means.rb
- [ ] centroid_linkage.rb
- [ ] clusterer.rb
- [ ] complete_linkage.rb
- [ ] diana.rb
- [ ] k_means.rb
- [ ] median_linkage.rb
- [ ] single_linkage.rb
- [ ] ward_linkage_hierarchical.rb
- [ ] ward_linkage.rb
- [ ] weighted_average_linkage.rb
- [ ] data
- [ ] data_set.rb
- [ ] parameterizable.rb
- [ ] proximity.rb
- [ ] statistics.rb
- [ ] experiment
- [ ] classifier_evaluator.rb
- [ ] genetic_algorithm
- [ ] genetic_algorithm.rb
- [ ] neural_network
- [x] backpropagation.rb
- [ ] hopfield.rb
- [ ] som
- [ ] layer.rb
- [ ] node.rb
- [ ] som.rb
- [ ] two_phase_layer.rb
- [ ] hopfield.rb
- [ ] som
- [ ] layer.rb
- [ ] node.rb
- [ ] som.rb
- [ ] two_phase_layer.rb

If you'd like another class of Ai4r ported, feel free to submit a [new issue](https://github.com/drhuffman12/ai4cr/issues/new).

Expand Down
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: ai4cr
version: 0.1.9
version: 0.1.10

authors:
- Daniel Huffman <drhuffman12@yahoo.com>
Expand Down
17 changes: 6 additions & 11 deletions spec/ai4cr/neural_network/cmn/connected_net_set/sequencial_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ describe Ai4cr::NeuralNetwork::Cmn::ConnectedNetSet::Sequencial do
[-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]
[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]
[1.0, -0.1],
]

puts "hard_coded_weights0: #{hard_coded_weights0.each { |a| puts a.join("\t") }}"
Expand All @@ -28,29 +28,26 @@ describe Ai4cr::NeuralNetwork::Cmn::ConnectedNetSet::Sequencial do
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

Expand All @@ -61,7 +58,7 @@ describe Ai4cr::NeuralNetwork::Cmn::ConnectedNetSet::Sequencial 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) } }}"

Expand All @@ -71,15 +68,14 @@ describe Ai4cr::NeuralNetwork::Cmn::ConnectedNetSet::Sequencial do
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)
Expand All @@ -88,6 +84,5 @@ describe Ai4cr::NeuralNetwork::Cmn::ConnectedNetSet::Sequencial do

assert_approximate_equality_of_nested_list outputs_guessed_after, expected_outputs_guessed_after
end

end
end
2 changes: 0 additions & 2 deletions spec_examples/ai4cr/neural_network/backpropagation_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require "json"
describe Ai4cr::NeuralNetwork::Backpropagation do
describe "#train" do
describe "with a shape of [256,3]" do

describe "using image data (input) and shape flags (output) for triangle, square, and cross" do
correct_count = 0

Expand Down Expand Up @@ -170,7 +169,6 @@ describe Ai4cr::NeuralNetwork::Backpropagation do
end

describe "with a shape of [256,300,3]" do

describe "using image data (input) and shape flags (output) for triangle, square, and cross" do
correct_count = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe Ai4cr::NeuralNetwork::Cmn::ConnectedNetSet::Sequencial do
net0 = Ai4cr::NeuralNetwork::Cmn::MiniNet::Exp.new(height: 256, width: 300, error_distance_history_max: 60)
net1 = Ai4cr::NeuralNetwork::Cmn::MiniNet::Exp.new(height: 300, width: 3, error_distance_history_max: 60)
cns = Ai4cr::NeuralNetwork::Cmn::ConnectedNetSet::Sequencial(Ai4cr::NeuralNetwork::Cmn::MiniNet::Exp).new([net0, net1])

# net.learning_rate = rand
qty = 500
qty_10_percent = qty // 10
Expand Down
4 changes: 2 additions & 2 deletions src/ai4cr/neural_network/backpropagation.cr
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ module Ai4cr
outputs = outputs.map { |v| v.to_f }
eval(inputs)
load_expected_outputs(outputs)
backpropagate # (outputs)
backpropagate # (outputs)
calculate_error # (outputs)
end

Expand Down Expand Up @@ -387,7 +387,7 @@ module Ai4cr
def load_expected_outputs(expected_outputs)
@expected_outputs.map_with_index! { |v, i| expected_outputs[i] }
end

# Calculate quadratic error for a expected output value
# Error = 0.5 * sum( (expected_value[i] - output_value[i])**2 )
def calculate_error # (expected_outputs)
Expand Down
10 changes: 4 additions & 6 deletions src/ai4cr/neural_network/cmn/connected_net_set/sequencial.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ module Ai4cr
property net_set

def initialize(@net_set : Array(T))

end

def validate!
index_max = @net_set.size-1
index_max = @net_set.size - 1
width_height_mismatch = [0..index_max].map do |index|
@net_set[index].width != @net_set[index + 1].height
end.any?
Expand All @@ -43,18 +42,17 @@ module Ai4cr

# TODO: utilize until_min_avg_error
def train(inputs_given, outputs_expected, until_min_avg_error = 0.1)

@net_set.each_with_index do |net, index|
index == 0 ? net.step_load_inputs(inputs_given) : net.step_load_inputs(@net_set[index - 1].outputs_guessed)
net.step_calc_forward
end

index_max = @net_set.size-1
index_max = @net_set.size - 1
(0..index_max).to_a.reverse.each do |index|
net = @net_set[index]

index == index_max ? net.step_load_outputs(outputs_expected) : net.step_load_outputs(@net_set[index + 1].input_deltas[0..@net_set[index + 1].height-1])
index == index_max ? net.step_load_outputs(outputs_expected) : net.step_load_outputs(@net_set[index + 1].input_deltas[0..@net_set[index + 1].height - 1])

net.step_calculate_error
net.step_backpropagate
end
Expand Down
2 changes: 1 addition & 1 deletion src/ai4cr/version.cr
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Ai4cr
VERSION = "0.1.9"
VERSION = "0.1.10"
end

0 comments on commit d4587dc

Please sign in to comment.