如何解决类型错误:QAgent() 不接受任何参数
我是强化学习的新手,我正在尝试编写代码来使用 Q 学习算法计算两个位置之间的距离。
每次我尝试使用片段 qagent=QAgent(alpha,gamma,location_to_state,actions,reward,state_to_location) 调用类 QAgent() 时 qagent.training('L9','l1',1000) 我收到一个错误类型错误:QAgent() 没有参数,请帮助
class QAgent():
def _init_(self,alpha,rewards,state_to_location):
self.gamma=gamma
self.alpha=alpha
self.location_to_state=location_to_state
self.actions=actions
self.rewards=rewards
self.state_to_location=state_to_location
M=len(location_to_state)
self.Q=np.zeros((M,M),dtype=None,order='C')
def training(self,start_location,end_location,iterations):
rewards_new=np.copy(self.rewards)
ending_state=self.location_to_state[end_location]
rewards_new[ending_state,ending_state]=999
for i in range(iterations):
current_state=np.random.randint(0,9)
playable_actions=[]
for j in range(9):
if rewards_new[current_state,j]>0:
playable_actions.append(j)
next_state=np.random.choice(playable_actions)
TD=rewards_new[current_state,next_state]+self.gamma*self.Q[next_state,np.argmax(self.Q[next_state,])]-self.Q[current_state]
self.Q[current_state,next_state]+=self.alpha*TD
route=[start_location]
next_location=start_location
self.get_optimal_route(start_location,next_location,route,self.Q)
def get_optimal_route(self,Q):
while(next_location!=end_location):
starting_state=self.location_to_state[start_location]
next_state=np.argmax(Q[starting_state,])
next_location=self.state_to_location[next_state]
route.append(next_location)
start_location=next_location
print(route)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。