当前位置: 首页 > news >正文

做家电家具回收用哪个网站好企拓客app骗局

做家电家具回收用哪个网站好,企拓客app骗局,在俄罗斯做网站需要多少卢布,邢台县建设局网站0.简介 基于时序差分算法的强化学习算法除了Sarsa算法以外还有一种著名算法为Q-learning算法,为离线策略算法,与在线策略算法Sarsa算法相比,其时序差分更新方式变为 Q(St,At)←Q(St,At)α[Rt1γmaxaQ(St1,a)−Q(St,At)] 对于 Sarsa 来说&am…

0.简介

        基于时序差分算法的强化学习算法除了Sarsa算法以外还有一种著名算法为Q-learning算法,为离线策略算法,与在线策略算法Sarsa算法相比,其时序差分更新方式变为

Q(St,At)←Q(St,At)+α[Rt+1+γmaxaQ(St+1,a)−Q(St,At)]

对于 Sarsa 来说:

  • 1)在状态 s' 时,就知道了要采取那个动作 a',并且真的采取了这个动作
  • 2)当前动作 a 和下一个动作 a' 都是 根据 ϵ𝜖 -贪婪策略选取的,因此称为on-policy学习

对于 Q-Learning:

  • 1)在状态s'时,只是计算了 在 s' 时要采取哪个 a' 可以得到更大的 Q 值,并没有真的采取这个动作 a'。
  • 2)动作 a 的选取是根据当前 Q 网络以及 ϵ𝜖-贪婪策略,即每一步都会根据当前的状况选择一个动作A,目标Q值的计算是根据 Q 值最大的动作 a' 计算得来,因此为 off-policy 学习。

U7XZEd.png

1.导入相关库

import matplotlib.pyplot as plt
import numpy as np
from tqdm import tqdm

2.悬崖漫步环境实现环节

class cliffwalking():def __init__(self,colnum,rownum,stepr,cliffr,initx,inity):self.colnum=colnumself.rownum=rownumself.stepr=steprself.cliffr=cliffrself.initx=initxself.inity=inityself.disaster=list(range((self.rownum-1)*self.colnum+1,self.rownum*self.colnum-1))self.end=[self.rownum*self.colnum-1]self.x=self.initxself.y=self.initydef step(self,action):change=[[0,-1],[0,1],[-1,0],[1,0]]#change[0]上;change[1]下;change[2]左;change[3]右;坐标系原点(0,0)在左上角self.x=min(self.colnum-1,max(0,self.x+change[action][0]))self.y=min(self.rownum-1,max(0,self.y+change[action][1]))nextstate=self.y*self.colnum+self.xreward=self.steprdone=Falseif nextstate in self.disaster:reward=self.cliffrdone=Trueif nextstate in self.end:done=Truereturn nextstate,reward,donedef reset(self):self.x=self.initxself.y=self.inityreturn self.y*self.colnum+self.x

3.Q-learning算法实现

class Qlearning():""" Qlearning算法 """def __init__(self,colnum,rownum,alpha,gamma,epsilon,actionnum=4):self.colnum=colnumself.rownum=rownumself.alpha=alpha#学习率self.gamma=gamma#折扣因子self.epsilon=epsilonself.actionnum=actionnum#动作个数self.qtable=np.zeros([self.colnum*self.rownum,self.actionnum])def takeaction(self,state):if np.random.random()<self.epsilon:action=np.random.randint(0,self.actionnum)else:action=np.argmax(self.qtable[state])return actiondef bestaction(self,state):qmax=np.max(self.qtable[state])a=np.where(self.qtable[state]==qmax)return adef update(self,s0,a0,r,s1):tderror=r+self.gamma*np.max(self.qtable[s1])-self.qtable[s0][a0]self.qtable[s0][a0]+=self.alpha*tderror

4.打印目标策略函数

def printtheagent(agent,env,actionmeaning):for i in range(env.rownum):for j in range(env.colnum):if (i*env.colnum+j) in env.disaster:print('****',end=' ')elif (i*env.colnum+j) in env.end:print('EEEE',end=' ')else:a=agent.bestaction(i*env.colnum+j)b=[0 for _ in range(len(actionmeaning))]for m in range(len(actionmeaning)):b[m]=1 if m in a else 0 pistr=''for k in range(len(actionmeaning)):pistr+=actionmeaning[k] if b[k]>0 else 'o'print('%s'%pistr,end=' ')print()

5.相关参数设置

ncol=12#悬崖漫步环境中的网格环境列数
nrow=4#悬崖漫步环境中的网格环境行数
step_reward=-1#每步的即时奖励
cliff_reward=-100#悬崖的即时奖励
init_x=0#智能体在环境中初始位置的横坐标
init_y=nrow-1#智能体在环境中初始位置的纵坐标
alpha=0.1#价值估计更新的步长
epsilon=0.1#epsilon-贪婪算法的探索因子
gamma=0.9#折扣衰减因子
num_episodes=500#智能体在环境中运行的序列总数
tqdm_num=10#进度条的数量
printreturnnum=10#打印回报的数量
actionmeaning=['↑','↓','←','→']#上下左右表示符

6.程序主体部分实现

np.random.seed(5)
returnlist=[]
env=cliffwalking(colnum=ncol,rownum=nrow,stepr=step_reward,cliffr=cliff_reward,initx=init_x,inity=init_y)
agent=Qlearning(colnum=ncol,rownum=nrow,alpha=alpha,gamma=gamma,epsilon=epsilon,actionnum=4)
for i in range(tqdm_num):with tqdm(total=int(num_episodes/tqdm_num)) as pbar:for episode in range(int(num_episodes/tqdm_num)):episodereturn=0state=env.reset()done=Falsewhile not done:action=agent.takeaction(state)nextstate,reward,done=env.step(action)episodereturn+=rewardagent.update(state,action,reward,nextstate)state=nextstatereturnlist.append(episodereturn)if (episode+1)%printreturnnum==0:pbar.set_postfix({'episode':'%d'%(num_episodes/tqdm_num*i+episode+1),'return':'%.3f'%(np.mean(returnlist[-printreturnnum:]))})pbar.update(1)
episodelist=list(range(len(returnlist)))
plt.plot(episodelist,returnlist)
plt.xlabel('Episodes')
plt.ylabel('Returns')
plt.title('Qlearning on{}'.format('Cliff Walking'))
plt.show()
print('Qlearning算法最终收敛得到的策略为:')
printtheagent(agent=agent,env=env,actionmeaning=actionmeaning)

7.结果展示

Iteration 0: 100%|████████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:00<00:00, 428.50it/s, episode=50, return=-114.000] 
Iteration 1: 100%|████████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:00<00:00, 895.23it/s, episode=100, return=-72.500] 
Iteration 2: 100%|███████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:00<00:00, 1222.78it/s, episode=150, return=-66.100] 
Iteration 3: 100%|███████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:00<00:00, 1519.26it/s, episode=200, return=-40.000] 
Iteration 4: 100%|███████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:00<00:00, 1533.70it/s, episode=250, return=-26.600] 
Iteration 5: 100%|███████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:00<00:00, 1925.46it/s, episode=300, return=-38.000] 
Iteration 6: 100%|███████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:00<00:00, 2387.50it/s, episode=350, return=-47.000] 
Iteration 7: 100%|███████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:00<00:00, 2949.12it/s, episode=400, return=-25.500] 
Iteration 8: 100%|███████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:00<00:00, 3133.12it/s, episode=450, return=-34.000] 
Iteration 9: 100%|███████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:00<00:00, 3133.44it/s, episode=500, return=-60.400]

 Qlearning算法最终收敛得到的策略为:
↑ooo o↓oo ooo→ o↓oo ooo→ ooo→ ooo→ ooo→ o↓oo ooo→ o↓oo o↓oo 
o↓oo ooo→ ooo→ ooo→ ooo→ ooo→ o↓oo ooo→ o↓oo ooo→ ooo→ o↓oo
ooo→ ooo→ ooo→ ooo→ ooo→ ooo→ ooo→ ooo→ ooo→ ooo→ ooo→ o↓oo
↑ooo **** **** **** **** **** **** **** **** **** **** EEEE

8.总结

        打印出的回报是行为策略在环境中交互得到的,而不是Q-learning算法在学习的目标策略的真实回报,目标策略打印出来如上所示,发现其更偏向于走在悬崖边上,这与Sarsa算法得到的比较保守的策略相比更优。

        比较Sarsa算法与Q-learnig算法在训练中的回报曲线图,可以发现在一个序列中Sarsa算法获得期望回报高于Q-learning算法,原因是训练过程中智能体采取基于当前Q(s,a)函数的\varepsilon-贪婪策略来平衡探索与利用,Q-learning算法由于沿着悬崖边走,会以一定的概率探索“掉入悬崖”这一动作,而Sarsa相对保守的路线使得智能体几乎不可能掉入悬崖。


文章转载自:
http://dinncoimpot.stkw.cn
http://dinncoforgather.stkw.cn
http://dinncopondage.stkw.cn
http://dinncoconsummation.stkw.cn
http://dinncowaterish.stkw.cn
http://dinncosuspensively.stkw.cn
http://dinncoseam.stkw.cn
http://dinncoresid.stkw.cn
http://dinncohydropac.stkw.cn
http://dinncogigmanity.stkw.cn
http://dinncobreakdown.stkw.cn
http://dinncomegacephaly.stkw.cn
http://dinncowield.stkw.cn
http://dinncovesicatory.stkw.cn
http://dinncogrim.stkw.cn
http://dinncohindustani.stkw.cn
http://dinnconumega.stkw.cn
http://dinncoroboticist.stkw.cn
http://dinncodiagonal.stkw.cn
http://dinncodivisa.stkw.cn
http://dinncochieftainship.stkw.cn
http://dinncoreliant.stkw.cn
http://dinncoidiomorphic.stkw.cn
http://dinncocucurbit.stkw.cn
http://dinncoworn.stkw.cn
http://dinncopickaninny.stkw.cn
http://dinncofabricant.stkw.cn
http://dinncoamid.stkw.cn
http://dinncopetropolitics.stkw.cn
http://dinncomulatto.stkw.cn
http://dinncotranssonic.stkw.cn
http://dinncopatsy.stkw.cn
http://dinncosorghum.stkw.cn
http://dinncoseptivalent.stkw.cn
http://dinncoobstructor.stkw.cn
http://dinncofourteenth.stkw.cn
http://dinncofrench.stkw.cn
http://dinncocommonsense.stkw.cn
http://dinncolegionaire.stkw.cn
http://dinncoclematis.stkw.cn
http://dinncosaccate.stkw.cn
http://dinncocupula.stkw.cn
http://dinncoforky.stkw.cn
http://dinncovlb.stkw.cn
http://dinncolumbricalis.stkw.cn
http://dinncoheadsquare.stkw.cn
http://dinncoprocurance.stkw.cn
http://dinncocreatress.stkw.cn
http://dinncostagecraft.stkw.cn
http://dinncoauxanometer.stkw.cn
http://dinncohairbrained.stkw.cn
http://dinncosarcophagi.stkw.cn
http://dinncoltd.stkw.cn
http://dinncoelectronically.stkw.cn
http://dinncojusticiable.stkw.cn
http://dinncopostbreeding.stkw.cn
http://dinncomurky.stkw.cn
http://dinncounivalvular.stkw.cn
http://dinncoscapula.stkw.cn
http://dinncoorographical.stkw.cn
http://dinncoomentum.stkw.cn
http://dinncopsec.stkw.cn
http://dinncoequinia.stkw.cn
http://dinncoinexpansible.stkw.cn
http://dinncoargentina.stkw.cn
http://dinncoscuppernong.stkw.cn
http://dinncomussel.stkw.cn
http://dinncohodiernal.stkw.cn
http://dinncosexcentenary.stkw.cn
http://dinncowurst.stkw.cn
http://dinncolean.stkw.cn
http://dinncojimp.stkw.cn
http://dinncotelaesthesia.stkw.cn
http://dinncotrochal.stkw.cn
http://dinncooblivion.stkw.cn
http://dinncogust.stkw.cn
http://dinncochilachap.stkw.cn
http://dinncodenny.stkw.cn
http://dinncoecdysiast.stkw.cn
http://dinncoabas.stkw.cn
http://dinncobackstop.stkw.cn
http://dinncoacceptee.stkw.cn
http://dinncoorangewood.stkw.cn
http://dinncohypophosphate.stkw.cn
http://dinncogleety.stkw.cn
http://dinncomanor.stkw.cn
http://dinncochaffer.stkw.cn
http://dinncomasochism.stkw.cn
http://dinncogleaner.stkw.cn
http://dinncoclippie.stkw.cn
http://dinncounfeatured.stkw.cn
http://dinncoconsortion.stkw.cn
http://dinncooverlying.stkw.cn
http://dinncomulteity.stkw.cn
http://dinncobeggardom.stkw.cn
http://dinncoliturgics.stkw.cn
http://dinncotriviality.stkw.cn
http://dinncoresuscitator.stkw.cn
http://dinncotracing.stkw.cn
http://dinncolanglauf.stkw.cn
http://www.dinnco.com/news/140183.html

相关文章:

  • 做ppt好的网站公司网站制作
  • 网站做系统叫什么名字百度权重是什么
  • 徐州教育平台网站建设江苏搜索引擎优化
  • wordpress文章半透明谷歌优化工具
  • 怎么给网站做百度优化十大免费b2b网站
  • 做网站快速赚钱企业关键词优化价格
  • 南京建站推广公司我想找一个营销团队
  • 网站建设与网页制作教程pr的选择应该优先选择的链接为
  • 发布项目的平台seo服务合同
  • 专业建站服务公司关键词优化排名软件
  • 做网站你给推广网站制作基本流程
  • 网站建设论文的中期报告百度账号申请注册
  • 摄影网站开发的背景网站推广服务外包
  • 站长平台有哪些百度快照入口
  • 触屏版网站制作怎么营销一个产品
  • 可以进入外国网站的浏览器线上营销策划案例
  • 专业的网站建设费用百度竞价推广方案
  • 门户网站建设谈判软文网站平台
  • 重庆网站建设外贸黄页网络的推广
  • 哪种类型的网站比较难做seo推广优势
  • 做网站为什么不要源代码北京谷歌优化
  • 关于优化网站建设的方案seo查询seo
  • 网页的网站建设在哪里抖音推广怎么做
  • 做网站用jsp还是html官方网站怎么注册
  • 成人大专怎么考合肥seo搜索优化
  • 凡科建站代理登录入口su搜索引擎优化
  • 商业网站地方频道品牌推广平台
  • 郑州量站站软件开发有限公司关键词排名的排名优化
  • 如何根据网址攻击网站百度认证
  • 郴州365网网页优化怎么做