TheAlgorithms-Python

Форк
0
/
soboleva_modified_hyperbolic_tangent.py 
48 строк · 1.6 Кб
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
import numpy as np
12

13

14
def soboleva_modified_hyperbolic_tangent(
15
    vector: np.ndarray, a_value: float, b_value: float, c_value: float, d_value: float
16
) -> np.ndarray:
17
    """
18
    Implements the Soboleva Modified Hyperbolic Tangent function
19

20
    Parameters:
21
        vector (ndarray): A vector that consists of numeric values
22
        a_value (float): parameter a of the equation
23
        b_value (float): parameter b of the equation
24
        c_value (float): parameter c of the equation
25
        d_value (float): parameter d of the equation
26

27
    Returns:
28
        vector (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)
32
    array([ 0.11075085, -0.28236685,  0.07861169, -0.1180085 ,  0.22999056,
33
            0.1566043 ])
34
    """
35

36
    # Separate the numerator and denominator for simplicity
37
    # Calculate the numerator and denominator element-wise
38
    numerator = np.exp(a_value * vector) - np.exp(-b_value * vector)
39
    denominator = np.exp(c_value * vector) + np.exp(-d_value * vector)
40

41
    # Calculate and return the final result element-wise
42
    return numerator / denominator
43

44

45
if __name__ == "__main__":
46
    import doctest
47

48
    doctest.testmod()
49

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.