0% found this document useful (0 votes)
7 views5 pages

Program 3

The program demonstrates the use of different activation functions (sigmoid, tanh, ReLU, and softmax) on a set of input values. It imports necessary libraries, applies each activation function to the input array, and prints the results. The outputs illustrate how each function transforms the input values, highlighting their respective ranges and applications in neural networks.

Uploaded by

Shaarif Ali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

Program 3

The program demonstrates the use of different activation functions (sigmoid, tanh, ReLU, and softmax) on a set of input values. It imports necessary libraries, applies each activation function to the input array, and prints the results. The outputs illustrate how each function transforms the input values, highlighting their respective ranges and applications in neural networks.

Uploaded by

Shaarif Ali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PROGRAM 3.

Write a program to demonstrate different activation


functions.

import numpy as np

from [Link] import sigmoid, tanh, relu, softmax

x = [Link]([-2.0, -1.0, 0.0, 1.0, 2.0])

print("Input values:", x)

sigmoid_output = sigmoid(x)

tanh_output = tanh(x)

relu_output = relu(x)

softmax_output = softmax(x)

print("\nSigmoid Activation Output:")

print(sigmoid_output.numpy())

print("\nTanh Activation Output:")

print(tanh_output.numpy())

print("\nReLU Activation Output:")

print(relu_output.numpy())

print("\nSoftmax Activation Output:")

print(softmax_output.numpy())
import numpy as np

Imports the NumPy library

Used for creating arrays and numerical operations

from [Link] import sigmoid, tanh, relu, softmax

Imports activation functions from Keras

These functions apply non-linearity to neural network outputs

Imported activations:

sigmoid

tanh

relu

softmax

x = [Link]([-2.0, -1.0, 0.0, 1.0, 2.0])

Creates an input array

Represents raw input values before activation

Includes: Negative values, Zero, Positive values

print("Input values:", x)

Prints the input array

sigmoid_output = sigmoid(x)

Applies sigmoid activation to each value in x

Output range: 0 to 1
Returns a TensorFlow tensor

tanh_output = tanh(x)

Applies tanh activation

Output range: –1 to +1

Produces a tensor with transformed values

relu_output = relu(x)

Applies ReLU activation

Converts:

Negative values → 0

Positive values → unchanged

Commonly used in hidden layers

softmax_output = softmax(x)

Applies softmax activation

Converts values into probabilities

Sum of all outputs = 1

Used in multi-class classification output layers

print("\nSigmoid Activation Output:")

Prints a label for sigmoid output

\n adds a new line for clean formatting


print(sigmoid_output.numpy())

Converts the TensorFlow tensor to a NumPy array

Prints the sigmoid output values

print("\nTanh Activation Output:")

Prints label for tanh output

print(tanh_output.numpy())

Converts tanh tensor to NumPy array

Displays tanh activation results

print("\nReLU Activation Output:")

Prints label for ReLU output

print(relu_output.numpy())

Converts ReLU tensor to NumPy array

Displays ReLU activation results

print("\nSoftmax Activation Output:")

Prints label for softmax output

print(softmax_output.numpy())
Converts softmax tensor to NumPy array

Displays probability distribution

You might also like