【路径规划】基于DQN实现机器人路径规划附matlab代码

网友投稿 396 2022-09-02


【路径规划】基于DQN实现机器人路径规划附matlab代码

1 简介

2 部分代码

classdef DQNEstimator < handle properties (SetAccess = private) env; alpha; weights; hidden_layer; end methods function obj = DQNEstimator(env,alpha,hidden_layer) obj.env = env; obj.alpha = alpha; obj.hidden_layer = hidden_layer; obj.weights.input = normrnd(0,1,[env.complexFeaturesLen+1, hidden_layer(1)])/sqrt(obj.env.complexFeaturesLen); obj.weights.hidden = normrnd(0,1,[hidden_layer(1)+1, hidden_layer(2)])/sqrt(hidden_layer(1)); obj.weights.out = normrnd(0,1,[hidden_layer(2)+1, length(obj.env.actionSpace)])/sqrt(hidden_layer(2)); end function set_weights(obj,weights) obj.weights = weights; end function value = predict(obj,state) features = obj.env.get_complex_state_features(state);%features are already scaled. value.hidden_in_value = [1 features] * obj.weights.input; value.hidden_out_value = sigmoid(value.hidden_in_value);%activation function value.hidden_in_value2 = [1 value.hidden_out_value] * obj.weights.hidden; value.hidden_out_value2 = sigmoid(value.hidden_in_value2);%activation function value.out_value = [1 value.hidden_out_value2] * obj.weights.out; end function update(obj,state,action,target) features = [1 obj.env.get_complex_state_features(state)]; value = obj.predict(state); out_value = value.out_value(action); hidden_out_value2 = value.hidden_out_value2; hidden_out_value = value.hidden_out_value; derivative_in(length(features), obj.hidden_layer(1)) = 0; for i=1:obj.hidden_layer(1) derivative_in(:,i) = (out_value - target) * ... sum(obj.weights.out(2:end,action)' .* ... (hidden_out_value2.*(1-hidden_out_value2)) .* ... obj.weights.hidden(i+1,:)) * ... hidden_out_value(i) * (1-hidden_out_value(i)) * features; obj.weights.input(:,i) = obj.weights.input(:,i) - obj.alpha * derivative_in(:,i); end derivative_hidden(obj.hidden_layer(2)+1, obj.hidden_layer(2)) = 0; for i=1:obj.hidden_layer(2) derivative_hidden(:,i) = (out_value - target) * obj.weights.out(i+1) * ... hidden_out_value2(i) * (1-hidden_out_value2(i)) * [1 hidden_out_value]; obj.weights.hidden(:,i) = obj.weights.hidden(:,i) - obj.alpha * derivative_hidden(:,i); end derivative_out(:,1) = (out_value- target) * [1 hidden_out_value2]; obj.weights.out(:,action) = obj.weights.out(:,action) - obj.alpha * derivative_out; end endend

3 仿真结果

4 参考文献

[1]王菁华, 崔世钢, 罗云林. 基于Matlab的智能机器人路径规划仿真[C]// '2008系统仿真技术及其应用学术会议论文集. 2008.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:【Python技能树共建】python autoscraper 模块(python)
下一篇:Spring bean配置单例或多例模式方式
相关文章

 发表评论

暂时没有评论,来抢沙发吧~