-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGaussian.py
49 lines (40 loc) · 2.65 KB
/
Gaussian.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#******************************************************************************************************
# Class representing the Gaussian activation function *
# *
# The formula implemented in the code for the PReLU activation function is: *
# *
# ---> For the activation function: f(x) = { alpha * x, if x < 0 *
# x, if x >= 0 }, *
# *
# where alpha is the parameter that determines the slope for negative values. *
# *
# ---> For the derivative of the activation function: f'(x) = { alpha, if x < 0 *
# 1, if x >= 0 }, *
# *
# which is a piecewise function that depends on the value of x. *
# *
# ---> This implementation allows the PReLU activation function to have different slopes *
# for negative values (alpha * x) compared to positive values (x), providing more *
# flexibility in modeling the activation behavior. *
# *
#******************************************************************************************************
import numpy as np
class Gaussian:
def activation(self, x):
"""
Compute the Gaussian activation function for the input x.
Args:
x (numpy.ndarray): Input array.
Returns:
numpy.ndarray: Output of the Gaussian activation function.
"""
return np.exp(-x**2)
def derivative(self, x):
"""
Compute the derivative of the Gaussian activation function for the input x.
Args:
x (numpy.ndarray): Input array.
Returns:
numpy.ndarray: Derivative of the Gaussian activation function.
"""
return -2 * x * np.exp(-x**2)