我正在脑筋急转,想出如何使用Sigmoid在自定义范围内缩放变量,然后反转该缩放比例。
例如,下面的Python脚本将变量x缩放到0到top之间,然后反转该缩放比例。
import math
# apply Sigmoid to x on scale between 0 and top:
def sigmoid(x, top):
y = top / (1 + math.exp(-x))
return y
# and to inverse:
def invSigmoid(y, top):
x = np.log(y/(top-y))
return x
我想做的是也设置底部,以便x在底部-顶部之间缩放,例如(10-100)。然后还要求逆。
答案 0 :(得分:1)
在我看来,您追求的是:
y = bottom + (top - bottom) / (1 + math.exp(-x))
和
x = np.log((y - bottom) / (top - y))