mvu_objectives.h

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  */
00032 /*
00033  * =====================================================================================
00034  * 
00035  *       Filename:  mvu_objectives.h
00036  * 
00037  *    Description:  
00038  * 
00039  *        Version:  1.0
00040  *        Created:  03/05/2008 12:00:56 PM EST
00041  *       Revision:  none
00042  *       Compiler:  gcc
00043  * 
00044  *         Author:  Nikolaos Vasiloglou (NV), nvasil@ieee.org
00045  *        Company:  Georgia Tech Fastlab-ESP Lab
00046  * 
00047  * =====================================================================================
00048  */
00049 
00050 #ifndef MVU_OBJECTIVES_H_
00051 #define MVU_OBJECTIVES_H_
00052 #include "fastlib/fastlib.h"
00053 #include "mlpack/allknn/allknn.h"
00054 #include "mlpack/allkfn/allkfn.h"
00055 //#include "mlpack/optimization/lbfgs/optimization_utils.h"
00056 #include "fastlib/optimization/lbfgs/optimization_utils.h"
00057 
00058 const fx_entry_doc mvu_entries[] = {
00059   {"new_dimension", FX_REQUIRED, FX_INT, NULL,
00060    " the number fo dimensions for the unfolded"},
00061   {"nearest_neighbor_file", FX_PARAM, FX_STR, NULL,
00062    " file with the nearest neighbor pairs and the squared distances \n"
00063    " defaults to nearest.txt"},
00064   {"furthest_neighbor_file", FX_PARAM, FX_STR, NULL,
00065    " file with the nearest neighbor pairs and the squared distances "},
00066   {"knns", FX_PARAM, FX_INT, NULL,
00067    " number of nearest neighbors to build the graph\n"
00068    " if you choose the option with the nearest file you don't need to specify it"},
00069  {"leaf_size", FX_PARAM, FX_INT, NULL,
00070    " leaf_size for the tree.\n "
00071    " if you choose the option with the nearest file you don't need to specify it"},
00072 FX_ENTRY_DOC_DONE
00073 };
00074 
00075 const fx_module_doc mvu_doc = {
00076   mvu_entries, NULL,
00077   " This program computes the Maximum Variance Unfolding"
00078   " and the Maximum Futhest Neighbor Unfolding as presented "
00079   " in the paper: \n"
00080   " @conference{vasiloglou2008ssm,\n"
00081   "   title={{Scalable semidefinite manifold learning}},\n"
00082   "   author={Vasiloglou, N. and Gray, A.G. and Anderson, D.V.},\n"
00083   "   booktitle={Machine Learning for Signal Processing, 2008. MLSP 2008. IEEE Workshop on},\n"
00084   "   pages={368--373},\n"
00085   "   year={2008}\n"
00086   " }\n"
00087 };
00088 
00089 class MaxVariance {
00090  public:
00091   static const index_t MAX_KNNS=30;
00092   void Init(fx_module *module, Matrix &data);
00093   void Init(fx_module *module);
00094   void Destruct();
00095   void ComputeGradient(Matrix &coordinates, Matrix *gradient);
00096   void ComputeObjective(Matrix &coordinates, double *objective);
00097   void ComputeFeasibilityError(Matrix &coordinates, double *error);
00098   double ComputeLagrangian(Matrix &coordinates);
00099   void UpdateLagrangeMult(Matrix &coordinates);
00100   void Project(Matrix *coordinates);
00101   void set_sigma(double sigma); 
00102   bool IsDiverging(double objective); 
00103   bool IsOptimizationOver(Matrix &coordinates, 
00104       Matrix &gradient, double step) { return false;}
00105   bool IsIntermediateStepOver(Matrix &coordinates, 
00106       Matrix &gradient, double step) {return false;}
00107   void GiveInitMatrix(Matrix *init_data);
00108  index_t num_of_points();
00109 
00110  private:
00111   datanode *module_;
00112   AllkNN allknn_;
00113   index_t knns_;
00114   index_t leaf_size_;
00115   ArrayList<std::pair<index_t, index_t> > nearest_neighbor_pairs_;
00116   ArrayList<double> nearest_distances_;
00117   Vector eq_lagrange_mult_;
00118   index_t num_of_nearest_pairs_;
00119   double sigma_;
00120   double sum_of_furthest_distances_;
00121   index_t num_of_points_;
00122   index_t new_dimension_;
00123 };
00124 
00125 class MaxFurthestNeighbors {
00126 public:
00127   static const index_t MAX_KNNS=30;
00128   void Init(fx_module *module, Matrix &data);
00129   void Init(fx_module *module);
00130   void Destruct();
00131   void ComputeGradient(Matrix &coordinates, Matrix *gradient);
00132   void ComputeObjective(Matrix &coordinates, double *objective);
00133   void ComputeFeasibilityError(Matrix &coordinates, double *error);
00134   double ComputeLagrangian(Matrix &coordinates);
00135   void UpdateLagrangeMult(Matrix &coordinates);
00136   void Project(Matrix *coordinates);
00137   void set_sigma(double sigma); 
00138   void set_lagrange_mult(double val);
00139   bool IsDiverging(double objective); 
00140   bool IsOptimizationOver(Matrix &coordinates, 
00141       Matrix &gradient, double step) ;
00142   bool IsIntermediateStepOver(Matrix &coordinates, 
00143       Matrix &gradient, double step); 
00144   index_t num_of_points();
00145   void GiveInitMatrix(Matrix *init_data);
00146 
00147 private:
00148   datanode *module_;
00149   AllkNN allknn_;
00150   AllkFN allkfn_;
00151   index_t knns_;
00152   index_t leaf_size_;
00153   ArrayList<std::pair<index_t, index_t> > nearest_neighbor_pairs_;
00154   ArrayList<double> nearest_distances_;
00155   Vector eq_lagrange_mult_;
00156   index_t num_of_nearest_pairs_;
00157   index_t num_of_furthest_pairs_;
00158   ArrayList<std::pair<index_t, index_t> > furthest_neighbor_pairs_;
00159   ArrayList<double> furthest_distances_;
00160   double sum_of_furthest_distances_;
00161   double sigma_;
00162   index_t num_of_points_;
00163   index_t new_dimension_;
00164   double infeasibility1_;
00165   double previous_infeasibility1_;
00166   double desired_feasibility_error_;
00167   double infeasibility_tolerance_;
00168   double sum_of_nearest_distances_;
00169   double grad_tolerance_;
00170 };
00171 
00172 class MaxVarianceUtils {
00173  public:
00174   static void ConsolidateNeighbors(ArrayList<index_t> &from_tree_ind,
00175       ArrayList<double>  &from_tree_dist,
00176       index_t num_of_neighbors,
00177       index_t chosen_neighbors,
00178       ArrayList<std::pair<index_t, index_t> > *neighbor_pairs,
00179       ArrayList<double> *distances,
00180       index_t *num_of_pairs);
00181   static void EstimateKnns(ArrayList<index_t> &neares_neighbors,
00182                                        ArrayList<double> &nearest_distances,
00183                                        index_t maximum_knns, 
00184                                        index_t num_of_points,
00185                                        index_t dimension,
00186                                        index_t *optimum_knns); 
00187 };
00188 
00189 #include "mvu_objectives_impl.h"
00190 #endif //MVU_OBJECTIVES_H_
Generated on Mon Jan 24 12:04:38 2011 for FASTlib by  doxygen 1.6.3