莫烦Python RL 代码阅读一
算法分析
不分析如何实现 environment
def build_q_table(n_states, actions)
def build_q_table(n_states, actions):
table = pd.DataFrame(
np.zeros((n_states, len(actions))), # q_table initial values
columns=actions, # actions's name
)
# print(table) # show table
return table
pd.DataFrame()
np.zeros(a,b)
在下方版块有整理
此函数用于构建n行,len(actions)列的Q-table,算是典型的表格型方法
def choose_action(state, q_table)
def choose_action(state, q_table):
# This is how to choose an action
state_actions = q_table.iloc[state, :]
if (np.random.uniform() > EPSILON) or ((state_actions == 0).all()): # act non-greedy or state-action have no value
action_name = np.random.choice(ACTIONS)
else: # act greedy
action_name = state_action