Package

Source Code of Hybrid_Test_V2

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


public class Hybrid_Test_V2  extends Test{
  public Hybrid_Test_V2() { 
    Debug.setDebug(true);
  }
 
  /*  %
    %                 L  
    %                 |   
    %                 |  
    %                 | 
    %                 B   (Y)
    %                 |   /
    %                 |  /
    %                 | /
    %                (W)
    %               
    %
    % */
  String mk_hybridTest_2d2c_bnet = new String(
      "defineNode(L, DescriptionA);"+
      "{ defineState(Discrete, b1, b2);" +
      "p( L ) = { b1:0.5; b2:0.5; } }" +
      
      "defineNode(B, DescriptionA);"+
      "{ defineState(Discrete, a1, a2);" +
      "p( B | L ) = if( L == b1 ) { a1:0.8; a2:0.2; } " +
      "else if( L == b2 ) { a1:0.3; a2:0.7; } " +
      "}" +
     
        "defineNode(Y, DescriptionY);"+
        "{ defineState(Continuous);" +
        "p( Y ) = NormalDist( 0, 1 ); " +
        "}" +
      
      "defineNode(W, DescriptionW);"+
      "{ defineState(Continuous);" +
      "p( W | B, Y ) = if( B == a1 ){ Y + NormalDist( 5, 1 ); } " +
      "else if( B == a2 ){ 2*Y + NormalDist( 10, 2 ); } " +
      "}" );
 
  /*  %
  %                 L  
  %                 |   
  %                 |  
  %                 | 
  %                 B   (Y)
  %                 |   /
  %                 |  /
  %                 | /
  %                (W)
  %               
  %
  % */
  String mk_hybridTest_2d2c_bnet_2 = new String(
      "defineNode(L, DescriptionA);"+
      "{ defineState(Discrete, b1, b2);" +
      "p( L ) = { b1:0.5; b2:0.5; } }" +
      
      "defineNode(B, DescriptionA);"+
      "{ defineState(Discrete, a1, a2);" +
      "p( B | L ) = if( L == b1 ) { a1:0.8; a2:0.2; } " +
      "else if( L == b2 ) { a1:0.3; a2:0.7; } " +
      "}" +
     
        "defineNode(Y, DescriptionY);"+
        "{ defineState(Continuous);" +
        "p( Y ) = NormalDist( 0, 1 ); " +
        "}" +
      
      "defineNode(W, DescriptionW);"+
      "{ defineState(Continuous);" +
      "p( W | B, Y ) = if( B == a1 ){ (0 + Y)  + 0 + ((NormalDist(5,1))*1);  } " +
      "else if( B == a2 ){ (0 + 2*Y)  + 0 + ((NormalDist(10,2))*1);  } " +
      "}" );
 
 
  /*  %
  %                 T  
  %                 |   
  %                 |  
  %                 | 
  %                (W)   
  %                 |  
  %                 | 
  %                 |
  %                (Z)
  %               
  %
  % */
  String mk_poly3clg_demo_Young_bnet = new String(
      "defineNode(T, DescriptionT);"+
      "{ defineState(Discrete, t1, t2);" +
      "p( T ) = { t1:0.5; t2:0.5; } }" +
      
      "defineNode(W, DescriptionW);"+
      "{ defineState(Continuous);" +
      "p( W | T ) = if( T == t1 ){ NormalDist(-1,1);  } " +
      "else if( T == t2 ){ NormalDist(1,1);  } " +
      "}" +
         
        "defineNode(Z, DescriptionZ);"+
        "{ defineState(Continuous);" +
        "p( Z | W ) = 0.5*W + NormalDist( 10, 1 ); " +
        "}"
   
  );

