Skip to content
Snippets Groups Projects
Commit 162737f0 authored by Martin Beseda's avatar Martin Beseda
Browse files

ENH: Enhanced info messages

parent e7563d14
No related branches found
No related tags found
No related merge requests found
...@@ -203,9 +203,11 @@ void ParticleSwarm::optimize( double gamma, double epsilon, double delta) { ...@@ -203,9 +203,11 @@ void ParticleSwarm::optimize( double gamma, double epsilon, double delta) {
double max_velocity; double max_velocity;
double max_vel_step = 0; double max_vel_step = 0;
double prev_max_vel_step; double prev_max_vel_step;
double euclidean_dist;
while( outer_it < this->iter_max ) { while( outer_it < this->iter_max ) {
max_velocity = 0; max_velocity = 0;
euclidean_dist = 0;
////////////////////////////////////////////////// //////////////////////////////////////////////////
// Clustering algorithm - termination condition // // Clustering algorithm - termination condition //
...@@ -237,7 +239,12 @@ void ParticleSwarm::optimize( double gamma, double epsilon, double delta) { ...@@ -237,7 +239,12 @@ void ParticleSwarm::optimize( double gamma, double epsilon, double delta) {
} }
/* Looking for nearby particles */ /* Looking for nearby particles */
printf("iter: %d, pi: %d, euclidean dist: %f\n", outer_it, pi, this->get_euclidean_distance(particle->get_coordinate(), coords, this->func_dim)); //printf("iter: %d, pi: %d, euclidean dist: %f\n", outer_it, pi, this->get_euclidean_distance(particle->get_coordinate(), coords, this->func_dim));
// TODO - only in verbose mode
// only for info purposes
euclidean_dist += this->get_euclidean_distance(particle->get_coordinate(), coords, this->func_dim);
if(this->get_euclidean_distance(particle->get_coordinate(), coords, this->func_dim) < epsilon) { if(this->get_euclidean_distance(particle->get_coordinate(), coords, this->func_dim) < epsilon) {
cluster.insert(particle); cluster.insert(particle);
} }
...@@ -248,22 +255,33 @@ void ParticleSwarm::optimize( double gamma, double epsilon, double delta) { ...@@ -248,22 +255,33 @@ void ParticleSwarm::optimize( double gamma, double epsilon, double delta) {
max_vel_step = max_velocity - prev_max_velocity; max_vel_step = max_velocity - prev_max_velocity;
/* Check if the particles are near to each other AND the maximal velocity is less than 'gamma' */ /* Check if the particles are near to each other AND the maximal velocity is less than 'gamma' */
// printf("cluster size: %ld, n particles: %d, %f\n", cluster.size(), this->n_particles, double(cluster.size())/this->n_particles);
printf("cluster: %f\n", double(cluster.size())/this->n_particles);
printf("real gamma: %f\n", std::abs(prev_max_vel_step/max_vel_step));
if(double(cluster.size())/this->n_particles > delta && std::abs(prev_max_vel_step/max_vel_step) > gamma) { if(double(cluster.size())/this->n_particles > delta && std::abs(prev_max_vel_step/max_vel_step) > gamma) {
break; break;
} }
//TODO only in verbose mode
euclidean_dist /= this->n_particles*5.;
printf("Iteration %d, avg euclidean distance: %f\n", outer_it, euclidean_dist);
outer_it++; outer_it++;
// this->w *= 0.99; // this->w *= 0.99;
} }
printf("Found optimum in %6d iterations: %10.8f at coordinate: ", outer_it, optimal_value); if(outer_it < this->iter_max) {
for(unsigned int i = 0; i < this->func_dim - 1; ++i){ /* Convergence reached */
printf("%10.8f, ", p_min_glob[i]);
printf("Found optimum in %d iterations: %10.8f at coordinates: \n", outer_it, optimal_value);
for (unsigned int i = 0; i <= this->func_dim - 1; ++i) {
printf("%10.8f \n", p_min_glob[i]);
}
} else {
/* Maximal number of iterations reached */
printf("Max number of iterations reached (%d)! Found value %10.8f at coordinates: \n", outer_it, optimal_value);
for (unsigned int i = 0; i <= this->func_dim - 1; ++i) {
printf("\t%10.8f \n", p_min_glob[i]);
}
} }
printf("%10.8f\n", p_min_glob[this->func_dim - 1]);
delete [] p_min_glob; delete [] p_min_glob;
delete [] coords; delete [] coords;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment