Python Forum
neural network- undefined name with sigmoid function
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
neural network- undefined name with sigmoid function
#1
my code is as follows:

import numpy as np
import scipy.optimize as opt
import matplotlib.pyplot as plt
#*matplotlib inline
def f(x,a, b, c, d):
    return a / (1+np.exp(-c*(x-d)))+b
a,c=np.random.exponential(size=2)
b,d=np.random.randn(2)
n=100
x=np.linspace(-10,10,n)
y_model=f(x,a,b,c,d)
y= y_model+a *.2*np.random.random(n)
fig, ax=plt.subplots(1,1, figsize=(6,4))
ax.plot(x,y_model, '--k')
ax.plot(x,y,'o')
(a_,b_,c_,d_), _=opt.curve_fit(f,x,y)
y_fit=f(x,a_,b_,c_,d_)

fig, ax =plt.subplots(1,1,figsize=(6,4))
ax.plot(x,y_model,'--k')
ax.plot(x,y,'o')
ax.plot(x,y_fit,'-')
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 feedforward(self):
        self.layer1 = sigmoid(np.dot(self.input, self.weights1))
        self.outout = sigmoid(np.dot(self.layer1, self.weights2))
    def backprop(self):
        # application of the chain rule to find derivative of the loss function with respect to weights
        d_weights2 = np.dot(self.layer1.T, (2*(self.y - self.output) * sigmoid_derivative(self.output)))
        d_weights1 = np.dot(self.input.T, (np.dot(2*(self.y - self.output) * sigmoid_derivative(self.output), self.weights2.T) * sigmoid_dervative(self.layer1)))
        #update the weights with the derivative (slope) of loss function
        self.weights1 += d_weights1
        self.weights2 += d_weights2
the sigmoid used is undefined. how do I fixed this?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Neural network and data analysis from clients survey result pthon3 2 1,896 Mar-17-2022, 02:21 AM
Last Post: jefsummers
  Multilayer Perceptron Neural Network erdemath 3 2,329 Aug-09-2021, 11:07 PM
Last Post: jefsummers
  Neural Network importance weights / coefficients jkaustin 1 2,058 Nov-10-2020, 07:44 PM
Last Post: jefsummers
  Get error message in a GAN neural network tutorial jdude50 0 1,674 Oct-22-2020, 11:11 PM
Last Post: jdude50
  Explain Me Neural Network Ai's Harshil 2 2,007 Oct-22-2020, 04:50 AM
Last Post: Harshil
  construction of Neural Network for solving Differential equations arshad 0 1,615 Jun-04-2020, 09:20 AM
Last Post: arshad
  Neural Network mensagem error Dalpi 2 2,861 May-20-2020, 04:03 PM
Last Post: Dalpi
  coding neural network programmer19890620 4 3,430 Feb-27-2020, 04:26 AM
Last Post: programmer19890620
  Why does this simple neural network not learn? PythonIsGreat 1 2,103 Aug-30-2019, 05:49 PM
Last Post: ThomasL
  First neural network: Problem with the weight factos 11112294 0 2,164 Jan-12-2019, 09:11 PM
Last Post: 11112294

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020