TheAlgorithms-Python
48 строк · 1.6 Кб
1"""
2This script implements the Soboleva Modified Hyperbolic Tangent function.
3
4The function applies the Soboleva Modified Hyperbolic Tangent function
5to each element of the vector.
6
7More details about the activation function can be found on:
8https://en.wikipedia.org/wiki/Soboleva_modified_hyperbolic_tangent
9"""
10
11import numpy as np
12
13
14def soboleva_modified_hyperbolic_tangent(
15vector: np.ndarray, a_value: float, b_value: float, c_value: float, d_value: float
16) -> np.ndarray:
17"""
18Implements the Soboleva Modified Hyperbolic Tangent function
19
20Parameters:
21vector (ndarray): A vector that consists of numeric values
22a_value (float): parameter a of the equation
23b_value (float): parameter b of the equation
24c_value (float): parameter c of the equation
25d_value (float): parameter d of the equation
26
27Returns:
28vector (ndarray): Input array after applying SMHT function
29
30>>> vector = np.array([5.4, -2.4, 6.3, -5.23, 3.27, 0.56])
31>>> soboleva_modified_hyperbolic_tangent(vector, 0.2, 0.4, 0.6, 0.8)
32array([ 0.11075085, -0.28236685, 0.07861169, -0.1180085 , 0.22999056,
330.1566043 ])
34"""
35
36# Separate the numerator and denominator for simplicity
37# Calculate the numerator and denominator element-wise
38numerator = np.exp(a_value * vector) - np.exp(-b_value * vector)
39denominator = np.exp(c_value * vector) + np.exp(-d_value * vector)
40
41# Calculate and return the final result element-wise
42return numerator / denominator
43
44
45if __name__ == "__main__":
46import doctest
47
48doctest.testmod()
49