Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions neural_network/activation_functions/mish.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Mish Activation Function

Use Case: Improved version of the ReLU activation function used in Computer Vision.
For more detailed information, you can refer to the following link:
https://en.wikipedia.org/wiki/Rectifier_(neural_networks)#Mish
"""

import numpy as np


def mish(vector: np.ndarray) -> np.ndarray:
"""
Implements the Mish activation function.

Parameters:
vector (np.ndarray): The input array for Mish activation.

Returns:
np.ndarray: The input array after applying the Mish activation.

Formula:
f(x) = x * tanh(softplus(x)) = x * tanh(ln(1 + e^x))

Examples:
>>> mish(vector=np.array([2.3,0.6,-2,-3.8]))
array([ 2.26211893, 0.46613649, -0.25250148, -0.08405831])

>>> mish(np.array([-9.2, -0.3, 0.45, -4.56]))
array([-0.00092952, -0.15113318, 0.33152014, -0.04745745])

"""
return vector * np.tanh(np.log(1 + np.exp(vector)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, but it'd be nice to implement this using the softplus function—once we have an implementation of softplus in this repo.



if __name__ == "__main__":
import doctest

doctest.testmod()