Created
August 2, 2018 20:43
-
-
Save anshmidt/477d79e85b30210776b53a1e2a0cadb2 to your computer and use it in GitHub Desktop.
Simple example of perceptron
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inputs = [0, 1, 0, 0] | |
weights = [0, 0, 0, 0] | |
desired_result = 1 | |
learning_rate = 0.2 | |
trials = 6 | |
def evaluate_neural_network(input_array, weight_array): | |
result = 0 | |
for i in range(len(input_array)): | |
layer_value = input_array[i] * weight_array[i] | |
result += layer_value | |
print("evaluate_neural_network: " + str(result)) | |
print("weights: " + str(weights)) | |
return result | |
def evaluate_error(desired, actual): | |
error = desired - actual | |
print("evaluate_error: " + str(error)) | |
return error | |
def learn(input_array, weight_array): | |
print("learning...") | |
for i in range(len(input_array)): | |
if input_array[i] > 0: | |
weight_array[i] += learning_rate | |
def train(trials): | |
for i in range(trials): | |
neural_net_result = evaluate_neural_network(inputs, weights) | |
learn(inputs, weights) | |
train(trials) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment