Skip to content

Commit 5de5b80

Browse files
added bipolar binary function
1 parent c6ca194 commit 5de5b80

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
This script demonstrates the implementation of the Bipolar Binary Step function.
3+
4+
It's an activation function in which the neuron outputs 1 if the input is positive
5+
or 0, else outputs -1 if the input is negative.
6+
7+
It's a simple activation function which is mentioned in this wikipedia article:
8+
https://en.wikipedia.org/wiki/Activation_function
9+
"""
10+
11+
import numpy as np
12+
13+
def bipolar_binary_step(vector: np.ndarray) -> np.ndarray:
14+
"""
15+
Implements the binary step function
16+
17+
Parameters:
18+
vector (ndarray): A vector that consists of numeric values
19+
20+
Returns:
21+
vector (ndarray): Input vector after applying binary step function
22+
23+
>>> vector = np.array([-1.2, 0, 2, 1.45, -3.7, 0.3])
24+
>>> bipolar_binary_step(vector) # doctest: +NORMALIZE_WHITESPACE
25+
array([-1, 1, 1, 1, -1, 1])
26+
"""
27+
28+
return np.where(vector >= 0, 1, -1)
29+
30+
31+
if __name__ == "__main__":
32+
import doctest
33+
34+
doctest.testmod()

0 commit comments

Comments
 (0)