statistics.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
5 * All Rights Reserved
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8 * See LICENSE for the license information
9 
10 * -------------------------------------------------------------------------- */
11 
18 #pragma once
19 
20 #include <gtsam/global_includes.h>
21 #include <gtsam/base/FastMap.h>
22 
23 #include <ostream>
24 
25 namespace gtsam {
26 
27  namespace treeTraversal {
28 
29  /* ************************************************************************* */
32  {
37 
38  static void Write(std::ostream& outStream, const Histogram& histogram)
39  {
40  if (!histogram.empty())
41  {
42  Histogram::const_iterator endIt = histogram.end();
43  -- endIt;
44  const int largest = endIt->first;
45  for (int bin = 0; bin <= largest; ++bin)
46  {
47  Histogram::const_iterator item = histogram.find(bin);
48  const int count = (item == histogram.end() ? 0 : *item->second);
49  outStream << bin << " " << count << "\n";
50  }
51  }
52  }
53  };
54 
55  /* ************************************************************************* */
56  namespace internal {
57  template<class NODE>
58  ForestStatistics* statisticsVisitor(const boost::shared_ptr<NODE>& node, ForestStatistics* stats)
59  {
60  (*stats->problemSizeHistogram[node->problemSize()]) ++;
61  (*stats->numberOfChildrenHistogram[(int)node->children.size()]) ++;
62  if (node->children.size() > 1)
63  {
64  int largestProblemSize = 0;
65  int secondLargestProblemSize = 0;
66  for(const boost::shared_ptr<NODE>& child: node->children)
67  {
68  if (child->problemSize() > largestProblemSize)
69  {
70  secondLargestProblemSize = largestProblemSize;
71  largestProblemSize = child->problemSize();
72  }
73  else if (child->problemSize() > secondLargestProblemSize)
74  {
75  secondLargestProblemSize = child->problemSize();
76  }
77  }
78  (*stats->problemSizeOfSecondLargestChildHistogram[secondLargestProblemSize]) ++;
79  }
80  return stats;
81  }
82  }
83 
84  /* ************************************************************************* */
85  template<class FOREST>
86  ForestStatistics GatherStatistics(const FOREST& forest)
87  {
89  ForestStatistics* statsPtr = &stats;
90  DepthFirstForest(forest, statsPtr, internal::statisticsVisitor<typename FOREST::Node>);
91  return stats;
92  }
93 
94  }
95 }
return int(ret)+1
Struct to store gathered statistics about a forest.
Definition: statistics.h:31
bool stats
Included from all GTSAM files.
void DepthFirstForest(FOREST &forest, DATA &rootData, VISITOR_PRE &visitorPre, VISITOR_POST &visitorPost)
static void Write(std::ostream &outStream, const Histogram &histogram)
Definition: statistics.h:38
ForestStatistics * statisticsVisitor(const boost::shared_ptr< NODE > &node, ForestStatistics *stats)
Definition: statistics.h:58
traits
Definition: chartTesting.h:28
A thin wrapper around std::map that uses boost&#39;s fast_pool_allocator.
FastMap< int, ValueWithDefault< int, 0 > > Histogram
Definition: statistics.h:33
ForestStatistics GatherStatistics(const FOREST &forest)
Definition: statistics.h:86


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:44:50