赞
踩
我们目前使用的都是state value表格形式
假设我有一些状态 s 1 , … , s ∣ S ∣ s_1, \ldots, s_{|\mathcal{S}|} s1,…,s∣S∣,他们的state value是 v π ( s 1 ) , … , v π ( s ∣ S ∣ ) v_\pi\left(s_1\right), \ldots, v_\pi\left(s_{|\mathcal{S}|}\right) vπ(s1),…,vπ(s∣S∣),其中 π \pi π是给定的策略。假设 ∣ S ∣ |\mathcal{S}| ∣S∣很大我们希望用一个曲线来代表这些点:
首先我们用直线拟合
v
^
(
s
,
w
)
=
a
s
+
b
=
[
s
,
1
]
⏟
ϕ
T
(
s
)
[
a
b
]
⏟
w
=
ϕ
T
(
s
)
w
\hat{v}(s, w)=a s+b=\underbrace{[s, 1]}_{\phi^T(s)} \underbrace{\left[
使用二阶曲线拟合
v
^
(
s
,
w
)
=
a
s
2
+
b
s
+
c
=
[
s
2
,
s
,
1
]
⏟
ϕ
T
(
s
)
[
a
b
c
]
⏟
w
=
ϕ
T
(
s
)
w
.
\hat{v}(s, w)=a s^2+b s+c=\underbrace{\left[s^2, s, 1\right]}_{\phi^T(s)} \underbrace{\left[
使用更高阶的曲线拟合,使得拟合更好但是参数增加
目标: v π ( s ) v_\pi(s) vπ(s)是真值, v ^ ( s , w ) \hat{v}(s, w) v^(s,w)是估计的值,我们的目标就是使估计的值接近真值。(当函数形式确定的时候我们主要找到最优的 w w w参数使得其接近 v π ( s ) v_\pi(s) vπ(s))
定义目标函数:
J
(
w
)
=
E
[
(
v
π
(
S
)
−
v
^
(
S
,
w
)
)
2
]
.
J(w)=\mathbb{E}\left[\left(v_\pi(S)-\hat{v}(S, w)\right)^2\right] .
J(w)=E[(vπ(S)−v^(S,w))2].
我们目标找到最优的 w w w优化这个 J ( w ) J(w) J(w)
s获得:
平均分布:给每个状态求平均的权重都是一样的 1 / ∣ S ∣ 1 /|\mathcal{S}| 1/∣S∣
目标函数变成:
J
(
w
)
=
E
[
(
v
π
(
S
)
−
v
^
(
S
,
w
)
)
2
]
=
1
∣
S
∣
∑
s
∈
S
(
v
π
(
s
)
−
v
^
(
s
,
w
)
)
2
J(w)=\mathbb{E}\left[\left(v_\pi(S)-\hat{v}(S, w)\right)^2\right]=\frac{1}{|\mathcal{S}|} \sum_{s \in \mathcal{S}}\left(v_\pi(s)-\hat{v}(s, w)\right)^2
J(w)=E[(vπ(S)−v^(S,w))2]=∣S∣1s∈S∑(vπ(s)−v^(s,w))2
平稳分布: { d π ( s ) } s ∈ S \left\{d_\pi(s)\right\}_{s \in \mathcal{S}} {dπ(s)}s∈S 为 s s s 的概率,其中每一个值 d π ( s ) ≥ 0 d_\pi(s) \geq 0 dπ(s)≥0 并且 ∑ s ∈ S d π ( s ) = 1 \sum_{s \in \mathcal{S}} d_\pi(s)=1 ∑s∈Sdπ(s)=1
目标函数变成:
J
(
w
)
=
E
[
(
v
π
(
S
)
−
v
^
(
S
,
w
)
)
2
]
=
∑
s
∈
S
d
π
(
s
)
(
v
π
(
s
)
−
v
^
(
s
,
w
)
)
2
J(w)=\mathbb{E}\left[\left(v_\pi(S)-\hat{v}(S, w)\right)^2\right]=\sum_{s \in \mathcal{S}} d_\pi(s)\left(v_\pi(s)-\hat{v}(s, w)\right)^2
J(w)=E[(vπ(S)−v^(S,w))2]=s∈S∑dπ(s)(vπ(s)−v^(s,w))2
为了最小化
J
(
w
)
J(w)
J(w),我们可以使用梯度下降法:
w
k
+
1
=
w
k
−
α
k
∇
w
J
(
w
k
)
w_{k+1}=w_k-\alpha_k \nabla_w J\left(w_k\right)
wk+1=wk−αk∇wJ(wk)
计算:
∇
w
J
(
w
)
=
∇
w
E
[
(
v
π
(
S
)
−
v
^
(
S
,
w
)
)
2
]
=
E
[
∇
w
(
v
π
(
S
)
−
v
^
(
S
,
w
)
)
2
]
=
2
E
[
(
v
π
(
S
)
−
v
^
(
S
,
w
)
)
(
−
∇
w
v
^
(
S
,
w
)
)
]
=
−
2
E
[
(
v
π
(
S
)
−
v
^
(
S
,
w
)
)
∇
w
v
^
(
S
,
w
)
]
这里我们需要计算一个均方,我们可以使用随机梯度进行替代:
w
t
+
1
=
w
t
+
α
t
(
v
π
(
s
t
)
−
v
^
(
s
t
,
w
t
)
)
∇
w
v
^
(
s
t
,
w
t
)
,
w_{t+1}=w_t+\alpha_t\left(v_\pi\left(s_t\right)-\hat{v}\left(s_t, w_t\right)\right) \nabla_w \hat{v}\left(s_t, w_t\right),
wt+1=wt+αt(vπ(st)−v^(st,wt))∇wv^(st,wt),
这里面涉及到
v
π
(
s
t
)
v_\pi(s_t)
vπ(st),我们有两种方法进行代替:
蒙特卡洛方法:用
g
t
g_t
gt作为
v
π
(
s
t
)
v_\pi(s_t)
vπ(st)的估计值
w
t
+
1
=
w
t
+
α
t
(
g
t
−
v
^
(
s
t
,
w
t
)
)
∇
w
v
^
(
s
t
,
w
t
)
.
w_{t+1}=w_t+\alpha_t\left(g_t-\hat{v}\left(s_t, w_t\right)\right) \nabla_w \hat{v}\left(s_t, w_t\right) .
wt+1=wt+αt(gt−v^(st,wt))∇wv^(st,wt).
TD learning:
w
t
+
1
=
w
t
+
α
t
[
r
t
+
1
+
γ
v
^
(
s
t
+
1
,
w
t
)
−
v
^
(
s
t
,
w
t
)
]
∇
w
v
^
(
s
t
,
w
t
)
w_{t+1}=w_t+\alpha_t\left[r_{t+1}+\gamma \hat{v}\left(s_{t+1}, w_t\right)-\hat{v}\left(s_t, w_t\right)\right] \nabla_w \hat{v}\left(s_t, w_t\right)
wt+1=wt+αt[rt+1+γv^(st+1,wt)−v^(st,wt)]∇wv^(st,wt)
v ^ ( s , w ) ⟶ V π \hat{v}(s, w) \longrightarrow V_\pi v^(s,w)⟶Vπ
第一种:线性函数
v
^
(
s
,
w
)
=
ϕ
T
(
s
)
w
\hat{v}(s, w)=\phi^T(s) w
v^(s,w)=ϕT(s)w
由于线性函数我们有了其梯度 ∇ w v ^ ( s , w ) = ϕ ( s ) \nabla_w \hat{v}(s, w)=\phi(s) ∇wv^(s,w)=ϕ(s)
将其带到TD learning中得到:也叫做TD-Linear
w
t
+
1
=
w
t
+
α
t
[
r
t
+
1
+
γ
v
^
(
s
t
+
1
,
w
t
)
−
v
^
(
s
t
,
w
t
)
]
∇
w
v
^
(
s
t
,
w
t
)
w
t
+
1
=
w
t
+
α
t
[
r
t
+
1
+
γ
ϕ
T
(
s
t
+
1
)
w
t
−
ϕ
T
(
s
t
)
w
t
]
ϕ
(
s
t
)
第二种:神经网络逼近函数
给定策略对任何的 s , a s,a s,a 其 π ( a ∣ s ) = 0.2 \pi(a \mid s)=0.2 π(a∣s)=0.2
目标:估计state values在这个策略
参数: r forbidden = r boundary = − 1 , r target = 1 r_{\text {forbidden }}=r_{\text {boundary }}=-1, r_{\text {target }}=1 rforbidden =rboundary =−1,rtarget =1, γ = 0.9 \gamma=0.9 γ=0.9
真实结果:
近似:我们有500个episodes,每个episodes有500步,每个episode出发是随机选择的且服从均匀分布
通过TD-Table绘制:
TD-Linear:
特征向量选择:
ϕ
(
s
)
=
[
1
x
y
]
∈
R
3
\phi(s)=\left[
近似状态值:
v
^
(
s
,
w
)
=
ϕ
T
(
s
)
w
=
[
1
,
x
,
y
]
[
w
1
w
2
w
3
]
=
w
1
+
w
2
x
+
w
3
y
\hat{v}(s, w)=\phi^T(s) w=[1, x, y]\left[
通过TD-Linear进行估计:
最终收敛了但是最终值不是0,我们后续可以通过高阶进行拟合
High-order feater vectors:
特征向量选择:
ϕ
(
s
)
=
[
1
,
x
,
y
,
x
2
,
y
2
,
x
y
]
T
∈
R
6
\phi(s)=\left[1, x, y, x^2, y^2, x y\right]^T \in \mathbb{R}^6
ϕ(s)=[1,x,y,x2,y2,xy]T∈R6
近似状态值:
v
^
(
s
,
w
)
=
ϕ
T
(
s
)
w
=
w
1
+
w
2
x
+
w
3
y
+
w
4
x
2
+
w
5
y
2
+
w
6
x
y
\hat{v}(s, w)=\phi^T(s) w=w_1+w_2 x+w_3 y+w_4 x^2+w_5 y^2+w_6 x y
v^(s,w)=ϕT(s)w=w1+w2x+w3y+w4x2+w5y2+w6xy
拟合结果:
从目标函数出发,为真实的state value和估计的state value的加权平均:
J
(
w
)
=
E
[
(
v
π
(
S
)
−
v
^
(
S
,
w
)
)
2
]
J(w)=\mathbb{E}\left[\left(v_\pi(S)-\hat{v}(S, w)\right)^2\right]
J(w)=E[(vπ(S)−v^(S,w))2]
对算法使用梯度下降进行优化:
w
t
+
1
=
w
t
+
α
t
(
v
π
(
s
t
)
−
v
^
(
s
t
,
w
t
)
)
∇
w
v
^
(
s
t
,
w
t
)
w_{t+1}=w_t+\alpha_t\left(v_\pi\left(s_t\right)-\hat{v}\left(s_t, w_t\right)\right) \nabla_w \hat{v}\left(s_t, w_t\right)
wt+1=wt+αt(vπ(st)−v^(st,wt))∇wv^(st,wt)
由于
v
π
(
s
t
)
v_\pi(s_t)
vπ(st)不知道,对其进行替代(这里不严谨可能会有问题):
w
t
+
1
=
w
t
+
α
t
[
r
t
+
1
+
γ
v
^
(
s
t
+
1
,
w
t
)
−
v
^
(
s
t
,
w
t
)
]
∇
w
v
^
(
s
t
,
w
t
)
w_{t+1}=w_t+\alpha_t\left[r_{t+1}+\gamma \hat{v}\left(s_{t+1}, w_t\right)-\hat{v}\left(s_t, w_t\right)\right] \nabla_w \hat{v}\left(s_t, w_t\right)
wt+1=wt+αt[rt+1+γv^(st+1,wt)−v^(st,wt)]∇wv^(st,wt)
w t + 1 = w t + α t [ r t + 1 + γ q ^ ( s t + 1 , a t + 1 , w t ) − q ^ ( s t , a t , w t ) ] ∇ w q ^ ( s t , a t , w t ) w_{t+1}=w_t+\alpha_t\left[r_{t+1}+\gamma \hat{q}\left(s_{t+1}, a_{t+1}, w_t\right)-\hat{q}\left(s_t, a_t, w_t\right)\right] \nabla_w \hat{q}\left(s_t, a_t, w_t\right) wt+1=wt+αt[rt+1+γq^(st+1,at+1,wt)−q^(st,at,wt)]∇wq^(st,at,wt)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。