Actor-critic算法

Actor-critic算法,第1张

Actor-critic算法 Actor-critic算法



import random
import matplotlib.pyplot as plt
x=[]
y=[]
def random_pick(some_list, probabilities): 
        random_num = random.uniform(0,1) 
        cumulative_probability = 0.0 
        for item, item_probability in zip(some_list, probabilities):   #遍历
            cumulative_probability += item_probability 
            if random_num < cumulative_probability:
                break 
        return item
probabilities=[0.5,0.5]

some_list=[1.02,1.74]
sum1=sum2=k=0

for i in range(10000):
    
    a=random_pick(some_list,probabilities)
    k+=1
    b=some_list.index(a)
    if b==0:
        sum1+=a
    else:
        sum2+=a
      
    if i%10==0:
        probabilities[0]+=0.01*sum1
        probabilities[1]+=0.01*sum2
        probabilities[0]=probabilities[0]/sum(probabilities)
        probabilities[1]=probabilities[1]/sum(probabilities)
        print(sum1,sum2)
        sum1=sum2=0
        #print(probabilities)
          
    y.append(probabilities[0])
    x.append(i)
print(probabilities)
plt.plot(x,y,color='g',linestyle='-')

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5592995.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存