Created
March 8, 2018 15:39
-
-
Save isheraz/bb21d6500efbdf66c2c695505e9a910d to your computer and use it in GitHub Desktop.
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
# 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