00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
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
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_