pub fn compute_marginals(&self) -> Option<Vec<NP>> {
        self.forest_topo_sort().map(|node_order| {
            let mut inboxes = self.make_inboxes();
            // belief propagation up from leaves to root
            self.propagate_messages(node_order.iter().rev(), &mut inboxes);
            // belief propagation down from root(s), still accumulating to inbox
            self.propagate_messages(node_order.iter(), &mut inboxes);
            self.node_potentials
                .iter()
                .zip(inboxes.iter())
                .map(|(np, inbox)| {
                    inbox
                        .iter()
                        .fold(np.clone(), |p, msg| p.update_potentials(&msg.1))
                })
                .collect()
        })
    }
/// Compute the marginal distribution at each node of the graph
/// Each marginal is expressed as a node potential
Compute the marginal distribution at each node of the graph
Each marginal is expressed as a node potential
Compute the marginal distribution at each node of the graph Each marginal is expressed as a node potential
pub fn compute_marginals(&self) -> Option<Vec<NP>> {
        self.forest_topo_sort().map(|node_order| {
            let mut inboxes = self.make_inboxes();
            // belief propagation up from leaves to root
            self.propagate_messages(node_order.iter().rev(), &mut inboxes);
            // belief propagation down from root(s), still accumulating to inbox
            self.propagate_messages(node_order.iter(), &mut inboxes);
            self.node_potentials
                .iter()
                .zip(inboxes.iter())
                .map(|(np, inbox)| {
                    inbox
                        .iter()
                        .fold(np.clone(), |p, msg| p.update_potentials(&msg.1))
                })
                .collect()
        })
    }
pub fn compute_marginals ( & self ) -> Option < Vec < NP > > { self . forest_topo_sort ( ) . map ( | node_order | { let mut inboxes = self . make_inboxes ( ) ; // belief propagation up from leaves to root self . propagate_messages ( node_order . iter ( ) . rev ( ) , & mut inboxes ) ; // belief propagation down from root(s), still accumulating to inbox self . propagate_messages ( node_order . iter ( ) , & mut inboxes ) ; self . node_potentials . iter ( ) . zip ( inboxes . iter ( ) ) . map ( | ( np , inbox ) | { inbox . iter ( ) . fold ( np . clone ( ) , | p , msg | p . update_potentials ( & msg . 1 ) ) } ) . collect ( ) } ) }
Compute the marginal distribution at each node of the graph
Each marginal is expressed as a node potential
Compute the marginal distribution at each node of the graph Each marginal is expressed as a node potential
&self