Matlab实现自适应动态规划——基于策略迭代的Q学习算法

1. 复现论文简介

该论文主要研究了离散时间确定性非线性系统的一种新型策略迭代型确定性Q学习算法。该算法的推导和与之前的Q学习算法的区别进行了讨论,对算法的收敛性和稳定性等性质进行了分析,采用神经网络实现了该算法,并通过仿真结果证明了其有效性。

参考文献:

[1] Wei, Qinglai, Ruizhuo Song, Benkai Li, Xiaofeng Lin. “A novel policy iteration-based deterministic Q-learning for discrete-time nonlinear systems.” Self-Learning Optimal Control of Nonlinear Systems: Adaptive Dynamic Programming Approach (2018): 85-109.

2. 具体算法实现

算法总结:

  1. 初始化神经网络的结构和权重;
  2. 随机选择一定数量的训练数据;
  3. 使用策略迭代型确定性Q学习算法对神经网络进行训练,迭代更新权重;
  4. 重复步骤3直到神经网络的训练误差小于设定阈值;
  5. 根据训练好的神经网络得到最优控制策略。

3. 系统模型及仿真结果

原论文主要在线性系统和扭摆非线性系统进行仿真验证,发现提出的策略迭代型确定性Q学习算法在离散时间的非线性系统取得了不错的效果。

在本次复现中,分别采用扭摆非线性系统算例、质量弹簧阻尼系统以及非线性数值算例进行仿真,通过在三个模型的仿真结果,的确说明了该算法的有效性。复现论文不易,有需要源代码的同学,请私信联系。

  • 扭摆系统 (Torsional Pendulum System)

文献出处:

[1] Liu D , Wei Q . Policy Iteration Adaptive Dynamic Programming Algorithm for Discrete-Time Nonlinear Systems[J]. IEEE Trans Neural Netw Learn Syst, 2014, 25(3):621-634.

[2] Mu C , Wang D , He H . Novel iterative neural dynamic programming for data-based approximate optimal control design[J]. Automatica, 2017, 81:240-252.

Dynamic:
{ d θ d t = ω J d ω d t = u − M g l sin ⁡ θ − f d d θ d t \left\{\begin{array}{l} \frac{d \theta}{d t}=\omega \\ J \frac{d \omega}{d t}=u-M g l \sin \theta-f_{d} \frac{d \theta}{d t} \end{array}\right. {dtdθ=ωJdtdω=uMglsinθfddtdθ
where M = 1 / 3 k g M=1 / 3 \mathrm{kg} M=1/3kg and l = 2 / 3 m l=2 / 3 \mathrm{m} l=2/3m are the mass and length of the pendulum bar, respectively. The system states are the current angle θ \theta θ and the angular velocity ω . \omega . ω. Let J = 4 / 3 M l 2 J=4 / 3 M l^{2} J=4/3Ml2 and f d = 0.2 f_{d}=0.2 fd=0.2 be the rotary inertia and frictional factor, respectively. Let g = 9.8 m / s 2 g=9.8 \mathrm{m} / \mathrm{s}^{2} g=9.8m/s2 be the gravity. Discretization of the system function and performance index function using Euler and trapezoidal methods with the sampling interval Δ t = 0.1 s \Delta t=0.1 \mathrm{s} Δt=0.1s leads to
[ x 1 ( k + 1 ) x 2 ( k + 1 ) ] = [ 0.1 x 2 k + x 1 k − 0.49 × sin ⁡ ( x 1 k ) − 0.1 × f d × x 2 k + x 2 k ] + [ 0 0.1 ] u k \begin{array}{r} {\left[\begin{array}{c} x_{1(k+1)} \\ x_{2(k+1)} \end{array}\right]=\left[\begin{array}{c} 0.1 x_{2 k}+x_{1 k} \\ -0.49 \times \sin \left(x_{1 k}\right)-0.1 \times f_{d} \times x_{2 k}+x_{2 k} \end{array}\right]} +\left[\begin{array}{c} 0 \\ 0.1 \end{array}\right] u_{k} \end{array} [x1(k+1)x2(k+1)]=[0.1x2k+x1k0.49×sin(x1k)0.1×fd×x2k+x2k]+[00.1]uk
or
x t + 1 = [ x 1 t + 0.1 x 2 t 0.2 ( − 0.49 sin ⁡ ( x 1 t ) − 0.2 x 2 t + x 2 t ) ] + [ 0 0.02 ] u t x_{t+1}=\left[\begin{array}{c} x_{1 t}+0.1 x_{2 t} \\ 0.2\left(-0.49 \sin \left(x_{1 t}\right)-0.2 x_{2 t}+x_{2 t}\right) \end{array}\right]+\left[\begin{array}{c} 0 \\ 0.02 \end{array}\right] u_{t} xt+1=[x1t+0.1x2t0.2(0.49sin(x1t)0.2x2t+x2t)]+[00.02]ut
The initial state is x 0 = [ 1 , − 1 ] T x_{0}=[1,-1]^{T} x0=[1,1]T.

仿真结果:PI_QLearning_case1.m

在这里插入图片描述
在这里插入图片描述在这里插入图片描述

  • “质量-弹簧-阻尼”系统(Mass-Spring-Damper System)

文献出处:

[1] Winston Alexander Baker. Observer incorporated neoclassical controller design: A discrete perspective[J]. Dissertations & Theses - Gradworks, 2010.
[ x 1 ( k + 1 ) x 2 ( k + 1 ) ] = [ 0.0099 x 2 k + 0.9996 x 1 k − 0.0887 x 1 k + 0.97 x 2 k ] + [ 0 0.0099 ] u ( k ) \left[\begin{array}{l} x_{1}(k+1) \\ x_{2}(k+1) \end{array}\right]=\left[\begin{array}{c} 0.0099 x_{2 k}+0.9996 x_{1 k} \\ -0.0887 x_{1 k}+0.97 x_{2 k} \end{array}\right]+\left[\begin{array}{c} 0 \\ 0.0099 \end{array}\right] u(k) [x1(k+1)x2(k+1)]=[0.0099x2k+0.9996x1k0.0887x1k+0.97x2k]+[00.0099]u(k)
The initial state vector is set as x 0 = [ − 1 , 1 ] T x_{0}=[-1,1]^{T} x0=[1,1]T.

仿真结果:PI_QLearning_case2.m

在这里插入图片描述请添加图片描述请添加图片描述

  • 非线性数值算例

文献出处:

[1] Wang F Y , Jin N , Liu D , et al. Adaptive dynamic programming for finite-horizon optimal control of discrete-time nonlinear systems with ε-error bound.[J]. IEEE Trans Neural Netw, 2011, 22(1):24-36.

[2] Zhang H , Wei Q , Luo Y . A Novel Infinite-Time Optimal Tracking Control Scheme for a Class of Discrete-Time Nonlinear Systems via the Greedy HDP Iteration Algorithm[J]. IEEE Transactions on Systems Man & Cybernetics Part B, 2008, 38(4):937-942.

[3] Liu D , Wei Q . Policy Iteration Adaptive Dynamic Programming Algorithm for Discrete-Time Nonlinear Systems[J]. IEEE Trans Neural Netw Learn Syst, 2014, 25(3):621-634.

We consider the following nonlinear system:
KaTeX parse error: No such environment: align at position 8: \begin{̲a̲l̲i̲g̲n̲}̲ x_{k+1}=f\left…
The system functions are given as
KaTeX parse error: No such environment: align at position 8: \begin{̲a̲l̲i̲g̲n̲}̲ f\left(x_{k}\r…
The initial state is x 0 = [ 2 , − 1 ] T x_{0}=[2,-1]^{T} x0=[2,1]T.

仿真结果:PI_QLearning_case3.m
在这里插入图片描述在这里插入图片描述在这里插入图片描述

  • 6
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
适应遗传算法(Adaptive Genetic Algorithm,AGA)是一种基于遗传算法的优化方法,它能够根据问题的特性自适应地调节遗传算法的参数,以达到更优的优化效果。在MATLAB实现适应遗传算法可以按照以下步骤进行: 1. 初始化种群:根据问题的特性和要求,确定种群规模和每个个体的染色体长度,随机生成初始种群。 2. 评价函数:根据问题的特性和要求,设计一个适应度函数来评价每个个体的适应度。 3. 选择操作:根据种群中每个个体的适应度大小,使用轮盘赌选择算法、锦标赛选择算法等方法选择部分个体作为下一代种群的父母。 4. 交叉操作:将父母个体的染色体进行交叉操作,生成新的个体,不同的交叉方式可以采用单点交叉、多点交叉、均匀交叉等方式。 5. 变异操作:对新个体进行变异操作,以增加种群的多样性,不同的变异方式可以采用位变异、基因变异等方式。 6. 更新种群:将新生成的个体和原有的个体合并,形成下一代种群。 7. 自适应调节:根据当前种群的适应度和进化过程中的变化情况,自适应地调节种群规模、交叉概率、变异概率等参数,以达到更优的优化效果。 8. 终止条件:当达到预设的终止条件(如达到最大代次数、适应度值达到预设值等)时,停止代,输出最优解。 下面是MATLAB代码示例:(以一维函数 f(x)=x^2+10sin(x) 的最大化为例) ``` % 初始化种群 pop_size = 50; % 种群规模 chrom_len = 20; % 每个个体的染色体长度 pop = randi([0,1],pop_size,chrom_len); % 评价函数 fun = @(x) x.^2 + 10*sin(x); fit = zeros(pop_size,1); for i = 1:pop_size x = bin2dec(num2str(pop(i,:))); x = x/(2^chrom_len-1) * 10; % 将二进制转化为实数 fit(i) = fun(x); end % 代 max_iter = 100; best_fit = zeros(max_iter,1); for iter = 1:max_iter % 选择操作 prob = fit/sum(fit); idx = randsrc(1,pop_size,[1:pop_size;prob']); parents = pop(idx,:); % 交叉操作 cross_prob = 0.8; cross_idx = rand(pop_size/2,chrom_len) < cross_prob; cross_pop = parents(1:2:end,:); cross_pop(cross_idx) = parents(2:2:end,cross_idx); % 变异操作 mut_prob = 0.05; mut_idx = rand(pop_size,chrom_len) < mut_prob; mut_pop = xor(cross_pop,mut_idx); % 更新种群和适应度 pop = [pop;mut_pop]; fit = zeros(2*pop_size,1); for i = 1:2*pop_size x = bin2dec(num2str(pop(i,:))); x = x/(2^chrom_len-1) * 10; fit(i) = fun(x); end % 自适应调节 pop_size = ceil(pop_size*1.1); if pop_size > 100 pop_size = 100; end cross_prob = cross_prob * exp((mean(fit) - best_fit(iter))/std(fit)); mut_prob = mut_prob * exp((mean(fit) - best_fit(iter))/std(fit)); % 输出当前最优解 [best_fit(iter),best_idx] = max(fit); x = bin2dec(num2str(pop(best_idx,:))); x = x/(2^chrom_len-1) * 10; fprintf('Iteration %d: f(%f)=%f\n',iter,x,best_fit(iter)); % 终止条件 if iter > 1 && abs(best_fit(iter) - best_fit(iter-1)) < 1e-6 break; end end ``` 在上述代码中,使用了轮盘赌选择算法、单点交叉、位变异等操作,同时自适应地调节了种群规模、交叉概率、变异概率等参数,以达到更优的优化效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值