Advertisement
Guest User

Untitled

a guest
Jun 1st, 2016
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. import random, time
  2. def step(x,t): # t is our threshold value
  3. if(x >= t):return 1
  4. else:return 0
  5. weights = [random.uniform(0,1),random.uniform(0,1)] #two inputs
  6. def train():
  7. global weights
  8. while True:
  9. # we use 1 & 1 for input each time, and 0.1 as a learning rate
  10. neuron_output = step(weights[0]+weights[1],1)
  11. for i in range(len(weights)):
  12. weights[i] += 0.1*(1-neuron_output) # inputs are always 1
  13. print "Neuron Output: {}\nw1: {}\nw2: {}".format(neuron_output,weights[0],weights[1])
  14.  
  15. if(neuron_output==1):
  16. print"Training Complete"
  17. break
  18. else:time.sleep(1)
  19.  
  20. train()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement