Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2013 George Tzanetakis <gtzan@cs.uvic.ca> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #include <marsyas/debug/debugger.h> 00020 00021 namespace Marsyas { namespace Debug { 00022 00023 void compare( const Record & actual, const Record & reference, BugReport & report ) 00024 { 00025 using Marsyas::mrs_realvec; 00026 using Marsyas::mrs_real; 00027 using Marsyas::mrs_natural; 00028 00029 for (const auto & ref_entry : reference.entries()) 00030 { 00031 Bug bug; 00032 00033 const std::string & path = ref_entry.first; 00034 00035 const auto & actual_entry_it = actual.entries().find(path); 00036 if (actual_entry_it == actual.entries().end()) 00037 { 00038 bug.flags = path_missing; 00039 report.insert( std::make_pair(path, bug) ); 00040 continue; 00041 } 00042 00043 const mrs_realvec & ref_data = ref_entry.second.output; 00044 const mrs_realvec & act_data = actual_entry_it->second.output; 00045 00046 if (ref_data.getRows() != act_data.getRows() || 00047 ref_data.getCols() != act_data.getCols()) 00048 { 00049 bug.flags = format_mismatch; 00050 report.insert( std::make_pair(path, bug) ); 00051 continue; 00052 } 00053 00054 mrs_real max_dev = 0.0, avg_dev = 0.0; 00055 for (int i = 0; i < ref_data.getSize(); ++i) 00056 { 00057 if (ref_data(i) != act_data(i)) 00058 { 00059 mrs_real dev = std::abs( act_data(i) - ref_data(i) ); 00060 if (dev > max_dev) 00061 max_dev = dev; 00062 avg_dev += dev; 00063 } 00064 } 00065 00066 if (ref_data.getSize()) 00067 avg_dev /= ref_data.getSize(); 00068 00069 if (max_dev != 0.0) 00070 { 00071 bug.flags = value_mismatch; 00072 bug.average_deviation = avg_dev; 00073 bug.max_deviation = max_dev; 00074 report.insert( std::make_pair(path, bug) ); 00075 continue; 00076 } 00077 } 00078 } 00079 00080 }} // namespace Marsyas::Debug