Skip to content

Commit 8457faa

Browse files
committedSep 7, 2015
1 parent 18a38a1 commit 8457faa

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed
 

‎src/feedforward/network.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function FFNNet(sizes::Int...)
3838
# Create an Array of Neural Network Layers of the right sizes
3939
# The first size corresponds to the input size of the network
4040
layers = Array(FFNNLayer, length(sizes) - 1)
41-
for i in 2:length(sizes) - 1
41+
@inbounds for i in 2:length(sizes) - 1
4242
layers[i - 1] = FFNNLayer(sizes[i])
4343
end
4444
layers[end] = FFNNLayer(sizes[end], bias=false) # Last layer without bias
@@ -70,7 +70,7 @@ function FFNNet(layers::Vector{FFNNLayer}, inputsize::Int)
7070
weights[1] = rand(size(layers[1]), inputsize + 1)*2*eps - eps
7171

7272
# Matrices from layer i-1 (including bias) to layer i
73-
for i in 2:length(layers)
73+
@inbounds for i in 2:length(layers)
7474
eps = ɛ(size(layers[i]), size(layers[i-1]))
7575
weights[i] = rand(size(layers[i]), size(layers[i-1]) + 1)
7676
end
@@ -120,7 +120,7 @@ function propagate(net::FFNNet, x::Vector{Float64})
120120
update!(net.layers[1], net.weights[1] * vcat([1.0], x))
121121

122122
# Update all remaining layers
123-
for i in 2:length(net)
123+
@inbounds for i in 2:length(net)
124124
update!(net.layers[i], net.weights[i] * activate(net.layers[i-1]))
125125
end
126126

@@ -153,7 +153,7 @@ function backpropagate(net::FFNNet,
153153
δ[L] = (der(last.activation)(last))' * der(cost)(output, target)
154154

155155
# Find δ of previous layers, backwards
156-
for l in (L-1):-1:1
156+
@inbounds for l in (L-1):-1:1
157157
layer = net.layers[l] # Current layer
158158
W = net.weights[l+1] # W^(l+1)
159159

@@ -230,7 +230,7 @@ function train!(net::FFNNet,
230230
end
231231
end
232232

233-
for l in 1:L
233+
@inbounds for l in 1:L
234234
# Update Weights using Momentum Gradient Descent
235235
# W^(l) = W^(l) - α∇E - η∇E_old
236236
net.weights[l] -= α*grad[l] + η*last_grad[l]

0 commit comments

Comments
 (0)
Please sign in to comment.