Implements the tanh function Parameters: vector: np.ndarray Returns: tanh (np.array): The input numpy array after applying tanh. mathematically (e^x - e^(-x))/(e^x + e^(-x)) can be written as (2/(1+e^(-2x))-1 Examples: >>> tang
(vector: np.ndarray)
| 14 | |
| 15 | |
| 16 | def tangent_hyperbolic(vector: np.ndarray) -> np.ndarray: |
| 17 | """ |
| 18 | Implements the tanh function |
| 19 | |
| 20 | Parameters: |
| 21 | vector: np.ndarray |
| 22 | |
| 23 | Returns: |
| 24 | tanh (np.array): The input numpy array after applying tanh. |
| 25 | |
| 26 | mathematically (e^x - e^(-x))/(e^x + e^(-x)) can be written as (2/(1+e^(-2x))-1 |
| 27 | |
| 28 | Examples: |
| 29 | >>> tangent_hyperbolic(np.array([1,5,6,-0.67])) |
| 30 | array([ 0.76159416, 0.9999092 , 0.99998771, -0.58497988]) |
| 31 | |
| 32 | >>> tangent_hyperbolic(np.array([8,10,2,-0.98,13])) |
| 33 | array([ 0.99999977, 1. , 0.96402758, -0.7530659 , 1. ]) |
| 34 | |
| 35 | """ |
| 36 | |
| 37 | return (2 / (1 + np.exp(-2 * vector))) - 1 |
| 38 | |
| 39 | |
| 40 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected