2

I am trying to create a neural network, but when i try implementing the sigmoid function (importing, or creating it manually like in this case) it just says that the variable sigmoid does not exist

Here is my code

Also, i am using visual studio code with Anaconda

from matplotlib import pylab
import pylab as plt
import numpy as np

class NeuralNetwork:
    def __init__(self,x,y):
        self.input = x
        self.weights1 = np.random.rand(self.input.shape[1],4)
        self.weights2 = np.random.rand(4,1)
        self.y = y
        self.output = np.zeros(self.y.shape)


    def sigmoid(self,x):
        return (1/(1+np.exp(-x)))      



    def feedforward(self):
        self.layer1 = sigmoid(np.dot(self.input, self.weights1))
        self.output = sigmoid(np.dot(self.layer1, self.weights2))```
  • You have to use self.sigmoid() as sigmoid is a method of the class – SajanGohil Jun 08 '20 at 09:02
  • If my answer below has helped you, consider upvoting and accepting it. It'll help me, you and others trying to get an answer to a similar question. – Eeshaan Jun 08 '20 at 11:12

1 Answers1

2

You've defined sigmoid as a class method, hence you need to use the self keyword like so

self.layer1 = self.sigmoid(np.dot(self.input, self.weights1))
self.output = self.sigmoid(np.dot(self.layer1, self.weights2))
Eeshaan
  • 1,557
  • 1
  • 10
  • 22