CardinalGaming

1ST EXERCISE AI

Jul 28th, 2021 (edited)
912
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2.  
  3. def sigmoid (x):
  4.   #activation function: f(x) = 1/(1 + e^(-x))
  5.   return 1 / (1 + np.exp(-x))
  6.  
  7. class Neuron:
  8.   def __init__(self, weights, bias):
  9.     self.weights = weights
  10.     self.bias = bias
  11.  
  12.   def feedforward(self, inputs):
  13.     #weights inputs, add bias, then use the activation method
  14.     total = np.dot(self.weights, inputs) + self.bias
  15.     return sigmoid(total)
  16.  
  17. weights = np.array([0,1]) #w1 = 0, w2 = 1
  18. bias = 4                  # b = 0
  19. n = Neuron(weights, bias)
  20.  
  21. x= np.array([2,3])  # x1= 2, x2 = 3
  22. print(n.feedforward(x)) #0.9990889488055994
RAW Paste Data