Alexander Siles
Alexander Siles

Reputation: 37

How to use sigmoid function in python when developing a NeuralNetwork

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))```

Upvotes: 2

Views: 667

Answers (1)

Eeshaan
Eeshaan

Reputation: 1635

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))

Upvotes: 2

Related Questions