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 java.util.List;

/**
 * Step 4. Assigns initial join-tree potentials using the conditional probabilities
 * from the belief network.
 */
public class Initialization {
  private Initialization() {

  }

  public static void initialization(JoinTree joinTree) {
    joinTree.allCliques().forEach(clique -> {
      Potential potential = getPotential(clique.nodes());
      joinTree.addPotential(clique, potential);
    });

    joinTree.nodes().forEach(node -> {
      List<Clique> cliques = joinTree.getCliquesContaining(node);
      if(cliques.size() > 0) {
        Potential p1 = joinTree.getPotential(cliques.get(0));
        Potential p2 = node.getPotential();
        if(null != p1 && null != p2) {
          multiply(p1, p2);
        } else {
          //hrmm.. why wasn't couldn't we get the potentials?
        }
      } else {
        //hrmmm.. why couldn't we find a clique containing the node?
      }
    });
  }


}

@@ -876,24 +876,64 @@
 ze() %3E 0) %7B%0A
+        Clique clique = cliques.get(0);%0A
         Pote
@@ -971,24 +971,16 @@
 l(clique
-s.get(0)
 );%0A     
@@ -1018,16 +1018,97 @@
 tial();%0A
+%0A        System.out.println(%22assigned %22 + node.getId() + %22 to %22 + clique.id());%0A%0A
         
@@ -1166,16 +1166,50 @@
 1, p2);%0A
+          System.out.println(p1);%0A
         

add system out (will remove later)