Commit 77eb852b authored by Martin Beseda's avatar Martin Beseda
Browse files

Merge branch 'dev' of code.it4i.cz:kra568/4Neuro into dev

parents 092e99fe 6ba86f29
......@@ -343,48 +343,77 @@ void dynamic_test(
std::vector<double> output;
output.resize(1);
double max_error_abs = 0.0, max_error_rel = 0.0;
double max_error_abs_normalized = 0.0, max_error_rel_normalized = 0.0;
double max_error_abs_denormalized = 0.0, max_error_rel_denormalized = 0.0;
std::vector<double> output_min = { -1.0 };
std::vector<double> output_max = { 1.0 };
ns->de_normalize_output( output_min );
ns->de_normalize_output( output_max );
double len_0_norm = 2;
double len_0_denorm = output_max[ 0 ] - output_min[ 0 ];
std::vector<std::vector<double>> out_dat;
for (auto e : *mse.get_dataset()->get_data()) {
net->eval_single(e.first,
output);
double v1 = e.second[0];
double v2 = output[0];
double error1 = std::abs(v1 - v2);
double error_rel1 = error1 / len_0_norm;
if (max_error_abs_normalized < error1) {
max_error_abs_normalized = error1;
}
if (error_rel1 > max_error_rel_normalized) {
max_error_rel_normalized = error_rel1;
}
ns->de_normalize_output( e.second );
ns->de_normalize_output( output );
double error_ = std::abs(e.second.at(0) - output.at(0));
double error_rel = 2.0 * error_ / (std::abs(output.at(0)) + std::abs(e.second.at(0)));
out_dat.push_back({e.second[0], output[0], error_, error_rel});
double u1 = e.second[0];
double u2 = output[0];
double error2 = std::abs(u1 - u2);
double error_rel2 = error2 / len_0_denorm;
out_dat.push_back({v1, v2, error1, error_rel1, u1, u2, error2, error_rel2});
if (max_error_abs < error_) {
max_error_abs = error_;
if (max_error_abs_denormalized < error2) {
max_error_abs_denormalized = error2;
}
if (error_rel > max_error_rel) {
max_error_rel = error_rel;
if (error_rel2 > max_error_rel_denormalized) {
max_error_rel_denormalized = error_rel2;
}
}
std::cout << "*****************************************************" << std::endl;
std::cout << "maximal absolute error: " << max_error_abs << std::endl;
std::cout << "maximal relative error: " << 100 * max_error_rel << " %" << std::endl;
std::cout << "********************NORMALIZED DATA******************" << std::endl;
std::cout << "output in range: " << -1.0 << " - " << 1.0 << std::endl;
std::cout << "maximal absolute error: " << max_error_abs_normalized << std::endl;
std::cout << "maximal relative error: " << 100 * max_error_rel_normalized << " %" << std::endl;
std::cout << "*******************DENORMALIZED DATA*****************" << std::endl;
std::cout << "output in range: " << output_min[ 0 ] << " - " << output_max[ 0 ] << std::endl;
std::cout << "maximal absolute error: " << max_error_abs_denormalized << std::endl;
std::cout << "maximal relative error: " << 100 * max_error_rel_denormalized << " %" << std::endl;
std::cout << "*****************************************************" << std::endl;
net->save_text( net_file );
ns->save_text( norm_file );
std::vector<unsigned int> data_indices(out_dat.size());
for( auto i = 0; i < out_dat.size(); ++i ){
for( auto i = 0; i < data_indices.size(); ++i ){
data_indices[ i ] = i;
}
std::sort(
data_indices.begin(),
data_indices.end(),
[&out_dat](const unsigned int a, const unsigned int b){
if( out_dat.at(a).at(3) < out_dat.at(b).at(3) ){
if( out_dat.at(a).at(6) < out_dat.at(b).at(6) ){
return false;
}
if( out_dat.at(b).at(3) < out_dat.at(a).at(3) ){
if( out_dat.at(b).at(6) < out_dat.at(a).at(6) ){
return true;
}
return false;
......@@ -392,9 +421,9 @@ void dynamic_test(
);
if( niters == 0 ){
std::cout << "expected output " << "predicted output " << "absolute error " << "relative error" << std::endl;
std::cout << "expected output[n] " << "predicted output[n] " << "absolute error[n] " << "relative error[n] " << "expected output[d] " << "predicted output[d] " << "absolute error[d] " << "relative error[d] " << std::endl;
for (auto el: data_indices) {
printf("%c%20.18f %c%20.18f %c%20.18f %c%20.18f\n",
printf("%c%20.18f %c%20.18f %c%20.18f %c%20.18f %c%20.18f %c%20.18f %c%20.18f %c%20.18f\n",
// el,
out_dat.at(el).at(0) < 0?'-':' ',
std::abs(out_dat.at(el).at(0)),
......@@ -403,18 +432,27 @@ void dynamic_test(
out_dat.at(el).at(2) < 0?'-':' ',
std::abs(out_dat.at(el).at(2)),
out_dat.at(el).at(3) < 0?'-':' ',
std::abs(out_dat.at(el).at(3))
std::abs(out_dat.at(el).at(3)),
out_dat.at(el).at(4) < 0?'-':' ',
std::abs(out_dat.at(el).at(4)),
out_dat.at(el).at(5) < 0?'-':' ',
std::abs(out_dat.at(el).at(5)),
out_dat.at(el).at(6) < 0?'-':' ',
std::abs(out_dat.at(el).at(6)),
out_dat.at(el).at(7) < 0?'-':' ',
std::abs(out_dat.at(el).at(7))
);
}
}
else{
std::cout << "index " << "expected output[n] " << "predicted output[n] " << "absolute error[n] " << "relative error[n] " << "expected output[d] " << "predicted output[d] " << "absolute error[d] " << "relative error[d] " << std::endl;
for (auto el: data_indices) {
double error_ = out_dat.at(el).at(2);
double error_rel = out_dat.at(el).at(3);
double error_rel1 = out_dat.at(el).at(3);
double error_rel2 = out_dat.at(el).at(7);
if (error_rel > 0.05) {
printf("[%6d] %c%20.18f %c%20.18f %c%20.18f %c%20.18f\n",
if (error_rel1 > 0.05 || error_rel2 > 0.05) {
printf("[%6d] %c%20.18f %c%20.18f %c%20.18f %c%20.18f %c%20.18f %c%20.18f %c%20.18f %c%20.18f\n",
el,
out_dat.at(el).at(0) < 0?'-':' ',
std::abs(out_dat.at(el).at(0)),
......@@ -423,7 +461,15 @@ void dynamic_test(
out_dat.at(el).at(2) < 0?'-':' ',
std::abs(out_dat.at(el).at(2)),
out_dat.at(el).at(3) < 0?'-':' ',
std::abs(out_dat.at(el).at(3))
std::abs(out_dat.at(el).at(3)),
out_dat.at(el).at(4) < 0?'-':' ',
std::abs(out_dat.at(el).at(4)),
out_dat.at(el).at(5) < 0?'-':' ',
std::abs(out_dat.at(el).at(5)),
out_dat.at(el).at(6) < 0?'-':' ',
std::abs(out_dat.at(el).at(6)),
out_dat.at(el).at(7) < 0?'-':' ',
std::abs(out_dat.at(el).at(7))
);
}
}
......
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