ich Grenzen auf einige der Parameter während der Kurvenanpassung, aber ich erhalte die folgende Fehlermeldung anzuwenden versuchen, wenn ich dies zu tun versucht:Grenzen zu bestimmten Variablen während curve_fit (scipy) Anwendung führt zu einem Fehler
Valueerror: zu viele Werte auszuzupacken
nicht jeder 2-Tupels in dem gebundenen Befehl entspricht x0, k, Verstreichen, nehmen in der sigmoidscaled Funktion in meinem Fall bzw. (Ie entsprechend auch zu p0). ?
Ich habe dann versucht, die herum spielen, in der Hoffnung, um herauszufinden, wie es funktioniert, indem das gebundene Befehl an die folgende Verringerung der ‚zu viele Werte‘ zu befreien:
bounds=((-np.inf,np.inf), (0,1))
Dann erhalte ich die Fehlermeldung :
ValueError: Inkonsistente Formen zwischen Grenzen und x0
.
Was bekomme ich hier falsch?
import pylab
from scipy.optimize import curve_fit
from matplotlib.pyplot import *
n = 20 #20 trials
ydata = [0/n, 9.0/n, 9.0/n, 14.0/n, 17.0/n] #Divided by n to fit to a plot of y =1
xdata = np.array([ 1.0, 2.0, 3.0, 4.0, 5.0])
#The scaled sigmoid function
def sigmoidscaled(x, x0, k, lapse, guess):
F = (1 + np.exp(-k*(x-x0)))
z = guess + (1-guess-lapse)/F
return z
p0=[1,1,0,0]
popt, pcov = curve_fit(sigmoidscaled, xdata, ydata, p0, bounds=((-np.inf,np.inf), (-np.inf,np.inf), (0,1), (0,1))
#Start and End of x-axis, in spaces of n. The higher the n, the smoother the curve.
x = np.linspace(1,5,20)
#The sigmoid values along the y-axis, generated in relation to the x values and the 50% point.
y = sigmoidscaled(x, *popt)
pylab.plot(xdata, ydata, 'o', label='Psychometric Raw', color = 'blue')
pylab.plot(x,y, label='Psychometric Fit', color = 'blue')
#y axis range.
pylab.ylim(0, 1)
#Replace x-axis numbers as labels and y-axis numbers as percentage
xticks([1., 2., 3., 4., 5.], ['C1','CN2','N3','CN4','S5'])
yticks([0.0, 0.2, 0.4, 0.6, 0.8, 1.0], ['0%','20%','40%','60%','80%','100%'])
pylab.legend(loc='best')
xlabel('Conditions')
ylabel('% perceived more sin like')
pylab.show()