zoukankan      html  css  js  c++  java
  • matlab 降维工具 转载【https://blog.csdn.net/tarim/article/details/51253536】

    降维工具箱drtool


      这个工具箱的主页如下,现在的最新版本是2013.3.21更新,版本v0.8.1b
        这里有两个这个工具箱的简单介绍:
    【Matlab】数据降维工具箱drtoolbox
    【Dimensionality Reduction】数据降维方法分类
     
        下面稍详细介绍一些这个工具箱。下载压缩包,解压后里面有一个Readme.txt文档,里面写有工具箱的相关介绍,这里做简单翻译吧。
    安装
        把解压后的文件夹放到$MATLAB_DIR/toolbox下,当然也可以放到任意自己想放的路径,然后打开matlab设置路径Set Path,选择'Add with subfolders...',选中drtoolbox,保存即可。
        设置完成后,需要对函数做编译,虽然一些压缩包自带一些编译好的mex文件,但可能并不适合你的平台,所以最好在自己电脑上完成编译,方法是让matlab进入drtoolbox文件,然后运行mexall命令。
    特性
        当前版本的工具箱包括34种数据降维技术,如下,这些可以通过compute_mapping函数或GUI调用:
    - Principal Component Analysis ('PCA') ---主成分分析
    - Linear Discriminant Analysis ('LDA') ---线性判别分析
    - Multidimensional scaling ('MDS') ---多维尺度分析
    - Probabilistic PCA ('ProbPCA')
    - Factor analysis ('FactorAnalysis') ---因子分析
    - Sammon mapping ('Sammon')
    - Isomap ('Isomap') ---等距映射
    - Landmark Isomap ('LandmarkIsomap')
    - Locally Linear Embedding ('LLE') ---局部线性嵌入
    - Laplacian Eigenmaps ('Laplacian') ---Laplacian特征映射
    - Hessian LLE ('HessianLLE')
    - Local Tangent Space Alignment ('LTSA') ---局部切空间排列
    - Diffusion maps ('DiffusionMaps')
    - Kernel PCA ('KernelPCA') ---核主成分分析
    - Generalized Discriminant Analysis ('KernelLDA')
    - Stochastic Neighbor Embedding ('SNE')
    - Symmetric Stochastic Neighbor Embedding ('SymSNE')
    - t-Distributed Stochastic Neighbor Embedding ('tSNE')
    - Neighborhood Preserving Embedding ('NPE')
    - Locality Preserving Projection ('LPP') ---局部保留投影
    - Stochastic Proximity Embedding ('SPE')
    - Linear Local Tangent Space Alignment ('LLTSA')
    - Conformal Eigenmaps ('CCA', implemented as an extension of LLE)
    - Maximum Variance Unfolding ('MVU', implemented as an extension of LLE) ---最大方差展开
    - Landmark Maximum Variance Unfolding ('LandmarkMVU')
    - Fast Maximum Variance Unfolding ('FastMVU')
    - Locally Linear Coordination ('LLC')
    - Manifold charting ('ManifoldChart')
    - Coordinated Factor Analysis ('CFA')
    - Gaussian Process Latent Variable Model ('GPLVM')
    - Deep autoencoders ('Autoencoder')
    - Neighborhood Components Analysis ('NCA')
    - Maximally Collapsing Metric Learning ('MCML')
    - Large Margin Nearest Neighhbor metric learning ('LMNN')
        这些算法在【Dimensionality Reduction】数据降维方法分类http://blog.csdn.net/xiaowei_cqu/article/details/7522368中有个小结,这里引用如下:
    线性/非线性
        线性降维是指通过降维所得到的低维数据能保持高维数据点之间的线性关系。线性降维方法主要包括PCA、LDA、LPP(LPP其实是Laplacian Eigenmaps的线性表示);非线性降维一类是基于核的,如KPCA,此处暂不讨论,另一类就是通常所说的流形学习:从高维采样数据中恢复出低维流形结构(假设数据是均匀采样于一个高维欧式空间中的低维流形),即找到高维空间中的低维流形,并求出相应的嵌入映射。非线性流形学习方法有:Isomap、LLE、Laplacian Eigenmaps、LTSA、MVU。
        整体来说,线性方法计算块,复杂度低,但对复杂的数据降维效果较差。
    监督/非监督
        监督式和非监督式学习的主要区别在于数据样本是否存在类别信息。非监督降维方法的目标是在降维时使得信息的损失最小,如PCA、LPP、Isomap、LLE、Laplacian Eigenmaps、LTSA、MVU;监督式降维方法的目标是最大化类别间的辨别信,如LDA。事实上,对于非监督式降维算法,都有相应的监督式或半监督式方法的研究。
    全局/局部
        局部方法仅考虑样品集合的局部信息,即数据点与临近点之间的关系。局部方法以LLE为代表,还包括Laplacian Eigenmaps、LPP、LTSA。
        全局方法不仅考虑样本几何的局部信息,和考虑样本集合的全局信息,及样本点与非临近点之间的关系。全局算法有PCA、LDA、Isomap、MVU。
        由于局部方法并不考虑数据流形上相距较远的样本之间的关系,因此,局部方法无法达到“使在数据流形上相距较远的样本的特征也相距较远”的目的。
     
        以下是对一组三维数据(900样本)降到一维,应用八种算法的时间对比:
     
        另外,工具箱还提供6种技术做本质维度估计intrinsic dimensionality estimation如下,就是估计降到多少维较好。这些技术可以利用intrinsic_dim函数调用。
    - Eigenvalue-based estimation ('EigValue')
    - Maximum Likelihood Estimator ('MLE')
    - Estimator based on correlation dimension ('CorrDim')
    - Estimator based on nearest neighbor evaluation ('NearNb')
    - Estimator based on packing numbers ('PackingNumbers')
    - Estimator based on geodesic minimum spanning tree ('GMST')
        此外,工具箱还包括数据白化函数prewhiten、样本外点外延的计算和估计out_of_sample(或out_of_sample_est)和产生测试数据集函数generate_data。这些方法和函数都可以通过GUI方便的调用,drgui可以调出此GUI,如下,样子比较粗糙,使用还算方便,工具箱具有的功能一目了然
    用法
        这个工具箱提供给用户使用的接口函数都在与这个Readme文件同路径的目录,主要包括如下文件:(基本上面都提到过)
    compute_mapping.m     This function performs the specified dimension reduction technique on the specified data set. Type HELP COMPUTE_MAPPING to get details on supported techniques and on the parameters of the techniques. 在指定的数据集上执行指定的降维技术。help compute_mapping可以查看函数用法和参数选项。
    drgui.m  This function allows you to use some of the toolbox functionality via a graphical user interface. 打开GUI,方便调用工具箱函数。
    generate_data.m     This function generates some artificial data sets such as the Swiss roll data set. 产生一些人工数据集,如Swiss环数据。
    intrinsic_dim.m   This function performs intrinsic dimensionality estimation using the specified estimator on the specified data set. 使用指定的估计器对指定的数据做本质维数估计。
    mexall.m      This function compiles all the MEX-files that are required to use the toolbox. Please run immediately after installation. 编译这个工具箱需要的所有mex文件。安装后请先运行此函数。
    out_of_sample.m      This function takes as input a dimension reduction mapping and a set of new test points, and outputs the locations of the test points in the reduced space. This function is only supported by parametric and spectral techniques. 以降维后的映射和新测试点为输入,输出这些新测试点在降维空间中的位置,这个函数只支持参数化和谱分析技术的样本外点外延。
    out_of_sample_est.m    This function takes as input a training set, a reduced version of that training set, and a set of new test points, and finds an approximate locations of the test points in the reduced space. Only use this function for techniques that do not support out-of-sample-extensions. 以训练集、维度降低后的训练集和一些新测试点为输入来找到这些新测试点在低维空间的大概位置。这个函数只适用于那些不支持样本外点外延的技术。
    prewhiten.m   This function whitens data, i.e., it makes it zero-mean, identity-covariance 数据白化,即去均值、协方差单位化。
    reconstruct_data.m    This function computes reconstructions of reduced data for linear techniques and autoencoders. 对线性技术和自编码技术做降维数据重构。
    test_toolbox.m  This function runs a full test of all functionalities of the toolbox. 快速对工具箱的所有函数做全测试。
         下面也是使用工具箱的例子,我做了整理和注释
    clc
    clear
    close all
     
    % 产生测试数据
    [X, labels] = generate_data('helix', 2000);
    figure
    scatter3(X(:,1), X(:,2), X(:,3), 5, labels)
    title('Original dataset')
    drawnow
     
    % 估计本质维数
    no_dims = round(intrinsic_dim(X, 'MLE'));
    disp(['MLE estimate of intrinsic dimensionality: ' num2str(no_dims)]);
     
    % PCA降维
    [mappedX, mapping] = compute_mapping(X, 'PCA', no_dims);
    figure
    scatter(mappedX(:,1), mappedX(:,2), 5, labels)
    title('Result of PCA')
     
    % Laplacian降维
    [mappedX, mapping] = compute_mapping(X, 'Laplacian', no_dims, 7);
    figure
    scatter(mappedX(:,1), mappedX(:,2), 5, labels(mapping.conn_comp))
    title('Result of Laplacian Eigenmaps')
    drawnow
     
    % Isomap降维
    [mappedX, mapping] = compute_mapping(X, 'Isomap', no_dims);
    figure
    scatter(mappedX(:,1), mappedX(:,2), 5, labels(mapping.conn_comp))
    title('Result of Isomap')
    drawnow
     
        运行结果如下
        此工具箱所有函数都可以用在著名模式识别PRTools工具箱的数据集上(http://prtools.org)。有关降维的更多选项可以看compute_mapping的帮助,help compute_mapping;有关本质维数估计的更多信息可以看intrinsic_dim的帮助,help intrinsic_dim。
    使用中的问题
        如果你在运行此工具箱的函数时,得到某些文件不存在的错误,这可能是因为一些mex函数被使用了。虽然工具箱提供了一些mex函数的编译版本,但可能并不适合你的平台,所以这个问题可以通过运行mexall函数编译全部mex函数来解决。这个命令也可以解决Isomap算法最短路径计算慢的问题。
        如果在运行FastMVU算法时遇到有关CSDP的错误,这是由于你平台上的二进制CSDP丢失的缘故。可以在网站https://projects.coin-or.org/Csdp/上得到二进制CSDP的发布版本,将其放在drtoolbox/techniques文件夹下即可。注意确保不同平台正确的文件名(csdp.exe for Windows, csdpmac for Mac OS X (PowerPC), csdpmaci for Mac OS X (Intel), and csdplinux for Linux)。
        很多降维方法都要执行稀疏矩阵的谱分析。当然特征值分析eigenanalysis是一个常用的方法,但大矩阵的特征值分解可能会很耗时,所以工具箱提供了两种特征值分析方法:
    - The original Matlab functions (based on Arnoldi methods)
    - The JDQR functions (based on Jacobi-Davidson methods)
    对于10000点以内的问题,建议使用Matlab setting,超过10000点,则JDQR值得一试。
     
        其他一些常见问题FAQ可以在http://homepage.tudelft.nl/19j49/Matlab_Toolbox_for_Dimensionality_Reduction.html中找到,这里简单说一下,详查上面网站
    1. When using the toolbox, the code quits saying that some function could not be found?
        运行出错、函数找不到的问题,上面已提到,一个原因也没添加路径,还有可能是与其他工具箱的函数冲突,如PCA函数,可以使用which命令找相关原因。如果报错说找不到bsxfun函数,这是因为你的matlab版本过低,没有提供这个函数,可以用这个代码代替http://www.mathworks.com/matlabcentral/fileexchange/18685
    2. Next to reducing the dimensionality of my data, Isomap/LLE/Laplacian Eigenmaps/LTSA also reduced the number of data points? Where did these points go?
        Isomap/LLE/Laplacian Eigenmaps/LTSA算法使用后,数据点数减少的问题。这个是基于邻域图的算法的普遍行为,这些算法把数据嵌入到相关连邻域图中,如果邻域图不相关连,则只嵌入最大关连成分,从而带来数据点数的减少。你可以通过mapping.conn_comp得到嵌入数据点的次序,mapping由调用compute_mapping函数得到。如果你不想丢失数据点,就不要用流形学习算法。
    3. How do I provide label information to the supervised techniques/metric learners?
        如何在监督学习中提供标签信息。在监督学习算法中(LDA, NCA, MCML, and LMNN),可以设置数据矩阵的第一列元素为相应标签,这些标签一定要是数值型的。如果要嵌入测试数据,则在out_of_sample函数中使用无标签的数据。
    4. How do I project low-dimensional data back into the data space?
        如何将低维数据映射回原空间。能反向映射的算法只有使用了线性技术、自编码和GPLVM的算法,但这个功能工具箱现在还不提供。
    5. Which techniques support an exact out-of-sample extension?
        哪些方法支持准确的样本外点外延。只有参数化降维技术,即学习得到一个原数据空间和低维潜在空间的确切函数的算法,支持准确的样本外点外延。所有的线性技术(PCA, LDA, NCA, MCML, LPP, and NPE)和自编码技术支持准确外延。谱分析技术如Isomap, LLE, and Laplacian Eigenmaps,支持基于Nyström approximation的样本外点外延估计。外延使用工具箱函数out_of_sample实现。
    6. Which technique should I use to visualize high-dimensional data in a scatter plot?
        哪些技术适合在散点图上展示高维数据。t-SNE是最适合的算法;流形学习常常并不适于数据展示,因为它有协方差约束的问题;参数化技术通常也不适合展示,因为他们在数据和展示之间存在约束。
     
    相关参考文献
    - L.J.P. van der Maaten, E.O. Postma, and H.J. van den Herik. Dimensionality Reduction: A Comparative Review. Tilburg University Technical Report, TiCC-TR 2009-005, 2009.
    - L.J.P. van der Maaten and G.E. Hinton. Visualizing High-Dimensional Data Using t-SNE. Journal of Machine Learning Research 9(Nov):2579-2605, 2008.
  • 相关阅读:
    挺好的 "简历修改"
    请问谁会破解QQ空间相册的密码呀教我下谢谢!!。
    SEO工具,站长必备
    解决vs2005自带水晶报表次数的限制的次数
    虚拟主机如何实现泛域名解析?
    读出数据库里面的数据,来 绑定列表框 DropDownList1
    取出数据里面相同的记录
    如何让文本框输入字母自动换行???? 很有意思的哦 
    net事件丢失解决方法
    暑假集训每日一题0727 (网络流)
  • 原文地址:https://www.cnblogs.com/xiaolong19910914/p/8686725.html
Copyright © 2011-2022 走看看