UFLDL教程:Exercise:Vectorization

载入数据并显示

下载MINIST数据集及加载数据集的函数。MINIST数据集的介绍。

% Change the filenames if you've saved the files under different names
% On some platforms, the files might be saved as
% train-images.idx3-ubyte / train-labels.idx1-ubyte
images = loadMNISTImages('train-images.idx3-ubyte');
labels = loadMNISTLabels('train-labels.idx1-ubyte');

% We are using display_network from the autoencoder code
display_network(images(:,1:100)); % Show the first 100 images
disp(labels(1:10));

修改train.m中的初始参数

visibleSize = 28*28;   % number of input units 输入层单元数
hiddenSize = 196;     % number of hidden units隐藏层单元数
sparsityParam = 0.1;   % desired average activation of the hidden units.稀疏值
                     % (This was denoted by the Greek alphabet rho, which looks like a lower-case "p",
             %  in the lecture notes).
lambda = 3e-3;     % weight decay parameter 权重衰减系数     
beta = 3;            % weight of sparsity penalty term稀疏值惩罚项的权重   

修改训练集,把step1里面的patches的产生改为

%% STEP 1: Implement sampleIMAGES 第1步:实现图片采样
%实现图片采样后,函数display_network从训练集中随机显示200张
% After implementing sampleIMAGES, the display_network command should
% display a random sample of 200 patches from the dataset
%从10000张中随机选择200张显示
% patches = sampleIMAGES;
% figure
% display_network(patches(:,randi(size(patches,2),200,1)),8)
% title('sampleIMAGES')
%%为产生一个200维的列向量,每一维的值为0~10000中的随机数,说明是随机取200个patch来显示

images = loadMNISTImages('train-images.idx3-ubyte');
labels = loadMNISTLabels('train-labels.idx1-ubyte');

% We are using display_network from the autoencoder code
figure
display_network(images(:,1:100)); % Show the first 100 images
title('first100images')
figure
disp(labels(1:10));
title('first100label')


patches=zeros(visibleSize,10000);


for i=1:10000
    patches(:,i)=reshape(images(:,i),visibleSize,1);
end

% patches = normalizeData(patches);
% 在实现手写字符识别时,是不需要对其做归一化处理的
%要清楚的是,MINIST数据集本身就已经对数据进行了归一化的处理


% Obtain random parameters theta 初始化参数向量theta
theta = initializeParameters(hiddenSize, visibleSize);

为了提高效率,可把train.m中的 STEP 3: Gradient Checking这步注释掉,因为在本例中训练集更大,梯度检查会比较慢。

参考文献

https://github.com/jiandanjinxin/matlab_code-ufldl-exercise-/tree/master/vectorization_exercise

深度学习入门教程UFLDL学习实验笔记二:使用向量化对MNIST数据集做稀疏自编码

Deep Learning 2_深度学习UFLDL教程:矢量化编程(斯坦福大学深度学习教程)

吴恩达 Andrew Ng 的公开课

你可能感兴趣的:(UFLDL教程:Exercise:Vectorization)