📄 old_code_2.svn-base
字号:
template <class RanVar>void ComputeMessage<RanVar>::set_origin_potential(DiscretePotential * a){ origin_potential = a;}template <class RanVar>inline void ComputeMessage<RanVar>::set_message_index (unsigned int a){ message.set_index(a);} // ************* End of ComputeMessage Declaration ********* // // ******************* MRFComputeMessage Declaration ******************** //// The derived classes all must have a operator()// These classes are used as functors, don't forget it.// Still they store information (in the Message), so they shouldn't be used with some of the STL algorithms...template <class RanVar>class MRFComputeMessage : public ComputeMessage <RanVar>{ private: //unsigned int destination_random_variable_idx; DiscretePotential & edge_potential; RanVar * origin_random_variable; RanVar * destination_random_variable; bool distribute_flag; public: MRFComputeMessage(DiscretePotential &, std::list <Message> &); inline void set_origin_random_variable(RanVar * ); void set_random_variable(RanVar *); void operator() (unsigned int);};template <class RanVar>void MRFComputeMessage<RanVar>::set_origin_random_variable(RanVar * a){ origin_random_variable = a;} // ************* End of MRFComputeMessage Declaration ********* // // ******************* VariableComputeMessage Declaration ******************** //template <class RanVar>class VariableComputeMessage : public ComputeMessage <RanVar>{ private: RanVar * origin_random_variable; unsigned int destination_potential_idx; std::list <Message>::const_iterator destination_message;public: VariableComputeMessage(std::list <Message> &, unsigned int); inline void set_origin_random_variable(RanVar *); void set_random_variable(RanVar *); void operator() (unsigned int);};template <class RanVar>void VariableComputeMessage<RanVar>::set_origin_random_variable(RanVar * ){} // ************* End of VariableComputeMessage Declaration ********* // // ******************* PotentialComputeMessage Declaration ***************** //template <class RanVar>class PotentialComputeMessage : public ComputeMessage <RanVar>{ std::list <Message>::const_iterator destination_message; unsigned int destination_random_variable_idx; std::vector <double> * product_messages; public: PotentialComputeMessage(std::list <Message> &); inline void set_product_messages (std::vector <double> *); // Here we have a definition for this, as it is quite important inline void set_origin_random_variable(RanVar *); void set_random_variable(RanVar *); void operator() (unsigned int);};template <class RanVar>void PotentialComputeMessage <RanVar>::set_product_messages (std::vector <double> * a){ product_messages = a;}template <class RanVar>void PotentialComputeMessage<RanVar>::set_origin_random_variable(RanVar * ){ } // ************* End of PotentialComputeMessage Declaration ********* // // ******************* ComputeMarginal Declaration ***************** //template <class RanVar>class ComputeMarginal: public ComputeOverInt <RanVar>{ private: RanVar * random_variable; DiscretePotential & pot; std::list <Message> & messages_list; // this is the message list used in the original Variable node public: ~ComputeMarginal(); ComputeMarginal( DiscretePotential &, std::list <Message> &); void set_random_variable(RanVar *); void operator() (unsigned int);};// ******************* ComputeMarginal Implementation ***************** //template <class RanVar>ComputeMarginal<RanVar>::ComputeMarginal( DiscretePotential & a , list <Message> & b) : pot(a), messages_list(b){}template <class RanVar>ComputeMarginal <RanVar>::~ComputeMarginal(){}template <class RanVar>void ComputeMarginal <RanVar>::set_random_variable (RanVar * a){ random_variable = a;}template <class RanVar>void ComputeMarginal <RanVar>::operator() (unsigned int xi){ random_variable->set_value(xi); pot.set_variable_value(*random_variable); random_variable->sampling_probabilities[xi] = pot.get_potential_value() * make_product_over (messages_list.begin(), messages_list.end(), ExtractFromMessage (xi) );}// ******************* End of ComputeMarginal Implementation ***************** ///*void DiscreteRandomVariable::compute_over_values (ComputeOverInt <DiscreteRandomVariable> & f){ f.set_random_variable(this); // Warning !! Probably very dangerous and buggy if (conditionned) { f(last_sampled_value); } else { for (unsigned int i = 0; i < number_values; ++i) { f(i); } }}*//*template <class RanVar, class Pot, class VertexDescriptor >void VariableMessageNode<RanVar, Pot, VertexDescriptor>::normalize_probabilities(){ variable_ptr->normalize_probabilities ();}*//* template < class Var, class Pot, class VertexDescriptor > Message VariableMessageNode < Var, Pot, VertexDescriptor >::send_message(MessageNode <Var, VertexDescriptor > &) { // Here we don't care at all about the extra unused_variable argument, in fact. All we need is contained on our Node ! // UPDATE: Not true. We still need the Index of the Potential we are sending to :-( // but it is taken care of in the constructor. comp_msg.set_origin_potential(potential_ptr); // We need to compute an entry on the message for each possible value on the origin variable variable_ptr->compute_over_values(comp_msg); comp_msg.set_message_index(variable_ptr->get_index()); // Now send the message to the destination // comp_msg.get_message().display(); return comp_msg.get_message();}*/ /*DiscretePotential * p = static_cast < DiscretePotential * > (g[*u]->get_potential()); GetProbabilities <Graph, RandomVariableClass> get_prob (g, *p, *u); rv->compute_over_values(get_prob); g[*u]->normalize_probabilities(); if ( record) { current_sample = rv->sample(); } else { current_sample = rv->sample_without_recording(); } get_prob.set_sampled_value(current_sample); */ } /* case variable: { RandomVariableClass * rv = g[*u]->get_random_variable(); DiscretePotential * p = g[*u]->get_potential(); FactorGraphGetProbabilities <Graph, RandomVariableClass> get_prob (g, *p, *u); rv->compute_over_values(get_prob); g[*u]->normalize_probabilities(); int a = rv->sample(); get_prob.set_sampled_value(a); if ( record) { sum_marginals[*u][a] = 1 + sum_marginals[*u][a]; } }; break; case potential : { // Do nothing }; break; default: cout << "ERROR (FATAL): we encountered an unknown type of MessageNode." << endl; } */ // We should somehow pass the value of rv to all the linked potentials... // ************* GetProbabilities Declaration ************** //template <class Graph, class RanVar >class GetProbabilities : public ComputeOverInt <RanVar> { typedef typename boost::graph_traits<Graph>::vertex_descriptor VertexDescriptor; typedef typename Graph::edge_bundled EdgeClassPointer; typedef typename std::iterator_traits< EdgeClassPointer>::value_type EdgeClass; typedef typename boost::graph_traits<Graph>::out_edge_iterator OutEdgeIterator; protected: Graph & g; DiscretePotential & variable_potential; RanVar * random_variable; unsigned int random_variable_index; OutEdgeIterator begin_edge, end_edge; public: ~GetProbabilities(); GetProbabilities(Graph &, DiscretePotential &); GetProbabilities(Graph &, DiscretePotential &, VertexDescriptor); void set_sampled_value(unsigned int); // No Need to be virtual yet void set_random_variable(RanVar *); void operator() (unsigned int);}; // ************* End of GetProbabilities Declaration ************** // // ************* FactorGraphGetProbabilities Declaration ********* ///*template <class Graph, class RanVar >class FactorGraphGetProbabilities : public GetProbabilities <Graph, RanVar>{ typedef typename boost::graph_traits<Graph>::vertex_descriptor VertexDescriptor; typedef typename boost::graph_traits<Graph>::adjacency_iterator AdjacencyIterator;private: AdjacencyIterator begin_potential, end_potential; public: ~FactorGraphGetProbabilities(); FactorGraphGetProbabilities(Graph &, DiscretePotential &, VertexDescriptor); void set_sampled_value(unsigned int); void operator() (unsigned int);};*/ // ************* End of FactorGraphGetProbabilities Declaration ********* // // ******************* GetProbabilities Implementation ***************** //template <class Graph, class RanVar >GetProbabilities <Graph, RanVar>::~GetProbabilities(){}template <class Graph, class RanVar >GetProbabilities <Graph, RanVar>::GetProbabilities (Graph & a, DiscretePotential & b) : g(a), variable_potential(b){ }template <class Graph, class RanVar >GetProbabilities <Graph, RanVar>::GetProbabilities (Graph & a, DiscretePotential & b, VertexDescriptor node_index) : g(a), variable_potential(b)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -