Compare commits

...

2 Commits

Author SHA1 Message Date
Kausthub Kannan
f6b12420ce
Added Leaky ReLU Activation Function (#8962)
* Added Leaky ReLU activation function

* Added Leaky ReLU activation function

* Added Leaky ReLU activation function

* Formatting and spelling fixes done
2023-08-16 18:22:15 -07:00
Caeden Perelli-Harris
fd7cc4cf8e
Rename norgate to nor_gate to keep consistency (#8968)
* refactor(boolean-algebra): Rename norgate to nor_gate

* updating DIRECTORY.md

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2023-08-16 18:21:00 -07:00
3 changed files with 40 additions and 1 deletions

View File

@ -62,7 +62,7 @@
## Boolean Algebra ## Boolean Algebra
* [And Gate](boolean_algebra/and_gate.py) * [And Gate](boolean_algebra/and_gate.py)
* [Nand Gate](boolean_algebra/nand_gate.py) * [Nand Gate](boolean_algebra/nand_gate.py)
* [Norgate](boolean_algebra/norgate.py) * [Nor Gate](boolean_algebra/nor_gate.py)
* [Not Gate](boolean_algebra/not_gate.py) * [Not Gate](boolean_algebra/not_gate.py)
* [Or Gate](boolean_algebra/or_gate.py) * [Or Gate](boolean_algebra/or_gate.py)
* [Quine Mc Cluskey](boolean_algebra/quine_mc_cluskey.py) * [Quine Mc Cluskey](boolean_algebra/quine_mc_cluskey.py)

View File

@ -0,0 +1,39 @@
"""
Leaky Rectified Linear Unit (Leaky ReLU)
Use Case: Leaky ReLU addresses the problem of the vanishing gradient.
For more detailed information, you can refer to the following link:
https://en.wikipedia.org/wiki/Rectifier_(neural_networks)#Leaky_ReLU
"""
import numpy as np
def leaky_rectified_linear_unit(vector: np.ndarray, alpha: float) -> np.ndarray:
"""
Implements the LeakyReLU activation function.
Parameters:
vector (np.ndarray): The input array for LeakyReLU activation.
alpha (float): The slope for negative values.
Returns:
np.ndarray: The input array after applying the LeakyReLU activation.
Formula: f(x) = x if x > 0 else f(x) = alpha * x
Examples:
>>> leaky_rectified_linear_unit(vector=np.array([2.3,0.6,-2,-3.8]), alpha=0.3)
array([ 2.3 , 0.6 , -0.6 , -1.14])
>>> leaky_rectified_linear_unit(np.array([-9.2, -0.3, 0.45, -4.56]), alpha=0.067)
array([-0.6164 , -0.0201 , 0.45 , -0.30552])
"""
return np.where(vector > 0, vector, alpha * vector)
if __name__ == "__main__":
import doctest
doctest.testmod()