diff --git a/fastlib2/contrib/nvasil/mvu/main.cc b/fastlib2/contrib/nvasil/mvu/main.cc index d8818e99d1..9ff0a26d1a 100644 --- a/fastlib2/contrib/nvasil/mvu/main.cc +++ b/fastlib2/contrib/nvasil/mvu/main.cc @@ -32,13 +32,13 @@ int main(int argc, char *argv[]){ datanode *optfun_node; datanode *l_bfgs_node; l_bfgs_node=fx_submodule(NULL, "opts/l_bfgs", "l_bfgs"); - optfun_node=fx_submodule(NULL, "opts/l_bfgs", "optfun"); + optfun_node=fx_submodule(NULL, "opts/optfun", "optfun"); //we need to insert the number of points char buffer[128]; sprintf(buffer, "%i", data_mat.n_cols()); fx_set_param(l_bfgs_node, "num_of_points", buffer); - std::string result_file=fx_param_str(NULL, "result_file", "result.csv"); + std::string result_file=fx_param_str(NULL, "opts/result_file", "result.csv"); bool done=false; if (optimized_function == "mvu") { diff --git a/fastlib2/contrib/nvasil/mvu/mvu_objectives.h b/fastlib2/contrib/nvasil/mvu/mvu_objectives.h index 76aa31dca3..4ea1aede5d 100644 --- a/fastlib2/contrib/nvasil/mvu/mvu_objectives.h +++ b/fastlib2/contrib/nvasil/mvu/mvu_objectives.h @@ -33,7 +33,8 @@ class MaxVariance { void UpdateLagrangeMult(Matrix &coordinates); void Project(Matrix *coordinates); void set_sigma(double sigma); - + bool IsDiverging(double objective); + private: datanode *module_; AllkNN allknn_; @@ -62,7 +63,8 @@ class MaxVarianceInequalityOnFurthest { double ComputeLagrangian(Matrix &coordinates); void UpdateLagrangeMult(Matrix &coordinates); void Project(Matrix *coordinates); - void set_sigma(double sigma); + void set_sigma(double sigma); + bool IsDiverging(double objective); private: datanode *module_; @@ -78,7 +80,6 @@ class MaxVarianceInequalityOnFurthest { index_t num_of_furthest_pairs_; ArrayList > furthest_neighbor_pairs_; ArrayList furthest_distances_; - double sigma_; void ConsolidateNeighbors_(ArrayList &from_tree_ind, @@ -99,8 +100,9 @@ public: void UpdateLagrangeMult(Matrix &coordinates); void Project(Matrix *coordinates); void set_sigma(double sigma); - - private: + bool IsDiverging(double objective); + +private: datanode *module_; AllkNN allknn_; AllkFN allkfn_; @@ -113,7 +115,7 @@ public: index_t num_of_furthest_pairs_; ArrayList > furthest_neighbor_pairs_; ArrayList furthest_distances_; - + double sum_of_furthest_distances_; double sigma_; void ConsolidateNeighbors_(ArrayList &from_tree_ind, diff --git a/fastlib2/contrib/nvasil/mvu/mvu_objectives_impl.h b/fastlib2/contrib/nvasil/mvu/mvu_objectives_impl.h index 0481013aa8..f2bcea8ff4 100644 --- a/fastlib2/contrib/nvasil/mvu/mvu_objectives_impl.h +++ b/fastlib2/contrib/nvasil/mvu/mvu_objectives_impl.h @@ -40,7 +40,7 @@ void MaxVariance::Init(datanode *module, Matrix &data) { &num_of_nearest_pairs_); eq_lagrange_mult_.Init(num_of_nearest_pairs_); eq_lagrange_mult_.SetAll(1.0); - + fx_format_result(module_, "num_of_constraints", "%i", num_of_nearest_pairs_); } void MaxVariance::ComputeGradient(Matrix &coordinates, Matrix *gradient) { @@ -128,6 +128,10 @@ void MaxVariance::set_sigma(double sigma) { sigma_=sigma; } +bool MaxVariance::IsDiverging(double feasibility_error){ + return false; +} + void MaxVariance::ConsolidateNeighbors_(ArrayList &from_tree_ind, ArrayList &from_tree_dist, index_t num_of_neighbors, @@ -189,6 +193,7 @@ void MaxVarianceInequalityOnFurthest::Init(datanode *module, Matrix &data) { &nearest_neighbor_pairs_, &nearest_distances_, &num_of_nearest_pairs_); + fx_format_result(module_, "num_of_constraints", "%i", num_of_nearest_pairs_); eq_lagrange_mult_.Init(num_of_nearest_pairs_); eq_lagrange_mult_.SetAll(1.0); NOTIFY("Furtherst neighbor constraints ...\n"); @@ -360,6 +365,10 @@ void MaxVarianceInequalityOnFurthest::set_sigma(double sigma) { sigma_=sigma; } +bool MaxVarianceInequalityOnFurthest::IsDiverging(double feasibility_error){ + return false; +} + void MaxVarianceInequalityOnFurthest::ConsolidateNeighbors_(ArrayList &from_tree_ind, ArrayList &from_tree_dist, index_t num_of_neighbors, @@ -414,6 +423,7 @@ void MaxFurthestNeighbors::Init(datanode *module, Matrix &data) { ArrayList from_tree_distances; allknn_.ComputeNeighbors(&from_tree_neighbors, &from_tree_distances); + NOTIFY("Neighborhoods computed...\n"); NOTIFY("Consolidating neighbors...\n"); ConsolidateNeighbors_(from_tree_neighbors, @@ -422,6 +432,8 @@ void MaxFurthestNeighbors::Init(datanode *module, Matrix &data) { &nearest_neighbor_pairs_, &nearest_distances_, &num_of_nearest_pairs_); + + fx_format_result(module_, "num_of_constraints", "%i", num_of_nearest_pairs_); eq_lagrange_mult_.Init(num_of_nearest_pairs_); eq_lagrange_mult_.SetAll(1.0); NOTIFY("Furtherst neighbor constraints ...\n"); @@ -441,6 +453,14 @@ void MaxFurthestNeighbors::Init(datanode *module, Matrix &data) { &furthest_neighbor_pairs_, &furthest_distances_, &num_of_furthest_pairs_); + double max_nearest_distance=0; + for(index_t i=0; i &from_tree_ind, ArrayList &from_tree_dist, index_t num_of_neighbors,