kernel_pca.h

Go to the documentation of this file.
00001 /* MLPACK 0.2
00002  *
00003  * Copyright (c) 2008, 2009 Alexander Gray,
00004  *                          Garry Boyer,
00005  *                          Ryan Riegel,
00006  *                          Nikolaos Vasiloglou,
00007  *                          Dongryeol Lee,
00008  *                          Chip Mappus, 
00009  *                          Nishant Mehta,
00010  *                          Hua Ouyang,
00011  *                          Parikshit Ram,
00012  *                          Long Tran,
00013  *                          Wee Chin Wong
00014  *
00015  * Copyright (c) 2008, 2009 Georgia Institute of Technology
00016  *
00017  * This program is free software; you can redistribute it and/or
00018  * modify it under the terms of the GNU General Public License as
00019  * published by the Free Software Foundation; either version 2 of the
00020  * License, or (at your option) any later version.
00021  *
00022  * This program is distributed in the hope that it will be useful, but
00023  * WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025  * General Public License for more details.
00026  *
00027  * You should have received a copy of the GNU General Public License
00028  * along with this program; if not, write to the Free Software
00029  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00030  * 02110-1301, USA.
00031  */
00036 #ifndef KERNEL_PCA_H_
00037 #define KERNEL_PCA_H_
00038 
00039 #include <string>
00040 #include <map>
00041 #include <stdio.h>
00042 #include <errno.h>
00043 #include <unistd.h>
00044 #include "fastlib/fastlib.h"
00045 #include "fastlib/la/matrix.h"
00046 #include "fastlib/sparse/sparse_matrix.h"
00047 #include "mlpack/allknn/allknn.h"
00048 
00049 class KernelPCATest;
00110 class KernelPCA {
00111  public:
00112   friend class KernelPCATest;
00118   class GaussianKernel {
00119    public:
00120     void set(double bandwidth) {
00121       bandwidth_ = bandwidth;
00122     }
00123     double operator()(double distance) {
00124       return exp(-distance/bandwidth_);
00125     }
00126    private:
00127     double bandwidth_;
00128   };  
00129   
00130   ~KernelPCA() {
00131     Destruct();
00132   }
00141   void Init(std::string data_file, index_t knns, 
00142       index_t leaf_size);
00143   void Destruct();
00148   void ComputeNeighborhoods();
00152   void LoadAffinityMatrix();
00157   void EstimateBandwidth(double *bandwidth);
00161   static void SaveToTextFile(std::string file, 
00162                              Matrix &eigen_vectors,
00163                              Vector &eigen_values);
00164   static void SaveToBinaryFile(std::string file, 
00165                              Matrix &eigen_vectors,
00166                              Vector &eigen_values);
00173   template<typename DISTANCEKERNEL>    
00174   void ComputeGeneralKernelPCA(DISTANCEKERNEL kernel,
00175                                index_t num_of_eigenvalues,
00176                                Matrix *eigen_vectors,
00177                                Vector *eigen_values);
00181   void ComputeIsomap(index_t num_of_eigenvalues);
00186   void ComputeLLE(index_t num_of_eigenvalues,
00187                   Matrix *eigen_vectors,
00188                   Vector *eigen_values);
00192   template<typename DISTANCEKERNEL>
00193   void ComputeDiffusionMaps(DISTANCEKERNEL kernel, index_t num_of_eigenvalues);
00197   void ComputeLaplacialnEigenmaps(index_t);
00203   template<typename DISTANCEKERNEL>
00204   void ComputeSpectralRegression(DISTANCEKERNEL kernel,
00205                                  std::map<index_t, index_t> &data_label,
00206                                  Matrix *embedded_coordinates, 
00207                                  Vector *eigenvalues);
00208     
00209  private:
00210   AllkNN allknn_;
00211   index_t knns_;
00212   Matrix data_;
00213   SparseMatrix kernel_matrix_;  
00214   SparseMatrix affinity_matrix_;
00215   index_t dimension_;
00216 };
00217 
00218 #include "kernel_pca_impl.h"
00219 #endif
Generated on Mon Jan 24 12:04:38 2011 for FASTlib by  doxygen 1.6.3