source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/ann_1.1.1/src/perf.cpp @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 5.1 KB
Line 
1//----------------------------------------------------------------------
2// File:                        perf.cpp
3// Programmer:          Sunil Arya and David Mount
4// Description:         Methods for performance stats
5// Last modified:       01/04/05 (Version 1.0)
6//----------------------------------------------------------------------
7// Copyright (c) 1997-2005 University of Maryland and Sunil Arya and
8// David Mount.  All Rights Reserved.
9//
10// This software and related documentation is part of the Approximate
11// Nearest Neighbor Library (ANN).  This software is provided under
12// the provisions of the Lesser GNU Public License (LGPL).  See the
13// file ../ReadMe.txt for further information.
14//
15// The University of Maryland (U.M.) and the authors make no
16// representations about the suitability or fitness of this software for
17// any purpose.  It is provided "as is" without express or implied
18// warranty.
19//----------------------------------------------------------------------
20// History:
21//      Revision 0.1  03/04/98
22//              Initial release
23//      Revision 1.0  04/01/05
24//              Changed names to avoid namespace conflicts.
25//              Added flush after printing performance stats to fix bug
26//                      in Microsoft Windows version.
27//----------------------------------------------------------------------
28
29#include <ANN/ANN.h>                                    // basic ANN includes
30#include <ANN/ANNperf.h>                                // performance includes
31
32using namespace std;                                    // make std:: available
33
34//----------------------------------------------------------------------
35//      Performance statistics
36//              The following data and routines are used for computing
37//              performance statistics for nearest neighbor searching.
38//              Because these routines can slow the code down, they can be
39//              activated and deactiviated by defining the PERF variable,
40//              by compiling with the option: -DPERF
41//----------------------------------------------------------------------
42
43//----------------------------------------------------------------------
44//      Global counters for performance measurement
45//----------------------------------------------------------------------
46
47int                             ann_Ndata_pts  = 0;             // number of data points
48int                             ann_Nvisit_lfs = 0;             // number of leaf nodes visited
49int                             ann_Nvisit_spl = 0;             // number of splitting nodes visited
50int                             ann_Nvisit_shr = 0;             // number of shrinking nodes visited
51int                             ann_Nvisit_pts = 0;             // visited points for one query
52int                             ann_Ncoord_hts = 0;             // coordinate hits for one query
53int                             ann_Nfloat_ops = 0;             // floating ops for one query
54ANNsampStat             ann_visit_lfs;                  // stats on leaf nodes visits
55ANNsampStat             ann_visit_spl;                  // stats on splitting nodes visits
56ANNsampStat             ann_visit_shr;                  // stats on shrinking nodes visits
57ANNsampStat             ann_visit_nds;                  // stats on total nodes visits
58ANNsampStat             ann_visit_pts;                  // stats on points visited
59ANNsampStat             ann_coord_hts;                  // stats on coordinate hits
60ANNsampStat             ann_float_ops;                  // stats on floating ops
61//
62ANNsampStat             ann_average_err;                // average error
63ANNsampStat             ann_rank_err;                   // rank error
64
65//----------------------------------------------------------------------
66//      Routines for statistics.
67//----------------------------------------------------------------------
68
69DLL_API void annResetStats(int data_size) // reset stats for a set of queries
70{
71        ann_Ndata_pts  = data_size;
72        ann_visit_lfs.reset();
73        ann_visit_spl.reset();
74        ann_visit_shr.reset();
75        ann_visit_nds.reset();
76        ann_visit_pts.reset();
77        ann_coord_hts.reset();
78        ann_float_ops.reset();
79        ann_average_err.reset();
80        ann_rank_err.reset();
81}
82
83DLL_API void annResetCounts()                           // reset counts for one query
84{
85        ann_Nvisit_lfs = 0;
86        ann_Nvisit_spl = 0;
87        ann_Nvisit_shr = 0;
88        ann_Nvisit_pts = 0;
89        ann_Ncoord_hts = 0;
90        ann_Nfloat_ops = 0;
91}
92
93DLL_API void annUpdateStats()                           // update stats with current counts
94{
95        ann_visit_lfs += ann_Nvisit_lfs;
96        ann_visit_nds += ann_Nvisit_spl + ann_Nvisit_lfs;
97        ann_visit_spl += ann_Nvisit_spl;
98        ann_visit_shr += ann_Nvisit_shr;
99        ann_visit_pts += ann_Nvisit_pts;
100        ann_coord_hts += ann_Ncoord_hts;
101        ann_float_ops += ann_Nfloat_ops;
102}
103
104                                                                                // print a single statistic
105void print_one_stat(char *title, ANNsampStat s, double div)
106{
107        cout << title << "= [ ";
108        cout.width(9); cout << s.mean()/div                     << " : ";
109        cout.width(9); cout << s.stdDev()/div           << " ]<";
110        cout.width(9); cout << s.min()/div                      << " , ";
111        cout.width(9); cout << s.max()/div                      << " >\n";
112}
113
114DLL_API void annPrintStats(                             // print statistics for a run
115        ANNbool validate)                                       // true if average errors desired
116{
117        cout.precision(4);                                      // set floating precision
118        cout << "  (Performance stats: "
119                 << " [      mean :    stddev ]<      min ,       max >\n";
120        print_one_stat("    leaf_nodes       ", ann_visit_lfs, 1);
121        print_one_stat("    splitting_nodes  ", ann_visit_spl, 1);
122        print_one_stat("    shrinking_nodes  ", ann_visit_shr, 1);
123        print_one_stat("    total_nodes      ", ann_visit_nds, 1);
124        print_one_stat("    points_visited   ", ann_visit_pts, 1);
125        print_one_stat("    coord_hits/pt    ", ann_coord_hts, ann_Ndata_pts);
126        print_one_stat("    floating_ops_(K) ", ann_float_ops, 1000);
127        if (validate) {
128                print_one_stat("    average_error    ", ann_average_err, 1);
129                print_one_stat("    rank_error       ", ann_rank_err, 1);
130        }
131        cout.precision(0);                                      // restore the default
132        cout << "  )\n";
133        cout.flush();
134}
Note: See TracBrowser for help on using the repository browser.