KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pt_scene_posterior.h
Go to the documentation of this file.
1 /* =========================================================================== *
2 |
3 | Copyright (c) 1994-2008 by Kobus Barnard (author).
4 |
5 | Personal and educational use of this code is granted, provided that this
6 | header is kept intact, and that the authorship is not misrepresented, that
7 | its use is acknowledged in publications, and relevant papers are cited.
8 |
9 | For other use contact the author (kobus AT cs DOT arizona DOT edu).
10 |
11 | Please note that the code in this file has not necessarily been adequately
12 | tested. Naturally, there is no guarantee of performance, support, or fitness
13 | for any particular task. Nonetheless, I am interested in hearing about
14 | problems that you encounter.
15 |
16 | Authors:
17 | Ernesto Brau
18 |
19 * =========================================================================== */
20 
21 /* $Id: pt_scene_posterior.h 18971 2015-04-29 23:31:48Z jguan1 $ */
22 
23 #ifndef PT_SCENE_POSTERIOR_H
24 #define PT_SCENE_POSTERIOR_H
25 
39 #include <detector_cpp/d_bbox.h>
40 #include <iostream>
41 
42 namespace kjb {
43 namespace pt {
44 
54 {
55 public:
57  (
63  const Position_prior& pos_prior,
64  const Direction_prior& dir_prior,
65  const Face_direction_prior& fdir_prior,
66  bool vis_off = false,
67  bool infer_head_off = false
68  ) :
69  box_likelihood_(box_likelihood),
70  fm_likelihood_(fm_likelihood),
71  of_likelihood_(of_likelihood),
72  ff_likelihood_(ff_likelihood),
73  color_likelihood_(color_likelihood),
74  pos_prior_(pos_prior),
75  dir_prior_(dir_prior),
76  fdir_prior_(fdir_prior),
83  use_box_lh_(true),
84  use_fm_lh_(true),
85  use_of_lh_(true),
86  use_ff_lh_(true),
87  use_color_lh_(false),
88  use_pos_prior_(true),
89  use_dir_prior_(true),
90  use_fdir_prior_(true),
91  use_dim_prior_(true),
92  m_vis_off(vis_off),
93  m_infer_head(!infer_head_off)
94  {}
95 
96 public:
98  double operator()(const Scene& scene) const;
99 
104  double local
105  (
106  const Target& target,
107  const Scene& scene,
108  size_t frame
109  ) const
110  {
111  return local(target, target, scene, frame, frame);
112  }
113 
118  double local
119  (
120  const Target& target1,
121  const Target& target2,
122  const Scene& scene,
123  size_t frame1,
124  size_t frame2
125  ) const;
126 
127 public:
129  bool& use_box_lh() const { return use_box_lh_; }
130 
132  bool& use_fm_lh() const { return use_fm_lh_; }
133 
135  bool& use_of_lh() const { return use_of_lh_; }
136 
138  bool& use_ff_lh() const { return use_ff_lh_; }
139 
141  bool& use_color_lh() const { return use_color_lh_; }
142 
144  bool& use_pos_prior() const { return use_pos_prior_; }
145 
147  bool& use_dir_prior() const { return use_dir_prior_; }
148 
150  bool& use_fdir_prior() const { return use_fdir_prior_; }
151 
153  bool& use_dim_prior() const { return use_dim_prior_; }
154 
156  bool vis_off() const { return m_vis_off; }
157 
159  bool infer_head() const { return m_infer_head; }
160 
161 public:
163  const Position_prior& position_prior() const { return pos_prior_; }
164 
166  const Direction_prior& direction_prior() const { return dir_prior_; }
167 
170  {
171  return fdir_prior_;
172  }
173 
175  const Normal_distribution& height_prior() const { return N_h; }
176 
178  const Normal_distribution& width_prior() const { return N_w; }
179 
181  const Normal_distribution& girth_prior() const { return N_g; }
182 
184  const Box_likelihood& box_likelihood() const { return box_likelihood_; }
185 
187  const Facemark_likelihood& fm_likelihood() const { return fm_likelihood_; }
188 
191  {
192  return of_likelihood_;
193  }
194 
196  const Face_flow_likelihood& ff_likelihood() const { return ff_likelihood_; }
197 
200  {
201  return color_likelihood_;
202  }
203 
204 //private:
206  double dimension_prior(const Scene& scene) const;
207 
208 private:
209  // distributions
210  const Box_likelihood& box_likelihood_;
211  const Facemark_likelihood& fm_likelihood_;
212  const Optical_flow_likelihood& of_likelihood_;
213  const Face_flow_likelihood& ff_likelihood_;
214  const Color_likelihood& color_likelihood_;
215  const Position_prior& pos_prior_;
216  const Direction_prior& dir_prior_;
217  const Face_direction_prior& fdir_prior_;
221 
222  // use distributions?
223  mutable bool use_box_lh_;
224  mutable bool use_fm_lh_;
225  mutable bool use_of_lh_;
226  mutable bool use_ff_lh_;
227  mutable bool use_color_lh_;
228  mutable bool use_pos_prior_;
229  mutable bool use_dir_prior_;
230  mutable bool use_fdir_prior_;
231  mutable bool use_dim_prior_;
232  bool m_vis_off;
233  bool m_infer_head;
234 };
235 
240 {
241 public:
243  posterior_(post), adapter_(post.vis_off(), post.infer_head()) {}
244 
245  double operator()(const Scene& sc, size_t i) const
246  {
247  const Target* tg_p;
248  size_t frame;
249  boost::tie(tg_p, frame) = adapter_.target_frame(&sc, i);
250 
251  IFT(tg_p != 0, Runtime_error, "Cannot compute ind. post.: bad index.");
252 
253  return posterior_.local(*tg_p, sc, frame);
254  }
255 
256  double operator()(const Scene& sc, size_t i, size_t j) const
257  {
258  const Target* tg_p1;
259  const Target* tg_p2;
260  size_t frame1;
261  size_t frame2;
262  boost::tie(tg_p1, frame1) = adapter_.target_frame(&sc, i);
263  boost::tie(tg_p2, frame2) = adapter_.target_frame(&sc, j);
264 
265  IFT(tg_p1 != 0, Runtime_error, "Cannot compute ind. post.: bad index.");
266  IFT(tg_p2 != 0, Runtime_error, "Cannot compute ind. post.: bad index.");
267 
268  return posterior_.local(*tg_p1, *tg_p2, sc, frame1, frame2);
269  }
270 
271  const Scene_adapter& adapter() const { return adapter_; }
272 
273  void reset() const { adapter_.reset(); }
274 
275 private:
276  const Scene_posterior& posterior_;
277  Scene_adapter adapter_;
278 };
279 
282 (
283  const Scene_posterior& post,
284  const Scene& scene,
285  double mlh,
286  std::ostream& ost
287 );
288 
289 }} // namespace kjb::pt
290 
291 #endif /*PT_SCENE_POSTERIOR_H */
292 
const Face_flow_likelihood & ff_likelihood() const
Returns the face flow likelihood.
Definition: pt_scene_posterior.h:196
bool vis_off() const
Returns whether visibilities is being used.
Definition: pt_scene_posterior.h:156
Class that represents the prior distribution of a trajectory.
Definition: pt_direction_prior.h:33
std::pair< const Target *, size_t > target_frame(const Scene *s, size_t i) const
Get target and frame corresponding to variable i.
Definition: pt_scene_adapter.h:244
bool infer_head() const
Returns whether inferring head.
Definition: pt_scene_posterior.h:159
Adapts a Scene into a VectorModel for HMC sampling.
Definition: pt_scene_adapter.h:183
const Face_direction_prior & face_direction_prior() const
Returns the face direction prior.
Definition: pt_scene_posterior.h:169
Definition of various standard probability distributions.
Class to compute face optical flow likelihood.
Definition: pt_face_flow_likelihood.h:42
double get_entity_type_average_height(Entity_type type)
Get the average height of an entity.
Definition: tracking_entity.cpp:110
const Scene_adapter & adapter() const
Definition: pt_scene_posterior.h:271
double get_entity_type_average_girth(Entity_type type)
Get the average girth of an entity.
Definition: tracking_entity.cpp:138
bool & use_ff_lh() const
Returns whether or not we are using the FF likelihood.
Definition: pt_scene_posterior.h:138
Class to compute face optical flow likelihood.
Definition: pt_optical_flow_likelihood.h:43
const Optical_flow_likelihood & of_likelihood() const
Returns the optical flow likelihood.
Definition: pt_scene_posterior.h:190
Class that represents the prior distribution of the face direction.
Definition: pt_direction_prior.h:137
Class that represents a full scene in the PT universe.
Definition: pt_scene.h:40
const Facemark_likelihood & fm_likelihood() const
Returns the facemark likelihood.
Definition: pt_scene_posterior.h:187
bool & use_pos_prior() const
Returns whether or not we are using the position prior.
Definition: pt_scene_posterior.h:144
const Position_prior & position_prior() const
Returns the position prior.
Definition: pt_scene_posterior.h:163
const Normal_distribution & width_prior() const
Returns the width prior.
Definition: pt_scene_posterior.h:178
bool & use_dir_prior() const
Returns whether or not we are using the direction prior.
Definition: pt_scene_posterior.h:147
bool & use_fdir_prior() const
Returns whether or not we are using the face direction prior.
Definition: pt_scene_posterior.h:150
void reset() const
Definition: pt_scene_posterior.h:273
double dimension_prior(const Scene &scene) const
Computes the dimension prior of a scene.
Definition: pt_scene_posterior.cpp:239
#define IFT(a, ex, msg)
Definition: l_exception.h:101
bool & use_dim_prior() const
Returns whether or not we are using the dimension prior.
Definition: pt_scene_posterior.h:153
const Normal_distribution & height_prior() const
Returns the height prior.
Definition: pt_scene_posterior.h:175
St_perspective_camera for modeling a perspective camera using the classic Forsyth and Ponce parametri...
double get_entity_type_stddev_girth(Entity_type type)
Get the standard deviation of the girth of an entity.
Definition: tracking_entity.cpp:145
Posterior adapter to work with independent gradient computation.
Definition: pt_scene_posterior.h:239
void reset() const
Restart state.
Definition: pt_scene_adapter.h:240
bool & use_fm_lh() const
Returns whether or not we are using the facemark likelihood.
Definition: pt_scene_posterior.h:132
Entity_type get_entity_type(const std::string &name)
Get the type of a entity name.
Definition: tracking_entity.cpp:96
Class that represents the prior distribution of a trajectory.
Definition: pt_position_prior.h:34
Class that represents a target moving through space.
Definition: pt_target.h:50
bool & use_of_lh() const
Returns whether or not we are using the OF likelihood.
Definition: pt_scene_posterior.h:135
Class that represents likelihood of a set of projected boxes given. detections. At the moment it only...
Definition: pt_box_likelihood.h:42
const Box_likelihood & box_likelihood() const
Returns the box likelihood.
Definition: pt_scene_posterior.h:184
const Normal_distribution & girth_prior() const
Returns the girth prior.
Definition: pt_scene_posterior.h:181
bool & use_color_lh() const
Returns whether or not we are using the color likelihood.
Definition: pt_scene_posterior.h:141
Posterior distribution of a scene.
Definition: pt_scene_posterior.h:53
double get_entity_type_average_width(Entity_type type)
Get the average width of an entity.
Definition: tracking_entity.cpp:124
void write_posterior_details(const Scene_posterior &post, const Scene &scene, double mlh, std::ostream &ost)
Write the details of the posterior in a table format.
Definition: pt_scene_posterior.cpp:263
Scene_posterior_ind(const Scene_posterior &post)
Definition: pt_scene_posterior.h:242
boost::math::normal Normal_distribution
Definition: prob_distribution.h:68
const Color_likelihood & color_likelihood() const
Returns the color likelihood.
Definition: pt_scene_posterior.h:199
Class that represents color likelihood of a set of projected boxes given detections.
Definition: pt_color_likelihood.h:42
bool & use_box_lh() const
Returns whether or not we are using the box likelihood.
Definition: pt_scene_posterior.h:129
double get_entity_type_stddev_width(Entity_type type)
Get the standard deviation of the width of an entity.
Definition: tracking_entity.cpp:131
double get_entity_type_stddev_height(Entity_type type)
Get the standard deviation of the height of an entity.
Definition: tracking_entity.cpp:117
const Direction_prior & direction_prior() const
Returns the direction prior.
Definition: pt_scene_posterior.h:166
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
Class to compute facemark likelihood.
Definition: pt_facemark_likelihood.h:39
double operator()(const Scene &sc, size_t i) const
Definition: pt_scene_posterior.h:245
double local(const Target &target, const Scene &scene, size_t frame) const
Computes the likelihood of a scene where only a single item moved.
Definition: pt_scene_posterior.h:105
Object thrown when computation fails somehow during execution.
Definition: l_exception.h:321
double operator()(const Scene &scene) const
Computes the posterior of a scene.
Definition: pt_scene_posterior.cpp:52
double operator()(const Scene &sc, size_t i, size_t j) const
Definition: pt_scene_posterior.h:256
Scene_posterior(const Box_likelihood &box_likelihood, const Facemark_likelihood &fm_likelihood, const Optical_flow_likelihood &of_likelihood, const Face_flow_likelihood &ff_likelihood, const Color_likelihood &color_likelihood, const Position_prior &pos_prior, const Direction_prior &dir_prior, const Face_direction_prior &fdir_prior, bool vis_off=false, bool infer_head_off=false)
Definition: pt_scene_posterior.h:57