Package

Source Code of Hybrid_MultipleNet_Test

import unbbayes.util.Debug;
import edu.gmu.seor.prognos.unbbayesplugin.cps.CPSCompilerMain;
import edu.gmu.seor.prognos.unbbayesplugin.cps.datastructure.EDB;


public class Hybrid_MultipleNet_Test  extends Test{
  public Hybrid_MultipleNet_Test() { 
    Debug.setDebug(true);
  }
   
  /*                   
  %            T o---  K
  %           / \    /  \
  %          o   o  o    o
  %               A      B
  %               |      |
  %               o      o
  %              (W)o---(Y)
  %               |      |
  %               o      o
  %              (Z)    (L)
  % */
  String mk_2d4c_bnet_Connected_with_a_bridge = new String(
      "defineNode(K, DescriptionK);"+
      "{ defineState(Discrete, k1, k2);" +
      "p( K ) = { k1:0.8; k2:0.2; } }" +
     
      "defineNode(T, DescriptionT);"+
      "{ defineState(Discrete, t1, t2);" +
      "p( T | K ) = if( K == k1 ) { t1:0.3; t2:0.7; }" +
      "else if( K == k2 ) {  t1:0.5; t2:0.5; } " +
       " }" +
     
      "defineNode(A, DescriptionA);"+
      "{ defineState(Discrete, a1, a2);" +
      "p( A | T, K ) = if( T == t1 && K == k1 ) { a1:0.8; a2:0.2; }" +
      "else if( T == t2 && K == k1 ) {  a1:0.1; a2:0.9; } " +
      "else if( T == t1 && K == k2 ) {  a1:0.3; a2:0.7; } " +
      "else if( T == t2 && K == k2 ) {  a1:0.5; a2:0.5; } " +
       " }" +
     
      "defineNode(B, DescriptionB);"+
      "{ defineState(Discrete, b1, b2);" +
      "p( B | T, K ) = if( T == t1 && K == k1 ) { b1:0.8; b2:0.2; }" +
      "else if( T == t2 && K == k1 ) {  b1:0.1; b2:0.9; } " +
      "else if( T == t1 && K == k2 ) {  b1:0.3; b2:0.7; } " +
      "else if( T == t2 && K == k2 ) {  b1:0.5; b2:0.5; } " +
       " }" +
      
      "defineNode(Y, DescriptionY);"+
      "{ defineState(Continuous);" +
      "p( Y | B ) = if( B == b1 ) { NormalDist( -1, 1 ); } " +
      " else if( B == b2 ){ NormalDist( 1, 1 ); } " +
      "}" +
     
      "defineNode(W, DescriptionW);"+
      "{ defineState(Continuous);" +
      "p( W | A, Y ) = if( A == a1 ) { Y + NormalDist( 2, 1 ); } " +
      " else if( A == a2 ){  Y + NormalDist( 1, 1 ); } " +
      "}"  +
      
      "defineNode(Z, DescriptionZ);"+
      "{ defineState(Continuous);" +
      "p( Z | W ) = 0.5 * W + NormalDist( 5, 1 ); }" +
     
      "defineNode(L, DescriptionL);"+
        "{ defineState(Continuous);" +
        "p( L | Y ) = 0.5 * Y + NormalDist( 0, 1 ); } " 
  );
  

  /*                   
  %               T      K
  %               |      |
  %               o      o
  %              (W)o---(Y)
  %               |      |
  %               o      o
  %              (Z)    (L)
  % */
  String mk_2d4c_bnet_Connected_with_a_bridge4 = new String(
      "defineNode(K, DescriptionK);"+
      "{ defineState(Discrete, k1, k2);" +
      "p( K ) = { k1:0.8; k2:0.2; } }" +
     
      "defineNode(T, DescriptionT);"+
      "{ defineState(Discrete, t1, t2);" +
      "p( T ) = { t1:0.3; t2:0.7; } }"  +
       
      "defineNode(Y, DescriptionY);"+
      "{ defineState(Continuous);" +
      "p( Y | K ) = if( K == k1 ) { NormalDist( 3, 1 ); } " +
      " else if( K == k2 ){ NormalDist( 4, 1 ); } " +
      "} " +
     
      "defineNode(W, DescriptionW);"+
      "{ defineState(Continuous);" +
      "p( W | T, Y ) = if( T == t1 ) { Y + NormalDist( 2, 1 ); } " +
      " else if( T == t2 ){  Y + NormalDist( 1, 1 ); } " +
      "} " +
      
      "defineNode(Z, DescriptionZ);"+
      "{ defineState(Continuous);" +
      "p( Z | W ) = 0.5 * W + NormalDist( 5, 1 ); } " +
     
      "defineNode(L, DescriptionL);"+
        "{ defineState(Continuous);" +
        "p( L | Y ) = 0.5 * Y + NormalDist( 0, 1 ); } " 
  );
    
  public void mk_2d4c_bnet_Connected_with_a_bridge4_test1() {
    CPSCompilerMain cpsCompiler = new CPSCompilerMain();
        cpsCompiler.InitCompiler();
        cpsCompiler.compile( mk_2d4c_bnet_Connected_with_a_bridge4 +
                    "defineEvidence( Z, 7.1 );"
                         "run(DMP);" )
       
        //Comparison
        check( EDB.This().get("ROOT.ENGINES.DMP.NODES.K.BEL").getNext().getData()0.81484 );   
       check( EDB.This().get("ROOT.ENGINES.DMP.NODES.T.BEL").getNext().getData()0.283486 );   
       check( EDB.This().get("ROOT.ENGINES.DMP.NODES.Y.BEL.MU").getMatrixData()3.14039 );
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.Y.BEL.SIGMA").getMatrixData()0.945136 );
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.W.BEL.MU").getMatrixData()4.3791 );
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.W.BEL.SIGMA").getMatrixData()1.48623 );
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.L.BEL.MU").getMatrixData()1.57019 );
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.L.BEL.SIGMA").getMatrixData(), 1.23628 );
    }
 
  public void mk_2d4c_bnet_Connected_with_a_bridge4_test2() {
    CPSCompilerMain cpsCompiler = new CPSCompilerMain();
        cpsCompiler.InitCompiler();
        cpsCompiler.compile( mk_2d4c_bnet_Connected_with_a_bridge4 +
                    "defineEvidence( Z, 7.1 );"+
                    "defineEvidence( L, 2.1 );"+
                         "run(DMP);" )
       
        //Comparison
        check( EDB.This().get("ROOT.ENGINES.DMP.NODES.K.BEL").getNext().getData()0.793885 );   
       check( EDB.This().get("ROOT.ENGINES.DMP.NODES.T.BEL").getNext().getData()0.275234 );   
       check( EDB.This().get("ROOT.ENGINES.DMP.NODES.Y.BEL.MU").getMatrixData()3.33391 );
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.Y.BEL.SIGMA").getMatrixData()0.772453 );
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.W.BEL.MU").getMatrixData()4.53154 );
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.W.BEL.SIGMA").getMatrixData()1.38283 );
    }
    
  public void mk_2d4c_bnet_Connected_with_a_bridge_test() {
    CPSCompilerMain cpsCompiler = new CPSCompilerMain();
        cpsCompiler.InitCompiler();
        cpsCompiler.compile( mk_2d4c_bnet_Connected_with_a_bridge +
                     "defineEvidence( Z, 7.1 );"+
                     "defineEvidence( T, t1 );"+
                         "run(DMP);" )
       
        //Comparison
        check( EDB.This().get("ROOT.ENGINES.DMP.NODES.K.BEL").getNext().getData()0.661762 );
        check( EDB.This().get("ROOT.ENGINES.DMP.NODES.A.BEL").getNext().getData()0.704419 );
        check( EDB.This().get("ROOT.ENGINES.DMP.NODES.B.BEL").getNext().getData()0.473715 );
       check( EDB.This().get("ROOT.ENGINES.DMP.NODES.Y.BEL.MU").getMatrixData()0.459827 );
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.Y.BEL.SIGMA").getMatrixData()1.54118 );
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.W.BEL.MU").getMatrixData()2.5714 );
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.W.BEL.SIGMA").getMatrixData()1.83854 );
       check( EDB.This().get("ROOT.ENGINES.DMP.NODES.L.BEL.MU").getMatrixData()0.229913 );
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.L.BEL.SIGMA").getMatrixData()1.38529 );
    }
       
  public void test_final() { 
    mk_2d4c_bnet_Connected_with_a_bridge4_test1();
    mk_2d4c_bnet_Connected_with_a_bridge4_test2();
    mk_2d4c_bnet_Connected_with_a_bridge_test();
   }
 
  public void test_All() {
    test_final();
  }
 
  /**
   * @param args
   */
  public static void main(String[] args) { 
    Hybrid_MultipleNet_Test t = new Hybrid_MultipleNet_Test();
    t.test_All()
  }

}
TOP

Related Classes of Hybrid_MultipleNet_Test

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.