Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random, time
- def step(x,t): # t is our threshold value
- if(x >= t):return 1
- else:return 0
- weights = [random.uniform(0,1),random.uniform(0,1)] #two inputs
- def train():
- global weights
- while True:
- # we use 1 & 1 for input each time, and 0.1 as a learning rate
- neuron_output = step(weights[0]+weights[1],1)
- for i in range(len(weights)):
- weights[i] += 0.1*(1-neuron_output) # inputs are always 1
- print "Neuron Output: {}\nw1: {}\nw2: {}".format(neuron_output,weights[0],weights[1])
- if(neuron_output==1):
- print"Training Complete"
- break
- else:time.sleep(1)
- train()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement