Skip to main content
Code Review

Return to Question

Notice removed Draw attention by Community Bot
Bounty Ended with no winning answer by Community Bot
added 2 characters in body
Source Link
penalosa
  • 269
  • 2
  • 6
Added testing code and extra details.
Source Link
penalosa
  • 269
  • 2
  • 6

EDIT: I tried leaving the network to learn for a few hours, over probably several million or more iterations, and the two lines on the grah did seem to come together more, however, the cost refused to budge below 0.41-ish.

Correct output(green line) vs network output(blue line), after about 15,000 iterations

Can anyone offer any feedback on my implementation, and whether the backprop algorithm is 'correct'?

EDIT:

Below is the testing code that I am using (just put after the neural network code in the same file). I realise that it is extremely messy, and contains many examples of bad practice, but it seems to work (however inelegantly). I have tested extensively with different hyperparameters, not just the ones used in the code below, and I have not been able to get the cost down below 0.41-ish, which does seem pretty poor. If anyone can find hyperparameters which would decrease the minimum bound on the cost significantly, that would also basically answer my question.

np.seterr(all='raise')
def plot():
 plt.clf()
 plt.plot([i/100 for i in range(100)],[net.predict(np.array([[1,f/100]]))[0][0] for f in range(100)])
 plt.plot([i/100 for i in range(100)],[((f/100)**2) for f in range(100)])
 plt.pause(0.05)
import random
net=neural_network([2,400,1],lambda x:1/(1+np.exp(-x)),lambda x:(1/(1+np.exp(-x)))*(1-(1/(1+np.exp(-x)))))
count=0
import matplotlib.pyplot as plt
plt.ion()
r=[i/1000 for i in range(1,1000)]
inp=np.array([[1,f] for f in r])
outp=np.array([[f**2] for f in r])
net.predict(inp)
while True:
 count+=1
 
 net.train(inp,outp,1,0.001)
 if count%100==0:
 
 print(net.cost(0.001))
 plot()
 

Correct output(green line) vs network output(blue line), after about 15,000 iterations

Can anyone offer any feedback on my implementation, and whether the backprop algorithm is 'correct'?

EDIT: I tried leaving the network to learn for a few hours, over probably several million or more iterations, and the two lines on the grah did seem to come together more, however, the cost refused to budge below 0.41-ish.

Correct output(green line) vs network output(blue line), after about 15,000 iterations

Can anyone offer any feedback on my implementation, and whether the backprop algorithm is 'correct'?

EDIT:

Below is the testing code that I am using (just put after the neural network code in the same file). I realise that it is extremely messy, and contains many examples of bad practice, but it seems to work (however inelegantly). I have tested extensively with different hyperparameters, not just the ones used in the code below, and I have not been able to get the cost down below 0.41-ish, which does seem pretty poor. If anyone can find hyperparameters which would decrease the minimum bound on the cost significantly, that would also basically answer my question.

np.seterr(all='raise')
def plot():
 plt.clf()
 plt.plot([i/100 for i in range(100)],[net.predict(np.array([[1,f/100]]))[0][0] for f in range(100)])
 plt.plot([i/100 for i in range(100)],[((f/100)**2) for f in range(100)])
 plt.pause(0.05)
import random
net=neural_network([2,400,1],lambda x:1/(1+np.exp(-x)),lambda x:(1/(1+np.exp(-x)))*(1-(1/(1+np.exp(-x)))))
count=0
import matplotlib.pyplot as plt
plt.ion()
r=[i/1000 for i in range(1,1000)]
inp=np.array([[1,f] for f in r])
outp=np.array([[f**2] for f in r])
net.predict(inp)
while True:
 count+=1
 
 net.train(inp,outp,1,0.001)
 if count%100==0:
 
 print(net.cost(0.001))
 plot()
 
Tweeted twitter.com/StackCodeReview/status/795420917698592769
Notice added Draw attention by penalosa
Bounty Started worth 100 reputation by penalosa
edited title
Link
penalosa
  • 269
  • 2
  • 6

Backpropagation in simple neural networkNeural Network

edited title; edited tags
Source Link
200_success
  • 145.6k
  • 22
  • 190
  • 479
Loading
edited body
Source Link
penalosa
  • 269
  • 2
  • 6
Loading
Source Link
penalosa
  • 269
  • 2
  • 6
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /