Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified Linear Regression to work on OLS, fixes #8847 #11311

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions neural_network/activation_functions/bipolar_binary_step.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
This script demonstrates the implementation of the Bipolar Binary Step function.

It's an activation function in which the neuron outputs 1 if the input is positive
or 0, else outputs -1 if the input is negative.

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 bipolar_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])
>>> bipolar_binary_step(vector) # doctest: +NORMALIZE_WHITESPACE
array([-1, 1, 1, 1, -1, 1])
"""

return np.where(vector >= 0, 1, -1)


if __name__ == "__main__":
import doctest

doctest.testmod()