From 747c8418a6b0269ea30bf5e48a4284e097de1f61 Mon Sep 17 00:00:00 2001 From: saahil-mahato Date: Sat, 7 Oct 2023 23:05:44 +0545 Subject: [PATCH 1/6] Add Sobovela Modified Hyberbolic Tangent function --- .../sobovela_modified_hyperbolic_tangent.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 neural_network/activation_functions/sobovela_modified_hyperbolic_tangent.py diff --git a/neural_network/activation_functions/sobovela_modified_hyperbolic_tangent.py b/neural_network/activation_functions/sobovela_modified_hyperbolic_tangent.py new file mode 100644 index 000000000000..641fc0773ed4 --- /dev/null +++ b/neural_network/activation_functions/sobovela_modified_hyperbolic_tangent.py @@ -0,0 +1,47 @@ +""" +This script implements the Sobovela Modified Hyperbolic Tangent function. + +The function the applies the Sobovela Modified Hyperbolic Tangent function +to each element of the vector. + +More details about the activation function can be found on: +https://en.wikipedia.org/wiki/Soboleva_modified_hyperbolic_tangent +""" + + +import numpy as np + + +def sobovela_modified_hyperbolic_tangent( + vector: np.ndarray, a_value: float, b_value: float, c_value: float, d_value: float +) -> np.ndarray: + """ + Implements the Sobovela Modified Hyperbolic Tangent function + + Parameters: + vector (ndarray): A vector that consitis of numeric values + alpha (float): alpha value + beta (float): beta value + + Returns: + vector (ndarray): Input array after applying SMHT function + + >>> vector = np.array([5.4, -2.4, 6.3, -5.23, 3.27, 0.56]) + >>> sobovela_modified_hyperbolic_tangent(vector, 0.2, 0.4, 0.6, 0.8) + array([ 0.11075085, -0.28236685, 0.07861169, -0.1180085 , 0.22999056, + 0.1566043 ]) + """ + + # Separate the numerator and denominator for simplicity + # Calculate the numerator and denominator element-wise + numerator = np.exp(a_value * vector) - np.exp(-b_value * vector) + denominator = np.exp(c_value * vector) + np.exp(-d_value * vector) + + # Calculate and return the final result element-wise + return numerator / denominator + + +if __name__ == "__main__": + import doctest + + doctest.testmod() From be0ba819549b316146aea835a4d4008c5680bfd7 Mon Sep 17 00:00:00 2001 From: saahil-mahato Date: Sat, 7 Oct 2023 23:07:46 +0545 Subject: [PATCH 2/6] fix: typo --- .../sobovela_modified_hyperbolic_tangent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neural_network/activation_functions/sobovela_modified_hyperbolic_tangent.py b/neural_network/activation_functions/sobovela_modified_hyperbolic_tangent.py index 641fc0773ed4..8b493c2d431c 100644 --- a/neural_network/activation_functions/sobovela_modified_hyperbolic_tangent.py +++ b/neural_network/activation_functions/sobovela_modified_hyperbolic_tangent.py @@ -1,7 +1,7 @@ """ This script implements the Sobovela Modified Hyperbolic Tangent function. -The function the applies the Sobovela Modified Hyperbolic Tangent function +The function applies the Sobovela Modified Hyperbolic Tangent function to each element of the vector. More details about the activation function can be found on: From 6a604d2c87f602ca25750d66f86ccdb7ae5800ab Mon Sep 17 00:00:00 2001 From: Saahil Mahato <115351000+saahil-mahato@users.noreply.github.com> Date: Mon, 9 Oct 2023 04:35:24 +0545 Subject: [PATCH 3/6] Update and rename sobovela_modified_hyperbolic_tangent.py to soboleva_modified_hyperbolic_tangent.py --- ...y => soboleva_modified_hyperbolic_tangent.py} | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) rename neural_network/activation_functions/{sobovela_modified_hyperbolic_tangent.py => soboleva_modified_hyperbolic_tangent.py} (67%) diff --git a/neural_network/activation_functions/sobovela_modified_hyperbolic_tangent.py b/neural_network/activation_functions/soboleva_modified_hyperbolic_tangent.py similarity index 67% rename from neural_network/activation_functions/sobovela_modified_hyperbolic_tangent.py rename to neural_network/activation_functions/soboleva_modified_hyperbolic_tangent.py index 8b493c2d431c..9299cd06db2c 100644 --- a/neural_network/activation_functions/sobovela_modified_hyperbolic_tangent.py +++ b/neural_network/activation_functions/soboleva_modified_hyperbolic_tangent.py @@ -1,7 +1,7 @@ """ -This script implements the Sobovela Modified Hyperbolic Tangent function. +This script implements the Soboleva Modified Hyperbolic Tangent function. -The function applies the Sobovela Modified Hyperbolic Tangent function +The function applies the Soboleva Modified Hyperbolic Tangent function to each element of the vector. More details about the activation function can be found on: @@ -12,22 +12,24 @@ import numpy as np -def sobovela_modified_hyperbolic_tangent( +def soboleva_modified_hyperbolic_tangent( vector: np.ndarray, a_value: float, b_value: float, c_value: float, d_value: float ) -> np.ndarray: """ - Implements the Sobovela Modified Hyperbolic Tangent function + Implements the Soboleva Modified Hyperbolic Tangent function Parameters: vector (ndarray): A vector that consitis of numeric values - alpha (float): alpha value - beta (float): beta value + a_value (float): paramenter a of the equation + b_value (float): parameter b of the equation + c_value (float): parameter c of the equation + d_value (float): parameter d of the equation Returns: vector (ndarray): Input array after applying SMHT function >>> vector = np.array([5.4, -2.4, 6.3, -5.23, 3.27, 0.56]) - >>> sobovela_modified_hyperbolic_tangent(vector, 0.2, 0.4, 0.6, 0.8) + >>> soboleva_modified_hyperbolic_tangent(vector, 0.2, 0.4, 0.6, 0.8) array([ 0.11075085, -0.28236685, 0.07861169, -0.1180085 , 0.22999056, 0.1566043 ]) """ From 78c3901d92228afe92b3b22907476a4883aa116c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 8 Oct 2023 22:50:57 +0000 Subject: [PATCH 4/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../soboleva_modified_hyperbolic_tangent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neural_network/activation_functions/soboleva_modified_hyperbolic_tangent.py b/neural_network/activation_functions/soboleva_modified_hyperbolic_tangent.py index 9299cd06db2c..b3e14253f661 100644 --- a/neural_network/activation_functions/soboleva_modified_hyperbolic_tangent.py +++ b/neural_network/activation_functions/soboleva_modified_hyperbolic_tangent.py @@ -22,7 +22,7 @@ def soboleva_modified_hyperbolic_tangent( vector (ndarray): A vector that consitis of numeric values a_value (float): paramenter a of the equation b_value (float): parameter b of the equation - c_value (float): parameter c of the equation + c_value (float): parameter c of the equation d_value (float): parameter d of the equation Returns: From 23b9251a6a88a8e341a9a1161c733fa932db96e0 Mon Sep 17 00:00:00 2001 From: Saahil Mahato <115351000+saahil-mahato@users.noreply.github.com> Date: Mon, 9 Oct 2023 04:37:07 +0545 Subject: [PATCH 5/6] fix: typo --- .../soboleva_modified_hyperbolic_tangent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neural_network/activation_functions/soboleva_modified_hyperbolic_tangent.py b/neural_network/activation_functions/soboleva_modified_hyperbolic_tangent.py index b3e14253f661..2802b30bf635 100644 --- a/neural_network/activation_functions/soboleva_modified_hyperbolic_tangent.py +++ b/neural_network/activation_functions/soboleva_modified_hyperbolic_tangent.py @@ -20,7 +20,7 @@ def soboleva_modified_hyperbolic_tangent( Parameters: vector (ndarray): A vector that consitis of numeric values - a_value (float): paramenter a of the equation + a_value (float): parameter a of the equation b_value (float): parameter b of the equation c_value (float): parameter c of the equation d_value (float): parameter d of the equation From 743552b9848e63af9eb55fb98876e6190551903b Mon Sep 17 00:00:00 2001 From: Tianyi Zheng Date: Sun, 8 Oct 2023 19:15:58 -0400 Subject: [PATCH 6/6] Apply suggestions from code review --- .../soboleva_modified_hyperbolic_tangent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neural_network/activation_functions/soboleva_modified_hyperbolic_tangent.py b/neural_network/activation_functions/soboleva_modified_hyperbolic_tangent.py index 2802b30bf635..603ac0b7e120 100644 --- a/neural_network/activation_functions/soboleva_modified_hyperbolic_tangent.py +++ b/neural_network/activation_functions/soboleva_modified_hyperbolic_tangent.py @@ -19,7 +19,7 @@ def soboleva_modified_hyperbolic_tangent( Implements the Soboleva Modified Hyperbolic Tangent function Parameters: - vector (ndarray): A vector that consitis of numeric values + vector (ndarray): A vector that consists of numeric values a_value (float): parameter a of the equation b_value (float): parameter b of the equation c_value (float): parameter c of the equation