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. Ubuntu升级到18.04

    1.更新 sudo apt-get update 2.升级 sudo apt-get upgrade 3.检测最新版本 sudo update-manager -c -d 然后就会弹出窗口,提示ubu ...

  2. Kendall's tau-b(肯德尔)等级相关系数

    Kendall's tau-b(肯德尔)等级相关系数:用于反映分类变量相关性的指标,适用于两个分类变量均为有序分类的情况.对相关的有序变量进行非参数相关检验:取值范围在-1-1之间,此检验适合于正方形 ...

  3. xshell tunnel的使用

    原文:https://www.jianshu.com/p/388a93b1e7f7 https://blog.csdn.net/qq_34039315/article/details/77510923 ...

  4. 转:写的不错的eclipse配置cdt的文章

    http://jingpin.jikexueyuan.com/article/22803.html

  5. Docker实战之创建一个tomcat容器

    一.Docker与虚拟机的区别 二.Docker学习步骤 2.1:安装宿主操作系统 在VMVare中安装了Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-62-generic ...

  6. Oracle中对数字加汉字的排序(完好)

    之前写过一篇 Oracle中对数字加汉字的排序以及REGEXP_SUBSTR介绍 后来在开发的过程中又遇到相似问题.数据不一样了,按之前的使用方法是不适用的. 之前的是数字在前汉字在后,最基本的差别是 ...

  7. C118+OSMCOMBB嗅探短信

    ubuntu系统:12.04.4, 下载地址:http://cdimage.ubuntu.com/releases/12.04.4/release/ 编译环境下载 : http://pan.baidu ...

  8. Ubuntu IntelliJ IDEA 注冊碼與Gradle相關

    一.Ubuntu IntelliJ IDEA 注冊碼 在线免费生成IntelliJ IDEA 15.0(16.+)注册码 注冊參考:https://www.iteblog.com/idea/ 依次选择 ...

  9. RPi Desktop盒子安装与服务配置

    批量安装配置盒子时候,可以先安装一个,其余的从这台copy过去. 之前的部分shell记录在本地,记录如下,以免忘记.下次可直接cp执行即可: Step1, 创建用户/组 sudo groupadd ...

  10. PYQT实现简单的浏览器功能

    主要的类 QMainWindow 提供一个有菜单条.锚接窗口(例如工具条)和一个状态条的主应用程序窗口. http://www.kuqin.com/qtdocument/qmainwindow.htm ...