SpinningUp Part 1: Key Concepts in RL 笔记

这是一篇关于OpenAI的强化学习课程(RL)的翻译和笔记 个人学习使用。

原文链接Part 1: Key Concepts in RL — Spinning Up documentation

简单记录一些笔记 并且用斜体字补充了来自chatgpt的注解(正确性注意甄别)

这章讲什么?

1.常用表达

2.概括解释RL算法做什么

3.一点关于算法的数学

概括的讲,强化学习研究agents以及它们如何在尝试和犯错中学习。

使用的理念是通过奖励或惩罚代理所做的行为来让它在未来更容易去重复或者忘记这些行为。

Tips:

在强化学习中,"agent"(代理,智能体)是指执行学习和决策的实体或系统。它是强化学习问题中的主体,负责与环境进行交互,并根据所选择的动作和环境提供的反馈来学习最佳的策略。代理根据当前的状态观察(observation)和奖励信号(reward signal)来选择动作,其目标通常是最大化长期累积奖励。

代理可以是物理机器人、虚拟智能体、计算机程序或任何可以感知环境并执行动作的系统。在强化学习中,代理通常基于某种学习算法来决定动作,这些算法可以是基于价值函数、策略函数或是两者结合的方法。代理的性能通常通过其在与环境交互的过程中获得的奖励来评估。

泛化能力强  无需建模

强化学习的主要部分包括agent和environment

The main characters of RL are the agent and the environment. The environment is the world that the agent lives in and interacts with.

 At every step of interaction, the agent sees a (possibly partial) observation of the state of the world, and then decides on an action to take.

The environment changes when the agent acts on it, but may also change on its own.

The agent also perceives a reward signal from the environment, a number that tells it how good or bad the current world state is. The goal of the agent is to maximize its cumulative reward, called return. Reinforcement learning methods are ways that the agent can learn behaviors to achieve its goal.

To talk more specifically what RL does, we need to introduce additional terminology. We need to talk about

  • states and observations,
  • action spaces,
  • policies,
  • trajectories,
  • different formulations of return,
  • the RL optimization problem,
  • and value functions.

States and Observations

state is a complete description of the state of the world. There is no information about the world which is hidden from the state. An observation is a partial description of a state, which may omit information.

The action is conditioned on the observation because the agent does not have access to the state

Action Spaces

Different environments allow different kinds of actions. The set of all valid actions in a given environment is often called the action space. Some environments, like Atari and Go, have discrete action spaces, where only a finite number of moves are available to the agent. Other environments, like where the agent controls a robot in a physical world,

have continuous action spaces. In continuous spaces, actions are real-valued vectors.

Policies

policy is a rule used by an agent to decide what actions to take. It can be deterministic, in which case it is usually denoted by 

or it may be stochastic, in which case it is usually denoted by pi:

Because the policy is essentially the agent’s brain, it’s not uncommon to substitute the word “policy” for “agent”, eg saying “The policy is trying to maximize reward.”

Deterministic Policies确定性策略
Stochastic Policies随机策略

The two most common kinds of stochastic policies in deep RL are categorical policies and diagonal Gaussian policies.Categorical policies can be used in discrete action spaces, while diagonal Gaussian policies are used in continuous action spaces.

两个关键计算对于使用和训练随机策略至关重要:

从策略中采样动作,

  • sampling actions from the policy,

以及计算特定动作的对数似然性

  • and computing log likelihoods of particular actions 

在下面的内容中,我们将描述如何对分类和对角高斯策略进行这些操作。

在使用和训练随机策略时,有两个关键的计算非常重要:

  1. 从策略中抽样动作:在强化学习中,策略是代理根据当前状态选择动作的规则。对于随机策略而言,通常是基于概率分布进行动作选择的。因此,在使用随机策略时,我们需要从策略的概率分布中进行抽样,以确定在给定状态下应该采取哪些动作。这个抽样过程是通过随机性来实现的,因此需要确保从策略中抽样的动作具有一定的探索性,以便探索不同的动作空间。

  2. 计算特定动作的对数似然值 \log \pi_{\theta}(a|s):对于确定性策略而言,给定状态,策略会直接输出相应的动作。但对于随机策略,策略通常会输出一个动作的概率分布,而不是确定性的动作。因此,在训练过程中,我们需要计算给定状态下每个动作的对数似然值,即根据策略的参数 \theta 计算在给定状态 s 下选择动作 a 的概率的对数值。这个对数似然值通常被用来构建强化学习算法的损失函数,以便优化策略参数,使得在给定状态下选择高概率动作的概率增大,从而提高整体性能。

