Ошибка типа: объект 'NoneType' не повторяется. Начинающий 2 - PullRequest
0 голосов
/ 20 мая 2018

У меня есть код и сообщение об ошибке, говорящее [Q_table, pre_s, pre_a, s, a]= select_action(x,x_dot,theta,theta_dot,R, Q_table, pre_s, s, pre_a, a, alpha, beta, gamma) TypeError: ' NoneType ' объект не повторяется

В основном я пытаюсь вызвать эту функцию где-то еще: в моем предыдущемПосле того, как у меня возникла похожая проблема с другим кодом, моей ошибкой было пропущенное выражение return, но теперь у меня есть возвращающиеся государственные деятели, так что я не могу понять проблему.Помогите мне, пожалуйста.Спасибо, ребята:)

[Q_table, pre_s, pre_a, s, a]= select_action(x,x_dot,theta,theta_dot,R, Q_table, pre_s, s, pre_a, a, alpha, beta, gamma)


def select_action(x,x_dot,theta,theta_dot,R,Q_table,pre_s,s,pre_a,a,alpha,beta,gamma):
pre_s = s
pre_a = a
s = select_box(x, x_dot, theta, theta_dot)


if (pre_a != -1):    # Update Q value. If previous action been taken
   if (s == -1):        # Current state is failed
      predicted_value = 0        # fail state's value is zero
   elif (Q_table[s, 0] <= Q_table[s, 1]):        # Left Q<= Right Q
        predicted_value = Q_table[s, 1]        #  set Q to bigger one
   else:
        predicted_value = Q_table[s, 1]

        Q_table[pre_s, pre_a] = Q_table[pre_s, pre_a] + alpha * (R + gamma * predicted_value - Q_table[pre_s, pre_a])

       # Determine best action
b=beta*random()
if ((Q_table[s, 0] + b <= Q_table[s, 1]).all()):
    a = 2            # push right
else:
    a = 1
    return [Q_table, pre_s, pre_a, s, a]

1 Ответ

0 голосов
/ 20 мая 2018

Очистить от двух 's'.

[Q_table, pre_s, pre_a, s, a]= select_action(x,x_dot,theta,theta_dot,R, Q_table, pre_s, s, pre_a, a, alpha, beta, gamma)


def select_action(x,x_dot,theta,theta_dot,R,Q_table,pre_s,s,pre_a,a,alpha,beta,gamma):
    pre_s = s
    pre_a = a
    s_another = select_box(x, x_dot, theta, theta_dot)


    if (pre_a != -1):    # Update Q value. If previous action been taken
       if (s_another == -1):        # Current state is failed
          predicted_value = 0        # fail state's value is zero
       else:
          if (Q_table[s_another, 0] <= Q_table[s_another, 1]):        # Left Q<= Right Q
            predicted_value = Q_table[s_another, 1]        #  set Q to bigger one
          else:
            predicted_value = Q_table[s_another, 0]

            Q_table[pre_s, pre_a] = Q_table[pre_s, pre_a] + alpha * (R + gamma * predicted_value - Q_table[pre_s, pre_a])

        # Determine best action
        b=beta*random()
        if ((Q_table[s_another, 0] + b <= Q_table[s_another, 1]).all()):
            a = 2            # push right
        else:
            a = 1
    return [Q_table, pre_s, pre_a, s_another, a]
...