perf.cpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------
00002 // File:                        perf.cpp
00003 // Programmer:          Sunil Arya and David Mount
00004 // Description:         Methods for performance stats
00005 // Last modified:       01/04/05 (Version 1.0)
00006 //----------------------------------------------------------------------
00007 // Copyright (c) 1997-2005 University of Maryland and Sunil Arya and
00008 // David Mount.  All Rights Reserved.
00009 // 
00010 // This software and related documentation is part of the Approximate
00011 // Nearest Neighbor Library (ANN).  This software is provided under
00012 // the provisions of the Lesser GNU Public License (LGPL).  See the
00013 // file ../ReadMe.txt for further information.
00014 // 
00015 // The University of Maryland (U.M.) and the authors make no
00016 // representations about the suitability or fitness of this software for
00017 // any purpose.  It is provided "as is" without express or implied
00018 // warranty.
00019 //----------------------------------------------------------------------
00020 // History:
00021 //      Revision 0.1  03/04/98
00022 //              Initial release
00023 //      Revision 1.0  04/01/05
00024 //              Changed names to avoid namespace conflicts.
00025 //              Added flush after printing performance stats to fix bug
00026 //                      in Microsoft Windows version.
00027 //----------------------------------------------------------------------
00028 
00029 #include <ANN/ANN.h>                                    // basic ANN includes
00030 #include <ANN/ANNperf.h>                                // performance includes
00031 
00032 using namespace std;                                    // make std:: available
00033 
00034 //----------------------------------------------------------------------
00035 //      Performance statistics
00036 //              The following data and routines are used for computing
00037 //              performance statistics for nearest neighbor searching.
00038 //              Because these routines can slow the code down, they can be
00039 //              activated and deactiviated by defining the PERF variable,
00040 //              by compiling with the option: -DPERF
00041 //----------------------------------------------------------------------
00042 
00043 //----------------------------------------------------------------------
00044 //      Global counters for performance measurement
00045 //----------------------------------------------------------------------
00046 
00047 int                             ann_Ndata_pts  = 0;             // number of data points
00048 int                             ann_Nvisit_lfs = 0;             // number of leaf nodes visited
00049 int                             ann_Nvisit_spl = 0;             // number of splitting nodes visited
00050 int                             ann_Nvisit_shr = 0;             // number of shrinking nodes visited
00051 int                             ann_Nvisit_pts = 0;             // visited points for one query
00052 int                             ann_Ncoord_hts = 0;             // coordinate hits for one query
00053 int                             ann_Nfloat_ops = 0;             // floating ops for one query
00054 ANNsampStat             ann_visit_lfs;                  // stats on leaf nodes visits
00055 ANNsampStat             ann_visit_spl;                  // stats on splitting nodes visits
00056 ANNsampStat             ann_visit_shr;                  // stats on shrinking nodes visits
00057 ANNsampStat             ann_visit_nds;                  // stats on total nodes visits
00058 ANNsampStat             ann_visit_pts;                  // stats on points visited
00059 ANNsampStat             ann_coord_hts;                  // stats on coordinate hits
00060 ANNsampStat             ann_float_ops;                  // stats on floating ops
00061 //
00062 ANNsampStat             ann_average_err;                // average error
00063 ANNsampStat             ann_rank_err;                   // rank error
00064 
00065 //----------------------------------------------------------------------
00066 //      Routines for statistics.
00067 //----------------------------------------------------------------------
00068 
00069 DLL_API void annResetStats(int data_size) // reset stats for a set of queries
00070 {
00071         ann_Ndata_pts  = data_size;
00072         ann_visit_lfs.reset();
00073         ann_visit_spl.reset();
00074         ann_visit_shr.reset();
00075         ann_visit_nds.reset();
00076         ann_visit_pts.reset();
00077         ann_coord_hts.reset();
00078         ann_float_ops.reset();
00079         ann_average_err.reset();
00080         ann_rank_err.reset();
00081 }
00082 
00083 DLL_API void annResetCounts()                           // reset counts for one query
00084 {
00085         ann_Nvisit_lfs = 0;
00086         ann_Nvisit_spl = 0;
00087         ann_Nvisit_shr = 0;
00088         ann_Nvisit_pts = 0;
00089         ann_Ncoord_hts = 0;
00090         ann_Nfloat_ops = 0;
00091 }
00092 
00093 DLL_API void annUpdateStats()                           // update stats with current counts
00094 {
00095         ann_visit_lfs += ann_Nvisit_lfs;
00096         ann_visit_nds += ann_Nvisit_spl + ann_Nvisit_lfs;
00097         ann_visit_spl += ann_Nvisit_spl;
00098         ann_visit_shr += ann_Nvisit_shr;
00099         ann_visit_pts += ann_Nvisit_pts;
00100         ann_coord_hts += ann_Ncoord_hts;
00101         ann_float_ops += ann_Nfloat_ops;
00102 }
00103 
00104                                                                                 // print a single statistic
00105 void print_one_stat(char *title, ANNsampStat s, double div)
00106 {
00107         cout << title << "= [ ";
00108         cout.width(9); cout << s.mean()/div                     << " : ";
00109         cout.width(9); cout << s.stdDev()/div           << " ]<";
00110         cout.width(9); cout << s.min()/div                      << " , ";
00111         cout.width(9); cout << s.max()/div                      << " >\n";
00112 }
00113 
00114 DLL_API void annPrintStats(                             // print statistics for a run
00115         ANNbool validate)                                       // true if average errors desired
00116 {
00117         cout.precision(4);                                      // set floating precision
00118         cout << "  (Performance stats: "
00119                  << " [      mean :    stddev ]<      min ,       max >\n";
00120         print_one_stat("    leaf_nodes       ", ann_visit_lfs, 1);
00121         print_one_stat("    splitting_nodes  ", ann_visit_spl, 1);
00122         print_one_stat("    shrinking_nodes  ", ann_visit_shr, 1);
00123         print_one_stat("    total_nodes      ", ann_visit_nds, 1);
00124         print_one_stat("    points_visited   ", ann_visit_pts, 1);
00125         print_one_stat("    coord_hits/pt    ", ann_coord_hts, ann_Ndata_pts);
00126         print_one_stat("    floating_ops_(K) ", ann_float_ops, 1000);
00127         if (validate) {
00128                 print_one_stat("    average_error    ", ann_average_err, 1);
00129                 print_one_stat("    rank_error       ", ann_rank_err, 1);
00130         }
00131         cout.precision(0);                                      // restore the default
00132         cout << "  )\n";
00133         cout.flush();
00134 }

Generated on Wed Nov 23 19:00:26 2011 for FreeCAD by  doxygen 1.6.1