Skip to content

Instantly share code, notes, and snippets.

@isheraz
Created March 8, 2018 15:39
Show Gist options
  • Save isheraz/bb21d6500efbdf66c2c695505e9a910d to your computer and use it in GitHub Desktop.
Save isheraz/bb21d6500efbdf66c2c695505e9a910d to your computer and use it in GitHub Desktop.
# Single Perceptron
import decimal
import random
def randfloat():
decimal.getcontext().prec = 3 # 3decimal points enough
return decimal.Decimal(0) + decimal.Decimal(random.uniform(-1, 1))
inputs = [7, 9, 86, 6, 10]
weight = []
''' Generating Random Weights '''
for x in range(len(inputs)):
weight.append(randfloat())
print(weight)
''' Assign weights to all inputs and their sum'''
new_inputs = sum([inputs[x] * weight[x] for x in range(len(inputs))])
''' Activation function || Step Functions '''
if new_inputs > 0:
print(1)
else:
print(-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment