我创建了这个 Python 函数来生成一个 sigmoid 函数,我可以在其中修改位置和宽度:
import numpy as np
import matplotlib.pyplot as plt
def sigmoid(x,a,b):
# sigmoid function with parameters a = center; b = width
return 1/(1+np.exp(-(x-a)/b))
例如更改参数 b 我可以使其更宽或更窄:
# testing changing sigmoid width (and slope at the same time) - parameter b
x = np.linspace(0,10,256)
y = sigmoid(x,5,1) # default
ymax = sigmoid(x,5,1.75)
ymin = sigmoid(x,5,0.25)
# Create the plot
plt.plot(x,y,lw=2,color='black')
plt.plot(x,ymax,lw=2,color='green')
plt.plot(x,ymin,lw=2,color='orange')
以上是相当简单的。
但是如果我想要一个旋转的 sigmoid 函数呢?我在下图中“以图形方式”模拟了我的预期结果:
我通过创建一个新的自变量 x(下面的“测试”变量)并交换 x 和 y 来绘制它:
test=np.linspace(0,1,128)
plt.plot(y2*255,test,lw=2,color='yellow')
有没有办法用一个新的类似 sigmoid 的函数来实现这个形状,或者旋转原来的?
我突然想到我可以使用类似的东西,-np.sinh(x)
但我真正想要的是有一个类似的指数表达式,带有参数 a 和 b 来控制曲线的形状。
这个问题也发布在 Stack Overflow https://stackoverflow.com/questions/25851287/how-to-generate-a-rotated-by-90-degrees-logistic-sigmoid-function-in-python