Exemplo n.º 1
0
BayesNet *SimpleCondSoftMaxModel()
{ 
    BayesNet *net;
    net = new BayesNet();
    
    net->AddNode("continuous^node0");
    net->AddNode("continuous^node1");
    net->AddNode("continuous^node2");
    net->AddNode("discrete^node3", "True False"); 

    net->AddNode("discrete^node5", "True False");// condsoftmax node
    net->AddNode("discrete^node6", "True False");

    net->AddArc("node0", "node5");
    net->AddArc("node1", "node5");
    net->AddArc("node2", "node5");
    net->AddArc("node3", "node5");
    net->AddArc("node5", "node6");

    net->SetPGaussian("node0", "0.1", "0.9");
    net->SetPGaussian("node1", "0.2", "0.8");
    net->SetPGaussian("node2", "0.3", "0.7");
  
    net->SetPTabular("node6^True node6^False", "0.3 0.7", "node5^True");
    net->SetPTabular("node6^True node6^False", "0.5 0.5", "node5^False");

    net->SetPSoftMax("node5^True node5^False", "0.3 0.4 0.5 0.6 0.7 0.8", "0.1 0.1", "node3^True");
    net->SetPSoftMax("node5^True node5^False", "0.23 0.24 0.25 0.26 0.27 0.28", "0.21 0.21", "node3^False");

    return net;
}
Exemplo n.º 2
0
BayesNet *TestsPnlHigh::CreateCondGaussianModel1()
{
    // Cont1  Tab1
    //    |   |
    //    \/ \/
    //    Cont2
    BayesNet *net;
    net = new BayesNet();
    
    net->AddNode(continuous^"Cont1 Cont2", "dim1"); 
    net->AddNode(discrete^"Tab1", "dim1 dim2");
    
    net->AddArc("Cont1 Tab1", "Cont2");
    
    return net;
}
Exemplo n.º 3
0
BayesNet *TestsPnlHigh::SimpleCGM1()
{
    //Cont0(3) Tab0(0)
    //  |      |
    //  \/    \/
    //   Cont1(1)
    //    |
    //    \/
    //   Cont2(2)
    BayesNet *net = new BayesNet();
    
    net->AddNode(discrete^"Tab0", "State0 State1");
    net->AddNode(continuous^"Cont1 Cont2", "Dim0");
    net->AddNode(continuous^"Cont0", "Dim0 Dim1");
    
    net->AddArc("Cont0 Tab0", "Cont1");
    net->AddArc("Cont1", "Cont2");
    
    return net;
};
Exemplo n.º 4
0
int main()
{
	int hold;
    int prob = 0;
    vector<double> probVec = { .7, .1 };
    vector<double> childProbVec = { .8 };

    BayesNet myNet;

    myNet.AddNode("someNode", probVec);
    myNet.AddNode("someNode", "childNode", childProbVec);
    
    myNet.PrintAllNodes(myNet.head);

    //change calcprobs to return an int
    Node* someNode = myNet.GetNode(myNet.head, "someNode");
    myNet.CalcProbs(someNode);

	cin >> hold;
	return 0;
}
Exemplo n.º 5
0
BayesNet *SevenNodesModel()
{ 
    BayesNet *net;
    net = new BayesNet();
    
    net->AddNode(continuous^"node0 node1 node5");
    net->AddNode(discrete^"node2 node3 node4 node6", "False True");

    net->AddArc("node0", "node3");
    net->AddArc("node1", "node3");
    net->AddArc("node2", "node3");
    net->AddArc("node3", "node4");
    net->AddArc("node3", "node5");
    net->AddArc("node0", "node6");
    net->AddArc("node4", "node6");
  
    net->SetPGaussian("node0", "0.5", "1.0");
    
    net->SetPGaussian("node1", "0.5", "1.0");
    
    net->SetPTabular("node2^True node2^False", "0.3 0.7");
    
    net->SetPSoftMax("node3^True node3^False", "0.5 0.4 0.5 0.7", "0.3 0.5", "node2^False");
    net->SetPSoftMax("node3^True node3^False", "0.5 0.1 0.5 0.7", "0.3 0.5 ", "node2^True");

    net->SetPTabular("node4^True node4^False", "0.8 0.2", "node3^True");
    net->SetPTabular("node4^True node4^False", "0.3 0.7", "node3^False");

    net->SetPGaussian("node5", "0.5", "0.5", "1.0", "node3^True");
    net->SetPGaussian("node5", "1.0", "1.0", "1.0", "node3^False");

    net->SetPSoftMax("node6^True node6^False", "0.8 0.2", "0.1 0.9", "node4^True");
    net->SetPSoftMax("node6^True node6^False", "0.5 0.9", "0.7 0.3", "node4^False");

    return net;
}
Exemplo n.º 6
0
BayesNet *VerySimpleMultivariateGaussianModel()
{
    // NodeA -> NodeB -> NodeC
    BayesNet *net;
    net = new BayesNet();
    
    net->AddNode(continuous^"NodeB NodeA NodeC", "dim1 dim2");
    //    net->AddNode(continuous^"NodeA NodeB NodeC", "dim1");
    net->AddArc("NodeA", "NodeB");
    net->AddArc("NodeB", "NodeC");
    
    net->SetPGaussian("NodeA", "1.0 2.0", "10.0 0.1 0.1 10.0");
    net->SetPGaussian("NodeB", "0.5 1.5", "7.0 0.0 0.0 7.0", "0.1 0.2 0.3 0.4");
    net->SetPGaussian("NodeC", "0.8 1.8", "3.5 0.5 0.5 3.5", "0.5 0.6 0.7 0.8");
    
    return net;
}
Exemplo n.º 7
0
BayesNet *VerySimpleGaussianModel()
{
    // NodeA -> NodeB -> NodeC
    BayesNet *net;
    net = new BayesNet();
    
    net->AddNode(continuous^"NodeB NodeA NodeC", "dim1");
    //    net->AddNode(continuous^"NodeA NodeB NodeC", "dim1");
    net->AddArc("NodeA", "NodeB");
    net->AddArc("NodeB", "NodeC");
    
    net->SetPGaussian("NodeA", "1.0", "10.0");
    net->SetPGaussian("NodeB", "0.5", "7.0", "0.1");
    net->SetPGaussian("NodeC", "0.8", "3.5", "0.4");
    
    return net;
}
Exemplo n.º 8
0
BayesNet *SimpleSoftMaxModel()
{ 
    BayesNet *net;
    net = new BayesNet();
    
    net->AddNode(continuous^"node0 node1 node2");
    net->AddNode(discrete^"node5", "True False");

    net->AddArc("node0", "node5");
    net->AddArc("node1", "node5");
    net->AddArc("node2", "node5");
  
    net->SetPGaussian("node0", "0.1", "0.9");
    net->SetPGaussian("node1", "0.2", "0.8");
    net->SetPGaussian("node2", "0.3", "0.7");

    net->SetPSoftMax("node5^True node5^False", "0.3 0.4 0.5 0.6 0.7 0.8", "0.1 0.1");
    return net;
}
Exemplo n.º 9
0
BayesNet* RPSModel()
{

    BayesNet *net;
    net = new BayesNet();

    TokArr aChoice = "Rock Paper Scissors";// possible values for nodes

    // build Graph
    // add nodes to net
    net->AddNode(discrete ^ "PreviousCompTurn PreviousHumanTurn CurrentHumanTurn", aChoice);

    // add arcs to create following Bayes net:
    //
    //  PreviousCompTurn    PreviousHumanTurn
    //               |         |
    //               V	       V
    //             CurrentHumanTurn
    net->AddArc("PreviousCompTurn", "CurrentHumanTurn");
    net->AddArc("PreviousHumanTurn", "CurrentHumanTurn");

    return net;
}
Exemplo n.º 10
0
int main(int arg,char * argv[])
{
    int a=1,b=2;
    int c=a+b;
    cout<<c<<endl;

    //creating bayes net
    //BayesNet net;
    BayesNet net;

    //adding node
    net.AddNode("discrete^Cloudy","true false");
    net.AddNode(discrete^"Sprinkler Rain WetGrass","true false");


    //adding edges
    net.AddArc("Cloudy","Sprinkler Rain");
    net.AddArc("Sprinkler Rain","WetGrass");


    //sopecfify the CPD
    //cloudy
    net.SetPTabular("Cloudy^true","0.6");
    net.SetPTabular("Cloudy^false","0.4");
    //spprinkler
    net.SetPTabular("Sprinkler^true Sprinkler^false","0.1 0.9","Cloudy^true");
    net.SetPTabular("Sprinkler^true Sprinkler^false","0.5 0.5","Cloudy^false");
    //rain
    net.SetPTabular("Rain^true Rain^false","0.8 0.2","Cloudy^true");
    net.SetPTabular("Rain^true Rain^false","0.2 0.8","Cloudy^false");
    //WetGrass
    net.SetPTabular("WetGrass^true WetGrass^false","0.99 0.01","Sprinkler^true Rain^true");
    net.SetPTabular("WetGrass^true WetGrass^false","0.9 0.1","Sprinkler^true Rain^false");
    net.SetPTabular("WetGrass^true WetGrass^false","0.9 0.1","Sprinkler^false Rain^true");
    net.SetPTabular("WetGrass^true WetGrass^false","0.0 1.0","Sprinkler^false Rain^false");


    //get the cpd
    TokArr PCloudy=net.GetPTabular("Cloudy");
    String PCloudyStr=String(PCloudy);
    float PCloudyTrueF=PCloudy[0].FltValue();
    float PCloudyFalseF=PCloudy[1].FltValue();
    cout<<endl<<"Cloudy"<<endl;
     cout<<PCloudyStr<<endl;
    cout<<PCloudyTrueF<<endl;
    cout<<PCloudyFalseF<<endl;

    /*
    //adding evidence
    //net.AddEvidToBuf("Rain^true WetGrass^true");
    net.EditEvidence("Rain^true WetGrass^true");
    net.CurEvidToBuf();
    net.LearnParameters();
    cout<<endl<<"evidence Rain^true WetGrass^true"<<endl;

    //get the jpd
    TokArr WetGrassMarg=net.GetJPD("WetGrass");
    String WetGrassMargStr=String(WetGrassMarg);
    cout<<endl<<"WetGrass JPD"<<endl<<WetGrassMargStr<<endl;

    TokArr WetGrassAndSprinklerMarg=net.GetJPD("WetGrass Sprinkler Rain");
    String WetGrassAndSprinklerMargStr=String(WetGrassAndSprinklerMarg);
    cout<<endl<<"WetGrass and Sprinkler JPD"<<endl<<WetGrassAndSprinklerMargStr<<endl;

    TokArr WetGrassMPE=net.GetMPE("WetGrass");
    String WetGrassMPEStr=String(WetGrassMPE);
    cout<<endl<<"WetGrass MPE"<<endl<<WetGrassMPEStr<<endl;

    TokArr WetGrassAndSprinklerMPE=net.GetMPE("WetGrass Sprinkler Rain");
    String WetGrassAndSprinklerMPEStr=String(WetGrassAndSprinklerMPE);
    cout<<endl<<"WetGrass and Spinkler MPE"<<endl<<WetGrassAndSprinklerMPEStr<<endl;

    //delete evidence
    net.ClearEvid();
    cout<<"ok"<<endl;*/
    //net.AddEvidToBuf("Sprinkler^true WetGrass^true");
    net.EditEvidence("Sprinkler^true WetGrass^true");
    net.CurEvidToBuf();
    net.LearnParameters();
    cout<<endl<<"evidence Sprinkler^true WetGrass^true"<<endl;

    //get jpd
    TokArr WetGrassMarg=net.GetJPD("WetGrass");
    String WetGrassMargStr=String(WetGrassMarg);
    cout<<endl<<"WetGrass JPD"<<endl<<WetGrassMargStr<<endl;

    TokArr WetGrassAndSprinklerMarg=net.GetJPD("WetGrass Sprinkler Rain");
    String WetGrassAndSprinklerMargStr=String(WetGrassAndSprinklerMarg);
    cout<<endl<<"WetGrass and Sprinkler JPD"<<endl<<WetGrassAndSprinklerMargStr<<endl;

    TokArr WetGrassMPE=net.GetMPE("WetGrass");
    String WetGrassMPEStr=String(WetGrassMPE);
    cout<<endl<<"WetGrass MPE"<<endl<<WetGrassMPEStr<<endl;

    TokArr WetGrassAndSprinklerMPE=net.GetMPE("WetGrass Sprinkler Rain Cloudy");
    String WetGrassAndSprinklerMPEStr=String(WetGrassAndSprinklerMPE);
    cout<<endl<<"WetGrass and Spinkler MPE"<<endl<<WetGrassAndSprinklerMPEStr<<endl;


    cout<<endl<<"moonsea"<<endl;
    return 0;

}
Exemplo n.º 11
0
int main()
{
    BayesNet net;
    // adding nodes
    net.AddNode("discrete^Cloudy", "true false"); 
    net.AddNode("discrete^Sprinkler", "true false");
    net.AddNode("discrete^Rain", "true false");
    net.AddNode("discrete^WetGrass", "true false");

    //adding edges
    net.AddArc("Cloudy", "Sprinkler Rain");
    net.AddArc("Sprinkler Rain", "WetGrass");

    // specifying the conditional probabilities
    net.SetPTabular("Cloudy^true Cloudy^false", "0.6 0.4");

    net.SetPTabular("Sprinkler^true Sprinkler^false", "0.1 0.9", "Cloudy^true");
    net.SetPTabular("Sprinkler^true Sprinkler^false", "0.5 0.5", "Cloudy^false");
    net.SetPTabular("Rain^true Rain^false", "0.8 0.2", "Cloudy^true");
    net.SetPTabular("Rain^true Rain^false", "0.2 0.8", "Cloudy^false");
    //
    net.SetPTabular("WetGrass^true WetGrass^false", "0.99 0.01", "Rain^true Sprinkler^true ");
    net.SetPTabular("WetGrass^true WetGrass^false", "0.9 0.1", "Sprinkler^true Rain^false");
    net.SetPTabular("WetGrass^true WetGrass^false", "0.9 0.1", "Sprinkler^false Rain^true");
    net.SetPTabular("WetGrass^true WetGrass^false", "0.0 1.0", "Sprinkler^false Rain^false");

    //To get the probability distribution of the node we must call the GetPTabular method:
    TokArr PCloudy = net.GetPTabular("Cloudy");

    // Now it is possible to represent this distribution as string or as float numbers:
    String PCloudyStr = String(PCloudy);
    float PCloudyTrueF = PCloudy[0].FltValue();
    float PCloudyFalseF = PCloudy[1].FltValue();

    cout << PCloudyStr <<  std::endl << PCloudyTrueF << "," << PCloudyFalseF << std::endl;
    
    TokArr PSprinkler = net.GetPTabular("Sprinkler", "Cloudy^true");
    String PSprinklerStr = String(PSprinkler);
    float PSprinklerTrue = PSprinkler[0].FltValue();
    float PSprinklerFalse = PSprinkler[1].FltValue();
    
    
    cout << PSprinklerStr <<  std::endl << PSprinklerTrue  << "," << PSprinklerFalse << std::endl;
    
    // net.EditEvidence("Cloudy^false WetGrass^false");
    // if the above line is un commented then after the net line the evidence buffer will have "Sprinkler^true Cloudy^true  WetGrass^false"
    net.EditEvidence("Sprinkler^true Cloudy^true");
    
    TokArr PRain = net.GetJPD("Rain");

    // Now it is possible to represent this distribution as string or as float numbers:
    String PRainStr = String(PRain);
    float PRainTrueF = PRain[0].FltValue();
    float PRainFalseF = PRain[1].FltValue();
    
    
    cout << PRainStr <<  std::endl << PRainTrueF << "," << PRainFalseF << std::endl;

    TokArr PWetGrass = net.GetJPD("WetGrass");
    String PWetGrassStr = String(PWetGrass);
    float PWetGrassTrue = PWetGrass[0].FltValue();
    float PWetGrassFalse = PWetGrass[1].FltValue();
    
    
    cout << PWetGrassStr <<  std::endl << PWetGrassTrue << "," << PWetGrassFalse << std::endl;
    return 0;
}
Exemplo n.º 12
0
BayesNet* CropModel()
{
    //  Subsidy(d) Crop(c)
    //          |   |
    //          V   V
    //         Price(c)
    //            |
    //            V
    //          Buy(d)

    BayesNet *net;
    net = new BayesNet();

    textcolor(WHITE);

    net->AddNode(discrete^"Subsidy", "Yes No");
    printf("\n net->AddNode(discrete^\"Subsidy\", \"Yes No\");");
    textcolor(LIGHTGREEN);

    printf("\t\t\t\t\t\tAdding of nodes is in process....");
    _sleep(2000);
    textcolor(WHITE);

    net->AddNode(continuous ^ "Crop");
    printf("\n net->AddNode(continuous ^ \"Crop\");");
    _sleep(1000);

    net->AddNode(continuous ^ "Price");
    printf("\n net->AddNode(continuous ^ \"Price\");");
    _sleep(1000);

    net->AddNode(discrete^"Buy", "Yes No");
    printf("\n net->AddNode(discrete^\"Buy\", \"Yes No\");");

    textcolor(LIGHTGREEN);
    printf("\n ......All nodes are added....\n");
    getch();

    // arcs
    textcolor(WHITE);

    net->AddArc("Subsidy Crop", "Price");
    printf("\n net->AddArc(\"Subsidy Crop\", \"Price\");");
    textcolor(LIGHTGREEN);
    printf("\t\t\t\t\t\t\tAdding of arcs is in process....");
    _sleep(2000);

    textcolor(WHITE);
    net->AddArc("Price", "Buy");
    printf("\n net->AddArc(\"Price\", \"Buy\");");
    textcolor(LIGHTGREEN);
    printf("\n ......All arcs are added....\n");
    getch();

    // distributions
    textcolor(WHITE);

    net->SetPTabular("Subsidy^Yes Subsidy^No", "0.3 0.7");
    printf("\n net->SetPTabular(\"Subsidy^Yes Subsidy^No\", \"0.3 0.7\");");
    textcolor(LIGHTGREEN);
    printf("\t\t\t\t\tAdding of distributions is in process....");
    _sleep(2000);

    textcolor(WHITE);

    net->SetPGaussian("Crop", "5.0", "1.0");
    printf("\n net->SetPGaussian(\"Crop\", \"5.0\", \"1.0\");");
    _sleep(1000);

    net->SetPGaussian("Price", "10.0", "1.0", "-1.0", "Subsidy^Yes");
    printf("\n net->SetPGaussian(\"Price\", \"10.0\", \"1.0\", \"-1.0\", \"Subsidy^Yes\");");
    _sleep(1000);

    net->SetPGaussian("Price", "20.0", "1.0", "-1.0", "Subsidy^No");
    printf("\n net->SetPGaussian(\"Price\", \"20.0\", \"1.0\", \"-1.0\", \"Subsidy^No\");");
    _sleep(1000);

    net->SetPSoftMax("Buy^Yes Buy^No", "-1.0 1.0", "5.0 -5.0");
    printf("\n net->SetPSoftMax(\"Buy^Yes Buy^No\", \"-1.0 1.0\", \"5.0 -5.0\");");

    textcolor(LIGHTGREEN);
    printf("\n ......All distributions are added....\n");
    getch();
    textcolor(WHITE);

    return net;
}
Exemplo n.º 13
0
BayesNet *WasteModel()
{
    BayesNet *net;
    net = new BayesNet();

    textcolor(WHITE);

    net->AddNode(discrete^"TypeOfWaste", "industrial household");
    net->AddNode(discrete^"FilterState", "intact defective");
    net->AddNode(discrete^"BurningRegime", "stable unstable");

    printf("\n net->AddNode(discrete^\"TypeOfWaste\", \"industrial household\");");
    textcolor(LIGHTGREEN);

    printf("\t\t\t\tAdding of nodes is in process....");
    _sleep(2000);
    textcolor(WHITE);

    printf("\n net->AddNode(discrete^\"FilterState\", \"intact defective\");");
    _sleep(1000);
    printf("\n net->AddNode(discrete^\"BurningRegime\", \"stable unstable\");");
    _sleep(1000);
    net->AddNode(continuous^"FilterEfficiency CO2Emission DustEmission", "dim1");
    printf("\n net->AddNode(continuous^\"FilterEfficiency CO2Emission DustEmission\", \"dim1\");");
    _sleep(1000);

    net->AddNode(continuous^"MetalInWaste MetalEmission Light", "dim1");
    printf("\n net->AddNode(continuous^\"MetalInWaste MetalEmission Light\", \"dim1\");");

    textcolor(LIGHTGREEN);
    printf("\n ......All nodes are added....\n");
    getch();

    // arcs
    textcolor(WHITE);
    net->AddArc("TypeOfWaste FilterState", "FilterEfficiency");
    printf("\n net->AddArc(\"TypeOfWaste FilterState\", \"FilterEfficiency\");");

    textcolor(LIGHTGREEN);
    printf("\t\t\t\tAdding of arcs is in process....");
    _sleep(2000);

    textcolor(WHITE);

    net->AddArc("FilterState FilterEfficiency BurningRegime", "DustEmission") ;
    printf("\n net->AddArc(\"FilterState FilterEfficiency BurningRegime\", \"DustEmission\") ;");
    _sleep(1000);

    net->AddArc( "FilterState", "MetalInWaste");
    printf("\n net->AddArc(\"FilterState\", \"MetalInWaste\");");
    _sleep(1000);

    net->AddArc( "BurningRegime", "CO2Emission");
    printf("\n net->AddArc(\"BurningRegime\", \"CO2Emission\");");
    _sleep(1000);

    net->AddArc( "DustEmission MetalInWaste", "MetalEmission");
    printf("\n net->AddArc(\"DustEmission MetalInWaste\", \"MetalEmission\");");
    _sleep(1000);

    net->AddArc( "MetalInWaste", "Light");
    printf("\n net->AddArc(\"MetalInWaste\", \"Light\");");
    _sleep(1000);
    textcolor(LIGHTGREEN);
    printf("\n ......All arcs are added....\n");
    getch();
    // distributions
    textcolor(WHITE);

    net->SetPTabular( "TypeOfWaste^industrial TypeOfWaste^household", "0.95 0.05");
    printf("\n net->SetPTabular(\"TypeOfWaste^industrial TypeOfWaste^household\", \"0.95 0.05\");");
    textcolor(LIGHTGREEN);
    printf("\t\tAdding of distributions is in process....");
    _sleep(2000);

    textcolor(WHITE);

    net->SetPTabular( "FilterState^intact FilterState^defective", "0.285714 0.714286");
    printf("\n net->SetPTabular(\"FilterState^intact FilterState^defective\", \"0.285714 0.714286\");");
    _sleep(1000);

    net->SetPTabular( "BurningRegime^stable BurningRegime^unstable", "0.85 0.15");
    printf("\n net->SetPTabular(\"BurningRegime^stable BurningRegime^unstable\", \"0.85 0.15\");");
    _sleep(1000);

    net->SetPGaussian( "FilterEfficiency", "-3.2", "0.00002", "", "TypeOfWaste^industrial FilterState^defective");
    printf("\n net->SetPGaussian(\"FilterEfficiency\", \"-3.2\", \"0.00002\", \"\", \n\t\t\"TypeOfWaste^industrial FilterState^defective\");");
    _sleep(1000);

    net->SetPGaussian( "FilterEfficiency", "-0.5", "0.0001", "", "TypeOfWaste^industrial FilterState^intact");
    printf("\n net->SetPGaussian(\"FilterEfficiency\", \"-0.5\", \"0.0001\", \"\", \n\t\t\"TypeOfWaste^industrial FilterState^intact\");");
    _sleep(1000);

    net->SetPGaussian( "FilterEfficiency", "-3.9", "0.00002", "", "TypeOfWaste^household FilterState^defective");
    printf("\n net->SetPGaussian(\"FilterEfficiency\", \"-3.9\", \"0.00002\", \"\", \n\t\t\"TypeOfWaste^household FilterState^defective\");");
    _sleep(1000);

    net->SetPGaussian( "FilterEfficiency", "-0.4", "0.0001", "", "TypeOfWaste^household FilterState^intact");
    printf("\n net->SetPGaussian(\"FilterEfficiency\", \"-0.4\", \"0.0001\", \"\", \n\t\t\"TypeOfWaste^household FilterState^intact\");");
    _sleep(1000);


    net->SetPGaussian( "CO2Emission", "-2", "0.1", "", "BurningRegime^stable");
    printf("\n net->SetPGaussian(\"CO2Emission\", \"-2\", \"0.1\", \"\", \"BurningRegime^stable\");");
    _sleep(1000);

    net->SetPGaussian( "CO2Emission", "-1", "0.3", "", "BurningRegime^unstable");
    printf("\n net->SetPGaussian(\"CO2Emission\", \"-1\", \"0.3\", \"\", \"BurningRegime^unstable\");");
    _sleep(1000);


    net->SetPGaussian( "DustEmission", "6.5", "0.03", "1.0", "FilterState^intact BurningRegime^stable");
    printf("\n net->SetPGaussian(\"DustEmission\", \"6.5\", \"0.03\", \"1.0\", \"FilterState^intact \n\t\tBurningRegime^stable\");");
    _sleep(1000);

    net->SetPGaussian( "DustEmission", "7.5", "0.1", "1.0", "FilterState^intact BurningRegime^unstable");
    printf("\n net->SetPGaussian(\"DustEmission\", \"7.5\", \"0.1\", \"1.0\", \"FilterState^intact \n\t\tBurningRegime^unstable\");");
    _sleep(1000);

    net->SetPGaussian( "DustEmission", "6.0", "0.04", "1.0", "FilterState^defective BurningRegime^stable");
    printf("\n net->SetPGaussian(\"DustEmission\", \"6.0\", \"0.04\", \"1.0\", \"FilterState^defective \n\t\tBurningRegime^stable\");");
    _sleep(1000);

    net->SetPGaussian( "DustEmission", "7.0", "0.01", "1.0", "FilterState^defective BurningRegime^unstable");
    printf("\n net->SetPGaussian(\"DustEmission\", \"7.0\", \"0.01\", \"1.0\", \"FilterState^defective \n\t\tBurningRegime^unstable\");");
    _sleep(1000);


    net->SetPGaussian( "MetalInWaste", "0.5", "0.01", "", "FilterState^intact");
    printf("\n net->SetPGaussian(\"MetalInWaste\", \"0.5\", \"0.01\", \"\", \"FilterState^intact\");");
    _sleep(1000);

    net->SetPGaussian( "MetalInWaste", "-0.5", "0.005", "", "FilterState^defective");
    printf("\n net->SetPGaussian(\"MetalInWaste\", \"-0.5\", \"0.005\", \"\", \"FilterState^defective\");");
    _sleep(1000);


    net->SetPGaussian( "MetalEmission", "0.0", "0.02", "1.0 1.0");
    printf("\n net->SetPGaussian(\"MetalEmission\", \"0.0\", \"0.02\", \"1.0 1.0\");");
    _sleep(1000);

    net->SetPGaussian( "Light", "3.0", "0.25", "-0.5");
    printf("\n net->SetPGaussian(\"Light\", \"3.0\", \"0.25\", \"-0.5\");");
    _sleep(1000);
    textcolor(LIGHTGREEN);
    printf("\n ......All distributions are added....\n");
    getch();
    textcolor(WHITE);

    return net;
}
Exemplo n.º 14
0
BayesNet *ScalarGaussianBNetModel()
{
    // NodeA  NodeB
    //     \ /
    //    NodeC
    //     / \
    // NodeD  NodeE

    BayesNet *net;
    net = new BayesNet();

    textcolor(WHITE);
    net->AddNode(continuous^"NodeA NodeB NodeC", "dim1");
    printf("\n net->AddNode(continuous^\"NodeA NodeB NodeC\", \"dim1\");");
    textcolor(LIGHTGREEN);

    printf("\t\t\t\tAdding of nodes is in process....");
    _sleep(2000);
    textcolor(WHITE);

    net->AddNode(continuous^"NodeD NodeE", "dim1");
    printf("\n net->AddNode(continuous^\"NodeD NodeE\", \"dim1\");");
    _sleep(1000);

    textcolor(LIGHTGREEN);
    printf("\n ......All nodes are added....\n");
    getch();

    // arcs
    textcolor(WHITE);
    net->AddArc("NodeA NodeB", "NodeC");
    printf("\n net->AddArc(\"NodeA NodeB\", \"NodeC\");");

    textcolor(LIGHTGREEN);
    printf("\t\t\t\t\t\tAdding of arcs is in process....");
    _sleep(2000);

    textcolor(WHITE);

    net->AddArc("NodeC", "NodeD NodeE");
    printf("\n net->AddArc(\"NodeC\", \"NodeD NodeE\");");
    _sleep(1000);

    textcolor(LIGHTGREEN);
    printf("\n ......All arcs are added....\n");
    getch();
    // distributions
    textcolor(WHITE);

    net->SetPGaussian("NodeA", "1.0", "4.0");
    printf("\n net->SetPGaussian(\"NodeA\", \"1.0\", \"4.0\");");
    textcolor(LIGHTGREEN);
    printf("\t\t\t\t\tAdding of distributions is in process....");
    _sleep(2000);

    textcolor(WHITE);

    net->SetPGaussian("NodeB", "1.0", "1.0");
    printf("\n net->SetPGaussian(\"NodeB\", \"1.0\", \"1.0\");");
    _sleep(1000);

    net->SetPGaussian("NodeC", "0.0", "2.0", "1.0 2.0");
    printf("\n net->SetPGaussian(\"NodeC\", \"0.0\", \"2.0\", \"1.0 2.0\");");
    _sleep(1000);

    net->SetPGaussian("NodeD", "0.0", "4.0", "1.1");
    printf("\n net->SetPGaussian(\"NodeD\", \"0.0\", \"4.0\", \"1.1\");");
    _sleep(1000);

    net->SetPGaussian("NodeE", "-0.8", "1.2", "2.0");
    printf("\n net->SetPGaussian(\"NodeE\", \"-0.8\", \"1.2\", \"2.0\");");
    textcolor(LIGHTGREEN);
    printf("\n ......All distributions are added....\n");
    getch();
    textcolor(WHITE);

    return net;
}
Exemplo n.º 15
0
PNLW_BEGIN

BayesNet *AsiaModel()
{
    BayesNet *net;
    net = new BayesNet();

    // nodes
    textcolor(WHITE);
    net->AddNode(discrete^"Smoking", "True False");
    printf("\n net->AddNode(discrete^\"Smoking\", \"True False\");");
    textcolor(LIGHTGREEN);

    printf("\t\t\t\tAdding of nodes is in process....");
    _sleep(2000);
    textcolor(WHITE);

    net->AddNode(discrete^"VisitToAsia", "True False");
    printf("\n net->AddNode(discrete^\"VisitToAsia\", \"True False\");");
    _sleep(1000);

    net->AddNode(discrete^"Bronchitis", "True False");
    printf("\n net->AddNode(discrete^\"Bronchitis\", \"True False\");");
    _sleep(1000);

    net->AddNode(discrete^"LungCancer", "True False");
    printf("\n net->AddNode(discrete^\"LungCancer\", \"True False\");");
    _sleep(1000);

    net->AddNode(discrete^"Tuberculosis", "True False");
    printf("\n net->AddNode(discrete^\"Tuberculosis\", \"True False\");");
    _sleep(1000);

    net->AddNode(discrete^"Dyspnoea", "True False");
    printf("\n net->AddNode(discrete^\"Dyspnoea\", \"True False\");");
    _sleep(1000);

    net->AddNode(discrete^"CancerOrTuberculosis", "True False");
    printf("\n net->AddNode(discrete^\"CancerOrTuberculosis\", \"True False\");");
    _sleep(1000);

    net->AddNode(discrete^"XRayPositive", "True False");
    printf("\n net->AddNode(discrete^\"XRayPositive\", \"True False\");");
    _sleep(1000);

    textcolor(LIGHTGREEN);
    printf("\n ......All nodes are added....\n");
    getch();

    // arcs
    textcolor(WHITE);
    net->AddArc("Smoking", "Bronchitis LungCancer");
    printf("\n net->AddArc(\"Smoking\", \"Bronchitis LungCancer\");");

    textcolor(LIGHTGREEN);
    printf("\t\t\t\tAdding of arcs is in process....");
    _sleep(2000);

    textcolor(WHITE);
    net->AddArc("VisitToAsia", "Tuberculosis");
    printf("\n net->AddArc(\"VisitToAsia\", \"Tuberculosis\");");
    _sleep(1000);

    net->AddArc("LungCancer Tuberculosis", "CancerOrTuberculosis");
    printf("\n net->AddArc(\"LungCancer Tuberculosis\", \"CancerOrTuberculosis\");");
    _sleep(1000);

    net->AddArc("Bronchitis", "Dyspnoea");
    printf("\n net->AddArc(\"Bronchitis\", \"Dyspnoea\");");
    _sleep(1000);

    net->AddArc("CancerOrTuberculosis", "Dyspnoea XRayPositive");
    printf("\n net->AddArc(\"CancerOrTuberculosis\", \"Dyspnoea XRayPositive\");");
    _sleep(1000);

    textcolor(LIGHTGREEN);
    printf("\n ......All arcs are added....\n");
    getch();
    // distributions
    textcolor(WHITE);
    net->SetPTabular("Smoking^True Smoking^False", "0.5 0.5");
    printf("\n net->SetPTabular(\"Smoking^True Smoking^False\", \"0.5 0.5\");");

    textcolor(LIGHTGREEN);
    printf("\t\t\tAdding of distributions is in process....");
    _sleep(2000);

    textcolor(WHITE);
    net->SetPTabular("VisitToAsia^True VisitToAsia^False", "0.01 0.99");
    printf("\n net->SetPTabular(\"VisitToAsia^True VisitToAsia^False\", \"0.01 0.99\");");
    _sleep(1000);

    net->SetPTabular("Bronchitis^True", "0.3", "Smoking^False");
    printf("\n net->SetPTabular(\"Bronchitis^True\", \"0.3\", \"Smoking^False\");");
    _sleep(1000);

    net->SetPTabular("Bronchitis^False", "0.7", "Smoking^False");
    printf("\n net->SetPTabular(\"Bronchitis^False\", \"0.7\", \"Smoking^False\");");
    _sleep(1000);

    net->SetPTabular("Bronchitis^True", "0.4", "Smoking^True");
    printf("\n net->SetPTabular(\"Bronchitis^True\", \"0.4\", \"Smoking^True\");");
    _sleep(1000);

    net->SetPTabular("Bronchitis^False", "0.6", "Smoking^True");
    printf("\n net->SetPTabular(\"Bronchitis^False\", \"0.6\", \"Smoking^True\");");
    _sleep(1000);

    net->SetPTabular("LungCancer^True", "0.01","Smoking^False");
    printf("\n net->SetPTabular(\"LungCancer^True\", \"0.01\",\"Smoking^False\");");
    _sleep(1000);

    net->SetPTabular("LungCancer^False", "0.99","Smoking^False");
    printf("\n net->SetPTabular(\"LungCancer^False\", \"0.99\",\"Smoking^False\");");
    _sleep(1000);

    net->SetPTabular("LungCancer^True", "0.1","Smoking^True");
    printf("\n net->SetPTabular(\"LungCancer^True\", \"0.1\",\"Smoking^True\");");
    _sleep(1000);

    net->SetPTabular("LungCancer^False", "0.9","Smoking^True");
    printf("\n net->SetPTabular(\"LungCancer^False\", \"0.9\",\"Smoking^True\");");
    _sleep(1000);

    net->SetPTabular("Tuberculosis^True", "0.01", "VisitToAsia^False");
    printf("\n net->SetPTabular(\"Tuberculosis^True\", \"0.01\", \"VisitToAsia^False\");");
    _sleep(1000);

    net->SetPTabular("Tuberculosis^False", "0.99", "VisitToAsia^False");
    printf("\n net->SetPTabular(\"Tuberculosis^False\", \"0.99\", \"VisitToAsia^False\");");
    _sleep(1000);

    net->SetPTabular("Tuberculosis^True", "0.05", "VisitToAsia^True" );
    printf("\n net->SetPTabular(\"Tuberculosis^True\", \"0.05\", \"VisitToAsia^True\" );");
    _sleep(1000);

    net->SetPTabular("Tuberculosis^False", "0.95", "VisitToAsia^True" );
    printf("\n net->SetPTabular(\"Tuberculosis^False\", \"0.95\", \"VisitToAsia^True\" );");
    _sleep(1000);

    net->SetPTabular("CancerOrTuberculosis^True", "0.0", "LungCancer^False Tuberculosis^False");
    printf("\n net->SetPTabular(\"CancerOrTuberculosis^True\", \"0.0\", \n \t \"LungCancer^False Tuberculosis^False\");");
    _sleep(1000);

    net->SetPTabular("CancerOrTuberculosis^False", "1.0", "LungCancer^False Tuberculosis^False");
    printf("\n net->SetPTabular(\"CancerOrTuberculosis^False\", \"1.0\", \n \t \"LungCancer^False Tuberculosis^False\");");
    _sleep(1000);

    net->SetPTabular("CancerOrTuberculosis^True CancerOrTuberculosis^False", "1.0 0.0", "LungCancer^False Tuberculosis^True");
    printf("\n net->SetPTabular(\"CancerOrTuberculosis^True CancerOrTuberculosis^False\",\n \t \"1.0 0.0\", \"LungCancer^False Tuberculosis^True\");");
    _sleep(1000);

    net->SetPTabular("CancerOrTuberculosis^True CancerOrTuberculosis^False", "1.0 0.0", "LungCancer^True Tuberculosis^False");
    printf("\n net->SetPTabular(\"CancerOrTuberculosis^True CancerOrTuberculosis^False\", \n \t\"1.0 0.0\", \"LungCancer^True Tuberculosis^False\");");
    _sleep(1000);

    net->SetPTabular("CancerOrTuberculosis^True CancerOrTuberculosis^False", "1.0 0.0", "LungCancer^True Tuberculosis^True");
    printf("\n net->SetPTabular(\"CancerOrTuberculosis^True CancerOrTuberculosis^False\", \n \t\"1.0 0.0\", \"LungCancer^True Tuberculosis^True\");");
    _sleep(1000);

    net->SetPTabular("Dyspnoea^True Dyspnoea^False", "0.1 0.9", "Bronchitis^False CancerOrTuberculosis^False");
    printf("\n net->SetPTabular(\"Dyspnoea^True Dyspnoea^False\", \"0.1 0.9\", \n \t\"Bronchitis^False CancerOrTuberculosis^False\");");
    _sleep(1000);

    net->SetPTabular("Dyspnoea^True Dyspnoea^False", "0.7 0.3", "Bronchitis^False CancerOrTuberculosis^True");
    printf("\n net->SetPTabular(\"Dyspnoea^True Dyspnoea^False\", \"0.7 0.3\", \n \t\"Bronchitis^False CancerOrTuberculosis^True\");");
    _sleep(1000);

    net->SetPTabular("Dyspnoea^True Dyspnoea^False", "0.8 0.2", "Bronchitis^True CancerOrTuberculosis^False");
    printf("\n net->SetPTabular(\"Dyspnoea^True Dyspnoea^False\", \"0.8 0.2\", \n \t\"Bronchitis^True CancerOrTuberculosis^False\");");
    _sleep(1000);

    net->SetPTabular("Dyspnoea^True Dyspnoea^False", "0.9 0.1", "Bronchitis^True CancerOrTuberculosis^True");
    printf("\n net->SetPTabular(\"Dyspnoea^True Dyspnoea^False\", \"0.9 0.1\", \n \t\"Bronchitis^True CancerOrTuberculosis^True\");");
    _sleep(1000);

    net->SetPTabular("XRayPositive^True XRayPositive^False", "0.05 0.95", "CancerOrTuberculosis^False");
    printf("\n net->SetPTabular(\"XRayPositive^True XRayPositive^False\", \"0.05 0.95\", \n \t\"CancerOrTuberculosis^False\");");
    _sleep(1000);

    net->SetPTabular("XRayPositive^True XRayPositive^False", "0.98 0.02", "CancerOrTuberculosis^True");
    printf("\n net->SetPTabular(\"XRayPositive^True XRayPositive^False\", \"0.98 0.02\", \n \t\"CancerOrTuberculosis^True\");");
    _sleep(1000);

    textcolor(LIGHTGREEN);
    printf("\n ......All distributions are added....\n");
    textcolor(WHITE);
    getch();
    return net;
}
Exemplo n.º 16
0
BayesNet* FraudModel()
{
//    David Heckerman
//    A Tutorial on Learning With Bayesian Networks, March 1995
    BayesNet *net;
    net = new BayesNet();

    textcolor(WHITE);
    net->AddNode(discrete^"Fraud", "Yes No");
    printf("\n net->AddNode(discrete^\"Fraud\", \"Yes No\");");
    textcolor(LIGHTGREEN);

    printf("\t\t\t\t\t\tAdding of nodes is in process....");
    _sleep(2000);
    textcolor(WHITE);
    net->AddNode(discrete^"Age", "Young MiddleAged InYears");
    printf("\n net->AddNode(discrete^\"Age\", \"Young MiddleAged InYears\");");
    _sleep(1000);

    net->AddNode(discrete^"Sex", "Male Female");
    printf("\n net->AddNode(discrete^\"Sex\", \"Male Female\");");
    _sleep(1000);

    net->AddNode(discrete^"Gas", "Yes No");
    printf("\n net->AddNode(discrete^\"Gas\", \"Yes No\");");
    _sleep(1000);

    net->AddNode(discrete^"Jewelry", "Yes No");
    printf("\n net->AddNode(discrete^\"Jewelry\", \"Yes No\");");
    textcolor(LIGHTGREEN);
    printf("\n ......All nodes are added....\n");
    textcolor(WHITE);

    getch();

    /*    net->AddArc("Fraud Age Sex", "Jewelry");
        net->AddArc("Fraud", "Gas");

        net->SetPTabular("Fraud^Yes Fraud^No", "0.00001 0.99999");
        net->SetPTabular("Age^Young Age^Middle-Aged Age^Elderly", "0.25 0.40 0.35");
        net->SetPTabular("Sex^Male Sex^Female", "0.5 0.5");

        net->SetPTabular("Gas^Yes Gas^No", "0.2 0.8", "Fraud^Yes");
        net->SetPTabular("Gas^Yes Gas^No", "0.01 0.99", "Fraud^No");

        net->SetPTabular("Jewelry^Yes Jewelry^No", "0.05 0.95", "Fraud^Yes Age^Young Sex^Male");
        net->SetPTabular("Jewelry^Yes Jewelry^No", "0.05 0.95", "Fraud^Yes Age^Middle-Aged Sex^Male");
        net->SetPTabular("Jewelry^Yes Jewelry^No", "0.05 0.95", "Fraud^Yes Age^Elderly Sex^Male");

        net->SetPTabular("Jewelry^Yes Jewelry^No", "0.05 0.95", "Fraud^Yes Age^Young Sex^Female");
        net->SetPTabular("Jewelry^Yes Jewelry^No", "0.05 0.95", "Fraud^Yes Age^Middle-Aged Sex^Female");
        net->SetPTabular("Jewelry^Yes Jewelry^No", "0.05 0.95", "Fraud^Yes Age^Elderly Sex^Female");
        net->SetPTabular("Jewelry^Yes Jewelry^No", "0.00001 0.99999", "Fraud^No Age^Young Sex^Male");

        net->SetPTabular("Jewelry^Yes Jewelry^No", "0.0004 0.9996", "Fraud^No Age^Middle-Aged Sex^Male");
        net->SetPTabular("Jewelry^Yes Jewelry^No", "0.0002 0.9998", "Fraud^No Age^Elderly Sex^Male");
        net->SetPTabular("Jewelry^Yes Jewelry^No", "0.00005 0.99995", "Fraud^No Age^Young Sex^Female");
        net->SetPTabular("Jewelry^Yes Jewelry^No", "0.002 0.998", "Fraud^No Age^Middle-Aged Sex^Female");
        net->SetPTabular("Jewelry^Yes Jewelry^No", "0.001 0.999", "Fraud^No Age^Elderly Sex^Female");
    */
    return net;
}