KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bbb_activity_library.h
Go to the documentation of this file.
1 /* =========================================================================== *
2  |
3  | Copyright (c) 1994-2011 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  | Author: Ernesto Brau
17  * =========================================================================== */
18 
19 /* $Id$ */
20 
21 #ifndef B3_ACTIVITY_LIBRARY_H
22 #define B3_ACTIVITY_LIBRARY_H
23 
24 #include <l_cpp/l_exception.h>
25 #include <gp_cpp/gp_covariance.h>
26 #include <m_cpp/m_vector.h>
27 #include <m_cpp/m_matrix.h>
28 #include <map>
29 #include <set>
30 #include <string>
31 #include <vector>
32 #include <utility>
33 #include <algorithm>
34 
35 namespace kjb {
36 namespace bbb {
37 
39 {
40 private:
41  typedef std::map<std::string, double> Sd_map;
42  typedef std::map<std::string, std::vector<double> > Sv_map;
43  typedef std::map<std::string, std::pair<double, double> > Sp_map;
44  typedef std::map<std::string, std::pair<Vector, Matrix> > Sc_map;
45  typedef std::vector<std::string> S_vec;
46  typedef std::vector<std::vector<double> > V_vec;
47 
48 public:
50  Activity_library(const std::string& lib_dp);
51 
52 public:
54  const std::string& activity_name(size_t a) const
55  {
56  return activities_.at(a);
57  }
58 
60  size_t num_activities() const { return activities_.size(); }
61 
63  const std::string& role_name(size_t r) const { return roles_.at(r); }
64 
66  size_t num_roles() const { return roles_.size(); }
67 
69  bool is_intentional(const std::string& act) const
70  {
71  return std::find(iacts_.begin(), iacts_.end(), act) != iacts_.end();
72  }
73 
75  bool is_physical(const std::string& act) const
76  {
77  return std::find(pacts_.begin(), pacts_.end(), act) != pacts_.end();
78  }
79 
81  template<class Iter>
82  void intentional_names(Iter out) const
83  {
84  std::copy(iacts_.begin(), iacts_.end(), out);
85  }
86 
88  template<class Iter>
89  void physical_names(Iter out) const
90  {
91  std::copy(pacts_.begin(), pacts_.end(), out);
92  }
93 
94 public:
96  const Sd_map::mapped_type& group_concentration(const std::string& act) const
97  {
98  Sd_map::const_iterator pr_p = crp_params_.find(act);
99  IFT(pr_p != crp_params_.end(), Illegal_argument,
100  "Cannot get group concentration: activity does not exist.");
101 
102  return pr_p->second;
103  }
104 
106  const Sv_map::mapped_type& role_distribution(const std::string& act) const
107  {
108  Sv_map::const_iterator pr_p = role_dists_.find(act);
109  IFT(pr_p != role_dists_.end(), Illegal_argument,
110  "Cannot get role distribution: activity does not exist.");
111 
112  return pr_p->second;
113  }
114 
116  gp::Sqex trajectory_kernel(const std::string& act) const
117  {
118  Sp_map::const_iterator pr_p = kernel_params_.find(act);
119  IFT(pr_p != kernel_params_.end(), Illegal_argument,
120  "Cannot get kernel: activity does not exist.");
121 
122  return gp::Sqex(pr_p->second.first, pr_p->second.second);
123  }
124 
126  const Sc_map::mapped_type& markov_chain(const std::string& role) const
127  {
128  Sc_map::const_iterator pr_p = role_mcs_.find(role);
129  IFT(pr_p != role_mcs_.end(), Illegal_argument,
130  "Cannot get role chain: role does not exist.");
131 
132  return pr_p->second;
133  }
134 
137  (
138  const std::string& name,
139  const std::string& pt_name,
140  const Vector& pt_params
141  ) const;
142 
144  bool has_target(const std::string& act) const
145  {
146  return act_target_.count(act);
147  }
148 
149 public:
151  size_t role_index(const std::string& role) const
152  {
153  std::vector<std::string>::const_iterator str_p = std::find(
154  roles_.begin(),
155  roles_.end(),
156  role);
157  IFT(str_p != roles_.end(), Illegal_argument, "Role does not exist");
158 
159  return std::distance(roles_.begin(), str_p);
160  }
161 
162 private:
163  std::pair<S_vec, V_vec> read_strs_and_vecs(const std::string& path);
164 
165 private:
166  // lists
167  std::vector<std::string> activities_;
168  std::vector<std::string> iacts_;
169  std::vector<std::string> pacts_;
170  std::vector<std::string> roles_;
171 
172  // other parameters
173  Sd_map crp_params_;
174  Sv_map role_dists_;
175  Sp_map kernel_params_;
176  Sc_map role_mcs_;
177  std::set<std::string> act_target_;
178 };
179 
180 }} // namespace kjb::bbb
181 
182 #endif /* B3_ACTIVITY_LIBRARY_H */
183 
bool is_physical(const std::string &act) const
Is the given activity physical?.
Definition: bbb_activity_library.h:75
Vector sample_parameters(const std::string &name, const std::string &pt_name, const Vector &pt_params) const
Sample the parameters of an activity.
Definition: bbb_activity_library.cpp:171
const std::string & role_name(size_t r) const
Get the name of the r-th role.
Definition: bbb_activity_library.h:63
Definition for the Matrix class, a thin wrapper on the KJB Matrix struct and its related functionalit...
size_t num_roles() const
Get number of roles avialable.
Definition: bbb_activity_library.h:66
Activity_library(const std::string &lib_dp)
Constructor.
Definition: bbb_activity_library.cpp:40
const Sd_map::mapped_type & group_concentration(const std::string &act) const
Get the concentration parameter for an activity.
Definition: bbb_activity_library.h:96
bool is_intentional(const std::string &act) const
Is the given activity intentional?.
Definition: bbb_activity_library.h:69
r
Definition: APPgetLargeConnectedEdges.m:127
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
const std::string & activity_name(size_t a) const
Get the name of the a-th activity.
Definition: bbb_activity_library.h:54
#define IFT(a, ex, msg)
Definition: l_exception.h:101
void physical_names(Iter out) const
Get a list of the physical activity names.
Definition: bbb_activity_library.h:89
void intentional_names(Iter out) const
Get a list of the intentional activity names.
Definition: bbb_activity_library.h:82
size_t role_index(const std::string &role) const
Get the index of a role (by name).
Definition: bbb_activity_library.h:151
size_t num_activities() const
Get number of activities avialable.
Definition: bbb_activity_library.h:60
gp::Sqex trajectory_kernel(const std::string &act) const
Get the trajectory kernel for an activity.
Definition: bbb_activity_library.h:116
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
Support for error handling exception classes in libKJB.
const Sv_map::mapped_type & role_distribution(const std::string &act) const
Get the distribution over roles for an activity.
Definition: bbb_activity_library.h:106
const Sc_map::mapped_type & markov_chain(const std::string &role) const
Get the MC parameters for an activity.
Definition: bbb_activity_library.h:126
Definition: bbb_activity_library.h:38
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
bool has_target(const std::string &act) const
Returns true if the given activity has a target.
Definition: bbb_activity_library.h:144