Ich weiß, dass es auf dieser Seite viele ähnliche Probleme gibt, aber leider konnte ich meine eigene mit der vorhandenen Antwort nicht beheben .. Ich hoffe es macht Ihnen nichts aus mir zu helfen. Ich habe einen Code und versuche, Werte an eine Liste anzuhängen, während ich durch den Code iteriere. Allerdings läuft dabei etwas schief und ich habe den Wert 0. Ich bin noch nicht sehr gut im Debuggen, also kann ich das Problem nicht finden. Ich habe eine einfachere Version des Codes mit weniger Variablen unter:Code iteriert nicht richtig
`import math
from pylab import *
import numpy as np
#---------------------------INITIALIZATION-----------------------
#initializing the parameters of the model
Dt = 1
time_step = 50
#initializing the connection weights
w1 = 1
#initializing parameter values for the alogistic function
steepness_SS_a=1
speed_SS_a=1
threshold_SS_a=1
#--------------------THE FUNCTIONS---------------------------
def initialize():
global t, timesteps, WS_a, SS_a, new_WS_a, new_SS_a
#initialize model states
WS_a=1
SS_a=0
# initialize lists to update all states
new_SS_a=np.array([SS_a])
#initializing time list
t=0.
timesteps=[t]
def observe():
global t, timesteps, WS_a, SS_a, new_WS_a, new_SS_a
np.append(SS_a, new_SS_a)
timesteps.append(t)
def update():
global t, timesteps, WS_a, SS_a, new_WS_a, new_SS_a
# for each state activation value, write how to update it in the form of new_WS(a)=function(WS(a))
SS_a = SS_a + speed_SS_a * (((1/(1+math.exp(-steepness_SS_a * (w1 * WS_a - threshold_SS_a))))-(1/(1+math.exp(steepness_SS_a *threshold_SS_a))))* (1+math.exp(-steepness_SS_a*threshold_SS_a))-SS_a)
# for each state activation value now move the state value to new value
SS_a=new_SS_a
#updating the timestep
t = t + Dt
#--------------------THE PROGRAM-----------------
initialize()
while t<30.:
update()
observe()
#--------------------PLOTTING--------------------
print SS_a
plot(new_SS_a)
show()`
und welches Ergebnis haben Sie erwartet? – Copperfield
Ich benutze eine logistische Funktion, die den vorherigen Wert eines Zustands und andere Parameter enthält, um es Schritt für Schritt erhöhen zu lassen –
mmm, probiere 'timesteps' statt – Copperfield