Package

Source Code of Discrete_Test

import java.io.File;
import java.io.IOException;
import java.util.List;

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


public class Discrete_Test extends Test {
  
  public Discrete_Test() {}
   
  String asiaNet = new String
    "defineNode(A, VisitToAsia);"+
  "{ defineState(Discrete, visit, noVisit);" +
  "p( A ) = { visit:0.01; noVisit:0.99; } }" +
 
  "defineNode(S, Smoking);"+
  "{ defineState(Discrete, smoker, nonSmoker);" +
  "p( S ) = { smoker:0.5; nonSmoker:0.5; } }" +
   
  "defineNode(L, LungCancer);"+
  "{ defineState(Discrete, present, absent);" +
  "p( L | S ) = if( S == smoker ) { present:0.1; absent:0.9; } " +
  "else if( S == nonSmoker ){ present:0.01; absent:0.99; } " +
  "}" +
 
  "defineNode(T, Tuberculosis);"+
  "{ defineState(Discrete, present,absent);" +
  "p( T | A ) = if( A == visit ){ present:0.05; absent:0.95; } " +
  "else if(  A == noVisit ){ present:0.01; absent:0.99; } " +
  "}" +
 
  "defineNode(B, Bronchitis);"+
  "{ defineState(Discrete, present,absent);" +
  "p( B | S ) = if( S == smoker ){ present:0.6; absent:0.4; } " +
  " else if(  S == nonSmoker ){ present:0.3; absent:0.7; } " +
  "}" +
 
  "defineNode(E, TuberculosisOrCancer);"+
  "{ defineState(Discrete, true, false);" +
  "p( E | T, L) = if(   T == present &&  L == present ){ true:1.0; false:0.0; } " +
  " else if(   T == present && L == absent ){ true:1.0; false:0.0; } " +
  " else if( T == absent && L == present ){ true:1.0; false:0.0; } " +
  " else if( T == absent && L == absent  ){ true:0.0; false:1.0; } " +
  "}" +
 
  "defineNode(X, XrayResult);"+     
    "{ defineState(Discrete, abnormal, normal);" +
  "p( X | E ) = if( E == true ){ abnormal:0.98; normal:0.02; } " +
  " else if( E == false ){ abnormal:0.05; normal:0.95; } " +
  "}" +
  
  "defineNode(D, Dyspnoea);"+
  "{ defineState(Discrete, present,absent);" +
  "p( D | B, E) = if(  B == present && E == true ){ present:0.9; absent:0.1; } " +
  " else if(  B == present && E == false ){ present:0.8; absent:0.2; } " +
  " else if(  B == absent && E == true ){ present:0.7; absent:0.3; } " +
  " else if(  B == absent && E == false  ){ present:0.1; absent:0.9; } " +
  "}" );
 
    //*** This works well at 6/16/2011 ***  
  public void test_Asia ()
  {
    CPSCompilerMain cpsCompiler = new CPSCompilerMain();
        cpsCompiler.InitCompiler();
       
        cpsCompiler.compile( asiaNet +
           "defineEvidence( X, abnormal );"+
           "defineEvidence( D, present );"+
          "run(DMP);"
       );
       
        //EDB.This().print("ROOT");
       
        //Comparison with correct values from DMP
        check( EDB.This().get("ROOT.ENGINES.DMP.NODES.A.BEL").getNext().getData()0.013744173683310858 );   
     check( EDB.This().get("ROOT.ENGINES.DMP.NODES.S.BEL").getNext().getData()0.7693022519124805 );
     check( EDB.This().get("ROOT.ENGINES.DMP.NODES.L.BEL").getNext().getData()0.6144222959831819 );
     check( EDB.This().get("ROOT.ENGINES.DMP.NODES.T.BEL").getNext().getData()0.10779868410508014 );
     check( EDB.This().get("ROOT.ENGINES.DMP.NODES.B.BEL").getNext().getData()0.67154914375061 );
     check( EDB.This().get("ROOT.ENGINES.DMP.NODES.E.BEL").getNext().getData()0.7158312539522764 );
  }
  
  /*
   * okay at 7-7-2011
   */
  public void test2() {
    CPSCompilerMain cpsCompiler = new CPSCompilerMain();
        cpsCompiler.InitCompiler();
    cpsCompiler.compile(
        "defineNode(C1, DescriptionC0);"+
        "{defineState(Discrete, 1, 2);" +
        "p( C1 ) = { 1: 0.2; 2: 0.8;  } " +
        "}" +
        "defineNode(C0, DescriptionC0);"+
        "{"+
        "defineState(Discrete, 1, 2);"+
        "p( C0 | C1 ) = if( C1 == 1 ) { 1: 0.3; 2: 0.7; }"+
        "else if ( C1 == 2 ) { 1: 0.1; 2: 0.9; }  "+
        "}"+
         
        "createCPT( C1, C0 );"
      );
       
      EDB.This().print("ROOT");
    }
 
  /*
   * okay at 7-11-2011
   */
  public void test4() {
    CPSCompilerMain cpsCompiler = new CPSCompilerMain();
        cpsCompiler.InitCompiler();
    cpsCompiler.compile(
        "defineNode(C1, DescriptionC0);"+
        "{defineState(Discrete, 1, 2);" +
        "p( C1 ) = { 1: 0.2; 2: 0.8;  } " +
        "}" +
        "defineNode(C2, DescriptionC2);"+
        "{defineState(Discrete, 1, 2);" +
        "p( C2 ) = { 1: 0.2; 2: 0.8;  } " +
        "}" +
       
        "defineNode(C0, DescriptionC0);"+
        "{"+
        "defineState(Discrete, 1, 2);"+
        "p( C0 | C1, C2 ) = if( C1 == 1 ) { 1: 0.3; 2: 0.7; }"+
        "else if ( C1 == 1 && C2 == 2 ) { 1: 0.1; 2: 0.9; }  "+
        "else if ( C1 == 2 && C2 == 1 ) { 1: 0.2; 2: 0.8; }  "+
        "else if ( C1 == 2 && C2 == 2 ) { 1: 0.3; 2: 0.7; }  "+
        "}"+
         
        "createCPT( C0 );"
      );
       
      EDB.This().print("ROOT");
    }
 
  /*
   * okay at 7-11-2011
   */
  public void test5() {
    CPSCompilerMain cpsCompiler = new CPSCompilerMain();
        cpsCompiler.InitCompiler();
    cpsCompiler.compile(
        "defineNode(C1, DescriptionC0);"+
        "{defineState(Discrete, 1, 2);" +
        "p( C1 ) = { 1: 0.2; 2: 0.8;  } " +
        "}" +
        "defineNode(C2, DescriptionC2);"+
        "{defineState(Discrete, 1, 2);" +
        "p( C2 ) = { 1: 0.2; 2: 0.8;  } " +
        "}" +
       
        "defineNode(C0, DescriptionC0);"+
        "{"+
        "defineState(Discrete, 1, 2);"+
        "p( C0 | C1, C2 ) = if( C1 == 1 ) { 1: 0.3; 2: 0.7; }"+
        "else if ( C1 == 1 && C2 == 2 ) { 1: 0.1; 2: 0.9; }  "+
        "else { 1: 0.5; 2: 0.5; }  "+
        "}" +
         
        "createCPT( C0 );"
      );
       
      EDB.This().print("ROOT");
    }
 
  public void test3() {
    CPSCompilerMain cpsCompiler = new CPSCompilerMain();
        cpsCompiler.InitCompiler();
    cpsCompiler.compile(
        "defineNode(C1, DescriptionC1);"+
        "{defineState(Discrete, 1, 2, 3, 4);" +
        "p( C1 ) = { 1: 0.4; 2: 0.3; 3: 0.2; 4: 0.1;  } " +
        "}" +
        "defineNode(C2, DescriptionC2);"+
        "{defineState(Discrete, 1, 2, 3, 4);" +
        "p( C2 ) = { 1: 0.4; 2: 0.3; 3: 0.2; 4: 0.1;  } " +
        "}" +
        "defineNode(C0, DescriptionC0);"+
        "{"+
        "defineState(Discrete, 1, 2);"+
        "p( C0 | C1, C2 ) = if( C1 <= 2 && C2 > 1 ) { 1: 0.3; 2: 0.7; }"+
        "else if ( C1 > 3 ) { 1: 0.1; 2: 0.9; }  "+
        "else { 1: 0.5; 2: 0.5; }  "+
        "}" +
          
        "createCPT( C1, C0 );"
      );
       
      EDB.This().print("ROOT");
    }
 
  /**
   * @param args
   */
  public static void main(String[] args) {
    Discrete_Test T = new Discrete_Test();
    T.test4();
  }

}
TOP

Related Classes of Discrete_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.