Commit 3118330d authored by Martin Beseda's avatar Martin Beseda

Merge branch 'tmp' into 'master'

final adjustments?

See merge request bes0030/lib4neuro!4
parents 5b826644 82e6fafe
......@@ -173,7 +173,6 @@ namespace lib4neuro {
for (size_t i = 0; i < data->size(); i++) {
/* Compute difference for every element of the output vector */
#ifdef L4N_DEBUG
std::stringstream ss_input;
for (size_t j = 0; j < dim_in; j++) {
denormalized_real_input = data_set->get_denormalized_value(data->at(i).first.at(j));
......@@ -183,7 +182,6 @@ namespace lib4neuro {
std::stringstream ss_real_output;
std::stringstream ss_predicted_output;
#endif
double loc_error = 0;
output_norm = 0;
......@@ -192,11 +190,9 @@ namespace lib4neuro {
denormalized_real_output = data_set->get_denormalized_value(data->at(i).second.at(j));
denormalized_output = data_set->get_denormalized_value(outputs.at(i).at(j));
#ifdef L4N_DEBUG
ss_real_output << separator << denormalized_real_output;
ss_predicted_output << separator << denormalized_output;
separator = ",";
#endif
val = denormalized_output - denormalized_real_output;
loc_error += val * val;
......@@ -205,9 +201,9 @@ namespace lib4neuro {
output_norm += denormalized_output * denormalized_output;
}
#ifdef L4N_DEBUG
std::stringstream ss_ind;
ss_ind << "[" << i << "]";
#ifdef L4N_DEBUG
if (verbose) {
COUT_DEBUG(R_ALIGN << ss_ind.str() << " "
......@@ -220,6 +216,8 @@ namespace lib4neuro {
<< std::endl);
}
#endif
if (results_file_path) {
*results_file_path << R_ALIGN << ss_ind.str() << " "
<< R_ALIGN << ss_input.str() << " "
......@@ -230,7 +228,6 @@ namespace lib4neuro {
<< 200.0 * std::sqrt(loc_error) / (std::sqrt(loc_error) + std::sqrt(output_norm))
<< std::endl;
}
#endif
}
double result = std::sqrt(error) / n_elements;
......
......@@ -242,10 +242,17 @@ namespace lib4neuro {
COUT_DEBUG("Iteration: " << iter_counter << " Current error: " << current_err << ", Current gradient norm: "
<< gradient_norm << ", Direction norm: " << update_norm << "\r");
if (ofs && ofs->is_open()) {
*ofs << "Iteration: " << iter_counter << " Current error: " << current_err << ", Current gradient norm: "
<< gradient_norm << ", Direction norm: " << update_norm << std::endl;
}
} while (iter_counter++ < this->p_impl->maximum_niters && (update_norm > this->p_impl->tolerance));
COUT_DEBUG("Iteration: " << iter_counter << " Current error: " << current_err << ", Current gradient norm: "
<< gradient_norm << ", Direction norm: " << update_norm << std::endl);
if (ofs && ofs->is_open()) {
*ofs << "Iteration: " << iter_counter << " Current error: " << current_err << ", Current gradient norm: "
<< gradient_norm << ", Direction norm: " << update_norm << std::endl;
}
/* Store the optimized parameters */
this->optimal_parameters = *params_current;
......
......@@ -295,6 +295,9 @@ namespace lib4neuro {
//TODO add output to the 'ofs'
COUT_INFO("Finding optima via Globalized Particle Swarm method..." << std::endl);
if (ofs && ofs->is_open()) {
*ofs << "Finding optima via Globalized Particle Swarm method..." << std::endl;
}
if (this->epsilon < 0 || this->gamma < 0 || this->delta < 0) {
THROW_INVALID_ARGUMENT_ERROR(
......@@ -422,6 +425,13 @@ namespace lib4neuro {
<< ". Total error: " << current_err
<< ". Objective function value: " << optimal_value
<< ".\r");
if (ofs && ofs->is_open()) {
*ofs << "Iteration: " << (outer_it)
<< ". Total error: " << current_err
<< ". Objective function value: " << optimal_value
<< std::endl;
}
if (this->err_thresh) {
......@@ -447,6 +457,12 @@ namespace lib4neuro {
<< ". Total error: " << current_err
<< ". Objective function value: " << optimal_value
<< "." << std::endl);
if (ofs && ofs->is_open()) {
*ofs << "Iteration: " << (outer_it)
<< ". Total error: " << current_err
<< ". Objective function value: " << optimal_value
<< std::endl;
}
this->determine_optimal_coordinate_and_value(this->optimal_parameters,
optimal_value);
......@@ -455,10 +471,18 @@ namespace lib4neuro {
/* Convergence reached */
COUT_INFO(std::endl << "Found optimum in " << outer_it << " iterations. Objective function value: "
<< optimal_value << std::endl);
if (ofs && ofs->is_open()) {
*ofs << "Found optimum in " << outer_it << " iterations. Objective function value: "
<< optimal_value << std::endl;
}
} else {
/* Maximal number of iterations reached */
COUT_INFO(std::endl << "Max number of iterations reached (" << outer_it << ")! Objective function value: "
<< optimal_value << std::endl);
if (ofs && ofs->is_open()) {
*ofs << "Max number of iterations reached (" << outer_it << ")! Objective function value: "
<< optimal_value << std::endl;
}
}
ef.set_parameters(this->optimal_parameters);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment