Example 3.8:Gridworld

这是一个使用C++实现的Gridworld强化学习模型,通过迭代更新每个格子的价值。模型设置了四个可能的动作(上、下、左、右),并在特定状态(State A 和 State B)给出了奖励值。模拟使用了折扣因子Gamma,并在每次迭代中更新价值网格。
摘要由CSDN通过智能技术生成
#include "iostream"
using namespace std;

const int GridCnt = 5;
const int MaxIterations = 1000;

int main()
{
   int    IterationCnt = 0;
	double Gamma = 0.9;
	double SelectProbability = 0.25;
	double TemporaryValue = 0.0;

	double OldValueGrid[GridCnt][GridCnt];
	double NewValueGrid[GridCnt][GridCnt];
	memset(OldValueGrid, 0, sizeof(double) * GridCnt * GridCnt);
	memset(NewValueGrid, 0, sizeof(double) * GridCnt * GridCnt);

   int a[20];
   memset(a, 10, sizeof(int));

	while (IterationCnt <= MaxIterations)
	{ 
	   for (int Row = 0; Row < GridCnt; Row++)
		{
			for (int  Column = 0;  Column < GridCnt;  Column++)
			{
				TemporaryValue = 0.0;

				//action = UP
				if (Row == 0)
					TemporaryValue = TemporaryValue + SelectProbability * (-1 + Gamma * OldValueGrid[Row][Column]);
				else                      
					TemporaryValue = TemporaryValue + S
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值