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 std::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 std::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 }
gtsam.examples.DogLegOptimizerExample.int
int
Definition: DogLegOptimizerExample.py:111
global_includes.h
Included from all GTSAM files.
gtsam::FastMap
Definition: FastMap.h:39
gtsam::treeTraversal::ForestStatistics::Histogram
FastMap< int, ValueWithDefault< int, 0 > > Histogram
Definition: statistics.h:33
stats
bool stats
Definition: SolverComparer.cpp:100
gtsam::treeTraversal::DepthFirstForest
void DepthFirstForest(FOREST &forest, DATA &rootData, VISITOR_PRE &visitorPre, VISITOR_POST &visitorPost)
Definition: treeTraversal-inst.h:77
gtsam::treeTraversal::ForestStatistics::problemSizeOfSecondLargestChildHistogram
Histogram problemSizeOfSecondLargestChildHistogram
Definition: statistics.h:36
gtsam::treeTraversal::ForestStatistics::problemSizeHistogram
Histogram problemSizeHistogram
Definition: statistics.h:34
gtsam
traits
Definition: SFMdata.h:40
gtsam::treeTraversal::GatherStatistics
ForestStatistics GatherStatistics(const FOREST &forest)
Definition: statistics.h:86
gtsam::treeTraversal::ForestStatistics
Struct to store gathered statistics about a forest.
Definition: statistics.h:31
gtsam::treeTraversal::ForestStatistics::Write
static void Write(std::ostream &outStream, const Histogram &histogram)
Definition: statistics.h:38
internal
Definition: BandTriangularSolver.h:13
gtsam::treeTraversal::ForestStatistics::numberOfChildrenHistogram
Histogram numberOfChildrenHistogram
Definition: statistics.h:35
gtsam::treeTraversal::internal::statisticsVisitor
ForestStatistics * statisticsVisitor(const std::shared_ptr< NODE > &node, ForestStatistics *stats)
Definition: statistics.h:58
FastMap.h
A thin wrapper around std::map that uses boost's fast_pool_allocator.


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:14:02