/** * Function to iterate the algorithm. */ static inline void optimize_iterate () { unsigned int i; #if DEBUG_OPTIMIZE fprintf (stderr, "optimize_iterate: start\n"); #endif optimize->error_old = (double *) g_malloc (optimize->nbest * sizeof (double)); optimize->value_old = (double *) g_malloc (optimize->nbest * optimize->nvariables * sizeof (double)); optimize_step (); optimize_save_old (); optimize_refine (); optimize_print (); for (i = 1; i < optimize->niterations && !optimize->stop; ++i) { optimize_step (); optimize_merge_old (); optimize_refine (); optimize_print (); } #if DEBUG_OPTIMIZE fprintf (stderr, "optimize_iterate: end\n"); #endif }
void optimize(InverseTemperatureIterator inverse_temperatures_begin, InverseTemperatureIterator inverse_temperatures_end) { // Initialise with the given temperature range this->initialize_inverse_temperatures(inverse_temperatures_begin, inverse_temperatures_end); // Do the number of given recursions for (unsigned int r = 0; r < this->optimization_steps; ++r) optimize_step(); // Calculate the weights std::vector<double> weights = WeightCalculator::calculate_weights(this->acceptance_probabilities); // Write the resulting temperatures into the given iterator range InverseTemperatureIterator inverse_temperature_it = inverse_temperatures_begin; for (unsigned int i = 0; i < this->replica_number; ++i) { // Weight the inverse temperature of the actual replica (*inverse_temperature_it) = 0.0; for (unsigned int r = 0; r < this->optimization_steps; ++r) (*inverse_temperature_it) += weights[r] * this->inverse_temperatures[r][i]; // Increase the iterator ++inverse_temperature_it; } }