close to automatic tuning
This commit is contained in:
@@ -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") {
|
||||
|
||||
@@ -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<std::pair<index_t, index_t> > furthest_neighbor_pairs_;
|
||||
ArrayList<double> furthest_distances_;
|
||||
|
||||
double sigma_;
|
||||
|
||||
void ConsolidateNeighbors_(ArrayList<index_t> &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<std::pair<index_t, index_t> > furthest_neighbor_pairs_;
|
||||
ArrayList<double> furthest_distances_;
|
||||
|
||||
double sum_of_furthest_distances_;
|
||||
double sigma_;
|
||||
|
||||
void ConsolidateNeighbors_(ArrayList<index_t> &from_tree_ind,
|
||||
|
||||
@@ -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<index_t> &from_tree_ind,
|
||||
ArrayList<double> &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<index_t> &from_tree_ind,
|
||||
ArrayList<double> &from_tree_dist,
|
||||
index_t num_of_neighbors,
|
||||
@@ -414,6 +423,7 @@ void MaxFurthestNeighbors::Init(datanode *module, Matrix &data) {
|
||||
ArrayList<double> 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<num_of_nearest_pairs_; i++) {
|
||||
max_nearest_distance=std::max(nearest_distances_[i], max_nearest_distance);
|
||||
}
|
||||
sum_of_furthest_distances_=-max_nearest_distance*
|
||||
data.n_cols()*num_of_furthest_pairs_;
|
||||
|
||||
NOTIFY("****************%lg", sum_of_furthest_distances_);
|
||||
}
|
||||
|
||||
void MaxFurthestNeighbors::ComputeGradient(Matrix &coordinates, Matrix *gradient) {
|
||||
@@ -545,6 +565,16 @@ void MaxFurthestNeighbors::set_sigma(double sigma) {
|
||||
sigma_=sigma;
|
||||
}
|
||||
|
||||
bool MaxFurthestNeighbors::IsDiverging(double objective) {
|
||||
if (objective < sum_of_furthest_distances_) {
|
||||
NOTIFY("objective(%lg) < sum_of_furthest_distances (%lg)", objective,
|
||||
sum_of_furthest_distances_);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void MaxFurthestNeighbors::ConsolidateNeighbors_(ArrayList<index_t> &from_tree_ind,
|
||||
ArrayList<double> &from_tree_dist,
|
||||
index_t num_of_neighbors,
|
||||
|
||||
Reference in New Issue
Block a user