mirror of https://github.com/CGAL/cgal
Updated test cases
This commit is contained in:
parent
1c390474ff
commit
b22fe586d2
|
|
@ -8,12 +8,11 @@
|
|||
* Then applies gmm fitting on these generated points.
|
||||
* Provides a heuristic score for each gmm fitting result.
|
||||
*
|
||||
* Note that it always return EXIT_SUCCESS
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
boost::mt19937 engine;
|
||||
engine.seed(1340818006);
|
||||
engine.seed(1340818006);
|
||||
|
||||
// generate random data using gauissians below
|
||||
std::vector< boost::normal_distribution<double> > distributions;
|
||||
|
|
@ -35,7 +34,7 @@ int main(void)
|
|||
|
||||
// calculate closest center (using above gauissians) for each generated points
|
||||
// we will compare it with gmm fitting results
|
||||
// also we might want to compute mixing coef for each center and select centers according to mixing_coef * prob(data)
|
||||
// also we might want to compute mixing coef for each center and select centers according to mixing_coef * prob(data)
|
||||
std::vector<int> data_centers;
|
||||
for(std::vector<double>::iterator it = data.begin(); it != data.end(); ++it)
|
||||
{
|
||||
|
|
@ -79,6 +78,11 @@ int main(void)
|
|||
{
|
||||
if( (*it) == (*calculated_it) ) { ++true_count; }
|
||||
}
|
||||
std::cout << "[0,1]: " << static_cast<double>(true_count) / data_centers.size() << std::endl;
|
||||
double app_fit = static_cast<double>(true_count) / data_centers.size();
|
||||
std::cout << "[0,1]: " << app_fit << std::endl;
|
||||
if(app_fit < 0.7) {
|
||||
std::cerr << "There might be a problem if above printed comparison is too low." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
|
||||
//
|
||||
#include <CGAL/internal/Surface_mesh_segmentation/K_means_clustering.h>
|
||||
|
||||
#include <boost/random.hpp>
|
||||
|
|
@ -8,12 +8,12 @@
|
|||
* Then applies k-means on these generated points.
|
||||
* Provides a heuristic score for each k-means clustering result.
|
||||
*
|
||||
* Note that it always return EXIT_SUCCESS
|
||||
* EXIT_FAILURE does not mean failure but if approximate matching is too low it is best to check
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
boost::mt19937 engine;
|
||||
engine.seed(1340818006);
|
||||
engine.seed(1340818006);
|
||||
|
||||
// generate random data using gauissians below
|
||||
std::vector< boost::normal_distribution<double> > distributions;
|
||||
|
|
@ -57,9 +57,7 @@ int main(void)
|
|||
typedef CGAL::internal::K_means_clustering K_means;
|
||||
std::vector<K_means> k_means;
|
||||
k_means.push_back(K_means(distributions.size(), data, K_means::PLUS_INITIALIZATION));
|
||||
k_means.push_back(K_means(distributions.size(), data, K_means::PLUS_INITIALIZATION, 2, 5));
|
||||
k_means.push_back(K_means(distributions.size(), data, K_means::RANDOM_INITIALIZATION));
|
||||
k_means.push_back(K_means(distributions.size(), data, K_means::RANDOM_INITIALIZATION, 2, 5));
|
||||
|
||||
std::vector< std::vector<int> > calculated_centers(k_means.size());
|
||||
std::vector< std::vector<int> >::iterator calc_centers_it = calculated_centers.begin();
|
||||
|
|
@ -79,6 +77,11 @@ int main(void)
|
|||
{
|
||||
if( (*it) == (*calculated_it) ) { ++true_count; }
|
||||
}
|
||||
std::cout << "[0,1]: " << static_cast<double>(true_count) / data_centers.size() << std::endl;
|
||||
double app_fit = static_cast<double>(true_count) / data_centers.size();
|
||||
std::cout << "[0,1]: " << app_fit << std::endl;
|
||||
if(app_fit < 0.7) {
|
||||
std::cerr << "There might be a problem if above printed comparison is too low." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
#include <CGAL/internal/Surface_mesh_segmentation/K_means_clustering.h>
|
||||
typedef CGAL::internal::K_means_clustering K_means;
|
||||
/**
|
||||
* Test degenerate cases
|
||||
*/
|
||||
|
||||
int main(void)
|
||||
{
|
||||
for(int init_type = 0; init_type < 2; ++init_type)
|
||||
{
|
||||
K_means::Initialization_types init_type_enum = init_type == 0 ? K_means::RANDOM_INITIALIZATION :
|
||||
K_means::PLUS_INITIALIZATION;
|
||||
for(int i = 1; i < 100; ++i) {
|
||||
std::vector<double> points(i, 1.0); // generate point set with same points
|
||||
K_means kmeans(points.size(), points, init_type_enum); // should not crash
|
||||
}
|
||||
}
|
||||
|
||||
for(int init_type = 0; init_type < 2; ++init_type)
|
||||
{
|
||||
K_means::Initialization_types init_type_enum = init_type == 0 ? K_means::RANDOM_INITIALIZATION :
|
||||
K_means::PLUS_INITIALIZATION;
|
||||
// Test case: number of points equals to number of clusters
|
||||
// and all points are unique
|
||||
for(int center_size = 1; center_size < 100; ++center_size)
|
||||
{
|
||||
// unique point generate
|
||||
std::vector<double> points;
|
||||
for(int i = 0; i < center_size; ++i) {
|
||||
points.push_back(i);
|
||||
}
|
||||
|
||||
// test kmeans, expected result: each point has its own cluster
|
||||
K_means kmeans(center_size, points, init_type_enum);
|
||||
std::vector<int> center_ids;
|
||||
kmeans.fill_with_center_ids(center_ids);
|
||||
|
||||
for(int i = 0; i < center_size -1; ++i) {
|
||||
if(center_ids[i] >= center_ids[i +1]) // center ids are ordered according to mean
|
||||
{ // and since points are generated ascendingly ...
|
||||
std::string init_type_s = init_type_enum == K_means::RANDOM_INITIALIZATION ? "Random " :
|
||||
"Plus plus ";
|
||||
std::cerr << "Init type: " << init_type_s << "center size: " << center_size << std::endl;
|
||||
CGAL_assertion(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,34 +18,26 @@ typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
|
|||
*/
|
||||
int main(void)
|
||||
{
|
||||
Polyhedron mesh;
|
||||
if( !read_to_polyhedron("./data/cactus.off", mesh) ) { return 1; }
|
||||
|
||||
typedef std::map<Polyhedron::Facet_const_handle, double> Facet_double_map;
|
||||
Polyhedron mesh;
|
||||
if( !read_to_polyhedron("./data/cactus.off", mesh) ) { return 1; }
|
||||
|
||||
typedef std::map<Polyhedron::Facet_const_handle, double> Facet_double_map;
|
||||
Facet_double_map internal_map;
|
||||
boost::associative_property_map<Facet_double_map> sdf_property_map(internal_map);
|
||||
|
||||
std::pair<double, double> min_max_sdf = CGAL::sdf_values_computation(mesh, sdf_property_map);
|
||||
std::cout << "minimum sdf: " << min_max_sdf.first << " maximum sdf: " << min_max_sdf.second << std::endl;
|
||||
|
||||
|
||||
typedef std::map<Polyhedron::Facet_const_handle, int> Facet_int_map;
|
||||
Facet_int_map internal_segment_map;
|
||||
|
||||
std::pair<double, double> min_max_sdf = CGAL::sdf_values_computation(mesh, sdf_property_map);
|
||||
std::cout << "minimum sdf: " << min_max_sdf.first << " maximum sdf: " << min_max_sdf.second << std::endl;
|
||||
|
||||
typedef std::map<Polyhedron::Facet_const_handle, int> Facet_int_map;
|
||||
Facet_int_map internal_segment_map;
|
||||
boost::associative_property_map<Facet_int_map> segment_property_map(internal_segment_map);
|
||||
|
||||
|
||||
int nb_segments = CGAL::surface_mesh_segmentation_from_sdf_values(
|
||||
mesh, sdf_property_map, segment_property_map);
|
||||
|
||||
if(nb_segments != 3)
|
||||
{
|
||||
std::cout << "Number of segments should be 3 for cactus model (since it is pretty easy model to segment)" << std::endl;
|
||||
}
|
||||
|
||||
int nb_segments_2 = CGAL::surface_mesh_segmentation(mesh, segment_property_map);
|
||||
|
||||
if(nb_segments_2 != nb_segments)
|
||||
{
|
||||
std::cout << "Inconsistency between 'surface_mesh_segmentation' and 'surface_mesh_segmentation_from_sdf_values'"
|
||||
<< std::endl;
|
||||
}
|
||||
mesh, sdf_property_map, segment_property_map);
|
||||
|
||||
if(nb_segments != 3)
|
||||
{
|
||||
std::cerr << "Number of segments should be 3 for cactus model (since it is pretty easy model to segment)" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue