Skip to content

Commit 2260961

Browse files
saahil-mahatopre-commit-ci[bot]tianyizheng02
authored
Add Soboleva Modified Hyberbolic Tangent function (#10043)
* Add Sobovela Modified Hyberbolic Tangent function * fix: typo * Update and rename sobovela_modified_hyperbolic_tangent.py to soboleva_modified_hyperbolic_tangent.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: typo * Apply suggestions from code review --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
1 parent a2b695d commit 2260961

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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

Comments
 (0)