KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Marginal_cell.h
Go to the documentation of this file.
1 #ifndef MARGINAL_CELL_H_
2 #define MARGINAL_CELL_H_
3 
13 #include <semantics/Cell_traits.h>
14 #include <m_cpp/m_vector.h>
16 #include <prob_cpp/prob_sample.h>
17 #include <boost/shared_ptr.hpp>
18 #include <boost/make_shared.hpp>
19 #include <boost/unordered_map.hpp>
20 #include <cmath>
21 #include <iostream>
22 #include <list>
23 
24 /*------------------------------------------------------------
25  * FORWARD DECLARATIONS
26  *------------------------------------------------------------*/
27 
28 namespace semantics
29 {
30 
31 template<typename T> class Prior_cell;
32 
36 template<typename T, size_t N> class Marginal_cell;
37 
41 template<typename T, size_t N> class Context_cell;
42 
43 
44 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
45 
46 template<class T>
47 class Prior_cell : public Marginal_cell_base
48 {
49 public:
51  typedef boost::shared_ptr<Prior_cell<T> > Self_ptr;
55  typedef boost::unordered_map<Key_type, Self_ptr> Map;
56  static Map map;
57 public:
58  Prior_cell(const Key_type& key) : key_(key) {}
59 
60  const Key_type& key() const {return key_;}
61 
62  void increment(const size_t&){}
63 
64  void decrement(const size_t&){}
65 
66  size_t sample_table_assignment() {return 0;}
67 
68  Base_ptr margin() const {return Base_ptr();}
69 
71 
72  double backoff_probability() const
73  {
74  return T::prior_prob(key_.front(), key_.back());
75  }
76 
78  {
79  return backoff_probability();
80  }
81 
82  double predictive_probability() const
83  {
84  return backoff_probability();
85  }
86 
88  const Key_type& key,
89  Cell::Step_sizes::const_reverse_iterator,
90  const size_t&,
91  const size_t&
92  )
93  {
94  Self_ptr result;
95  typename Map::iterator it = map.find(key);
96  if(it == map.end()) result = boost::make_shared<Self>(key);
97  else result = it->second;
98  return result;
99  }
100 private:
101  Key_type key_;
102 };
103 
104 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
105 
106 template<class T, size_t N>
107 std::ostream& operator<<(
108  std::ostream&,
109  const typename Marginal_cell<T,N>::Map&
110  );
111 
112 template<class T>
113 std::ostream& operator<<(
114  std::ostream&,
115  const typename Marginal_cell<T,1>::Map&
116  );
117 
118 template<class T, size_t N>
119 std::ostream& operator<<(
120  std::ostream&,
121  const typename Context_cell<T,N>::Map&
122  );
123 
124 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
125 
126 template<class T, size_t N>
127 class Marginal_cell : public Marginal_cell_base
128 {
129  // T is the event type
130  // N is the smoothing level (higher values are less smoothed)
131 public:
133  typedef boost::shared_ptr<Self> Self_ptr;
138  typedef boost::unordered_map<Key_type, Self_ptr> Map;
140  typedef boost::shared_ptr<Context_type> Context_ptr;
142  typedef boost::shared_ptr<Margin_type> Margin_ptr;
143  // Associative container from keys to cells
144  static Map map;
145  static bool& VERBOSE;
146 public:
147  /*------------------------------------------------------------
148  * CONSTRUCTORS/DESTRUCTOR
149  *------------------------------------------------------------*/
150 
154  Marginal_cell(const Key_type& key);
155 
158  Marginal_cell(const Marginal_cell& other);
159 
162  virtual ~Marginal_cell();
163 
164  /*------------------------------------------------------------
165  * ACCESSORS
166  *------------------------------------------------------------*/
167 
170  const Key_type& key() const {return key_;}
171 
174  Base_ptr margin() const {return margin_;}
175 
178  Context_base_ptr context() const {return context_;}
179 
180  /*------------------------------------------------------------
181  * MANIPULATORS
182  *------------------------------------------------------------*/
183 
186  void increment(const size_t& table_code);
187 
190  void decrement(const size_t& table_code);
191 
194  void increment_table_count();
195 
198  void decrement_table_count();
199  /*------------------------------------------------------------
200  * COMPUTATION
201  *------------------------------------------------------------*/
202 
210  {
211  assert(!unused_table_codes_.empty());
219  table_weights.insert(
220  unused_table_codes_.front(),
221  context_->alpha() * backoff_probability()
222  );
223  size_t result = kjb::sample(table_weights);
224 
225  if(result == unused_table_codes_.front())
226  {
228  per_table_counts_.insert(
229  std::pair<size_t, size_t>(unused_table_codes_.front(), 0)
230  );
232  unused_table_codes_.pop_front();
233  used_table_codes_.push_back(result);
234  if(unused_table_codes_.empty())
235  {
240  unused_table_codes_.push_back(used_table_codes_.size());
241  }
242  }
243  return result;
244  }
245 
250  double backoff_probability() const
251  {
252  return table_count_ / (context_->effective_tables()) +
253  context_->table_backoff_weight() * margin_->backoff_probability();
254  }
255 
261  double predictive_probability() const
262  {
263  return count_ / (context_->effective_observations()) +
264  context_->observation_backoff_weight() * margin_->backoff_probability();
265  }
266 
270  {
271  update_probabilities();
272  return smoothed_probability_;
273  }
274 
275  /*------------------------------------------------------------
276  * STATIC AND FRIEND FUNCTIONS
277  *------------------------------------------------------------*/
278 
281  static Self_ptr add_event(
282  const Key_type& key,
283  Cell::Step_sizes::const_reverse_iterator first,
284  const size_t& size,
285  const size_t& out_size
286  );
287 
291  const typename Context_type::Key_type& key);
292 
295  friend std::ostream& operator<< <T,N>(std::ostream& os, const Map& map);
296 private:
299  void update_probabilities();
300 
301  const Key_type key_;
302  Context_ptr context_;
303  Margin_ptr margin_;
304  std::list<size_t> used_table_codes_;
305  std::list<size_t> unused_table_codes_;
306  double smoothed_probability_;
307 };
308 
309 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
310 
311 template<class T, size_t N>
312 class Context_cell : public Context_cell_base
313 {
314 public:
315  // T is the event type
316  // N is the smoothing level (higher values are less smoothed)
317 
318  /*------------------------------------------------------------
319  * TYPEDEFS
320  *------------------------------------------------------------*/
321 
322  typedef boost::shared_ptr<Context_cell<T, N> > Self_ptr;
325  typedef boost::unordered_map<Key_type, Self_ptr> Map;
326 
327  /*------------------------------------------------------------
328  * STATIC MEMBERS
329  *------------------------------------------------------------*/
330  static Map map;
331  static bool& VERBOSE;
332 
333 public:
334  /*------------------------------------------------------------
335  * CONSTRUCTORS/DESTRUCTOR
336  *------------------------------------------------------------*/
337 
341  Context_cell(const Key_type& key);
342 
345  Context_cell(const Context_cell& other);
346 
349  virtual ~Context_cell();
350 
351  /*------------------------------------------------------------
352  * ACCESSORS
353  *------------------------------------------------------------*/
354 
357  const Key_type& key() const {return key_;}
358 
359  /*------------------------------------------------------------
360  * STATIC AND FRIEND FUNCTIONS
361  *------------------------------------------------------------*/
362 
365  static void resample_all_alphas();
366 
369  friend std::ostream& operator<< <T,N>(
370  std::ostream& os,
371  const Map& map
372  );
373 private:
374  const Key_type key_;
375 };
376 
377 
378 /*------------------------------------------------------------
379  * MEMBER IMPLEMENTATION (Context_cell)
380  *------------------------------------------------------------*/
381 
382 template<class T, size_t N>
384 : Context_cell_base(), key_(key)
385 {
386  if(VERBOSE)
387  {
388  std::cerr << "Constructed context event at level " << N
389  << " with key " << key_ << std::endl;
390  }
391 }
392 
393 
394 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
395 
396 template<class T, size_t N>
398  const Context_cell& other
399  ) : Cell(other),
400  key_(other.key_)
401 {
403  std::cerr << "COPYING Context_cell<T,N>" << std::endl;
405 }
406 
407 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
408 
409 template<class T, size_t N>
411 {}
412 
413 /*------------------------------------------------------------
414  * STATIC MEMBER IMPLEMENTATION (Context_cell)
415  *------------------------------------------------------------*/
416 
417 template<class T, size_t N>
419 {
420  for(typename Map::iterator it = map.begin();
421  it != map.end(); ++it)
422  {
423  it->second->resample_alpha();
424  }
425 }
426 
429 
430 template<size_t M>
432 {};
433 
434 template<size_t M>
435 static const Dummy_template_class<M>& create_dummy_template_class()
436 {
438  return d;
439 }
440 
441 template<class T>
443 {
444 public:
445 
446  template<size_t M>
449  )
450  {
452  recursively_resample_all_alphas(create_dummy_template_class<M-1>());
453  }
454 
457  )
458  {
460  }
461 
462 };
463 
465 
466 /*------------------------------------------------------------
467  * MEMBER IMPLEMENTATION (Marginal_cell)
468  *------------------------------------------------------------*/
469 
470 template<class T, size_t N>
473  key_(key),
474  context_(),
475  margin_(),
476  used_table_codes_(),
477  unused_table_codes_(1,0),
478  smoothed_probability_(1.0)
479 {}
480 
481 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
482 
483 template<class T, size_t N>
485  const Marginal_cell& other
486  ) : Cell(other),
487  key_(other.key_),
488  margin_(other.margin_),
489  context_(other.context_)
490 {}
491 
492 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
493 
494 template<class T, size_t N>
496 {}
497 
498 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
499 
500 template<class T, size_t N>
501 void Marginal_cell<T,N>::increment(const size_t& table_code)
502 {
503  margin_->increment(table_code);
504  if(count() == 0) context_->increment_diversity();
505  context_->increment();
506  if(per_table_counts_[table_code] == 0) {increment_table_count();}
507  ++per_table_counts_[table_code];
508  Cell::increment();
509  if(VERBOSE)
510  {
511  std::cerr << "Incremented marginal cell"
512  << "at level " << N << " with key " << key_
513  << " to " << count()
514  << std::endl;
515  }
516 }
517 
518 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
519 
520 template<class T, size_t N>
521 void Marginal_cell<T,N>::decrement(const size_t& table_code)
522 {
523  assert(per_table_counts_[table_code] > 0);
525  Cell::decrement();
526  --per_table_counts_[table_code];
528  if(per_table_counts_[table_code] == 0)
529  {
530  unused_table_codes_.push_front(table_code);
531  used_table_codes_.remove(table_code);
532  decrement_table_count();
533  per_table_counts_.erase(table_code);
534  }
535  context_->decrement();
537  if(count() == 0) context_->decrement_diversity();
538  margin_->decrement(table_code);
539 }
540 
541 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
542 
543 template<class T, size_t N>
545 {
546  margin_->increment_table_count();
547  context_->increment_table_count();
549 }
550 
551 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
552 
553 template<class T, size_t N>
555 {
557  context_->decrement_table_count();
558  margin_->decrement_table_count();
559 }
560 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
561 
562 template<class T, size_t N>
564 {
565  const int f = context_ -> count();
566  const int u = context_ -> diversity();
567  const double next_prob = margin_ -> smoothed_probability();
568  if(f == 0 && u == 0)
569  {
570  smoothed_probability_ = next_prob;
571  } else {
572  assert(f > 0 && u > 0); // can't have positive f without positive u;
573  const double bo = T::diversity_weight() * u;
574  assert(bo > 0);
575  smoothed_probability_ = log(bo * exp(next_prob) + count()) - log(f + bo);
576  }
577 }
578 
579 /*------------------------------------------------------------
580  * FREE FUNCTIONS
581  *------------------------------------------------------------*/
582 
583 template<typename T, size_t N>
585 {
588 }
589 
590 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
591 
592 template<typename T, size_t N>
594  const Key_type& key,
595  Cell::Step_sizes::const_reverse_iterator first,
596  const size_t& size,
597  const size_t& out_size
598  )
599 {
600  Self_ptr result;
601  typename Map::iterator it = map.find(key);
602  if(it == map.end())
603  {
604  typename Context_type::Key_type context_key = get_context(key, out_size);
605  typename Margin_type::Key_type margin_key = smooth(key, *first);
606  result = boost::make_shared<Self>(key);
607  map.insert(typename Map::value_type(key,result));
608  result->context_ = add_context_event(context_key);
609  result->margin_ =
610  Margin_type::add_event(
611  margin_key, first + 1, size - *first, out_size);
612  } else {
613  result = it->second;
614  }
615  return result;
616 }
617 
618 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
619 
620 template<typename T, size_t N>
623  const typename Context_type::Key_type& key)
624 {
625  Context_ptr result;
626  typename Context_type::Map::iterator it = Context_type::map.find(key);
627  if(it == Context_type::map.end())
628  {
629  result = boost::make_shared<Context_type>(key);
630  Context_type::map.insert(
631  typename Context_type::Map::value_type(key,result)
632  );
633  } else {
634  result = it->second;
635  }
636  return result;
637 }
638 
639 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
640 
641 template<class T, size_t N>
642 std::ostream& operator<<(
643  std::ostream& os,
644  const typename Marginal_cell<T,N>::Map& map
645  )
646 {
647  for(typename Marginal_cell<T,N>::Map::const_iterator it = map.begin();
648  it != map.end();
649  it++)
650  {
651  os << (it->first) << " : " << (it->second->count()) << std::endl;
652  }
653  return os;
654 }
655 
656 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
657 
658 template<class T>
659 std::ostream& operator<<(
660  std::ostream& os,
661  const typename Marginal_cell<T,1>::Map& map
662  )
663 {
664  for(typename Marginal_cell<T,1>::Map::const_iterator it = map.begin();
665  it != map.end();
666  it++)
667  {
668  os << "Total : " << (it->second->count()) << std::endl;
669  }
670  return os;
671 }
672 
673 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
674 
675 template<class T, size_t N>
676 std::ostream& operator<<(
677  std::ostream& os,
678  const typename Context_cell<T,N>::Map& map
679  )
680 {
681  for(typename Context_cell<T,N>::Map::const_iterator it = map.begin();
682  it != map.end();
683  it++)
684  {
685  os << (it->first) << " : " << (it->second->count()) << std::endl;
686  }
687  return os;
688 }
689 
690 
691 /*------------------------------------------------------------
692  * STATIC INITIALIZATION
693  *------------------------------------------------------------*/
694 
695 template<class T, size_t N>
696 bool& Marginal_cell<T, N>::VERBOSE = Cell::VERBOSE;
697 
698 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
699 
700 template<class T, size_t N>
701 bool& Context_cell<T, N>::VERBOSE = Cell::VERBOSE;
702 
703 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
704 
705 template<typename T>
706 typename Prior_cell<T>::Map Prior_cell<T>::map;
707 
708 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
709 
710 template<typename T, size_t N>
711 typename Marginal_cell<T, N>::Map Marginal_cell<T, N>::map;
712 
713 /* /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ */
714 
715 template<typename T, size_t N>
716 typename Context_cell<T, N>::Map Context_cell<T, N>::map;
717 
718 }; // namespace semantics
719 
720 #endif
Prior_cell< T > Self
Definition: Marginal_cell.h:50
Context_base_ptr context() const
get ptr to conditioning context cell
Definition: Marginal_cell.h:70
Definition: Marginal_cell.h:442
const Key_type & key() const
return data
Definition: Marginal_cell.h:170
Categorical_event< N > Key_type
Definition: Marginal_cell.h:137
Categorical_event< N > get_context(const Categorical_event< N > &event, const size_t steps=1)
returns RHS of conditioning expression
Definition: Categorical_event.h:283
double smoothed_probability()
predictive probability under original Collins algorithm
Definition: Marginal_cell.h:269
Definition of various standard probability distributions.
Definition: Marginal_cell.h:431
static Context_ptr add_context_event(const typename Context_type::Key_type &key)
creates a new context cell and returns a pointer to it
Definition: Marginal_cell.h:622
Definition: Cell_base_classes.h:156
Definition: Cell_traits.h:28
Definition: Cell_base_classes.h:82
Prior_cell(const Key_type &key)
Definition: Marginal_cell.h:58
Marginal_cell_base::Self_ptr Base_ptr
Definition: Marginal_cell.h:135
size_t sample_table_assignment()
sample from the conditional predictive distribution of table assignment
Definition: Marginal_cell.h:66
boost::shared_ptr< Context_cell_base > Context_ptr
Definition: Cell_base_classes.h:86
Traits::Margin_type Margin_type
Definition: Marginal_cell.h:141
std::ostream & operator<<(std::ostream &os, const Categorical_event_base &e)
display key in human readable form
Definition: Categorical_event.cpp:13
Categorical_event< N-1 > smooth(const Categorical_event< N > &event, const size_t steps=1)
marginalizes look-up key by <steps> from back (generalizes context)
Definition: Categorical_event.h:264
Definition: Cell_base_classes.h:24
Base_ptr margin() const
get smoothed marginal cell ptr
Definition: Marginal_cell.h:68
const Key_type & key() const
return variable values in this cell
Definition: Marginal_cell.h:60
boost::shared_ptr< Prior_cell< T > > Self_ptr
Definition: Marginal_cell.h:51
Cell_traits< T, N > Traits
Definition: Marginal_cell.h:323
Context_cell_base::Self_ptr Context_base_ptr
Definition: Marginal_cell.h:53
class containing conditioning context for marginal cells
Definition: Marginal_cell.h:41
Categorical_event< N > Key_type
Definition: Marginal_cell.h:324
Vector sample(const MV_gaussian_distribution &dist)
Sample from a multivariate normal distribution.
Definition: prob_sample.cpp:42
Marginal_cell< T, N > Self
Definition: Marginal_cell.h:132
Marginal_cell(const Key_type &key)
ctor to create a new cell out of a key
Definition: Marginal_cell.h:471
static bool & VERBOSE
Definition: Marginal_cell.h:145
virtual ~Context_cell()
destructor
Definition: Marginal_cell.h:410
double predictive_probability() const
predictive probability of this outcome in this context
Definition: Marginal_cell.h:261
boost::shared_ptr< Context_cell< T, N > > Self_ptr
Definition: Marginal_cell.h:322
double backoff_probability() const
prob of this outcome conditioned on starting a new table
Definition: Marginal_cell.h:250
void increment(const size_t &)
increment the count associated with a particular table
Definition: Marginal_cell.h:62
boost::shared_ptr< Context_type > Context_ptr
Definition: Marginal_cell.h:140
Table_count_map per_table_counts_
Definition: Cell_base_classes.h:151
double predictive_probability() const
predictive probability of this outcome in this context
Definition: Marginal_cell.h:82
Marginal_cell_base::Self_ptr Base_ptr
Definition: Marginal_cell.h:52
concrete class for contingency table cell
Definition: Cell_traits.h:24
boost::shared_ptr< Marginal_cell_base > Self_ptr
Definition: Cell_base_classes.h:85
Context_base_ptr context() const
get conditioning context
Definition: Marginal_cell.h:178
size_t count_
Definition: Cell_base_classes.h:68
const Key_type & key() const
return data
Definition: Marginal_cell.h:357
virtual void increment_table_count()
increment table count
Definition: Cell_base_classes.h:57
static Self_ptr add_event(const Key_type &key, Cell::Step_sizes::const_reverse_iterator, const size_t &, const size_t &)
Definition: Marginal_cell.h:87
virtual void decrement()
decrement count
Definition: Cell_base_classes.h:49
boost::shared_ptr< Self > Self_ptr
Definition: Marginal_cell.h:133
Context_cell< T, N > Context_type
Definition: Marginal_cell.h:139
Context_cell_base::Self_ptr Context_base_ptr
Definition: Marginal_cell.h:136
virtual void increment()
increment count
Definition: Cell_base_classes.h:45
count
Definition: APPgetLargeConnectedEdges.m:71
void decrement(const size_t &)
increment the count associated with a particular table
Definition: Marginal_cell.h:64
boost::shared_ptr< Context_cell_base > Self_ptr
Definition: Cell_base_classes.h:162
virtual void decrement_table_count()
decrement table count
Definition: Cell_base_classes.h:61
Sampling functionality for the different distributions defined in "prob_distributions.h".
size_t sample_table_assignment()
stochastically return a new table assignment for an observation
Definition: Marginal_cell.h:209
Context_cell(const Key_type &key)
Constructs a cell which is purely context information.
Definition: Marginal_cell.h:383
Base_ptr margin() const
get smoothed cell
Definition: Marginal_cell.h:174
void increment_table_count()
increment the number of distinct tables with this value
Definition: Marginal_cell.h:544
double backoff_probability() const
prob of this outcome conditioned on starting a new table
Definition: Marginal_cell.h:72
static bool VERBOSE
Definition: Cell_base_classes.h:29
virtual ~Marginal_cell()
destructor
Definition: Marginal_cell.h:495
const size_t & front() const
get first data entry
Definition: Categorical_event.h:127
Categorical_event< 0 > Key_type
Definition: Marginal_cell.h:54
boost::unordered_map< Key_type, Self_ptr > Map
Definition: Marginal_cell.h:55
boost::unordered_map< Key_type, Self_ptr > Map
Definition: Marginal_cell.h:325
boost::shared_ptr< Cell > Self_ptr
Definition: Cell_base_classes.h:27
static Map map
Definition: Marginal_cell.h:144
static void resample_all_alphas()
resample all CRP alpha values at this level only
Definition: Marginal_cell.h:418
size_t table_count_
Definition: Cell_base_classes.h:69
Definition: Cell_traits.h:18
boost::shared_ptr< Margin_type > Margin_ptr
Definition: Marginal_cell.h:142
boost::bimap< int, std::string > Map
Definition: Event_traits.h:34
static Map map
Definition: Marginal_cell.h:330
void decrement_table_count()
decrement the number of distinct tables with this value
Definition: Marginal_cell.h:554
static bool & VERBOSE
Definition: Marginal_cell.h:331
static void recursively_resample_all_alphas(const Dummy_template_class< 1 > &)
Definition: Marginal_cell.h:455
const size_t & back() const
get last data entry
Definition: Categorical_event.h:131
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
Cell_traits< T, N > Traits
Definition: Marginal_cell.h:134
boost::unordered_map< Key_type, Self_ptr > Map
Definition: Marginal_cell.h:138
double smoothed_probability()
get smoothed probability estimate
Definition: Marginal_cell.h:77
void set_contingency_table_verbosity(bool value)
Definition: Marginal_cell.h:584
static Map map
Definition: Marginal_cell.h:56
static void recursively_resample_all_alphas(const Dummy_template_class< M > &)
Definition: Marginal_cell.h:447
static Self_ptr add_event(const Key_type &key, Cell::Step_sizes::const_reverse_iterator first, const size_t &size, const size_t &out_size)
creates a new instance and sets its margin and context
Definition: Marginal_cell.h:593