Exercise:PCA in 2D

习题的链接:Exercise:PCA in 2D

pca_2d.m

close all

%%================================================================
%% Step : Load data
% We have provided the code to load data from pcaData.txt into x.
% x is a * matrix, where the kth column x(:,k) corresponds to
% the kth data point.Here we provide the code to load natural image data into x.
% You do not need to change the code below. x = load('pcaData.txt','-ascii');
figure();
scatter(x(, :), x(, :));
title('Raw data'); %%================================================================
%% Step 1a: Implement PCA to obtain U
% Implement PCA to obtain the rotation matrix U, which is the eigenbasis
% sigma. % -------------------- YOUR CODE HERE --------------------
%u = zeros(size(x, )); %You need to compute this
sigma = (x*x') ./ size(x,2); %covariance matrix
[u,s,v] = svd(sigma); % --------------------------------------------------------
hold on
plot([ u(,)], [ u(,)]);
plot([ u(,)], [ u(,)]);
scatter(x(, :), x(, :));
hold off %%================================================================
%% Step 1b: Compute xRot, the projection on to the eigenbasis
% Now, compute xRot by projecting the data on to the basis defined
% by U. Visualize the points by performing a scatter plot. % -------------------- YOUR CODE HERE --------------------
%xRot = zeros(size(x)); % You need to compute this
xRot = u'*x; % -------------------------------------------------------- % Visualise the covariance matrix. You should see a line across the
% diagonal against a blue background.
figure();
scatter(xRot(, :), xRot(, :));
title('xRot'); %%================================================================
%% Step : Reduce the number of dimensions from to .
% Compute xRot again (this time projecting to dimension).
% Then, compute xHat by projecting the xRot back onto the original axes
% to see the effect of dimension reduction % -------------------- YOUR CODE HERE --------------------
k = ; % Use k = and project the data onto the first eigenbasis
%xHat = zeros(size(x)); % You need to compute this
%Recovering an Approximation of the Data
xRot(k+:size(x,), :) = ;
xHat = u*xRot; % --------------------------------------------------------
figure();
scatter(xHat(, :), xHat(, :));
title('xHat'); %%================================================================
%% Step : PCA Whitening
% Complute xPCAWhite and plot the results. epsilon = 1e-;
% -------------------- YOUR CODE HERE --------------------
%xPCAWhite = zeros(size(x)); % You need to compute this
xPCAWhite = diag( ./ sqrt(diag(s)+epsilon)) * u' * x; % --------------------------------------------------------
figure();
scatter(xPCAWhite(, :), xPCAWhite(, :));
title('xPCAWhite'); %%================================================================
%% Step : ZCA Whitening
% Complute xZCAWhite and plot the results. % -------------------- YOUR CODE HERE --------------------
%xZCAWhite = zeros(size(x)); % You need to compute this
xZCAWhite = u * xPCAWhite; % --------------------------------------------------------
figure();
scatter(xZCAWhite(, :), xZCAWhite(, :));
title('xZCAWhite'); %% Congratulations! When you have reached this point, you are done!
% You can now move onto the next PCA exercise. :)

【DeepLearning】Exercise:PCA in 2D的更多相关文章

  1. 【DeepLearning】Exercise:PCA and Whitening

    Exercise:PCA and Whitening 习题链接:Exercise:PCA and Whitening pca_gen.m %%============================= ...

  2. 【DeepLearning】Exercise:Convolution and Pooling

    Exercise:Convolution and Pooling 习题链接:Exercise:Convolution and Pooling cnnExercise.m %% CS294A/CS294 ...

  3. 【DeepLearning】Exercise:Softmax Regression

    Exercise:Softmax Regression 习题的链接:Exercise:Softmax Regression softmaxCost.m function [cost, grad] = ...

  4. 【DeepLearning】Exercise:Learning color features with Sparse Autoencoders

    Exercise:Learning color features with Sparse Autoencoders 习题链接:Exercise:Learning color features with ...

  5. 【DeepLearning】Exercise: Implement deep networks for digit classification

    Exercise: Implement deep networks for digit classification 习题链接:Exercise: Implement deep networks fo ...

  6. 【DeepLearning】Exercise:Self-Taught Learning

    Exercise:Self-Taught Learning 习题链接:Exercise:Self-Taught Learning feedForwardAutoencoder.m function [ ...

  7. 【DeepLearning】Exercise:Vectorization

    Exercise:Vectorization 习题的链接:Exercise:Vectorization 注意点: MNIST图片的像素点已经经过归一化. 如果再使用Exercise:Sparse Au ...

  8. 【DeepLearning】Exercise:Sparse Autoencoder

    Exercise:Sparse Autoencoder 习题的链接:Exercise:Sparse Autoencoder 注意点: 1.训练样本像素值需要归一化. 因为输出层的激活函数是logist ...

  9. 【UFLDL】Exercise: Convolutional Neural Network

    这个exercise需要完成cnn中的forward pass,cost,error和gradient的计算.需要弄清楚每一层的以上四个步骤的原理,并且要充分利用matlab的矩阵运算.大概把过程总结 ...

随机推荐

  1. 使用Java语言开发微信公众平台(八)——自定义菜单功能

    随着上一篇文章的结束,我们已经实现了所有消息的类型的回复功能.今天,我们来学习更加高大上,也更加重要的自定义菜单功能. 一.了解自定义菜单 自定义菜单是微信公众平台最常用也是最重要的功能之一.根据微信 ...

  2. 用Python开始机器学习(2:决策树分类算法)

    http://blog.csdn.net/lsldd/article/details/41223147 从这一章开始进入正式的算法学习. 首先我们学习经典而有效的分类算法:决策树分类算法. 1.决策树 ...

  3. JavaScript筛选出数组种连续的数字

    function arrange(source) { var t; var ta; var r = []; for(var j=0;j<source.length;j++){ var v=sou ...

  4. iredmail安装问题

    =================================== 已解决::::(据铭哥说 只有最新版0.9.2才会出现这个问题) 解决办法::(都是IPv6惹的祸) vi /etc/dovec ...

  5. 【BLE】CC2541之加入自己定义任务

    本篇博文最后改动时间:2017年01月06日,11:06. 一.简单介绍 本文介绍怎样在SimpleBLEPeripheralproject中.加入一个香瓜任务. (香瓜任务与project原有任务相 ...

  6. angular5 基于ngx-translate实现多语言切换

    angular的坑永远都是那么多,当然了,主要还是我太菜~ 基于ngx-translate实现多语言切换这个功能,我又是折腾了很久,下面是我实现的过程: 1.安装ngx-translate 需要安装@ ...

  7. IE6.0 PNG背景透明图片插件

    <!--[if lte IE 6]><script src="http://xian.qq.com/js/2013js/2013index/DD_belatedPNG_0. ...

  8. Windows服务安装与控制

    Windows服务安装与控制 1.建立服务 (1)定义一个ServiceInstaller using System; using System.Collections.Generic; using ...

  9. vue循环中的v-show

    v-show如果使用循环对象的属性来时控制, 这个属性必须是加载时就存在的 <div class="list-group col-sm-12" v-for="(is ...

  10. Cocos开发中可能会遇到的问题

      开发中碰到的问题及解决方案: 1:场景工程中没有被依赖关联的图片声音或者其它资源,导出到微信后找不到 有些在场景工程中没有指定而通过代码中动态加载的资源,cocos creator不会导出到发布目 ...