DBN (深度信念网络) MATLAB DeepLearnToolbox 源码学习


 DeepLearnToolbox  源码  下载地址 https://github.com/rasmusbergpalm/DeepLearnToolbox


解压后可得到

 

data里面有数据集,tests里面有测试代码例子。如下

% function test_example_DBN
load mnist_uint8;  % 该数据集为集为手写数字数据集该数据集为集为手写数字数据集数据集改mnist   28*28 的图片。放在data文件夹中。
train_x = double(train_x) / 255;   % train_x为784个像素值, 这里是在做数据归一化,(0-1)
test_x  = double(test_x) / 255;
train_y = double(train_y);
test_y  = double(test_y);

%%  ex1 train a 100 hidden unit RBM and visualize its weights
% rng(0);
dbn.sizes = [  100  ];  %设置网络隐藏单元数为100
opts.numepochs =   1;       %设置训练迭代次数。
opts.batchsize = 100;     %批次大小
opts.momentum  =   0;    %动量
opts.alpha     =   1;     % 学习率
dbn = dbnsetup(dbn, train_x, opts);  %初始化RBM的参数
dbn = dbntrain(dbn, train_x, opts);   %开始训练
figure; visualize(dbn.rbm{1}.W');   %  Visualize the RBM weights

%%  ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NN
% rng(0);
%train dbn
dbn.sizes = [100 100];
opts.numepochs =   10;
opts.batchsize = 100;
opts.momentum  =   0;
opts.alpha     =   1;
dbn = dbnsetup(dbn, train_x, opts);
dbn = dbntrain(dbn, train_x, opts);

%unfold dbn to nn 
nn = dbnunfoldtonn(dbn, 10);           %设计一个有十个输出单元的NN,并用已经训练好的DBN的权值参数去初始化相应结构的NN网络
nn.activation_function = 'sigm';        %设置激活函数为 sigm

%train nn
opts.numepochs =  1;                   % 设置训练参数
opts.batchsize = 10;                           
nn = nntrain(nn, train_x, train_y, opts);   %训练网络
[er, bad] = nntest(nn, test_x, test_y);     %测试网络错误率

assert(er < 0.10, 'Too big error');

 







  • 12
    点赞
  • 71
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值