-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sigmoid.py
34 lines (26 loc) · 1.22 KB
/
Sigmoid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#************************************************************************************************************
# Class representing the sigmoid activation function *
# The sigmoid function is defined as: f(x) = 1 / (1 + exp(-x)) *
# The derivative of the sigmoid function can be computed as: f'(x) = f(x) * (1 - f(x)) *
#************************************************************************************************************
import numpy as np
class Sigmoid:
def activation(self, x):
"""
Compute the sigmoid activation function for the input x.
Args:
x (numpy.ndarray): Input array.
Returns:
numpy.ndarray: Output of the sigmoid activation function.
"""
return 1 / (1 + np.exp(-x))
def derivative(self, x):
"""
Compute the derivative of the sigmoid activation function for the input x.
Args:
x (numpy.ndarray): Input array.
Returns:
numpy.ndarray: Derivative of the sigmoid activation function.
"""
sig_x = self.activation(x)
return sig_x * (1 - sig_x)