• 大小: 14.04MB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2023-08-06
  • 语言: Matlab
  • 标签: matlab  BP网络  Optime  

资源简介

神经元节点的个数,隐藏层的个数,都是可以调节的,Optimer优化器有'SGD','mSGD','nSGD','AdaGrad','RMSProp','nRMSProp','Adam',激活函数有relu和sigmoid

资源截图

代码片段和文件信息

function [dnn] = backprop(xlabeldnnparameter)
%UNtitleD2 此处显示有关此函数的摘要
%   parameter 是结构体,包括参数:
%                       learning_rate: 学习率
%                       momentum: 动量系数一般为0.5,0.9,0.99
%                       attenuation_rate: 衰减系数
%                       delta:稳定数值
%                       step: 步长 一般为 0.001
%                       method: 方法{‘SGD‘‘mSGD‘‘nSGD‘‘AdaGrad‘‘RMSProp‘‘nRMSProp‘‘Adam‘}
%
L = size(dnn2)+1;
m = size(x2);
[y Y] = forwordprop(dnnx);
g = -label./y + (1 - label)./(1 - y);
method = {‘SGD‘‘mSGD‘‘nSGD‘‘AdaGrad‘‘RMSProp‘‘nRMSProp‘‘Adam‘};

persistent global_step;
if isempty(global_step)
   global_step = 0;
end
global_step = global_step + 1;
% fprintf(“global_step %d\n“global_step)
global E;
E(global_step) = sum(sum(-label.*log(y)-(1 - label).*log(1 - y)))/m;
persistent V;
if isempty(V)
    for i = 1:L-1
        V{i}.vw = dnn{i}.W*0;
        V{i}.vb = dnn{i}.b*0;
    end
end

if strcmp(parameter.method method{11})
    for i = L : -1 : 2
        if strcmp(dnn{i-1}.function‘relu‘)
            g = g.*(Y{i} > 0);
        end
        if strcmp(dnn{i-1}.function ‘sigmoid‘)
            g = g.*Y{i}.*(1 - Y{i});
        end
            dw = g*Y{i - 1}.‘/m;
            db = sum(g2)/m;
            g = dnn{i-1}.W‘*g;
            dnn{i-1}.W = dnn{i-1}.W - parameter.learning_rate*dw;
            dnn{i-1}.b = dnn{i-1}.b - parameter.learning_rate*db;
    end                                                                                                                                                                                                                                                                                        
end

if strcmp(parameter.method method{12})
    for i = L : -1 : 2
        if strcmp(dnn{i-1}.function ‘relu‘)
            g = g.*(Y{i} > 0);
        end
        if strcmp(dnn{i-1}.function ‘sigmoid‘)
            g = g.*Y{i}.*(1 - Y{i});
        end
            dw = g*Y{i - 1}.‘/m;
            db = sum(g2)/m;
            g = dnn{i-1}.W‘*g;
            V{i-1}.vw = parameter.momentum*V{i-1}.vw - parameter.learning_rate*dw; 
            V{i-1}.vb = parameter.momentum*V{i-1}.vb - parameter.learning_rate*db;
            dnn{i-1}.W = dnn{i-1}.W + V{i-1}.vw;
            dnn{i-1}.b = dnn{i-1}.b + V{i-1}.vb;
    end
end

if strcmp(parameter.method method{13}) % 未实现    
    for i = L : -1 : 2
        if strcmp(dnn{i-1}.function  ‘relu‘)
            g = g.*(Y{i} > 0);
        end
        if strcmp(dnn{i-1}.function ‘sigmoid‘)
            g = g.*Y{i}.*(1 - Y{i});
        end
            dw = g*Y{i - 1}.‘/m;
            db = sum(g2)/m;
            g = dnn{i-1}.W‘*g;
            V{i-1}.vw = parameter.momentum*V{i-1}.vw - parameter.learning_rate*dw; 
            V{i-1}.vb = parameter.momentum*V{i-1}.vb - parameter.learning_rate*db;
            dnn{i-1}.W = dnn{i-1}.W + V{i-1}.vw;
            dnn{i-1}.b = dnn{i-1}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        5783  2019-04-26 14:52  backprop.m
     文件         977  2019-04-26 14:26  creatnn.m
     文件         391  2019-04-26 14:36  forwordprop.m
     文件    14735220  2018-08-25 09:50  mnist_uint8.mat
     文件        2503  2019-04-24 13:30  NN_in.mat
     文件       18702  2019-04-24 13:30  NN_out.mat
     文件         115  2018-08-24 15:51  relu.m
     文件         116  2018-08-24 15:52  sigmoid.m
     文件        1569  2019-04-27 09:19  Threenn.m

评论

共有 条评论