import unbbayes.util.Debug;
import edu.gmu.seor.prognos.unbbayesplugin.cps.CPSCompilerMain;
import edu.gmu.seor.prognos.unbbayesplugin.cps.EquationOperator;
import edu.gmu.seor.prognos.unbbayesplugin.cps.datastructure.EDB;
import edu.gmu.seor.prognos.unbbayesplugin.cps.datastructure.EDBUnit;
public class InverseFunction_Test extends Test{
public InverseFunction_Test() {
Debug.setDebug(true);
EDB.This().printSet(true);
}
String testNet = new String(
"defineNode(T, DescriptionT);"+
"{ defineState(Discrete, 1,2);" +
"p( T ) = { 1:0.5; 2:0.5; } }" +
"defineNode(D, DescriptionD);"+
"{ defineState(Discrete, 1,2 );" +
"p( D | T ) = if( 1 ) { 1:0.3; 2:0.7;}" +
"else if( 2 ) { 1:0.6; 2:0.4 ;} }" +
"defineNode(U, DescriptionU);"+
"{ defineState(Continuous);" +
"p( U ) = NormalDist( 30, 2); }"+
"defineNode(X, DescriptionX);"+
"{ defineState(Continuous);" +
"p( X | D, U ) = if( D == 1 ) {U + 5 + NormalDist( 0, 1 );} " +
"else if( D == 2 ) {U - 5 + NormalDist( 0, 1 );} }"
);
String testNet2 = new String(
"defineNode(U, DescriptionU);"+
"{ defineState(Continuous);" +
"p( U ) = NormalDist( 30, 2); }"+
"defineNode(Y, DescriptionU);"+
"{ defineState(Continuous);" +
"p( Y ) = NormalDist( 30, 2); }"+
"defineNode(X, DescriptionX);"+
"{ defineState(Continuous);" +
//"p( X | Y, U ) = Root(Exp(Y, e), 2) - U + NormalDist(0, 0.1); }"
"p( X | Y, U ) = 1*Y + 1* U + NormalDist(0, 0.1); }"
);
public void test1() {
CPSCompilerMain cpsCompiler = new CPSCompilerMain();
cpsCompiler.InitCompiler();
cpsCompiler.compile( testNet +
"defineNode(E, DescriptionE);"+
"{ defineState(Continuous);" +
"p( E | X ) = 3 * X - 2; }"
);
EquationOperator e = new EquationOperator();
e.convert( EDB.This().get("ROOT.NODES.E.EQUATION"), "X" );
}
public void test2() {
CPSCompilerMain cpsCompiler = new CPSCompilerMain();
cpsCompiler.InitCompiler();
cpsCompiler.compile( testNet +
"defineNode(E, DescriptionE);"+
"{ defineState(Continuous);" +
"p( E | X ) = Root( X, 2 ) + 6; }"
);
EquationOperator e = new EquationOperator();
e.convert( EDB.This().get("ROOT.NODES.E.EQUATION"), "X" );
}
public void test3() {
CPSCompilerMain cpsCompiler = new CPSCompilerMain();
cpsCompiler.InitCompiler();
cpsCompiler.compile( testNet +
"defineNode(E, DescriptionE);"+
"{ defineState(Continuous);" +
"p( E | X ) = Exp( Root( X, 3 ), e ); }"
);
EquationOperator e = new EquationOperator();
e.convert( EDB.This().get("ROOT.NODES.E.EQUATION"), "X" );
}
public void test4() {
CPSCompilerMain cpsCompiler = new CPSCompilerMain();
cpsCompiler.InitCompiler();
cpsCompiler.compile( testNet +
"defineNode(E, DescriptionE);"+
"{ defineState(Continuous);" +
"p( E | X ) = Root(R, 2) * Log( X, e ) - C; }"
);
EquationOperator e = new EquationOperator();
EDBUnit r = e.convert( EDB.This().get("ROOT.NODES.E.EQUATION"), "X" );
r.print("Inv ");
}
public void test5() {
CPSCompilerMain cpsCompiler = new CPSCompilerMain();
cpsCompiler.InitCompiler();
cpsCompiler.compile( testNet +
"defineNode(E, DescriptionE);"+
"{ defineState(Continuous);" +
"p( E | X ) = 5 * X + R * 3; }"
);
EquationOperator e = new EquationOperator();
e.convert( EDB.This().get("ROOT.NODES.E.EQUATION"), "X" );
}
public void test6() {
CPSCompilerMain cpsCompiler = new CPSCompilerMain();
cpsCompiler.InitCompiler();
cpsCompiler.compile( "defineInferenceEngine( DMP );" + testNet +
"defineNode(E, DescriptionE);"+
"{ defineState(Continuous);" +
"p( E | X, T ) = X - 2 * T;}"
//"p( E | X, T ) = 3*X-2;}"
//"p( E | X, T ) = 3*X-normal();}"
);
EDB.This().get("ROOT.NODES.E.EQUATION").print("");
EquationOperator e = new EquationOperator();
EDBUnit r = e.convert( EDB.This().get("ROOT.NODES.E.EQUATION"), "T", "Y" );
r.print("Inv ");
// String str = e.getStringFromInv(EDB.This().get("ROOT.NODES.E.EQUATION"));
// System.out.println(str);
}
public void test7() {
CPSCompilerMain cpsCompiler = new CPSCompilerMain();
cpsCompiler.InitCompiler();
cpsCompiler.compile( testNet2 +
"run(DMP);" );
EDB.This().get("ROOT").print("");
EquationOperator e = new EquationOperator();
EDBUnit r = e.convert( EDB.This().get("ROOT.NODES.X.EQUATION"), "U", "X" );
r.print("Inv ");
}
/**
* @param args
*/
public static void main(String[] args) {
InverseFunction_Test t = new InverseFunction_Test();
//t.test1();
//t.test2();
//t.test3();
//t.test4();
//t.test5();
//t.test6();
t.test7();
}
}