Code Monkey home page Code Monkey logo

sigmoid-activation-function's Introduction

EX NO: 05

DATE:

SIGMOID ACTIVATION FUNCTION

Aim:

To develop a python code that creates a simple feed-forward neural networks or perception with the Sigmoid activation function. The neuron has to be trained such that it can predict the correct output value when provided with a new set of input data.

image

Equipments Required:

  1. Hardware โ€“ PCs
  2. Anaconda โ€“ Python 3.7 Installation / Moodle-Code Runner / Google Colab

Related Theoritical Concept:

  • Sigmoid Activation Function is commonly used for models where we have to predict the probability as an output. Since probability of anything exists only between the range of 0 and 1, sigmoid is the right choice because of its range.

  • The function is differentiable and provides a smooth gradient, i.e., preventing jumps in output values. This is represented by an S-shape of the sigmoid activation function.

  • The limitations of sigmoid function are :

    • The derivative of the function is f'(x) = sigmoid(x)*(1-sigmoid(x)).
  • The output of the logistic function is not symmetric around zero. So the output of all the neurons will be of the same sign. This makes the training of the neural network more difficult and unstable.

Algorithm

  1. Import packages.
  2. Define neural network class.
  3. Model single neuron with 3 inputs and 1 output and assign random weights to a 3 x 1 matrix with values between -1 and 1.
  4. Define sigmoid function and calculate the error.
  5. Multiply the error by the input and again by the gradient of the sigmoid curve.
  6. Initialize a single neuron neural network.
  7. Train neural network using training data.
  8. Test neural network with new data.

Program:

Program to implement the sigmoid activation function in a feed forward ANN.
Developed by: KAYALVIZHI M
RegisterNumber:  212220230024
import numpy as np
class NeuralNetwork():
    def __init__(self):
        np.random.seed(1)
        self.synaptic_weights=2*np.random.random((3,1)) -1
        
    def sigmoid(self,x):
        return 1/(1+np.exp(-x))
    
    def sigmoid_derivative(self,x):
        return x*(1-x)
    
    def train(self,training_inputs,training_outputs,training_iterations):
        
        for iteration in range(training_iterations):
            output=self.think(training_inputs)
            error=training_outputs-output
            adjustments=np.dot(training_inputs.T,error*self.sigmoid_derivative(output))
            self.synaptic_weights += adjustments
    def  think(self,inputs):
        inputs=inputs.astype(float)
        output=self.sigmoid(np.dot(inputs,self.synaptic_weights))
        return output

if __name__=="__main__":
    neuron=NeuralNetwork()
    
    print("Beginning Randomly Generated weights: ")
    print(neuron.synaptic_weights)
    
    training_inputs=np.array([[0,0,1],[1,1,1],[1,0,1],[0,1,1]])
    
    training_outputs=np.array([[0,1,1,0]]).T
    
    neuron.train(training_inputs,training_outputs, 15000)
    
    print("Ending Weights After Training")
    print(neuron.synaptic_weights)
    
    user_input_one=str(input("User Input One : "))
    user_input_two=str(input("User Input Two : "))
    user_input_three=str(input("User Input Three : "))
    
    print("Considering New Situation: ",user_input_one, user_input_two, user_input_three)
    print("New Output data: ")
    print(neuron.think(np.array([user_input_one, user_input_two, user_input_three])))

Output:

img

Result:

Thus created a perception to employ the Sigmoid activation function. This neuron was successfully trained to predict the correct output value, when provided with a new set of input data.

sigmoid-activation-function's People

Contributors

hemalatha2021 avatar kayalvizhi02 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.