From 1f9cd3b80b5c64e39eb144104827b5ccf3668f1b Mon Sep 17 00:00:00 2001 From: saahil-mahato Date: Sat, 7 Oct 2023 22:03:51 +0545 Subject: [PATCH 1/8] Add binary step activation function --- .../activation_functions/binary_step.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 neural_network/activation_functions/binary_step.py diff --git a/neural_network/activation_functions/binary_step.py b/neural_network/activation_functions/binary_step.py new file mode 100644 index 000000000000..37ffb8a98e80 --- /dev/null +++ b/neural_network/activation_functions/binary_step.py @@ -0,0 +1,33 @@ +""" +This script demonstrates the implementation of the Binary Step function. + +It's a kind of activation functionif in which if the input to the activation function is greater than a threshold, +the neuron is activated, else it is deactivated +""" + + +import numpy as np + + +def binary_step(vector: np.ndarray) -> np.ndarray: + """ + Implements the binary step function + + Parameters: + vector (ndarray): A vector that consitis of numeric values + + Returns: + vector (ndarray): A vector that consitis of values 0 or 1 + + >>> vector = np.array([-1.2, 0, 2, 1.45, -3.7, 0.3]) + >>> binary_step(vector) + array([0, 0, 1, 1, 0, 1]) + """ + + return np.where(vector > 0, 1, 0) + + +if __name__ == "__main__": + import doctest + + doctest.testmod() From 6c5ed9f9bcc93e49ae8c17eff0a29fba6fc95f63 Mon Sep 17 00:00:00 2001 From: saahil-mahato Date: Sat, 7 Oct 2023 22:14:40 +0545 Subject: [PATCH 2/8] fix: ruff line too long error --- neural_network/activation_functions/binary_step.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/neural_network/activation_functions/binary_step.py b/neural_network/activation_functions/binary_step.py index 37ffb8a98e80..ecb7bf50cbf0 100644 --- a/neural_network/activation_functions/binary_step.py +++ b/neural_network/activation_functions/binary_step.py @@ -1,8 +1,12 @@ """ This script demonstrates the implementation of the Binary Step function. -It's a kind of activation functionif in which if the input to the activation function is greater than a threshold, -the neuron is activated, else it is deactivated +It's an activation function in which if the input to the +activation function is greater than a threshold, the neuron is +activated, else it is deactivated + +It's a simple activation function which is mentioned in this wikipedia article: +https://en.wikipedia.org/wiki/Activation_function """ From f70141f97d75258c474192c66bddb371baf2e19d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 7 Oct 2023 16:30:53 +0000 Subject: [PATCH 3/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- neural_network/activation_functions/binary_step.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neural_network/activation_functions/binary_step.py b/neural_network/activation_functions/binary_step.py index ecb7bf50cbf0..e83fbaf5dc9d 100644 --- a/neural_network/activation_functions/binary_step.py +++ b/neural_network/activation_functions/binary_step.py @@ -1,8 +1,8 @@ """ This script demonstrates the implementation of the Binary Step function. -It's an activation function in which if the input to the -activation function is greater than a threshold, the neuron is +It's an activation function in which if the input to the +activation function is greater than a threshold, the neuron is activated, else it is deactivated It's a simple activation function which is mentioned in this wikipedia article: From 33bc965d42953d2299f75cf7ca11e7094866484a Mon Sep 17 00:00:00 2001 From: saahil-mahato Date: Sat, 7 Oct 2023 22:28:00 +0545 Subject: [PATCH 4/8] refactor: add link to directory --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index a975b9264be0..9db085ef43b3 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -726,6 +726,7 @@ * [Rectified Linear Unit](neural_network/activation_functions/rectified_linear_unit.py) * [Scaled Exponential Linear Unit](neural_network/activation_functions/scaled_exponential_linear_unit.py) * [Sigmoid Linear Unit](neural_network/activation_functions/sigmoid_linear_unit.py) + * [Binary Step](neural_network/activation_functions/binary_step.py) * [Back Propagation Neural Network](neural_network/back_propagation_neural_network.py) * [Convolution Neural Network](neural_network/convolution_neural_network.py) * [Perceptron](neural_network/perceptron.py) From c6ec5818b843a4a293fbb48297d9afc174c19cd6 Mon Sep 17 00:00:00 2001 From: saahil-mahato Date: Sat, 7 Oct 2023 22:33:31 +0545 Subject: [PATCH 5/8] revert: add link to directory --- DIRECTORY.md | 1 - 1 file changed, 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 9db085ef43b3..a975b9264be0 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -726,7 +726,6 @@ * [Rectified Linear Unit](neural_network/activation_functions/rectified_linear_unit.py) * [Scaled Exponential Linear Unit](neural_network/activation_functions/scaled_exponential_linear_unit.py) * [Sigmoid Linear Unit](neural_network/activation_functions/sigmoid_linear_unit.py) - * [Binary Step](neural_network/activation_functions/binary_step.py) * [Back Propagation Neural Network](neural_network/back_propagation_neural_network.py) * [Convolution Neural Network](neural_network/convolution_neural_network.py) * [Perceptron](neural_network/perceptron.py) From 948036503d714b82ccf1bba6db0abde49cca4a4d Mon Sep 17 00:00:00 2001 From: Saahil Mahato <115351000+saahil-mahato@users.noreply.github.com> Date: Mon, 9 Oct 2023 04:44:36 +0545 Subject: [PATCH 6/8] fix: algorithm bug and docs --- neural_network/activation_functions/binary_step.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/neural_network/activation_functions/binary_step.py b/neural_network/activation_functions/binary_step.py index e83fbaf5dc9d..0f7915f25828 100644 --- a/neural_network/activation_functions/binary_step.py +++ b/neural_network/activation_functions/binary_step.py @@ -1,9 +1,8 @@ """ This script demonstrates the implementation of the Binary Step function. -It's an activation function in which if the input to the -activation function is greater than a threshold, the neuron is -activated, else it is deactivated +It's an activation function in which the neuron is activated if the input is positive, +else it is deactivated It's a simple activation function which is mentioned in this wikipedia article: https://en.wikipedia.org/wiki/Activation_function @@ -18,17 +17,17 @@ def binary_step(vector: np.ndarray) -> np.ndarray: Implements the binary step function Parameters: - vector (ndarray): A vector that consitis of numeric values + vector (ndarray): A vector that consists of numeric values Returns: - vector (ndarray): A vector that consitis of values 0 or 1 + vector (ndarray): Input vector after applying binary step function >>> vector = np.array([-1.2, 0, 2, 1.45, -3.7, 0.3]) >>> binary_step(vector) - array([0, 0, 1, 1, 0, 1]) + array([0, 1, 1, 1, 0, 1]) """ - return np.where(vector > 0, 1, 0) + return np.where(vector >= 0, 1, 0) if __name__ == "__main__": From 486b4bac3f58c5781f32f10afce83262c9b2de9c Mon Sep 17 00:00:00 2001 From: Tianyi Zheng Date: Sun, 8 Oct 2023 19:24:52 -0400 Subject: [PATCH 7/8] Update neural_network/activation_functions/binary_step.py --- neural_network/activation_functions/binary_step.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neural_network/activation_functions/binary_step.py b/neural_network/activation_functions/binary_step.py index 0f7915f25828..e9c3626feefa 100644 --- a/neural_network/activation_functions/binary_step.py +++ b/neural_network/activation_functions/binary_step.py @@ -1,7 +1,7 @@ """ This script demonstrates the implementation of the Binary Step function. -It's an activation function in which the neuron is activated if the input is positive, +It's an activation function in which the neuron is activated if the input is positive or 0, else it is deactivated It's a simple activation function which is mentioned in this wikipedia article: From 398e641c984dc4caebaf118d737e10fef686d8bc Mon Sep 17 00:00:00 2001 From: Saahil Mahato <115351000+saahil-mahato@users.noreply.github.com> Date: Mon, 9 Oct 2023 05:15:29 +0545 Subject: [PATCH 8/8] fix: ruff line too long error --- neural_network/activation_functions/binary_step.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neural_network/activation_functions/binary_step.py b/neural_network/activation_functions/binary_step.py index e9c3626feefa..8f8f4d405fd2 100644 --- a/neural_network/activation_functions/binary_step.py +++ b/neural_network/activation_functions/binary_step.py @@ -1,8 +1,8 @@ """ This script demonstrates the implementation of the Binary Step function. -It's an activation function in which the neuron is activated if the input is positive or 0, -else it is deactivated +It's an activation function in which the neuron is activated if the input is positive +or 0, else it is deactivated It's a simple activation function which is mentioned in this wikipedia article: https://en.wikipedia.org/wiki/Activation_function