13 #include <boost/shared_ptr.hpp>
14 #include <boost/make_shared.hpp>
15 #include <boost/tuple/tuple.hpp>
16 #include <boost/array.hpp>
26 template<
typename T>
struct View_traits;
31 template<
class T,
class Traits = View_traits<T> >
38 template<
class T,
class Traits>
72 typename Data_type::iterator first,
73 typename Data_type::iterator last,
81 values_ = other.values_;
82 learn_ = other.learn_;
142 static const double&
prior_prob(
const size_t& val,
const size_t& type)
144 return Traits::prior_prob(val, type);
162 void unlearn() {
if(learn_ ==
true) {cleanup(); learn_ =
false;}}
166 void learn() {
if(learn_ ==
false) {learn_ =
true; initialize();}}
174 cell_ptr_->decrement(table_code_);
175 table_code_ = cell_ptr_->sample_table_assignment();
176 cell_ptr_->increment(table_code_);
192 template<
class T,
class Traits>
194 typename Data_type::iterator first,
195 typename Data_type::iterator last,
198 : values_(first, last, Traits::size), table_code_(0), learn_(learn)
205 template<
class T,
class Traits>
208 values_ = source.values_;
209 table_code_ = source.table_code_;
210 learn_ = source.learn_;
217 template<
class T,
class Traits>
220 using namespace boost;
221 std::vector<int> result(smoothing_levels, 0);
224 p != NULL && j < smoothing_levels;
228 if(p != NULL && p -> context() != NULL)
230 result[j] = p ->
count();
233 std::cerr <<
"Level " << smoothing_levels - j <<
" key:"
234 << p -> key() << std::endl;
244 template<
class T,
class Traits>
247 using namespace boost;
248 std::vector<int> result(smoothing_levels, 0);
251 j < smoothing_levels;
254 if(p != NULL && p -> context() != NULL)
256 result[j] = p -> context() ->
count();
259 std::cerr <<
"Level " << smoothing_levels - j <<
" key:"
260 << p -> context() -> key() << std::endl;
271 template<
class T,
class Traits>
274 using namespace boost;
275 std::vector<int> result(smoothing_levels, 0);
278 j < smoothing_levels;
282 if(p != NULL && p -> context() != NULL)
284 result[j] = p -> context() -> diversity();
294 template<
class T,
class Traits>
inline
300 Traits::step_sizes.rbegin(),
304 assert(cell_ptr_ != NULL);
307 table_code_ = cell_ptr_->sample_table_assignment();
308 cell_ptr_->increment(table_code_);
309 assert(cell_ptr_->count() > 0);
315 template<
class T,
class Traits>
inline
316 void Event_view<T, Traits>::cleanup()
320 assert(cell_ptr_->count() > 0);
321 cell_ptr_->decrement(table_code_);
327 template<
class T,
class Traits>
333 typename Traits::Var_list::const_iterator marker;
334 typename Traits::Var_list::const_iterator given =
335 Traits::variable_names.begin() + Traits::out_size;
336 for(marker = Traits::variable_names.begin(); marker != given; marker++)
338 os << *marker <<
" ";
341 for(
typename Traits::Step_sizes::const_iterator it =
342 Traits::step_sizes.begin();
343 it != Traits::step_sizes.end();
349 os << *marker <<
" ";
362 template<
class T,
class Traits>
365 template<
class T,
class Traits>
368 template<
class T,
class Traits>
M_cell::Map Map
Definition: Event_view.h:53
std::vector< Val_type > Data_type
Definition: Categorical_event.h:63
static const double & prior_prob(const size_t &val, const size_t &type)
unconditional prior probability of a particular outcome
Definition: Event_view.h:142
virtual ~Event_view()
Destructor.
Definition: Event_view.h:88
Self & operator=(const Self &source)
Assignment operator.
Definition: Event_view.h:206
Marginal_cell_base::Self_ptr Base_ptr
Definition: Marginal_cell.h:135
Event_view< T, Traits > Self
Definition: Event_view.h:47
void learn()
add counts to database (treat as observed)
Definition: Event_view.h:166
void display_conditioning_expression(std::ostream &os) const
show output and context variables
Definition: Event_view.h:328
static const size_t & smoothing_levels
Definition: Event_view.h:60
static Map & map
Definition: Event_view.h:59
double smoothed_probability(const bool &collins=false) const
get smoothed conditional probability via Collins' method
Definition: Event_view.h:116
static const double & diversity_weight()
hard-coded diversity-weight parameter for this event type
Definition: Event_view.h:150
T Event
Definition: Event_view.h:48
std::vector< int > get_diversities() const
get counts of how many different events occur at this context
Definition: Event_view.h:272
concrete class for contingency table cell
Definition: Cell_traits.h:24
static bool VERBOSE
Definition: Event_view.h:61
count
Definition: APPgetLargeConnectedEdges.m:71
Marginal_cell< Self, Traits::context_levels > M_cell
Definition: Event_view.h:50
Template class to represent different "views" of syntactic events.
Definition: Event_view.h:32
void unlearn()
remove counts from database (treat as unobserved)
Definition: Event_view.h:162
Key_type::Data_type Data_type
Definition: Event_view.h:52
Traits Event_traits
Definition: Event_view.h:49
look-up key class for contingency table
Definition: Categorical_event.h:29
double predictive_probability() const
get predictive prob according to HCRP model
Definition: Event_view.h:128
Event_view(const Self &other)
Copy constructor.
Definition: Event_view.h:79
M_cell::Key_type Key_type
Definition: Event_view.h:51
void resample_table_assignment()
resample the CRP table assignment for this event
Definition: Event_view.h:170
std::vector< int > get_numerators() const
get counts of event at various smoothing levels
Definition: Event_view.h:218
Support for error handling exception classes in libKJB.
std::vector< int > get_denominators() const
get counts of context at various smoothing levels
Definition: Event_view.h:245
boost::unordered_map< Key_type, Self_ptr > Map
Definition: Marginal_cell.h:138
Event_view(const bool learn=true)
Definition: Event_view.h:67