资源简介
Sutton课本中的小车爬山例程,强化学习中的基本仿真实验程序。

代码片段和文件信息
/*
This is an example program for reinforcement learning with linear
function approximation. The code follows the psuedo-code for linear
gradient-descent Sarsa(lambda) given in Figure 8.8 of the book
“Reinforcement Learning: An Introduction“ by Sutton and Barto.
One difference is that we use the implementation trick mentioned on
page 189 to only keep track of the traces that are larger
than “min-trace“.
Before running the program you need to obtain the tile-coding
software available at http://envy.cs.umass.edu/~rich/tiles.C and tiles.h
(see http://envy.cs.umass.edu/~rich/tiles.html for documentation).
The code below is in three main parts: 1) Mountain Car code 2) General
RL code and 3) top-level code and misc.
Written by Rich Sutton 12/19/00
*/
#include
#include “tiles.h“
#include “stdio.h“
#include “stdlib.h“
#include
#include
#include
////////// Part 1: Mountain Car code //////////////
// Global variables:
float mcar_position mcar_velocity; //位置和速度值
#define mcar_min_position -1.2
#define mcar_max_position 0.6
#define mcar_max_velocity 0.07 // the negative of this in the minimum velocity
#define mcar_goal_position 0.5
#define POS_WIDTH (1.7 / 8) // the tile width for position
#define VEL_WIDTH (0.14 / 8) // the tile width for velocity
// Profiles
void MCarInit(); // initialize car state
void MCarStep(int a); // update car state for given action
bool MCarAtGoal (); // is car at goal?
void MCarInit()
// Initialize state of Car
{ mcar_position = -0.5;
mcar_velocity = 0.0;}
void MCarStep(int a)
// Take action a update state of car
{ mcar_velocity += (a-1)*0.001 + cos(3*mcar_position)*(-0.0025);
if (mcar_velocity > mcar_max_velocity) mcar_velocity = mcar_max_velocity;
if (mcar_velocity < -mcar_max_velocity) mcar_velocity = -mcar_max_velocity;
mcar_position += mcar_velocity;
if (mcar_position > mcar_max_position) mcar_position = mcar_max_position;
if (mcar_position < mcar_min_position) mcar_position = mcar_min_position;
if (mcar_position==mcar_min_position && mcar_velocity<0) mcar_velocity = 0;}
bool MCarAtGoal ()
// Is Car within goal region?
{ return mcar_position >= mcar_goal_position;}
////////// Part 2: Semi-General RL code //////////////
#define MEMORY_SIZE 10000 // number of parameters to theta memory size
#define NUM_ACTIONS 3 // number of actions
#define NUM_TILINGS 10
// Global RL variables:
float Q[NUM_ACTIONS]; // action values
float theta[MEMORY_SIZE]; // modifyable parameter vector aka memory weights
float e[MEMORY_SIZE]; // eligibility traces 资格轨迹
int F[NUM_ACTIONS][NUM_TILINGS];
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 13541 2015-08-24 10:28 mountaincar1.cpp
文件 4306 2015-08-24 10:29 tiles.C
文件 339 2015-08-20 09:42 tiles.h
----------- --------- ---------- ----- ----
18186 3
相关资源
- VisualStudioUninstaller vs卸载工具
- 组态王驱动开发包3.0.0.7(中文)
- 多窗口后台鼠标连点器
- 使用选择性重传协议实现UDP可靠通信
- VC 获得文件属性 获取文件的创建时
- 读者写者问题(读者优先,写者优先
- 用VC 编写的仿QQ聊天室程序源代码
- 外点法程序
- 外罚函数程序
- qt-电子点菜系统
- 推箱子及人工智能寻路C 源代码
- 自己写的航空订票系统c 版--数据结构
- 数据结构实验魔王语言
- MUSIC算法c 实现
- C 餐厅叫号系统(QT平)
- 国际象棋c 完整版
-
ob
jectARX给Auto CAD加工具条 - 画图程序MFC/VC/VC CRectTracker 串行化
- MFC网络编程实例
- c 课程设计 职工信息管理系统
- VC 游戏编程—附源代码
- IpHlpApi.h&IpHlpApi.lib
- 清华大学 c 郑莉 ppt课件
- c 程序判断离散数学中命题公式
- 多项式求和(数据结构C 版)
- vc 6.0开发的流程图编辑器
- VC 天空盒(skyBox)实现(附源代码)
- c MFC 画多边形
- 用C 实现的对网络上的ARP数据包进行
- Microsoft基本类库 (MFC)(C 库)
评论
共有 条评论