本文整理汇总了C++中CBNet::GetGraph方法的典型用法代码示例。如果您正苦于以下问题:C++ CBNet::GetGraph方法的具体用法?C++ CBNet::GetGraph怎么用?C++ CBNet::GetGraph使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBNet
的用法示例。
在下文中一共展示了CBNet::GetGraph方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TraverseSubobjectOfGrModel
void
CPersistBNet::TraverseSubobject(CPNLBase *pObj, CContext *pContext)
{
CBNet *pModel = dynamic_cast<CBNet*>(pObj);
pContext->Put(pModel->GetGraph(), "Graph");
TraverseSubobjectOfGrModel(pModel, pContext);
}
示例2: Create_BNet_CompleteGraph
CBNet* Create_BNet_CompleteGraph(int num_nodes, int max_num_states,
long &num_edges)
{
CGraph* pGraph = CreateCompleteGraph(num_nodes);
CBNet* pBNet = CreateRandomBayessian(pGraph, max_num_states);
num_edges = pBNet->GetGraph()->GetNumberOfEdges();
return pBNet;
}
示例3: Create_BNet_RegularGrid
CBNet* Create_BNet_RegularGrid(int& num_nodes, int width, int height,
int max_num_states, long& num_edges, int num_layers)
{
CGraph* pGraph = CreateGraphWithRegularGridSpecific(num_nodes,
width, height, num_layers);
CBNet* pBNet = CreateRandomBayessian(pGraph, max_num_states);
num_edges = pBNet->GetGraph()->GetNumberOfEdges();
return pBNet;
}
示例4: Create_BNet_Pyramid
CBNet* Create_BNet_Pyramid(int &num_nodes, int max_num_states,
int num_indep_nodes, int num_layers, long& num_edges)
{
CGraph* pGraph = CreateGraphWithPyramidSpecific(
num_nodes, num_indep_nodes, num_layers);
CBNet* pBNet = CreateRandomBayessian(pGraph, max_num_states);
num_edges = pBNet->GetGraph()->GetNumberOfEdges();
return pBNet;
}
示例5: Create_BNet_toyQMR
CBNet* Create_BNet_toyQMR(int num_nodes, int max_num_states,
int num_indep_nodes, int max_size_family, long& num_edges)
{
CGraph* pGraph = CreateRandomGraphWithToyQMRSpecific(
num_nodes, num_indep_nodes, max_size_family);
CBNet* pBNet = CreateRandomBayessian(pGraph, max_num_states);
num_edges = pBNet->GetGraph()->GetNumberOfEdges();
return pBNet;
}
示例6: testRandomFactors
int testRandomFactors()
{
int ret = TRS_OK;
int nnodes = 0;
int i;
while(nnodes <= 0)
{
trsiRead( &nnodes, "5", "Number of nodes in Model" );
}
//create node types
int seed1 = pnlTestRandSeed();
//create string to display the value
char *value = new char[20];
#if 0
value = _itoa(seed1, value, 10);
#else
sprintf( value, "%d", seed1 );
#endif
trsiRead(&seed1, value, "Seed for srand to define NodeTypes etc.");
delete []value;
trsWrite(TW_CON|TW_RUN|TW_DEBUG|TW_LST, "seed for rand = %d\n", seed1);
//create 2 node types and model domain for them
nodeTypeVector modelNodeType;
modelNodeType.resize(2);
modelNodeType[0] = CNodeType( 1, 4 );
modelNodeType[1] = CNodeType( 1, 3 );
intVector NodeAssociat;
NodeAssociat.assign(nnodes, 0);
for( i = 0; i < nnodes; i++ )
{
float rand = pnlRand( 0.0f, 1.0f );
if( rand < 0.5f )
{
NodeAssociat[i] = 1;
}
}
CModelDomain* pMDDiscr = CModelDomain::Create( modelNodeType,
NodeAssociat );
//create random graph - number of nodes for every node is rand too
int lowBorder = nnodes - 1;
int upperBorder = int((nnodes * (nnodes - 1))/2);
int numEdges = pnlRand( lowBorder, upperBorder );
mark:
CGraph* pGraph = tCreateRandomDAG( nnodes, numEdges, 1 );
if ( pGraph->NumberOfConnectivityComponents() != 1 )
{
delete pGraph;
goto mark;
}
CBNet* pDiscrBNet = CBNet::CreateWithRandomMatrices( pGraph, pMDDiscr );
//start jtree inference just for checking
//the model is valid for inference and all operations can be made
CEvidence* pDiscrEmptyEvid = CEvidence::Create( pMDDiscr, 0, NULL, valueVector() );
CJtreeInfEngine* pDiscrInf = CJtreeInfEngine::Create( pDiscrBNet );
pDiscrInf->EnterEvidence( pDiscrEmptyEvid );
const CPotential* pot = NULL;
for( i = 0; i < nnodes; i++ )
{
intVector domain;
pDiscrBNet->GetFactor(i)->GetDomain( &domain );
pDiscrInf->MarginalNodes( &domain.front(), domain.size() );
pot = pDiscrInf->GetQueryJPD();
}
//make copy of Graph for using with other models
pGraph = CGraph::Copy( pDiscrBNet->GetGraph() );
delete pDiscrInf;
delete pDiscrBNet;
delete pDiscrEmptyEvid;
delete pMDDiscr;
//create gaussian model domain
modelNodeType[0] = CNodeType( 0, 4 );
modelNodeType[1] = CNodeType( 0, 2 );
CModelDomain* pMDCont = CModelDomain::Create( modelNodeType,
NodeAssociat );
CBNet* pContBNet = CBNet::CreateWithRandomMatrices( pGraph, pMDCont );
CEvidence* pContEmptyEvid = CEvidence::Create( pMDCont, 0, NULL, valueVector() );
CNaiveInfEngine* pContInf = CNaiveInfEngine::Create( pContBNet );
pContInf->EnterEvidence( pContEmptyEvid );
for( i = 0; i < nnodes; i++ )
{
intVector domain;
pContBNet->GetFactor(i)->GetDomain( &domain );
pContInf->MarginalNodes( &domain.front(), domain.size() );
pot = pContInf->GetQueryJPD();
}
pGraph = CGraph::Copy(pContBNet->GetGraph());
delete pContInf;
delete pContBNet;
delete pContEmptyEvid;
delete pMDCont;
//find the node that haven't any parents
//and change its node type for it to create Conditional Gaussian CPD
int numOfNodeWithoutParents = -1;
intVector parents;
parents.reserve(nnodes);
for( i = 0; i < nnodes; i++ )
{
//.........这里部分代码省略.........
示例7: testSetStatistics
int testSetStatistics()
{
int ret = TRS_OK;
float eps = 0.1f;
int seed = pnlTestRandSeed();
pnlSeed( seed );
CBNet *pBNet = pnlExCreateCondGaussArBNet();
CModelDomain *pMD = pBNet->GetModelDomain();
CGraph *pGraph = CGraph::Copy(pBNet->GetGraph());
CBNet *pBNet1 = CBNet::CreateWithRandomMatrices( pGraph, pMD );
pEvidencesVector evidences;
int nEvidences = pnlRand( 3000, 4000);
pBNet->GenerateSamples( &evidences, nEvidences );
int i;
for( i = 0; i < nEvidences; i++)
{
//evidences[i]->MakeNodeHiddenBySerialNum(0);
}
CEMLearningEngine *pLearn = CEMLearningEngine::Create(pBNet1);
pLearn->SetData( nEvidences, &evidences.front() );
pLearn->SetMaxIterEM();
pLearn->Learn();
for( i = 0; i < pBNet->GetNumberOfFactors(); i++ )
{
if( ! pBNet->GetFactor(i)->IsFactorsDistribFunEqual(pBNet1->GetFactor(i), eps))
{
ret = TRS_FAIL;
pBNet->GetFactor(i)->GetDistribFun()->Dump();
pBNet1->GetFactor(i)->GetDistribFun()->Dump();
}
}
CDistribFun *pDistr;
const CMatrix<float>* pMat;
CFactor *pCPD;
pDistr = pBNet1->GetFactor(0)->GetDistribFun();
pMat = pDistr->GetStatisticalMatrix(stMatTable);
pCPD = pBNet->GetFactor(0);
pCPD->SetStatistics(pMat, stMatTable);
pCPD->ProcessingStatisticalData(nEvidences);
if( ! pCPD->IsFactorsDistribFunEqual(pBNet1->GetFactor(0), 0.0001f) )
{
ret = TRS_FAIL;
}
pDistr = pBNet1->GetFactor(1)->GetDistribFun();
int parentVal;
pCPD = pBNet->GetFactor(1);
parentVal = 0;
pCPD->SetStatistics(pMat, stMatCoeff);
pMat = pDistr->GetStatisticalMatrix(stMatMu, &parentVal);
pCPD->SetStatistics(pMat, stMatMu, &parentVal);
pMat = pDistr->GetStatisticalMatrix(stMatSigma, &parentVal);
pCPD->SetStatistics(pMat, stMatSigma, &parentVal);
parentVal = 1;
pMat = pDistr->GetStatisticalMatrix(stMatMu, &parentVal);
pCPD->SetStatistics(pMat, stMatMu, &parentVal);
pMat = pDistr->GetStatisticalMatrix(stMatSigma, &parentVal);
pCPD->SetStatistics(pMat, stMatSigma, &parentVal);
pCPD->ProcessingStatisticalData(nEvidences);
if( ! pCPD->IsFactorsDistribFunEqual(pBNet1->GetFactor(1), eps) )
{
ret = TRS_FAIL;
}
for( i = 0; i < nEvidences; i++)
{
delete evidences[i];
}
delete pLearn;
//.........这里部分代码省略.........
示例8: main
int main()
{
int i, j;
CBNet* pAlarm = CreateAlarmBNet();
const int nnodes = pAlarm->GetNumberOfNodes();
pAlarm->GetGraph()->Dump();
CGraph *graph = CGraph::Create( nnodes, NULL, NULL, NULL );
for(i=0; i<nnodes-1; i++)
{
graph->AddEdge(i, i+1, 1);
}
CBNet *bnet = CBNet::CreateWithRandomMatrices( graph, pAlarm->GetModelDomain() );
int nEv = 50;
CEvidence **pEvidences = new CEvidence *[nEv];
int dataSize = nnodes;//summ all sizes
int* obs_nodes = new int[nnodes];
for(i=0; i<nnodes; i++)obs_nodes[i] = i;
//read data from file alarm.dat to evidences
FILE * fp = fopen("../../examples/Data/alarm.dat", "r");
if( !fp && !(fp = fopen("../../c_pgmtk/examples/Data/alarm.dat", "r")) )
{
std::cout<<"can't open cases file"<<std::endl;
exit(1);
}
valueVector input_data;
input_data.resize(dataSize);
for(i = 0 ; i < nEv; i++)
{
for (j = 0; j < dataSize ; j++)
{
int val;
fscanf(fp, "%d,", &val);
input_data[j].SetInt(val);
}
pEvidences[i] = CEvidence::Create(pAlarm, nnodes, obs_nodes, input_data);
}
fclose(fp);
intVector vA;
intVector vD;
CMlStaticStructLearn *pLearn = CMlStaticStructLearnHC::Create(bnet, itStructLearnML,
StructLearnHC, BIC, 5, vA, vD, 1);
pLearn->SetData(nEv, pEvidences);
pLearn->Learn();
// pLearn->CreateResultBNet(const_cast<CDAG*>(pLearn->GetResultDAG()));
// const CBNet* pBNet = pLearn->GetResultBNet();
///////////////////////////////////////////////////////////////////////////////
const CDAG* pDAG = pLearn->GetResultDAG();
CDAG* iDAG = CDAG::Create(*(pAlarm->GetGraph()));
int diff = iDAG->SymmetricDifference(pDAG);
pDAG->Dump();
delete pLearn;
delete iDAG;
delete[] obs_nodes;
delete pAlarm;
delete bnet;
for( i = 0; i < nEv; i++)
{
delete pEvidences[i];
}
return 1;
}