message.h.svn-base

来自「Probabilistic graphical models in matlab」· SVN-BASE 代码 · 共 114 行

SVN-BASE
114
字号
#include <vector>#include <functional>#include <RandomVariable.h>#ifndef NDEBUG#include <iostream>#endif//*************** Message Declaration *******************//class Message {	public:		// Constructors		Message ();	Message (const RandomVariable &, const RandomVariable &);	Message (const unsigned int, const RandomVariable &);		// Normal methods		void reduce();		void set_index(unsigned int);	unsigned int get_index() const;	void set_size(unsigned int);		double get_value(const unsigned int) const;	double get_value(const RandomVariable &) const;	void set_value(const RandomVariable & , double);		// Debug methods	#ifndef NDEBUG	void display();#endif		friend class ExtractFromMessage;	private:		unsigned int index;	std::vector <double> values;	};inline void Message::set_index(unsigned int a){	index = a;}inline unsigned int Message::get_index() const{	return index;}inline void Message::set_size(unsigned int a){	values.resize(a);}inline double Message::get_value(const unsigned int a) const{	return values[a];	}inline double Message::get_value(const RandomVariable & rv) const{	// For now we only use these messages with Discrete Random Variables	// But it could be more generic later		const DiscreteRandomVariable & drv = static_cast < const DiscreteRandomVariable & > (rv);		return values[drv.last_sampled_value];}inline void Message::set_value(const RandomVariable & rv, double a){	// For now we only use these messages with Discrete Random Variables	// But it could be more generic later		const DiscreteRandomVariable & drv = static_cast < const DiscreteRandomVariable & > (rv);		values[drv.last_sampled_value] = a;}//*************** End of Message Declaration *******************////*************** ExtractFromMessage Declaration *******************//class ExtractFromMessage : public std::unary_function <Message, double>{	public:			double operator ()  (const Message & x) const;		ExtractFromMessage( const unsigned int, const bool = false);		ExtractFromMessage(const RandomVariable &);	ExtractFromMessage(const RandomVariable &, const RandomVariable &);	ExtractFromMessage(const RandomVariable &, const unsigned int);	private : 			bool forbidden;	const unsigned int index_of_extraction;	const unsigned int forbidden_index;};//*************** End of ExtractFromMessage Declaration *******************//

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?