Skip to content

Commit 4a892ad

Browse files
committed
moor tidy up!
1 parent c7d75ab commit 4a892ad

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

nature-of-code/animation/Exercise_10_05_LayeredNetworkAnimation.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
require 'propane'
77
# An animated drawing of a Neural Network
88
class LayeredNetwork < Propane::App
9-
109
load_libraries :neural_network
11-
1210
attr_reader :network, :output
1311

1412
def setup
@@ -29,7 +27,7 @@ def setup
2927
network.connect(prev, n, rand)
3028
end
3129
end
32-
network.connect(n, output, rand) if (i == layers - 1)
30+
network.connect(n, output, rand) if i == (layers - 1)
3331
network.add_neuron(n)
3432
end
3533
end

nature-of-code/animation/library/neural_network/lib/connection.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def feedforward(val)
2424

2525
# Update traveling sender
2626
def update
27-
return unless sending # favour a guard clause in ruby
27+
return unless sending # favour a guard clause in ruby
2828
# Use a simple interpolation
2929
sender.lerp!(b.location, 0.1)
3030
d = sender.dist(b.location)

nature-of-code/animation/library/neural_network/lib/neuron.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ def feedforward(input)
3030
# Activate it?
3131
return sum unless sum > 1
3232
fire
33-
@sum = 0 # Reset the sum to 0 if it fires
33+
@sum = 0 # Reset the sum to 0 if it fires
3434
end
3535

3636
# The Neuron fires
3737
def fire
38-
@r = 64 # It suddenly is bigger
38+
@r = 64 # It suddenly is bigger
3939
# We send the output through all connections
4040
connections.each { |c| c.feedforward(sum) }
4141
end
@@ -45,7 +45,7 @@ def display
4545
stroke(0)
4646
stroke_weight(1)
4747
# Brightness is mapped to sum
48-
b = map1d(sum, (0 .. 1), (255 .. 0))
48+
b = map1d(sum, (0..1), (255..0))
4949
fill(b)
5050
ellipse(location.x, location.y, r, r)
5151
# Size shrinks down back to original dimensions

nature-of-code/animation/library/neural_network/lib/static_network.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ class StaticNetwork
77
attr_reader :neurons, :location
88

99
def initialize(layers, inputs, _outputs)
10-
@location = Vec2D.new($app.width / 2, $app.height / 2)
10+
@location = Vec2D.new(width / 2, height / 2)
1111
@neurons = []
1212
output = Neuron.new(250, 0)
1313
layers.times do |i|
1414
inputs.times do |j|
15-
x = map1d(i, (0 .. layers), (-200 .. 200))
16-
y = map1d(j, (0 .. inputs-1), (-100 .. 100))
15+
x = map1d(i, (0..layers), (-200..200))
16+
y = map1d(j, (0..inputs - 1), (-100..100))
1717
puts "#{j} #{y}"
1818
n = Neuron.new(x, y)
1919
if i > 0
@@ -22,7 +22,7 @@ def initialize(layers, inputs, _outputs)
2222
prev.join(n)
2323
end
2424
end
25-
n.join(output) if (i == layers - 1)
25+
n.join(output) if i == (layers - 1)
2626
neurons << n
2727
end
2828
end

0 commit comments

Comments
 (0)