UFLDL教程 Exercise:Sparse Autoencoder(答案)
2014-10-11 16:17
351 查看
(注:本人刚刚着手DL,所以博文也仅属于学习笔记范畴,每篇博文我都会将内容摘抄地址附在最上面,如果冒犯原作者,请见谅哈~))
参考链接:
/article/5196566.html
网页教程参考:
Exercise:Sparse Autoencoder
Exercise:Sparse Autoencoder
Step1 generate training set
在sampleIMAGES.m文件中完成生成训练集的代码,如下,tic和toc用来计时的:
2. Step2 Sparse autoencoder objective
在sparseAutoencoderCost.m文件中完成前向传播和后向传播等相关代码,如下:
3. Step3 Gradient checking
梯度检查,在computeNumericalGradient.m文件中完成梯度检查的相关代码,如下:
4. Step4 Train the sparse autoencoder
执行train.m文件
参考链接:
/article/5196566.html
网页教程参考:
Exercise:Sparse Autoencoder
Exercise:Sparse Autoencoder
Step1 generate training set
在sampleIMAGES.m文件中完成生成训练集的代码,如下,tic和toc用来计时的:
tic image_size=size(IMAGES); i=randi(image_size(1)-patchsize+1,1,numpatches); j=randi(image_size(2)-patchsize+1,1,numpatches); k=randi(image_size(3),1,numpatches); for num=1:numpatches patches(:,num)=reshape(IMAGES(i(num):i(num)+patchsize-1,j(num):j(num)+patchsize-1,k(num)),1,patchsize*patchsize); end toc
2. Step2 Sparse autoencoder objective
在sparseAutoencoderCost.m文件中完成前向传播和后向传播等相关代码,如下:
%1.forward propagation data_size=size(data); active_value2=repmat(b1,1,data_size(2)); active_value3=repmat(b2,1,data_size(2)); active_value2=sigmoid(W1*data+active_value2); active_value3=sigmoid(W2*active_value2+active_value3); %2.computing error term and cost ave_square=sum(sum((active_value3-data).^2)./2)/data_size(2); weight_decay=lambda/2*(sum(sum(W1.^2))+sum(sum(W2.^2))); p_real=sum(active_value2,2)./data_size(2); p_para=repmat(sparsityParam,hiddenSize,1); sparsity=beta.*sum(p_para.*log(p_para./p_real)+(1-p_para).*log((1-p_para)./(1-p_real))); cost=ave_square+weight_decay+sparsity; delta3=(active_value3-data).*(active_value3).*(1-active_value3); average_sparsity=repmat(sum(active_value2,2)./data_size(2),1,data_size(2)); default_sparsity=repmat(sparsityParam,hiddenSize,data_size(2)); sparsity_penalty=beta.*(-(default_sparsity./average_sparsity)+((1-default_sparsity)./(1-average_sparsity))); delta2=(W2'*delta3+sparsity_penalty).*((active_value2).*(1-active_value2)); %3.backword propagation W2grad=delta3*active_value2'./data_size(2)+lambda.*W2; W1grad=delta2*data'./data_size(2)+lambda.*W1; b2grad=sum(delta3,2)./data_size(2); b1grad=sum(delta2,2)./data_size(2);
3. Step3 Gradient checking
梯度检查,在computeNumericalGradient.m文件中完成梯度检查的相关代码,如下:
EPSILON=0.0001; for i=1:size(theta) theta_plus=theta; theta_minu=theta; theta_plus(i)=theta_plus(i)+EPSILON; theta_minu(i)=theta_minu(i)-EPSILON; numgrad(i)=(J(theta_plus)-J(theta_minu))/(2*EPSILON); end
4. Step4 Train the sparse autoencoder
执行train.m文件
相关文章推荐
- UFLDL教程Exercise答案(1):Sparse Autoencoder
- UFLDL教程: Exercise: Sparse Autoencoder
- UFLDL教程答案(7):Exercise:Learning color features with Sparse Autoencoders
- UFLDL教程Exercise答案(7):Learning color features with Sparse Autoencoders
- UFLDL教程: Exercise:Learning color features with Sparse Autoencoders
- UFLDL教程之一 (Sparse Autoencoder练习)
- Stanford UFLDL教程 Exercise:Sparse Autoencoder
- Deep Learning 1_深度学习UFLDL教程:Sparse Autoencoder练习(斯坦福大学深度学习教程)
- UFLDL教程答案(1):Exercise:Sparse_Autoencoder
- UFLDL——Exercise: Sparse Autoencoder 稀疏自动编码
- UFLDL Exercise:Sparse Autoencoder
- 【UFLDL-exercise1-Sparse Autoencoder】
- Convolutional neural networks(CNN) (三) Sparse Autoencoder Exercise(Vectorization)
- UFLDL教程Exercise答案(3.2):PCA and Whitening
- Exercise:Sparse Autoencoder 代码示例
- UFLDL教程答案(2):Exercise:Vectorization
- UFLDL教程练习(exercise)答案(1)
- 稀疏自编码http://deeplearning.stanford.edu/wiki/index.php/Exercise:Sparse_Autoencoder#Results
- UFLDL教程练习(exercise)答案(2)
- UFLDL教程答案(3):Exercise:PCA_in_2D&PCA_and_Whitening