降維工具箱drtool


工具箱下載:http://leelab.googlecode.com/svn/trunk/apps/drtoolbox/

————————————————————————————————————————————

參考:https://chunqiu.blog.ustc.edu.cn/?p=413

  這個工具箱的 主頁如下,現在的最新版本是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.
 
有關流形學習
    之前看過一些流行學習的博文,推薦一篇
流形學習
    另外,有人做了個好事情,做了個系統,把幾個流行方法的matlab代碼放在了一起 http://www.math.ucla.edu/~wittman/mani/

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM