Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kaedonkers/71b3b9dfe9f214a108ada38d4b5c5fd6 to your computer and use it in GitHub Desktop.
Save kaedonkers/71b3b9dfe9f214a108ada38d4b5c5fd6 to your computer and use it in GitHub Desktop.
Reverse piecewise linear sigmoid function
import numpy as np
def reverse_piecewise_linear_sigmoid(self, x, upper, lower):
'''
Reverse piecewise linear sigmoid function to filter a value between two thresholds in a vectorised manner according to:
if x <= lower:
y = 1
else:
y = (upper-x)/(upper-lower)
if x > upper:
y = 0
1 ----------
\
\
\
\
\
0 ----------
Parameters
----------
x : float
Value to be filtered
upper : float
Upper bound of the sigmoid
lower : float
Lower bound of the sigmoid
Returns
-------
y : float
Filtered value
'''
y = np.maximum(np.minimum((upper-x)/(upper-lower), 1.0), 0.0)
return y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment