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

 1 简介

【路径规划】基于DQN实现机器人路径规划附matlab代码_第1张图片

【路径规划】基于DQN实现机器人路径规划附matlab代码_第2张图片

【路径规划】基于DQN实现机器人路径规划附matlab代码_第3张图片

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 仿真结果

【路径规划】基于DQN实现机器人路径规划附matlab代码_第4张图片

4 参考文献

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

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

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

5 代码下载

你可能感兴趣的:(路径规划,matlab,开发语言,算法)