1 #ifndef CATEGORICAL_EVENT_H_
2 #define CATEGORICAL_EVENT_H_
12 #include <boost/functional/hash.hpp>
22 class Categorical_event_base;
38 const size_t steps = 1);
47 const size_t steps = 1);
65 virtual std::ostream&
print_to(std::ostream& os)
const {
return os;}
72 class Categorical_event :
public Categorical_event_base
103 Data_type::const_iterator first,
104 Data_type::const_iterator last,
114 hash_val_(other.hash_val_)
123 const size_t&
size()
const {
return size_;}
127 const size_t&
front()
const {
return data_.front();}
131 const size_t&
back()
const {
return data_.back();}
147 std::ostream&
print_to(std::ostream& os)
const;
176 void check_size()
const
178 if(data_.size() != size_)
180 std::cerr <<
"Data has size: " << data_.size() <<
","
181 <<
"Size required is " << size_ << std::endl;
184 "Categorical_event constructed with incorrect length.");
193 template<
size_t N>
inline
197 hash_val_(boost::hash_range(data.begin(), data.end()))
205 std::cout << e.
get_msg() << std::endl;
211 template<
size_t N>
inline
213 Data_type::const_iterator first,
214 Data_type::const_iterator last,
218 hash_val_(boost::hash_range(first, last))
226 std::cout << e.
get_msg() << std::endl;
232 template<
size_t N>
inline
235 return hash_val_ == other.hash_val_;
243 if(data_.size() == 0)
248 for(Data_type::const_iterator it = data_.begin();
249 it != data_.end(); it++)
269 if(steps > event.size())
273 "steps argument of smooth() too large for event");
276 event.data_.begin(),
event.data_.end() - steps,
277 event.size() - steps);
288 event.data_.begin() + steps,
event.data_.end(),
289 event.size() - steps);
Categorical_event< N > Self_type
Definition: Categorical_event.h:80
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
std::vector< Val_type > Data_type
Definition: Categorical_event.h:63
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
friend size_t hash_value(Self_type const &e)
return underlying hash value
Definition: Categorical_event.h:167
size_t Hash_type
Definition: Categorical_event.h:64
const std::string & get_msg() const
Returns the error message for the Exception.
Definition: l_exception.h:152
virtual bool operator==(const Self_type &) const
Definition: Categorical_event.h:66
const size_t & size() const
get length of data key
Definition: Categorical_event.h:123
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
look-up key class for contingency table
Definition: Categorical_event.h:29
bool operator==(const Self_type &other) const
two keys are equal iff their hash values are equal
Definition: Categorical_event.h:233
virtual std::ostream & print_to(std::ostream &os) const
Definition: Categorical_event.h:65
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
const size_t & front() const
get first data entry
Definition: Categorical_event.h:127
Categorical_event()
default ctor
Definition: Categorical_event.h:89
abstract base class for look-up keys
Definition: Categorical_event.h:58
Support for error handling exception classes in libKJB.
size_t Val_type
Definition: Categorical_event.h:62
Categorical_event_base Self_type
Definition: Categorical_event.h:61
const size_t & back() const
get last data entry
Definition: Categorical_event.h:131
std::ostream & print_to(std::ostream &os) const
print key data to ostream os
Definition: Categorical_event.h:241
Categorical_event(const Self_type &other)
copy constructor
Definition: Categorical_event.h:110