Created
June 1, 2022 12:27
-
-
Save kaedonkers/71b3b9dfe9f214a108ada38d4b5c5fd6 to your computer and use it in GitHub Desktop.
Reverse piecewise linear sigmoid function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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