KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
psi_metrics.h
Go to the documentation of this file.
1 /* $Id: psi_metrics.h 12743 2012-07-25 23:52:02Z jguan1 $ */
2 /* {{{=========================================================================== *
3  |
4  | Copyright (c) 1994-2011 by Kobus Barnard (author)
5  |
6  | Personal and educational use of this code is granted, provided that this
7  | header is kept intact, and that the authorship is not misrepresented, that
8  | its use is acknowledged in publications, and relevant papers are cited.
9  |
10  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
11  |
12  | Please note that the code in this file has not necessarily been adequately
13  | tested. Naturally, there is no guarantee of performance, support, or fitness
14  | for any particular task. Nonetheless, I am interested in hearing about
15  | problems that you encounter.
16  |
17  | Author: Kyle Simek
18  * =========================================================================== }}}*/
19 
20 // vim: tabstop=4 shiftwidth=4 foldmethod=marker
21 #include <m_cpp/m_matrix.h>
22 #include <m_cpp/m_vector_d.h>
25 
26 #include <boost/bimap.hpp>
27 #include <boost/foreach.hpp>
28 #include <boost/iterator/counting_iterator.hpp>
29 
30 #include <utility>
31 #include <vector>
32 #include <algorithm>
33 
34 #ifndef PSI_TRACKING_METRICS_H
35 #define PSI_TRACKING_METRICS_H
36 namespace kjb
37 {
38 namespace psi
39 {
40 
41 namespace metrics
42 {
43  typedef boost::bimap<pt::Entity_id, pt::Entity_id> Correspondence;
44  void get_best_matching(
45  const kjb::Matrix& pw_distance,
46  double threshold,
47  std::vector<std::pair<int, int> >& matching);
48 
49  void get_pw_distance(
50  const std::vector<const Vector3*>& pts1,
51  const std::vector<const Vector3*>& pts2,
52  kjb::Matrix& distance);
53 
55  const pt::Trajectory_map& gt_track_map,
56  const pt::Trajectory_map& test_track_map,
57  double threshold,
58  std::vector<Correspondence>& corrs);
59 }
60 
61 
62 class Track_metrics; // forward declaration
63 
64 class Track_frame_metrics : public std::vector<Track_metrics>
65 {
66 typedef std::vector<Track_metrics> Base;
67 public:
68 typedef boost::bimap<pt::Entity_id, pt::Entity_id> Correspondence;
70  const pt::Trajectory_map& gt_track,
71  const pt::Trajectory_map& test_track,
72  double threshold);
73 
74 protected:
75  void init_distance_(
76  const pt::Trajectory_map& gt_track_map,
77  const pt::Trajectory_map& test_track_map,
78  double threshold,
79  const std::vector<Correspondence>& corrs
80  );
81 
82  void init_counts_(
83  const pt::Trajectory_map& gt_track,
84  const pt::Trajectory_map& test_track,
85  const std::vector<Correspondence >& corrs);
86 };
87 
89 {
90 public:
91 typedef boost::bimap<pt::Entity_id, pt::Entity_id> Correspondence;
92 
93 public:
94 
95  Track_metrics(double threshold = 1.0) :
96  threshold_(threshold),
97  total_distance_(0),
98  mme_ct_(0),
99  fp_ct_(0),
100  miss_ct_(0),
101  match_ct_(0),
102  obj_ct_(0),
103  mt_(0.0),
104  ml_(0.0),
105  frag_(0),
106  ids_(0),
107  total_num_gt_tracks_(0)
108  {}
109 
111  const pt::Trajectory_map& gt_track,
112  const pt::Trajectory_map& test_track,
113  double threshold);
114 
116  const pt::Trajectory_map& gt_track,
117  const pt::Trajectory_map& test_track,
118  double threshold,
119  const std::vector<Correspondence>& corrs);
120 
121  double motp() const
122  {
123  if(match_ct_ == 0)
124  {
125  // can't have distance without matches
126  assert(total_distance_ == 0);
127 
128  if(obj_ct_ == 0)
129  {
130  // no ground truth tracks, so it's correct to have no matches
131  return 0.0;
132  }
133  else
134  {
135  // Utter failure.
136  // Threshold is the ceiling for this metric, so return that
137  return threshold_;
138  }
139  }
140 
141  return total_distance_ / match_ct_;
142  }
143 
144  double mota() const
145  {
146  double error_ratio;
147  if(obj_count() == 0 && error_count() == 0)
148  {
149  // This happens if there are no ground truth tracks.
150  error_ratio = 0.0;
151  }
152  else
153  {
154  error_ratio = (error_count()) / static_cast<double>(obj_count());
155  }
156  return 1.0 - error_ratio;
157  }
158 
159  // Mostly tracked
160  double mt() const
161  {
162  return mt_;
163  }
164 
165  // Mostly lost
166  double ml() const
167  {
168  return ml_;
169  }
170 
171  // Partially tracked
172  double pt() const
173  {
174  return 1.0 - mt_ - ml_;
175  }
176 
177  // Fragments: the total number of times that a ground truth
178  // trajectory is interrupted
179  size_t frag() const
180  {
181  return frag_;
182  }
183 
184  // ID switchs: the total number of times that a tracked trajectory
185  // changes its matched GT identity
186  size_t ids() const
187  {
188  return ids_;
189  }
190 
191  // Return the total number of gt tracks
192  size_t total_gt_tracks() const
193  {
194  return total_num_gt_tracks_;
195  }
196 
197 //
198 // const std::vector<Correspondence>& get_correspondence() const
199 // {
200 // return corrs_;
201 // }
202 
203  size_t obj_count() const
204  {
205  return obj_ct_;
206  }
207 
208  size_t error_count() const
209  {
210  return fp_ct_ + miss_ct_ + mme_ct_;
211  }
212 
213  double total_distance() const
214  {
215  return total_distance_;
216  }
217 
218  size_t match_count() const
219  {
220  return match_ct_;
221  }
222 
223 protected:
224  void init_distance_(
225  const pt::Trajectory_map& gt_track_map,
226  const pt::Trajectory_map& test_track_map,
227  double threshold,
228  const std::vector<Correspondence >& corrs);
229 
230  void init_counts_(
231  const pt::Trajectory_map& gt_track,
232  const pt::Trajectory_map& test_track,
233  const std::vector<Correspondence >& corrs);
234 
235 private:
236  double threshold_;
237  double total_distance_;
238  size_t mme_ct_;
239  size_t fp_ct_;
240  size_t miss_ct_;
241  size_t match_ct_;
242  size_t obj_ct_;
243  double mt_;
244  double ml_;
245  size_t frag_;
246  size_t ids_;
247  size_t total_num_gt_tracks_;
248 
249 friend class Track_frame_metrics;
250 };
251 
252 } // namespace psi
253 } // namespace kjb
254 
255 #endif
boost::bimap< pt::Entity_id, pt::Entity_id > Correspondence
Definition: psi_metrics.h:91
void init_counts_(const pt::Trajectory_map &gt_track, const pt::Trajectory_map &test_track, const std::vector< Correspondence > &corrs)
Definition: psi_metrics.cpp:435
size_t error_count() const
Definition: psi_metrics.h:208
Definition for the Matrix class, a thin wrapper on the KJB Matrix struct and its related functionalit...
double motp() const
Definition: psi_metrics.h:121
boost::bimap< pt::Entity_id, pt::Entity_id > Correspondence
Definition: psi_metrics.h:43
Track_metrics(double threshold=1.0)
Definition: psi_metrics.h:95
void init_distance_(const pt::Trajectory_map &gt_track_map, const pt::Trajectory_map &test_track_map, double threshold, const std::vector< Correspondence > &corrs)
Definition: psi_metrics.cpp:528
Track_frame_metrics(const pt::Trajectory_map &gt_track, const pt::Trajectory_map &test_track, double threshold)
Definition: psi_metrics.cpp:394
double pt() const
Definition: psi_metrics.h:172
void get_best_matching(const kjb::Matrix &pw_distance, double threshold, std::vector< std::pair< int, int > > &matching)
Compute the best matching using hungarian algorithm.
Definition: psi_metrics.cpp:170
double mt() const
Definition: psi_metrics.h:160
void init_counts_(const pt::Trajectory_map &gt_track, const pt::Trajectory_map &test_track, const std::vector< Correspondence > &corrs)
Definition: psi_metrics.cpp:544
size_t match_count() const
Definition: psi_metrics.h:218
size_t frag() const
Definition: psi_metrics.h:179
double mota() const
Definition: psi_metrics.h:144
size_t total_gt_tracks() const
Definition: psi_metrics.h:192
void get_pw_distance(const std::vector< const Vector3 * > &pts1, const std::vector< const Vector3 * > &pts2, kjb::Matrix &distance)
Definition: psi_metrics.cpp:183
Represents a set of trajectories; it is a map from entity to trajectory.
Definition: tracking_trajectory.h:53
void init_correspondence(const pt::Trajectory_map &gt_track_map, const pt::Trajectory_map &test_track_map, double threshold, std::vector< Correspondence > &corrs)
Definition: psi_metrics.cpp:200
size_t obj_count() const
Definition: psi_metrics.h:203
void init_distance_(const pt::Trajectory_map &gt_track_map, const pt::Trajectory_map &test_track_map, double threshold, const std::vector< Correspondence > &corrs)
Definition: psi_metrics.cpp:420
size_t ids() const
Definition: psi_metrics.h:186
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
Definition: psi_metrics.h:88
Definition: psi_metrics.h:64
boost::bimap< pt::Entity_id, pt::Entity_id > Correspondence
Definition: psi_metrics.h:68
double ml() const
Definition: psi_metrics.h:166
double total_distance() const
Definition: psi_metrics.h:213