package com.github.vangj.jbayes.inf.exact.graph.pptc.blocks;

import static com.github.vangj.jbayes.inf.exact.graph.util.PotentialUtil.*;

import com.github.vangj.jbayes.inf.exact.graph.lpd.Potential;
import com.github.vangj.jbayes.inf.exact.graph.pptc.Clique;
import com.github.vangj.jbayes.inf.exact.graph.pptc.JoinTree;
import com.github.vangj.jbayes.inf.exact.graph.pptc.SepSet;

/**
 * Part of global propagation.
 */
public class SingleMessagePass {
  private SingleMessagePass() {

  }

  /**
   * A single message pass between the specified cliques joined by the specified separation set.
   * @param joinTree Join tree.
   * @param x Clique.
   * @param s Separation set.
   * @param y Clique.
   */
  public static void singleMessagePass(JoinTree joinTree, Clique x, SepSet s, Clique y) {
    Potential oldSepSetPotential = joinTree.getPotential(s);
    Potential yPotential = joinTree.getPotential(y);
    Potential newSepSetPotential = marginalizeFor(joinTree, x, s.nodes());
    multiply(yPotential, divide(newSepSetPotential, oldSepSetPotential));
  }
}

@@ -905,16 +905,34 @@
 tial(y);
+%0A%0A    //projection
 %0A    Pot
@@ -999,16 +999,84 @@
 des());%0A
+    joinTree.addPotential(s, newSepSetPotential);%0A%0A    //absorption%0A
     mult

update the sepset's new potential