Training a deep autoencoder or a classifier on MNIST digits_之调试运行与理解

来源:互联网 发布:程序员杂志订阅 编辑:程序博客网 时间:2024/06/14 15:22
运行这个程序的主要目的:深入理解deep autoencoder 的基本原理和基本架构,搞明白是如何搭建起来的,弄清它是如何训练学习的,又是如何提取目标的特征的,最终又是怎样分类的。

代码主程序如下:
mnistdeepauto.m
[plain] view plaincopy在CODE上查看代码片派生到我的代码片
  1. <pre code_snippet_id="148729" snippet_file_name="blog_20140109_1_7166930" name="code" class="plain"><pre code_snippet_id="148729" snippet_file_name="blog_20140109_1_7166930" name="code" class="plain">% Version 1.000  
  2. %  
  3. % Code provided by Ruslan Salakhutdinov and Geoff Hinton    
  4. %  
  5. % Permission is granted for anyone to copy, use, modify, or distribute this  
  6. % program and accompanying programs and documents for any purpose, provided  
  7. % this copyright notice is retained and prominently displayed, along with  
  8. % a note saying that the original programs are available from our   
  9. % web page.   
  10. % The programs and documents are distributed without any warranty, express or  
  11. % implied.  As the programs were written for research purposes only, they have  
  12. % not been tested to the degree that would be advisable in any important  
  13. % application.  All use of these programs is entirely at the user's own risk.  
  14.   
  15.   
  16. % This program pretrains a deep autoencoder for MNIST dataset-  
  17.   % 这个程序是关于MNIST数据库的深度自编码预训练  
  18. % You can set the maximum number of epochs for pretraining each layer  
  19.   %在预训练各个隐藏层的时候,你可以设置epochs的最大值  
  20. % and you can set the architecture of the multilayer net.  
  21.   %你可以设置多层网络的架构  
  22.   
  23. clear all  %清除工作所有的变量  
  24. close all  %关闭其他的窗口  
  25.   
  26. maxepoch=10; %In the Science paper we use maxepoch=50, but it works just fine.   
  27. numhid=1000; numpen=500; numpen2=250; numopen=30;</pre><pre code_snippet_id="148729" snippet_file_name="blog_20140109_2_7730833" name="code" class="plain">%设置各个隐藏层的神经元的个数;这个程序所采用的网络共有四层,你可以追踪这个变量,就很容易知道这四个变量的代表的含义。【1000 500 250 30】  
  28.   
  29. fprintf(1,'Converting Raw files into Matlab format \n');  
  30. converter; </pre><pre code_snippet_id="148729" snippet_file_name="blog_20140109_3_2856028" name="code" class="plain">%作者提供的二进制数据需要转换Matlab格式的;当程序运行到第一个函数fread时,程序报错,提示说所产生的文件标志是错误的,建议采用fopen函数。  
  31.   
  32. fprintf(1,'Pretraining a deep autoencoder. \n');  
  33. fprintf(1,'The Science paper used 50 epochs. This uses %3i \n', maxepoch);  
  34.   
  35. makebatches;  
  36. [numcases numdims numbatches]=size(batchdata);  
  37.   
  38. fprintf(1,'Pretraining Layer 1 with RBM: %d-%d \n',numdims,numhid);  
  39. restart=1;  
  40. rbm;  
  41. hidrecbiases=hidbiases;   
  42. save mnistvh vishid hidrecbiases visbiases;  
  43.   
  44. fprintf(1,'\nPretraining Layer 2 with RBM: %d-%d \n',numhid,numpen);  
  45. batchdata=batchposhidprobs;  
  46. numhid=numpen;  
  47. restart=1;  
  48. rbm;  
  49. hidpen=vishid; penrecbiases=hidbiases; hidgenbiases=visbiases;  
  50. save mnisthp hidpen penrecbiases hidgenbiases;  
  51.   
  52. fprintf(1,'\nPretraining Layer 3 with RBM: %d-%d \n',numpen,numpen2);  
  53. batchdata=batchposhidprobs;  
  54. numhid=numpen2;  
  55. restart=1;  
  56. rbm;  
  57. hidpen2=vishid; penrecbiases2=hidbiases; hidgenbiases2=visbiases;  
  58. save mnisthp2 hidpen2 penrecbiases2 hidgenbiases2;  
  59.   
  60. fprintf(1,'\nPretraining Layer 4 with RBM: %d-%d \n',numpen2,numopen);  
  61. batchdata=batchposhidprobs;  
  62. numhid=numopen;   
  63. restart=1;  
  64. rbmhidlinear;  
  65. hidtop=vishid; toprecbiases=hidbiases; topgenbiases=visbiases;  
  66. save mnistpo hidtop toprecbiases topgenbiases;  
  67.   
  68. backprop;   
  69. </pre><br>  
  70. <br>  
  71. <pre></pre>  
  72. <pre></pre>  
  73. <pre></pre>  
  74. <pre></pre>  
  75. </pre>  

原文地址:http://blog.csdn.net/liyuanhao_1114/article/details/18033223

0 0
原创粉丝点击