summaryrefslogtreecommitdiff
path: root/src/Witness_complex/example
diff options
context:
space:
mode:
authorskachano <skachano@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-07-06 07:04:53 +0000
committerskachano <skachano@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-07-06 07:04:53 +0000
commit1bcbd5e259d3c13211a9b71c66cacadaad35404c (patch)
tree9d67535366c6cfa3455382fdfa6d758b9c967f41 /src/Witness_complex/example
parentd4c823dce7436f561c8cd545f5a4f80d2d301ca1 (diff)
Corrected errors in witness_complex_cube
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/witness@680 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: e0a33544c992889344cdaaed947479a5bc458ce3
Diffstat (limited to 'src/Witness_complex/example')
-rw-r--r--src/Witness_complex/example/witness_complex_cube.cpp59
-rw-r--r--src/Witness_complex/example/witness_complex_flat_torus.cpp6
-rw-r--r--src/Witness_complex/example/witness_complex_perturbations.cpp20
-rw-r--r--src/Witness_complex/example/witness_complex_sphere.cpp7
4 files changed, 44 insertions, 48 deletions
diff --git a/src/Witness_complex/example/witness_complex_cube.cpp b/src/Witness_complex/example/witness_complex_cube.cpp
index 7545f156..b6051a5f 100644
--- a/src/Witness_complex/example/witness_complex_cube.cpp
+++ b/src/Witness_complex/example/witness_complex_cube.cpp
@@ -291,8 +291,8 @@ bool triangulation_is_protected(Delaunay_triangulation& t, FT delta)
void fill_landmarks(Point_Vector& W, Point_Vector& landmarks, std::vector<int>& landmarks_ind)
{
- for (int j = 0; j < landmarks_ind.size(); ++j)
- landmarks.push_back(W[landmarks_ind[j]][l]);
+ for (unsigned j = 0; j < landmarks_ind.size(); ++j)
+ landmarks.push_back(W[landmarks_ind[j]]);
}
void landmark_choice_by_delaunay(Point_Vector& W, int nbP, int nbL, Point_Vector& landmarks, std::vector<int>& landmarks_ind, FT delta)
@@ -356,7 +356,7 @@ void landmark_choice_protected_delaunay(Point_Vector& W, int nbP, Point_Vector&
}
else
list_it++;
- fill_landmark_copies(W, landmarks, landmarks_ind);
+ fill_landmarks(W, landmarks, landmarks_ind);
}
@@ -427,6 +427,7 @@ int landmark_perturbation(Point_Vector &W, int nbL, Point_Vector& landmarks, std
witnessComplex.witness_complex(WL);
//******************** Making a set of bad link landmarks
+ /*
std::cout << "Entered bad links\n";
std::set< int > perturbL;
int count_badlinks = 0;
@@ -453,8 +454,9 @@ int landmark_perturbation(Point_Vector &W, int nbL, Point_Vector& landmarks, std
if (count_bad[i] != 0)
std::cout << "count_bad[" << i << "] = " << count_bad[i] << std::endl;
std::cout << "\nBad links total: " << count_badlinks << " Points to perturb: " << perturbL.size() << std::endl;
-
+ */
//*********************** Perturb bad link landmarks
+ /*
for (auto u: perturbL)
{
Random_point_iterator rp(D,sqrt(lambda)/8);
@@ -486,56 +488,41 @@ int landmark_perturbation(Point_Vector &W, int nbL, Point_Vector& landmarks, std
}
write_edges("landmarks/edges", witnessComplex, landmarks);
return count_badlinks;
+ */
+ return 0;
}
int main (int argc, char * const argv[])
{
- if (argc != 5)
+ if (argc != 3)
{
std::cerr << "Usage: " << argv[0]
- << " nbP nbL dim delta\n";
+ << " nbP dim\n";
return 0;
}
int nbP = atoi(argv[1]);
- int nbL = atoi(argv[2]);
- int dim = atoi(argv[3]);
- FT delta = atof(argv[4]);
+ int dim = atoi(argv[2]);
std::cout << "Let the carnage begin!\n";
Point_Vector point_vector;
generate_points_random_box(point_vector, nbP, dim);
Point_Vector L;
std::vector<int> chosen_landmarks;
- bool ok=false;
- while (!ok)
- {
- ok = true;
- L = {};
- chosen_landmarks = {};
- //landmark_choice_by_delaunay(point_vector, nbP, nbL, L, chosen_landmarks, delta);
- landmark_choice_protected_delaunay(point_vector, nbP, L, chosen_landmarks, delta);
- nbL = chosen_landmarks.size();
- std::cout << "Number of landmarks is " << nbL << std::endl;
- //int width = (int)pow(nbL, 1.0/dim); landmark_choice_bcc(point_vector, nbP, width, L, chosen_landmarks);
- for (auto i: chosen_landmarks)
- {
- ok = ok && (std::count(chosen_landmarks.begin(),chosen_landmarks.end(),i) == 1);
- if (!ok) break;
- }
-
- }
- int bl = nbL, curr_min = bl;
- write_points("landmarks/initial_pointset",point_vector);
+ //write_points("landmarks/initial_pointset",point_vector);
//write_points("landmarks/initial_landmarks",L);
- //for (int i = 0; i < 1; i++)
- for (int i = 0; bl > 0; i++)
+ for (int i = 0; i < 11; i++)
+ //for (int i = 0; bl > 0; i++)
{
- std::cout << "========== Start iteration " << i << "== curr_min(" << curr_min << ")========\n";
- bl=landmark_perturbation(point_vector, nbL, L, chosen_landmarks);
- if (bl < curr_min)
- curr_min=bl;
- write_points("landmarks/landmarks0",L);
+ //std::cout << "========== Start iteration " << i << "== curr_min(" << curr_min << ")========\n";
+ double delta = pow(10, -(1.0*i)/2);
+ std::cout << "delta = " << delta << std::endl;
+ L = {}; chosen_landmarks = {};
+ landmark_choice_protected_delaunay(point_vector, nbP, L, chosen_landmarks, delta);
+ int nbL = chosen_landmarks.size();
+ std::cout << "Number of landmarks = " << nbL << std::endl;
+ landmark_perturbation(point_vector, nbL, L, chosen_landmarks);
+ //write_points("landmarks/landmarks0",L);
}
}
diff --git a/src/Witness_complex/example/witness_complex_flat_torus.cpp b/src/Witness_complex/example/witness_complex_flat_torus.cpp
index 06bf5a9f..69ef5fbf 100644
--- a/src/Witness_complex/example/witness_complex_flat_torus.cpp
+++ b/src/Witness_complex/example/witness_complex_flat_torus.cpp
@@ -335,7 +335,7 @@ void generate_points_grid(Point_Vector& W, int width, int D)
int cell_i = i;
for (int l = 0; l < D; ++l)
{
- point.push_back(0.01*(cell_i%width));
+ point.push_back((2.0/width)*(cell_i%width));
cell_i /= width;
}
W.push_back(point);
@@ -516,7 +516,7 @@ void landmark_choice(Point_Vector &W, int nbP, int nbL, Point_Vector& landmarks,
// while (!res.second)
// {
do chosen_landmark = rand.get_int(0,nbP);
- while (std::count(landmarks_ind.begin(),landmarks_ind.end(),chosen_landmark)!=0);
+ while (std::find(landmarks_ind.begin(),landmarks_ind.end(),chosen_landmark)!=landmarks_ind.end());
//rand++;
//std::cout << "Chose " << chosen_landmark << std::endl;
p = &W[chosen_landmark];
@@ -672,7 +672,7 @@ int landmark_perturbation(Point_Vector &W, Point_Vector& landmarks, std::vector<
count_badlinks++;
//std::cout << u << " ";
Point_d& l = landmarks[u];
- Fuzzy_sphere fs(l, sqrt(lambda)*3, 0, traits);
+ Fuzzy_sphere fs(l, sqrt(lambda), 0, traits);
std::vector<int> curr_perturb;
L.search(std::insert_iterator<std::vector<int>>(curr_perturb,curr_perturb.begin()),fs);
for (int i: curr_perturb)
diff --git a/src/Witness_complex/example/witness_complex_perturbations.cpp b/src/Witness_complex/example/witness_complex_perturbations.cpp
index b3b84b1f..f78bcdab 100644
--- a/src/Witness_complex/example/witness_complex_perturbations.cpp
+++ b/src/Witness_complex/example/witness_complex_perturbations.cpp
@@ -267,6 +267,8 @@ int landmark_perturbation(Point_Vector &W, Point_Vector& landmarks, std::vector<
std::cout << "Enter (D+1) nearest landmarks\n";
//std::cout << "Size of the tree is " << L.size() << std::endl;
int D = W[0].size();
+ clock_t start, end;
+ start = clock();
for (int i = 0; i < nbP; i++)
{
//std::cout << "Entered witness number " << i << std::endl;
@@ -294,18 +296,23 @@ int landmark_perturbation(Point_Vector &W, Point_Vector& landmarks, std::vector<
lambda = dist;
}
//std::cout << "\nBad links total: " << count_badlinks << " Points to perturb: " << perturbL.size() << std::endl;
-
- }
+ }
//std::cout << "\n";
+ end = clock();
+ std::cout << "WL matrix construction on " << nbL << " landmarks took " << (double)(end-start)/CLOCKS_PER_SEC << "s.\n";
+
std::string out_file = "wl_result";
- write_wl(out_file,WL);
+ //write_wl(out_file,WL);
//******************** Constructng a witness complex
std::cout << "Entered witness complex construction\n";
Witness_complex<> witnessComplex;
witnessComplex.setNbL(nbL);
+ start = clock();
witnessComplex.witness_complex(WL);
+ end = clock();
+ std::cout << "Witness complex construction on " << nbL << " landmarks took " << (double)(end-start)/CLOCKS_PER_SEC << "s.\n";
//******************** Making a set of bad link landmarks
std::cout << "Entered bad links\n";
std::set< int > perturbL;
@@ -355,7 +362,7 @@ int landmark_perturbation(Point_Vector &W, Point_Vector& landmarks, std::vector<
std::cout << "lambda=" << lambda << std::endl;
// Write the WL matrix in a file
-
+ /*
char buffer[100];
int i = sprintf(buffer,"stree_result.txt");
@@ -366,8 +373,9 @@ int landmark_perturbation(Point_Vector &W, Point_Vector& landmarks, std::vector<
witnessComplex.st_to_file(ofs);
ofs.close();
}
+ */
//witnessComplex.write_badlinks("badlinks");
- write_edges_gnuplot("landmarks/edges", witnessComplex, landmarks);
+ //write_edges_gnuplot("landmarks/edges", witnessComplex, landmarks);
return count_badlinks;
}
@@ -417,7 +425,7 @@ int main (int argc, char * const argv[])
file_name.erase(0, last_slash_idx + 1);
}
write_points("landmarks/initial_pointset",point_vector);
- write_points("landmarks/initial_landmarks",L);
+ //write_points("landmarks/initial_landmarks",L);
//for (int i = 0; bl != 0; i++)
for (int i = 0; i < 1; i++)
{
diff --git a/src/Witness_complex/example/witness_complex_sphere.cpp b/src/Witness_complex/example/witness_complex_sphere.cpp
index 74aae875..550c9392 100644
--- a/src/Witness_complex/example/witness_complex_sphere.cpp
+++ b/src/Witness_complex/example/witness_complex_sphere.cpp
@@ -431,6 +431,7 @@ int landmark_perturbation(Point_Vector &W, Point_Vector& landmarks, std::vector<
else
std::cout << "??NO. IT IS NOT A WITNESS COMPLEX??\n";
*/
+ */
//******************** Making a set of bad link landmarks
std::cout << "Entered bad links\n";
std::set< int > perturbL;
@@ -446,7 +447,7 @@ int landmark_perturbation(Point_Vector &W, Point_Vector& landmarks, std::vector<
count_badlinks++;
//std::cout << u << " ";
Point_d& l = landmarks[u];
- Fuzzy_sphere fs(l, sqrt(lambda)*3, 0, traits);
+ Fuzzy_sphere fs(l, sqrt(lambda), 0, traits);
std::vector<int> curr_perturb;
L.search(std::insert_iterator<std::vector<int>>(curr_perturb,curr_perturb.begin()),fs);
for (int i: curr_perturb)
@@ -577,8 +578,8 @@ int main (int argc, char * const argv[])
write_points("landmarks/initial_pointset",point_vector);
write_points("landmarks/initial_landmarks",L);
- //for (int i = 0; bl > 0; i++)
- for (int i = 0; i < 1; i++)
+ for (int i = 0; bl > 0; i++)
+ //for (int i = 0; i < 1; i++)
{
std::cout << "========== Start iteration " << i << "== curr_min(" << curr_min << ")========\n";
bl=landmark_perturbation(point_vector, L, chosen_landmarks);