综上所述,随机策略的两个关键计算是从策略中抽样动作,以及计算给定状态下选择特定动作的对数似然值。这两个计算在使用和训练随机策略时都是非常重要的。

Categorical Policies

分类策略就像是对离散动作的分类器。你用与分类器相同的方式为分类策略构建神经网络:输入是观察,然后是一些层(可能是卷积的或密集连接的,取决于输入的类型),然后你有一个最后的线性层,为每个动作提供logits,然后是一个softmax,将logits转换为概率。

Sampling.

Given the probabilities for each action, frameworks like PyTorch and Tensorflow have built-in tools for sampling. For example, see the documentation forCategorical distributions in PyTorchtorch.multinomialtf.distributions.Categorical, or tf.multinomial.

Log-Likelihood. 

Denote the last layer of probabilities as 

It is a vector with however many entries as there are actions, so we can treat the actions as indices for the vector. The log likelihood for an action a can then be obtained by indexing into the vector:

它是一个向量,有多少个条目就有多少个动作,所以我们可以将这些动作视为向量的索引。然后,可以通过索引到向量中来获得动作a的对数似然性:

Tips:

对数似然性是在统计学和概率论中常用的概念,通常用于估计参数或进行模型比较。它是指在给定一组观察数据下,参数值产生观察数据的概率的对数。

在机器学习和统计建模中,通常使用对数似然性来表示模型对数据的拟合程度。对于给定的数据集,我们可以计算出模型的对数似然性。通过最大化对数似然性,我们可以找到最优的模型参数值,使得模型对观察数据的拟合程度最高。

对数似然性的值通常越高,表示模型对观察数据的拟合程度越好。因此,在参数估计、模型选择和比较中,通常会使用对数似然性作为评估模型性能的指标。

Diagonal Gaussian Policies

A multivariate Gaussian distribution (or multivariate normal distribution, if you prefer) is described by a mean vector, , and a covariance matrix, . A diagonal Gaussian distribution is a special case where the covariance matrix only has entries on the diagonal. As a result, we can represent it by a vector.

多元高斯分布(或多元正态分布,如果你喜欢的话)由均值向量\mu和协方差矩阵\Sigma描述。对角线高斯分布是一种特殊情况,其中协方差矩阵只有对角线上的条目。因此,我们可以用向量来表示它。

A diagonal Gaussian policy always has a neural network that maps from observations to mean actions, . There are two different ways that the covariance matrix is typically represented.

对角高斯策略总是有一个神经网络,它将观测映射到平均作用,。协方差矩阵通常有两种不同的表示方式。

The first way: There is a single vector of log standard deviations, , which is not a function of state: the  are standalone parameters. (You Should Know: our implementations of VPG, TRPO, and PPO do it this way.)

第一种方法:有一个单一的log标准偏差向量,它不是状态的函数:是独立的参数。(您应该知道:我们的VPG、TRPO和PPO都是这样实现的。)

The second way: There is a neural network that maps from states to log standard deviations, . It may optionally share some layers with the mean network.

第二种方法:有一个神经网络,它将状态映射到对数标准偏差,。它可以选择性地与平均网络共享一些层。

Note that in both cases we output log standard deviations instead of standard deviations directly. This is because log stds are free to take on any values in , while stds must be nonnegative. It’s easier to train parameters if you don’t have to enforce those kinds of constraints. The standard deviations can be obtained immediately from the log standard deviations by exponentiating them, so we do not lose anything by representing them this way.

  1. 对数标准差可以取任何在(-∞, ∞)范围内的值,而标准差必须是非负的。这使得对数标准差在训练参数时更容易,因为我们不必强制施加这些约束条件。这意味着模型在学习时不受到参数范围的限制,而可以更自由地调整参数以最大程度地提高模型性能。

  2. 通过取对数,我们可以使得标准差的值可以直接从对数标准差中获得。对数和指数是互为逆运算的,所以通过对数操作,我们可以更方便地计算标准差,而且不会丢失任何信息。

综上所述,选择输出对数标准差而不是标准差的主要原因是为了训练参数更加简单且灵活,并且不会损失信息,因为我们可以轻松地通过指数操作得到标准差的值。

Given the mean action  and standard deviation , and a vector  of noise from a spherical Gaussian , an action sample can be computed with

where  denotes the elementwise product of two vectors. Standard frameworks have built-in ways to generate the noise vectors, such as torch.normal or tf.random_normal. Alternatively, you can build distribution objects, eg through torch.distributions.Normal or tf.distributions.Normal, and use them to generate samples. (The advantage of the latter approach is that those objects can also calculate log-likelihoods for you.)

给定平均作用和标准差,以及来自球面高斯的噪声矢量,可以用

计算action sample。其中表示两个向量的元素乘积。标准框架具有生成噪声向量的内置方法,如torch.normal或tf.random_normal。或者,您也可以构建分布对象,例如通过 torch.distributions.Normal or tf.distributions.Normal,并使用它们生成样本。(后一种方法的优点是,这些对象还可以为您计算对数似然性。)

Log-Likelihood. The log-likelihood of a k-dimensional action a, for a diagonal Gaussian with mean  and standard deviation , is given by

这个公式表示了对角高斯分布下,给定状态 s 下动作 a 的对数似然值 \log \pi_{\theta}(a|s)

首先,我们将动作 a的每个维度 a_i与相应维度的高斯分布均值​ \mu_i进行比较,并计算它们之间的偏差的平方,然后除以方差 \sigma_i^2。这一部分表示了动作 a 与高斯分布均值 \mu之间的差异的度量。

然后,我们将这些差异的平方和除以 2 ,并取负值。这一部分表示了负对数似然中的一个重要组成部分,它度量了动作 a 与高斯分布的偏差程度。

接着,我们对每个维度的标准差 \sigma_i取对数,并将其乘以 2 加到上述部分中。这一部分表示了标准差 σ 的对数在计算中的作用,它对整体对数似然值的贡献。

最后,我们加上 k \log 2\pi,其中 k 是动作的维度,表示了高斯分布的归一化常数。这一项是常数项,与动作 a 和状态 s 无关。

综上所述,这个公式通过计算动作 a 与给定状态 s 下高斯分布的对数似然值,从而描述了动作 a 在该状态下出现的概率。

Trajectories

A trajectory  is a sequence of states and actions in the world,

Reward and Return

The reward function R is critically important in reinforcement learning. It depends on the current state of the world, the action just taken, and the next state of the world:

finite-horizon undiscounted return

infinite-horizon discounted return

The RL Problem

Whatever the choice of return measure (whether infinite-horizon discounted, or finite-horizon undiscounted), and whatever the choice of policy, the goal in RL is to select a policy which maximizes expected return when the agent acts according to it.

无论用那种价值函数 无论用什么策略 RL的目标是选取一个能让agent获得最大化期望价值的策略

To talk about expected return, we first have to talk about probability distributions over trajectories.要讨论预期回报,我们首先必须讨论轨迹上的概率分布。

Let’s suppose that both the environment transitions and the policy are stochastic. In this case, the probability of a T -step trajectory is:

这个方程描述了一个有限时间跨度下,考虑了环境状态转移和策略随机性的情况下,T 步轨迹的概率。P(\tau|\pi) = \rho_0 (s_0) \prod_{t=0}^{T-1} P(s_{t+1} | s_t, a_t) \pi(a_t | s_t).

在这个方程中:

  • P(\tau|\pi)表示给定策略 π 的情况下,T 步轨迹 τ 出现的概率。
  • \rho_0 (s_0)是初始状态s_0的初始分布,表示开始时处于状态 s_0的概率。
  • \prod_{t=0}^{T-1} P(s_{t+1} | s_t, a_t)表示在时间步 t,从状态 st​ 经过动作 at​ 转移到状态 st+1​ 的概率的连乘积,表示了环境的状态转移。
  • \pi(a_t | s_t)表示在状态 st​ 下选择动作 at​ 的概率,表示了策略对动作的选择。

因此,整个概率 P(\tau|\pi)是初始状态的分布 \rho_0 (s_0)\rho_0 (s_0)乘以所有状态转移和动作选择的概率的连乘积,表示了在给定策略下产生 T 步轨迹的概率。

