Beispiel #1
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;
}
Beispiel #2
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;
}
Beispiel #3
0
void TestsPnlHigh::TestGetGaussianMeanCovarWeights()
{
    printf("TestGetGaussianMeanCovarWeights\n");
    
    BayesNet *net = SimpleCGM1();
    
    net->SetPGaussian("Cont1", "0.0", "2.5", "1.0 3.0", "Tab0^State0");
    net->SetPGaussian("Cont1", "-1.5", "0.75", "0.5 2.5", "Tab0^State1");
    
    if (net->GetGaussianMean("Cont1", "Tab0^State0")[0].FltValue() != 0.0f)
    {
	PNL_THROW(pnl::CAlgorithmicException, "GetGaussianMean works incorrectly");
    };
    
    if (net->GetGaussianMean("Cont1", "Tab0^State1")[0].FltValue() != -1.5f)
    {
	PNL_THROW(pnl::CAlgorithmicException, "GetGaussianMean works incorrectly");
    };
    
    if (net->GetGaussianCovar("Cont1", "Tab0^State0")[0].FltValue() != 2.5f)
    {
	PNL_THROW(pnl::CAlgorithmicException, "GetGaussianCovar works incorrectly");
    };
    
    if (net->GetGaussianCovar("Cont1", "Tab0^State1")[0].FltValue() != 0.75f)
    {
	PNL_THROW(pnl::CAlgorithmicException, "GetGaussianCovar works incorrectly");
    };  
    
    if (String(net->GetGaussianWeights("Cont1", "Cont0", "Tab0^State0")[0]) != "1.000000^3.000000")
    {
	PNL_THROW(pnl::CAlgorithmicException, "GetGaussianCovar works incorrectly");
    }; 
    
    if (String(net->GetGaussianWeights("Cont1", "Cont0", "Tab0^State1")[0]) != "0.500000^2.500000")
    {
	PNL_THROW(pnl::CAlgorithmicException, "GetGaussianCovar works incorrectly");
    }; 
    
    delete net;
};
Beispiel #4
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;
}
Beispiel #5
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;
}
Beispiel #6
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;
}
Beispiel #7
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;
}