Python/neural_network/activation_functions/binary_step.py
pre-commit-ci[bot] bc8df6de31
[pre-commit.ci] pre-commit autoupdate (#11322)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.2.2 → v0.3.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.2.2...v0.3.2)
- [github.com/pre-commit/mirrors-mypy: v1.8.0 → v1.9.0](https://github.com/pre-commit/mirrors-mypy/compare/v1.8.0...v1.9.0)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-03-13 07:52:41 +01:00

36 lines
857 B
Python

"""
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 a simple activation function which is mentioned in this wikipedia article:
https://en.wikipedia.org/wiki/Activation_function
"""
import numpy as np
def binary_step(vector: np.ndarray) -> np.ndarray:
"""
Implements the binary step function
Parameters:
vector (ndarray): A vector that consists of numeric values
Returns:
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, 1, 1, 1, 0, 1])
"""
return np.where(vector >= 0, 1, 0)
if __name__ == "__main__":
import doctest
doctest.testmod()