The expected return (for whichever measure), denoted by , is then:

The central optimization problem in RL can then be expressed by

with  being the optimal policy.

这个方程描述了强化学习中的核心优化问题:

\pi^* = \arg \max_{\pi} J(\pi)

其中 π∗ 是最优策略。

在这个方程中:

  • J(\pi)表示给定策略 π 下的期望回报。
  • \arg \max_{\pi}表示在所有可能的策略 π 中寻找使期望回报 J(π) 最大化的策略。
  • 因此,π∗ 表示使期望回报 J(π) 达到最大值的最优策略。

这个方程表达了强化学习中的核心目标:找到一个能够最大化期望回报的最优策略。解决这个优化问题意味着找到了对于给定的环境和奖励信号,最好的行为策略,这样代理就能在环境中获得最大的累积奖励。

"argmax" 是一个数学术语,表示对函数取最大值的参数值。具体来说,对于一个函数 f(x),它的 argmax 是使得 f(x) 达到最大值的 x 值。换句话说,argmax 是指使函数取得最大值的参数值。

Value Functions

经常需要知道一个状态或状态行为对的价值。

It’s often useful to know the value of a state, or state-action pair. By value, we mean the expected return if you start in that state or state-action pair, and then act according to a particular policy forever after. Value functions are used, one way or another, in almost every RL algorithm.

了解状态或状态-动作对的值通常很有用。我们所说的值是指如果您从该状态或状态操作对开始,然后永远根据特定策略进行操作,则预期的回报。在几乎每一种RL算法中都以某种方式使用值函数。

The On-Policy Value Function

which gives the expected return if you start in state s and always act according to policy pi:

基于策略的状态价值函数,在这个方程中:

  • Vπ(s) 表示基于策略 π 的状态价值函数,即在给定策略下,从状态 s 开始的预期回报。
  • τ 表示一个轨迹(trajectory),包括一系列的状态-动作对 (s0​,a0​),(s1​,a1​),...,(sT​,aT​) 和对应的奖励序列 R(τ)。
  • \underEτ∼π 表示对所有可能的轨迹 τ 进行期望值的计算,其中轨迹是根据策略 π 生成的。
  • R(τ) 表示轨迹 τ 的累积奖励,即所有时刻的奖励之和。
  • s0​=s 表示轨迹 τ 的起始状态是 s

因此,Vπ(s) 表示在给定策略 π 下,从状态 s 开始,并且始终根据策略 π 采取行动,可能获得的期望回报。

The On-Policy Action-Value Function, which gives the expected return if you start in state s, take an arbitrary action a (which may not have come from the policy), and then forever after act according to policy pi:

基于策略的动作价值函数

在这个方程中:

  • Qπ(s,a) 表示基于策略 π 的动作价值函数,即在给定策略下,从状态 s 开始,采取动作 a 后,根据策略 π 一直采取行动,可能获得的期望回报。
  • τ 表示一个轨迹(trajectory),包括一系列的状态-动作对 (s0​,a0​),(s1​,a1​),...,(sT​,aT​) 和对应的奖励序列 R(τ)。
  • \underEτ∼π 表示对所有可能的轨迹 τ 进行期望值的计算,其中轨迹是根据策略 π 生成的。
  • R(τ) 表示轨迹 τ 的累积奖励,即所有时刻的奖励之和。
  • ∣s0​=s,a0​=a 表示轨迹 τ 的起始状态是 s,并且首次采取的动作是 a

因此,Qπ(s,a) 表示在给定策略 π 下,从状态 s 开始,采取动作 a 后,根据策略 π 一直采取行动,可能获得的期望回报。

The Optimal Value Function, which gives the expected return if you start in state s and always act according to the optimal policy in the environment:

这个方程描述了最优状态价值函数V∗(s),它给出了在状态 s 下,如果始终根据环境中的最优策略采取行动,可能获得的期望回报。

在这个方程中:

  • V∗(s) 表示最优状态价值函数,即在采取最优策略的情况下,从状态 s 开始,可能获得的期望回报。
  • τ 表示一个轨迹(trajectory),包括一系列的状态-动作对 (s0​,a0​),(s1​,a1​),...,(sT​,aT​) 和对应的奖励序列 R(τ)。
  • \underEτ∼π 表示对所有可能的轨迹 τ 进行期望值的计算,其中轨迹是根据策略 π 生成的。
  • maxπ​ 表示在所有可能的策略 π 中选择使得期望回报最大化的策略。
  • ∣s0​=s 表示轨迹 τ 的起始状态是 s

因此,V∗(s) 表示在采取最优策略的情况下,从状态 s 开始,可能获得的期望回报,即在给定环境中的最佳行为策略下,状态 s 的价值。

The Optimal Action-Value Function, which gives the expected return if you start in state s, take an arbitrary action a, and then forever after act according to the optimal policy in the environment:

这个方程描述了最优动作价值函数 Q∗(s,a),它给出了在状态 s 下,如果采取任意动作 a,然后根据环境中的最优策略一直采取行动,可能获得的期望回报。

在这个方程中:

  • Q∗(s,a) 表示最优动作价值函数,即在采取最优策略的情况下,从状态 s 开始,采取动作 a 后,根据最优策略一直采取行动,可能获得的期望回报。
  • τ 表示一个轨迹(trajectory),包括一系列的状态-动作对(s0​,a0​),(s1​,a1​),...,(sT​,aT​) 和对应的奖励序列 R(τ)。
  • \underEτ∼π 表示对所有可能的轨迹 τ 进行期望值的计算,其中轨迹是根据策略 π 生成的。
  • maxπ​ 表示在所有可能的策略 π 中选择使得期望回报最大化的策略。
  • ∣s0​=s,a0​=a 表示轨迹 τ 的起始状态是 s,并且首次采取的动作是 a

因此,Q∗(s,a) 表示在采取最优策略的情况下,从状态 s 开始,采取动作 a 后,根据最优策略一直采取行动,可能获得的期望回报,即在给定环境中的最佳行为策略下,状态 s 和动作 a 的价值。

There are two key connections between the value function and the action-value function that come up pretty often:

and

  1. 基于策略的状态价值函数与基于策略的动作价值函数之间的关系

这个方程表达了基于策略的状态价值函数 Vπ(s) 与基于策略的动作价值函数 Qπ(s,a) 之间的关系。

在这个方程中:

  • Vπ(s) 表示基于策略 π 的状态价值函数,即在状态 s 下,根据策略 π 采取行动的期望回报。
  • Qπ(s,a) 表示基于策略 π 的动作价值函数,即在状态 s 下采取动作 a 后,根据策略 π 采取行动的期望回报。
  • a∼π 表示从策略 π 的动作分布中随机采样动作 a。
  • \underEa∼π 表示对所有可能的动作 a,根据策略 π 的概率分布取期望。

因此,方程表示了在给定策略 π 下,状态 s 的价值等于对所有可能的动作 a,根据策略 π 的概率分布取动作价值的期望值。

证明:

我们有:

其中V^{\pi}(s)是基于策略 π 的状态价值函数,定义为在状态 s 下,按照策略 π 的行动,所获得的期望回报;而 Qπ(s,a) 是基于策略 π 的动作价值函数,定义为在状态 s 采取动作 a,然后按照策略 π 的行动,所获得的期望回报。

动作价值函数 Qπ(s,a) 可以表示为状态价值函数Vπ(s′) 的加权和,其中 s′ 是在状态 s 下采取动作 a 后可能到达的下一个状态。因此:

其中 P(s′∣s,a) 是在状态 s 采取动作 a 后转移到状态 s′ 的转移概率,r(s,a,s′) 是在状态 s 采取动作 a 后在状态 s′ 下所获得的即时奖励。

根据策略 π 的定义,动作 a 由策略 π 的动作分布给出,即 a∼π(⋅∣s),因此我们可以用 π(a∣s) 来表示。

因此,将 Qπ(s,a) 的表达式代入状态价值函数的期望中:

最优状态价值函数与最优动作价值函数之间的关系

这个方程表示最优状态价值函数 V∗(s) 等于在状态 s 下选择动作 a 后的最大动作价值函数 Q∗(s,a)。

让我们逐步解释这个方程:

  1. 定义最优状态价值函数 V∗(s) 和最优动作价值函数 Q∗(s,a)

    • V∗(s) 是最优状态价值函数,表示在状态 s 下按照最优策略采取行动所能获得的期望回报。
    • Q∗(s,a) 是最优动作价值函数,表示在状态 s 下采取动作 a 后,按照最优策略采取行动所能获得的期望回报。
  2. 动作价值函数 Q∗(s,a) 的定义

    最优动作价值函数 Q∗(s,a) 表示在状态 s 下采取动作 a 后,然后按照最优策略采取行动所能获得的期望回报。因此,V∗(s) 可以表示为选择所有可能动作 a 后的最大动作价值,即:

    V∗(s)=maxa​Q∗(s,a)

    这意味着最优状态价值V∗(s) 是在状态 s 下选择动作 a 后,其动作价值函数 Q∗(s,a) 的最大值。

这个方程强调了最优状态价值函数和最优动作价值函数之间的关系:最优状态价值等于在状态 s 下选择动作 a 后的最大动作价值。

The Optimal Q-Function and the Optimal Action

最有动作价值函数和所选取的最优策略之间有重要的联系。

根据定义,给了从状态s采取(任意)动作a,并更具最优策略进行行动的期望汇报。

在状态s的最优策略会选择使得从s状态出发能得到期望汇报最大化的动作

所以,如果有了,我们可以直接获得最优动作,通过

Note: there may be multiple actions which maximize , in which case, all of them are optimal, and the optimal policy may randomly select any of them. But there is always an optimal policy which deterministically selects an action.

注意:可能有多个操作使Q^*(s,a)最大化,在这种情况下,所有操作都是最优的,最优策略可以随机选择其中的任何一个。但是,总有一个最优的政策,它决定性地选择一个行动。

换句话说,最优策略可能会在多个最优动作之间进行随机选择,但总是有一种最优策略,它会以确定性的方式选择其中一个最优动作。这种情况下,即使有多个最优动作,最优策略也会确切地选择其中一个动作执行,而不是通过随机选择的方式。

Bellman Equations

All four of the value functions obey special self-consistency equations called Bellman equations. The basic idea behind the Bellman equations is this:

The value of your starting point is the reward you expect to get from being there, plus the value of wherever you land next.

所有四个值函数都服从称为Bellman方程的特殊自洽方程。Bellman方程背后的基本思想是:

起点的价值是你期望从那里得到的回报再加上你下一个着陆点的价值。

The Bellman equations for the on-policy value functions are

where  is shorthand for , indicating that the next state  is sampled from the environment’s transition rules;  is shorthand for ; and  is shorthand for 

这个方程表示基于策略 π 的状态价值函数 Vπ(s) 等于在状态 s 下根据策略 π 选择动作 a,然后转移到下一个状态 s′ 并获得即时奖励 r(s,a) 的期望值,再加上下一个状态 s′ 的状态价值函数 Vπ(s′) 乘以折扣因子 γ 的期望值。

让我们逐步解释这个方程:

  1. 定义基于策略 π 的状态价值函数 Vπ(s)

    • Vπ(s) 是在状态 s 下按照策略 π 选择动作后所能获得的期望回报。
  2. 期望操作符 \underEa∼πs′∼P

    这个操作符表示对动作 a 和下一个状态 s′ 分别根据策略 π 和环境的转移概率 P 取期望。

  3. 转移过程和奖励

    在状态 s 下根据策略 π 选择动作 a 后,根据环境的转移概率 P 转移到下一个状态 s′,并获得即时奖励 r(s,a)。

  4. 下一个状态的价值

    在下一个状态 s′ 下按照相同的策略 π 继续选择动作,因此下一个状态 s′ 的价值 Vπ(s′) 是基于策略 π 的状态价值函数。

  5. 折扣因子 γ

    折扣因子 γ 用于对未来回报的重要性进行折减,以平衡当前回报和未来回报的影响。

The Bellman equations for the optimal value functions are

The crucial difference between the Bellman equations for the on-policy value functions and the optimal value functions, is the absence or presence of the max over actions. Its inclusion reflects the fact that whenever the agent gets to choose its action, in order to act optimally, it has to pick whichever action leads to the highest value.

The term “Bellman backup” comes up quite frequently in the RL literature. The Bellman backup for a state, or state-action pair, is the right-hand side of the Bellman equation: the reward-plus-next-value.

Advantage Functions

Sometimes in RL, we don’t need to describe how good an action is in an absolute sense, but only how much better it is than others on average. That is to say, we want to know the relative advantage of that action. We make this concept precise with the advantage function.

