Probabilistic graphical models in matlab.
源代码在线查看: message.cc.svn-base
#include #include //*************** Message Implementation *******************// Message::Message() { } Message::Message(const RandomVariable & a , const RandomVariable & b): index(a.get_index() ), values ( static_cast < const DiscreteRandomVariable & > (b).get_number_values(), 0.0 ) { } Message::Message(const unsigned int a, const RandomVariable & b): index(a ), values ( static_cast < const DiscreteRandomVariable & > (b).get_number_values(), 0.0 ) { } void Message::reduce() { fast_double_reduce_over (values.begin(), values.end() ); } #ifndef NDEBUG void Message::display() { std::cout for ( std::vector ::iterator it = values.begin(); it != values.end(); it++) { std::cout } std::cout } #endif //*************** End of Message Implementation *******************// //*************** ExtractFromMessage Implementation *****************// ExtractFromMessage::ExtractFromMessage( const unsigned int b, const bool a): forbidden(a), index_of_extraction(b), forbidden_index(0) { } ExtractFromMessage::ExtractFromMessage(const RandomVariable & rv_a): forbidden(false), index_of_extraction( static_cast < const DiscreteRandomVariable & > (rv_a).last_sampled_value), forbidden_index(0) { } ExtractFromMessage::ExtractFromMessage(const RandomVariable & rv_a, const RandomVariable & rv_b): forbidden(true), index_of_extraction( static_cast < const DiscreteRandomVariable & > (rv_a).last_sampled_value), forbidden_index(rv_b.get_index()) { } ExtractFromMessage::ExtractFromMessage(const RandomVariable & rv_a, const unsigned int b): forbidden(true), index_of_extraction( static_cast < const DiscreteRandomVariable & > (rv_a).last_sampled_value), forbidden_index(b) { } double ExtractFromMessage::operator () (const Message & x) const { //cout if ( (forbidden == true) && (x.index == forbidden_index) ) { return 1.0; } else { return x.values[index_of_extraction]; } } //*************** End of ExtractFromMessage Implementation *****************//