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