The advantage function  corresponding to a policy  describes how much better it is to take a specific action a in state s, over randomly selecting an action according to , assuming you act according to  forever after. Mathematically, the advantage function is defined by

We’ll discuss this more later, but the advantage function is crucially important to policy gradient methods.

我们稍后将对此进行更多讨论,但优势函数对策略梯度方法至关重要。

(Optional) Formalism

So far, we’ve discussed the agent’s environment in an informal way, but if you try to go digging through the literature, you’re likely to run into the standard mathematical formalism for this setting: Markov Decision Processes (MDPs). An MDP is a 5-tuple, , where

  • S is the set of all valid states,
  • A is the set of all valid actions,
  • R : S \times A \times S \to \mathbb{R} is the reward function, with r_t = R(s_t, a_t, s_{t+1}),,
  • P : S \times A \to \mathcal{P}(S) is the transition probability function, with P(s'|s,a) being the probability of transitioning into state s' if you start in state s and take action a,
  • and \rho_0 is the starting state distribution.

The name Markov Decision Process refers to the fact that the system obeys the Markov property: transitions only depend on the most recent state and action, and no prior history.

Markov Decision Processes(MDPs)是一种用来描述强化学习问题的数学框架。它是一个包含五个元素的5元组,表示为 〈S,A,R,P,ρ0​〉,其中:

  • S 表示状态(State)的集合,即环境中可能出现的所有状态的集合。
  • A 表示动作(Action)的集合,即智能体可以采取的所有可能动作的集合。
  • R 表示奖励(Reward)函数,定义了在状态转移过程中智能体获得的即时奖励的函数。通常表示为 R:S×A×S→R,即在给定状态 s、采取动作 a 后转移到状态 s′ 所获得的即时奖励。
  • P 表示转移概率(Transition Probability)函数,定义了从一个状态转移到下一个状态的概率分布。通常表示为 P:S×A×S→[0,1],即在给定状态 s 和采取动作 a 后转移到状态 s′ 的概率。
  • ρ0​ 表示初始状态(Initial State)的分布,即智能体在开始时所处的状态的概率分布。通常表示为 ρ0​:S→[0,1],即在开始时智能体处于每个状态的概率。

5-tuple,在数学和计算机科学中,一个 "5元组" 指的是一个有序的包含五个元素的集合。这个术语常常用于描述数学中的元组或在计算机编程中的数据结构。在上下文中,"5元组" 通常指的是一个包含五个值或组件的数据结构,这些值按照固定的顺序排列。

这个表达式描述了奖励函数 R 的定义,其中:

  • R 是一个函数,其定义域为状态空间 S、动作空间 A 和状态空间 S 的笛卡尔积。
  • 它将一个三元组 (s,a,s′) 映射到一个实数值,表示在状态 s 下采取动作 a 并转移到状态 s′ 所获得的即时奖励。

换句话说,奖励函数 R 接受一个当前状态 s、采取的动作 a 和转移到的下一个状态 s′,然后返回一个实数值,表示智能体在这个转换过程中所获得的即时奖励。

笛卡尔积是数学中的一个概念,用于描述两个集合之间的所有可能的组合。如果有两个集合 A 和 B,它们的笛卡尔积(Cartesian product)A×B 是一个集合,其中的元素是形如 (a,b) 的有序对,其中 a 是来自集合 A 的元素,而 b 是来自集合 B 的元素。

更一般地,如果有 n 个集合 A1​,A2​,…,An​,它们的笛卡尔积 A1​×A2​×…×An​ 是一个集合,其中的元素是形如(a1​,a2​,…,an​) 的 n-元组,其中每个 ai​ 是来自对应集合 Ai​ 的元素。

在上下文中,S×A×S 表示状态空间 S、动作空间 A 和状态空间 S 之间的笛卡尔积。这个笛卡尔积包含了所有可能的三元组,其中第一个元素来自状态空间 S,第二个元素来自动作空间 A,第三个元素同样来自状态空间 S。

The name Markov Decision Process refers to the fact that the system obeys the Markov property: transitions only depend on the most recent state and action, and no prior history.

马尔可夫决策过程(Markov Decision Process)这个名字指的是系统服从马尔可夫性质的事实:转换只取决于最近的状态和动作,而不取决于先前的历史。

  • 7
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值