From 162737f0728e8b08532613eec97002966e2a605d Mon Sep 17 00:00:00 2001 From: Martin Beseda <martinbeseda@seznam.cz> Date: Wed, 25 Jul 2018 16:15:13 +0200 Subject: [PATCH] ENH: Enhanced info messages --- src/LearningMethods/ParticleSwarm.cpp | 34 ++++++++++++++++++++------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/LearningMethods/ParticleSwarm.cpp b/src/LearningMethods/ParticleSwarm.cpp index 20c79490..8d9702c2 100644 --- a/src/LearningMethods/ParticleSwarm.cpp +++ b/src/LearningMethods/ParticleSwarm.cpp @@ -203,9 +203,11 @@ void ParticleSwarm::optimize( double gamma, double epsilon, double delta) { double max_velocity; double max_vel_step = 0; double prev_max_vel_step; + double euclidean_dist; while( outer_it < this->iter_max ) { max_velocity = 0; + euclidean_dist = 0; ////////////////////////////////////////////////// // Clustering algorithm - termination condition // @@ -237,7 +239,12 @@ void ParticleSwarm::optimize( double gamma, double epsilon, double delta) { } /* 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) { cluster.insert(particle); } @@ -248,22 +255,33 @@ void ParticleSwarm::optimize( double gamma, double epsilon, double delta) { 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' */ -// 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) { 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++; // this->w *= 0.99; } - printf("Found optimum in %6d iterations: %10.8f at coordinate: ", outer_it, optimal_value); - for(unsigned int i = 0; i < this->func_dim - 1; ++i){ - printf("%10.8f, ", p_min_glob[i]); + if(outer_it < this->iter_max) { + /* Convergence reached */ + + 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 [] coords; -- GitLab