MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / squareplus

Function squareplus

neural_network/activation_functions/squareplus.py:12–32  ·  view source on GitHub ↗

Implements the SquarePlus activation function. Parameters: vector (np.ndarray): The input array for the SquarePlus activation. beta (float): size of the curved region Returns: np.ndarray: The input array after applying the SquarePlus activation. Formula: f

(vector: np.ndarray, beta: float)

Source from the content-addressed store, hash-verified

10
11
12def squareplus(vector: np.ndarray, beta: float) -> np.ndarray:
13 """
14 Implements the SquarePlus activation function.
15
16 Parameters:
17 vector (np.ndarray): The input array for the SquarePlus activation.
18 beta (float): size of the curved region
19
20 Returns:
21 np.ndarray: The input array after applying the SquarePlus activation.
22
23 Formula: f(x) = ( x + sqrt(x^2 + b) ) / 2
24
25 Examples:
26 >>> squareplus(np.array([2.3, 0.6, -2, -3.8]), beta=2)
27 array([2.5 , 1.06811457, 0.22474487, 0.12731349])
28
29 >>> squareplus(np.array([-9.2, -0.3, 0.45, -4.56]), beta=3)
30 array([0.0808119 , 0.72891979, 1.11977651, 0.15893419])
31 """
32 return (vector + np.sqrt(vector**2 + beta)) / 2
33
34
35if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected