本文整理汇总了C++中BayesNet::AddNode方法的典型用法代码示例。如果您正苦于以下问题:C++ BayesNet::AddNode方法的具体用法?C++ BayesNet::AddNode怎么用?C++ BayesNet::AddNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BayesNet
的用法示例。
在下文中一共展示了BayesNet::AddNode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BayesNet
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;
}
示例2: BayesNet
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;
}
示例3: main
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;
}
示例4: RPSModel
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;
}
示例5: main
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;
//.........这里部分代码省略.........
示例6: main
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;
}
示例7: CropModel
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;
}
示例8: BayesNet
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);
//.........这里部分代码省略.........
示例9: FraudModel
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;
}