  /*  %
  %                    
  %             T      (Y)    
  %            / \     / 
  %           /   \   / 
  %          C     (W)   
  %                 |  
  %                 | 
  %                 |
  %                (Z)
  %               
  %
  % */
  String mk_poly5clg_demo_bnet = new String(
      "defineNode(T, DescriptionT);"+
      "{ defineState(Discrete, t1, t2);" +
      "p( T ) = { t1:0.5; t2:0.5; } }" +
   
      "defineNode(C, DescriptionC);"+
      "{ defineState(Discrete, c1, c2);" +
      "p( C | T ) = if( T == t1 ) { c1:0.8; c2:0.2; } " +
      "else if( T == t2 ) { c1:0.3; c2:0.7; } " +
      "}" +
     
        "defineNode(Y, DescriptionY);"+
        "{ defineState(Continuous);" +
        "p( Y ) = NormalDist( 10, 1 ); " +
        "}" +
       
      "defineNode(W, DescriptionW);"+
      "{ defineState(Continuous);" +
      "p( W | T, Y ) = if( T == t1 ){ Y + NormalDist(-1,1);  } " +
      "else if( T == t2 ){ Y + NormalDist(1,1);  } " +
      "}" +
         
        "defineNode(Z, DescriptionZ);"+
        "{ defineState(Continuous);" +
        "p( Z | W ) = 0.5*W + NormalDist( 0, 1 ); " +
        "}"
   
  );
 
  /*  %
  %                    
  %             T       K    
  %              \     / \
  %               \   /   \
  %                (W)----(Y)   
  %                 |  
  %                 | 
  %                 |
  %                (Z)
  %               
  %
  % */
  String mk_poly5clg_demo_bnet_Connected = new String(
      "defineNode(T, DescriptionT);"+
      "{ defineState(Discrete, t1, t2);" +
      "p( T ) = { t1:0.3; t2:0.7; } }" +
   
      "defineNode(K, DescriptionK);"+
      "{ defineState(Discrete, k1, k2);" +
      "p( K ) = { k1:0.8; k2:0.2; } }" +
       
        "defineNode(Y, DescriptionY);"+
        "{ defineState(Continuous);" +
        "p( Y | K ) = if( K == k1 ) { NormalDist( -1, 1 ); }" +
        "else if( K == k2 ) { NormalDist( 1, 1 ); } " +
        "}" +
       
      "defineNode(W, DescriptionW);"+
      "{ defineState(Continuous);" +
      "p( W | T, K, Y ) = if( T == t1 && K == k1 ){ 1*Y + NormalDist(2,1);  } " +
      "else if( T == t1 && K == k2 ){ 1*Y + NormalDist(-2,1);  } " +
      "else if( T == t2 && K == k1 ){ 1*Y + NormalDist(1,1);  } " +
      "else if( T == t2 && K == k2 ){ 1*Y + NormalDist(0,1);  } " +
      "}" +
         
        "defineNode(Z, DescriptionZ);"+
        "{ defineState(Continuous);" +
        "p( Z | W ) = 0.5*W + NormalDist( 0, 1 ); " +
        "}"
   
  );
 
  public void mk_hybridTest_2d2c_bnet_test() {
    CPSCompilerMain cpsCompiler = new CPSCompilerMain();
        cpsCompiler.InitCompiler();
        cpsCompiler.compile( mk_hybridTest_2d2c_bnet +
                   "defineEvidence( W, 2 );"+
                         "run(DMP);" );
       
        //Comparison
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.L.BEL").getNext("b1").getData()0.716576);   
    check( EDB.This().get("ROOT.ENGINES.DMP.NODES.B.BEL").getNext("a1").getData()0.97882 );   
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.Y.BEL.MU").getMatrixData(),  -1.52471 );   
    check( EDB.This().get("ROOT.ENGINES.DMP.NODES.Y.BEL.SIGMA").getMatrixData()0.524687 );       

    }
 
  
  public void mk_hybridTest_2d2c_bnet_test_2() {
    CPSCompilerMain cpsCompiler = new CPSCompilerMain();
        cpsCompiler.InitCompiler();
        cpsCompiler.compile( mk_hybridTest_2d2c_bnet_2 +
                   "defineEvidence( W, 2 );"+
                         "run(DMP);" );
       
        //Comparison
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.L.BEL").getNext("b1").getData()0.716576);   
    check( EDB.This().get("ROOT.ENGINES.DMP.NODES.B.BEL").getNext("a1").getData()0.97882 );   
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.Y.BEL.MU").getMatrixData(),  -1.52471 );   
    check( EDB.This().get("ROOT.ENGINES.DMP.NODES.Y.BEL.SIGMA").getMatrixData()0.524687 );       

    }
 

  public void mk_poly3clg_demo_Young_bnet_test() {
    CPSCompilerMain cpsCompiler = new CPSCompilerMain();
        cpsCompiler.InitCompiler();
        cpsCompiler.compile( mk_poly3clg_demo_Young_bnet +
                   "defineEvidence( Z, 2 );"+
                         "run(DMP);" );
       
        //Comparison
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.T.BEL").getNext("t1").getData()0.998341 );   
       check( EDB.This().get("ROOT.ENGINES.DMP.NODES.W.BEL.MU").getMatrixData(),  -3.99735 );   
     check( EDB.This().get("ROOT.ENGINES.DMP.NODES.W.BEL.SIGMA").getMatrixData()0.804239 );       

    }

  public void mk_poly5clg_demo_bnet_test() {
    CPSCompilerMain cpsCompiler = new CPSCompilerMain();
        cpsCompiler.InitCompiler();
        cpsCompiler.compile( mk_poly5clg_demo_bnet +
                   "defineEvidence( Z, 2 );"+
                         "run(DMP);" );
       
        //Comparison
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.T.BEL").getNext("t1").getData()0.880797);   
    check( EDB.This().get("ROOT.ENGINES.DMP.NODES.C.BEL").getNext("c1").getData()0.740399);   
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.Y.BEL.MU").getMatrixData()9.12693 );   
    check( EDB.This().get("ROOT.ENGINES.DMP.NODES.Y.BEL.SIGMA").getMatrixData()0.844999 );       
    check( EDB.This().get("ROOT.ENGINES.DMP.NODES.W.BEL.MU").getMatrixData()7.49227 );   
    check( EDB.This().get("ROOT.ENGINES.DMP.NODES.W.BEL.SIGMA").getMatrixData()1.51999 );
    }
 
  public void mk_poly5clg_demo_bnet_Connected_test() {
    CPSCompilerMain cpsCompiler = new CPSCompilerMain();
        cpsCompiler.InitCompiler();
        cpsCompiler.compile( mk_poly5clg_demo_bnet_Connected +
                   "defineEvidence( W, 2 );"+
                         "run(DMP);" );
       
        //Comparison
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.T.BEL").getNext("t1").getData()0.412736);   
    check( EDB.This().get("ROOT.ENGINES.DMP.NODES.K.BEL").getNext("k1").getData()0.898263);   
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.Y.BEL.MU").getMatrixData(),  -0.050799 );   
    check( EDB.This().get("ROOT.ENGINES.DMP.NODES.Y.BEL.SIGMA").getMatrixData()0.743017 );       
    check( EDB.This().get("ROOT.ENGINES.DMP.NODES.Z.BEL.MU").getMatrixData()1.0 );   
    check( EDB.This().get("ROOT.ENGINES.DMP.NODES.Z.BEL.SIGMA").getMatrixData()1.0);
    }
 
  public void mk_poly5clg_demo_bnet_Connected_test_2() {
    CPSCompilerMain cpsCompiler = new CPSCompilerMain();
        cpsCompiler.InitCompiler();
        cpsCompiler.compile( mk_poly5clg_demo_bnet_Connected +
                   "defineEvidence( Z, 2 );"+
                         "run(DMP);" );
       
        //Comparison
        check( EDB.This().get("ROOT.ENGINES.DMP.NODES.T.BEL").getNext("t1").getData()0.361127);   
    check( EDB.This().get("ROOT.ENGINES.DMP.NODES.K.BEL").getNext("k1").getData()0.829239);   
      check( EDB.This().get("ROOT.ENGINES.DMP.NODES.Y.BEL.MU").getMatrixData(),  -0.0747527 );   
    check( EDB.This().get("ROOT.ENGINES.DMP.NODES.Y.BEL.SIGMA").getMatrixData()1.25935 );       
    check( EDB.This().get("ROOT.ENGINES.DMP.NODES.W.BEL.MU").getMatrixData()1.66548 );   
    check( EDB.This().get("ROOT.ENGINES.DMP.NODES.W.BEL.SIGMA").getMatrixData()1.79344);
    }
 
  public void test_final() {
    mk_hybridTest_2d2c_bnet_test();
    mk_hybridTest_2d2c_bnet_test_2();
    mk_poly5clg_demo_bnet_test();
    mk_poly3clg_demo_Young_bnet_test();
    mk_poly5clg_demo_bnet_Connected_test();
    mk_poly5clg_demo_bnet_Connected_test_2();
   }
 
  public void test_All() {
    test_final();
  }
 
  /**
   * @param args
   */
  public static void main(String[] args) { 
    Hybrid_Test_V2 t = new Hybrid_Test_V2();
    t.test_All()
  }

}
TOP

Related Classes of Hybrid_Test_V2

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.