本文整理汇总了C++中CBNet::AttachParameter方法的典型用法代码示例。如果您正苦于以下问题:C++ CBNet::AttachParameter方法的具体用法?C++ CBNet::AttachParameter怎么用?C++ CBNet::AttachParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBNet
的用法示例。
在下文中一共展示了CBNet::AttachParameter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateTwoNodeExDiscrete
CBNet* CreateTwoNodeExDiscrete(void)
{
const int numOfNds = 2;
int numOfNbrs[numOfNds] = { 1, 1 };
int nbrs0[] = { 1 };
int nbrs1[] = { 0 };
ENeighborType nbrsTypes0[] = { ntChild };
ENeighborType nbrsTypes1[] = { ntParent };
int *nbrs[] = { nbrs0, nbrs1 };
ENeighborType *nbrsTypes[] = { nbrsTypes0, nbrsTypes1 };
CGraph* pGraph = CGraph::Create( numOfNds, numOfNbrs, nbrs, nbrsTypes );
// 2) Creation of the Model Domain.
CModelDomain* pMD;
nodeTypeVector variableTypes;
int nVariableTypes = 1;
variableTypes.resize( nVariableTypes );
variableTypes[0].SetType( 1, 2 ); // discrete, 2 states
intVector variableAssociation;
int nnodes = pGraph->GetNumberOfNodes();
variableAssociation.assign(nnodes, 1);
variableAssociation[0] = 0;
variableAssociation[1] = 0;
pMD = CModelDomain::Create( variableTypes, variableAssociation );
// 2) Creation base for BNet using Graph, and Model Domain
CBNet *pBNet = CBNet::Create(pGraph, pMD);
// 3)Allocation space for all factors of the model
pBNet->AllocFactors();
int nnodes0 = 1;
int domain0[] = { 0 };
float table0[] = { 0.3f, 0.7f};
CTabularCPD *pCPD0 = CTabularCPD::Create( domain0, nnodes0, pMD, table0 );
pCPD0->AllocMatrix(table0, matTable);
pBNet->AttachParameter(pCPD0);
int nnodes1 = 2;
int domain1[] = { 0, 1 };
float table1[] = { 0.3f, 0.7f, 0.3f, 0.7f};
CTabularCPD *pCPD1 = CTabularCPD::Create( domain1, nnodes1, pMD, table1 );
pCPD1->AllocMatrix(table1, matTable);
pBNet->AttachParameter(pCPD1);
return pBNet;
}
示例2: CreateFourNodeExampleNew
CBNet* CreateFourNodeExampleNew(void)
{
CBNet *pBNet;
const int nnodes = 4;
const int numberOfNodeTypes = 2;
int numOfNeigh[] = { 1, 1, 3, 1 };
int neigh0[] = { 2 };
int neigh1[] = { 2 };
int neigh2[] = { 0, 1, 3 };
int neigh3[] = { 2 };
ENeighborType orient0[] = { ntChild };
ENeighborType orient1[] = { ntChild };
ENeighborType orient2[] = { ntParent, ntParent, ntChild };
ENeighborType orient3[] = { ntParent };
int *neigh[] = { neigh0, neigh1, neigh2, neigh3 };
ENeighborType *orient[] = { orient0, orient1, orient2, orient3 };
CGraph *pGraph = CGraph::Create( nnodes, numOfNeigh, neigh, orient );
CNodeType *nodeTypes = new CNodeType [numberOfNodeTypes];
nodeTypes[0].SetType(1, 2);
nodeTypes[1].SetType(0, 1);
int *nodeAssociation = new int[nnodes];
nodeAssociation[0]=0;
nodeAssociation[1]=1;
nodeAssociation[2]=1;
nodeAssociation[3]=1;
pBNet = CBNet::Create(nnodes, numberOfNodeTypes, nodeTypes, nodeAssociation, pGraph);
CModelDomain* pMD = pBNet->GetModelDomain();
//number of parameters is the same as number of nodes - one CPD per node
// CFactor *myParams = new CFactor[1];
int *nodeNumbers = new int [nnodes];
int domain0[] = { 0 };
int domain1[] = { 1 };
int domain2[] = { 0, 1, 2 };
int domain3[] = { 2, 3 };
int *domains[] = { domain0, domain1, domain2, domain3 };
nodeNumbers[0] = 1;
nodeNumbers[1] = 1;
nodeNumbers[2] = 3;
nodeNumbers[3] = 2;
pBNet->AllocParameters();
CFactor *myParams = CTabularCPD::Create( domains[0], nodeNumbers[0], pMD );
// data creation for all CPDs of the model
float data0[] = { 0.5f, 0.5f };
myParams->AllocMatrix(data0, matTable);
pBNet->AttachParameter(myParams);
float mean0 = 0.0f;
float cov0 = 1.0f;
CGaussianCPD* pCPD = CGaussianCPD::Create( domain1, 1, pMD );
pCPD->AllocDistribution( &mean0, &cov0, 1.0f, NULL);
pBNet->AttachFactor(pCPD);
float mean1[] = { 8.0f };
float mean2[] = { 2.0f };
float cov1[] = { 1.0f };
float cov2[] = { 1.0f };
float weight[] = { 0.01f, 0.03f };
float weight1[] = { 0.01f };
const float *pData = weight;
const float *pData1 = weight1;
CGaussianCPD* pCPD1 = CGaussianCPD::Create( domain2, 3, pMD );
int ParentCom[] = { 0, 1 };
pCPD1->AllocDistribution( mean1, cov1, 0.5f, &pData, &ParentCom[0] );
pCPD1->AllocDistribution( mean2, cov2, 0.5f, &pData, &ParentCom[1] );
pBNet->AttachFactor(pCPD1);
CGaussianCPD* pCPD2 = CGaussianCPD::Create( domain3, 2, pMD );
pCPD2->AllocDistribution( mean1, cov1, 0.5f, &pData1 );
pBNet->AttachFactor(pCPD2);
delete [] nodeTypes;
return pBNet;
}
示例3: CreateSevenNodeExDiscrete
// ----------------------------------------------------------------------------
CBNet* CreateSevenNodeExDiscrete(void)
{
// 0 1 2
// |\ \ /
// | \ \ /
// | 3
// | / \
// | 4 5
// |/
// 6
// 0, 1, 5 - continuous
// 3, 6 - softmax
// 2, 4 - discrete
const int numOfNds = 7;
int numOfNbrs[numOfNds] = { 2, 1, 1, 5, 2, 1, 2 };
int nbrs0[] = { 3, 6 };
int nbrs1[] = { 3 };
int nbrs2[] = { 3 };
int nbrs3[] = { 0, 1, 2, 4, 5 };
int nbrs4[] = { 3, 6 };
int nbrs5[] = { 3 };
int nbrs6[] = { 0, 4 };
ENeighborType nbrsTypes0[] = { ntChild, ntChild };
ENeighborType nbrsTypes1[] = { ntChild };
ENeighborType nbrsTypes2[] = { ntChild };
ENeighborType nbrsTypes3[] = { ntParent, ntParent, ntParent, ntChild, ntChild };
ENeighborType nbrsTypes4[] = { ntParent, ntChild };
ENeighborType nbrsTypes5[] = { ntParent };
ENeighborType nbrsTypes6[] = { ntParent, ntParent };
int *nbrs[] = { nbrs0, nbrs1, nbrs2, nbrs3, nbrs4, nbrs5, nbrs6 };
ENeighborType *nbrsTypes[] = { nbrsTypes0, nbrsTypes1, nbrsTypes2, nbrsTypes3, nbrsTypes4,
nbrsTypes5, nbrsTypes6
};
CGraph* pGraph = CGraph::Create( numOfNds, numOfNbrs, nbrs, nbrsTypes );
// 2) Creation of the Model Domain.
CModelDomain* pMD;
nodeTypeVector variableTypes;
int nVariableTypes = 2;
variableTypes.resize( nVariableTypes );
variableTypes[0].SetType( 0, 1 ); // continuous
variableTypes[1].SetType( 1, 2 ); // discrete, 2 states
intVector variableAssociation;
int nnodes = pGraph->GetNumberOfNodes();
variableAssociation.assign(nnodes, 1);
variableAssociation[0] = 1;
variableAssociation[1] = 1;
variableAssociation[2] = 1;
variableAssociation[3] = 1;
variableAssociation[4] = 1;
variableAssociation[5] = 1;
variableAssociation[6] = 1;
pMD = CModelDomain::Create( variableTypes, variableAssociation );
// 2) Creation base for BNet using Graph, and Model Domain
CBNet *pBNet = CBNet::Create(pGraph, pMD);
// 3)Allocation space for all factors of the model
pBNet->AllocFactors();
int nnodes0 = 1;
int domain0[] = { 0 };
float table0[] = { 0.3f, 0.7f};
CTabularCPD *pCPD0 = CTabularCPD::Create( domain0, nnodes0, pMD, table0 );
pCPD0->AllocMatrix(table0, matTable);
pBNet->AttachParameter(pCPD0);
int nnodes1 = 1;
int domain1[] = { 1 };
float table1[] = { 0.3f, 0.7f};
CTabularCPD *pCPD1 = CTabularCPD::Create( domain1, nnodes1, pMD, table1 );
pCPD1->AllocMatrix(table1, matTable);
pBNet->AttachParameter(pCPD1);
int nnodes2 = 1;
int domain2[] = { 2 };
float table2[] = { 0.3f, 0.7f};
CTabularCPD *pCPD2 = CTabularCPD::Create( domain2, nnodes2, pMD, table2 );
pCPD2->AllocMatrix(table2, matTable);
pBNet->AttachParameter(pCPD2);
int nnodes3 = 4;
int domain3[] = { 0, 1, 2, 3 };
float table3[] = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f};
CTabularCPD *pCPD3 = CTabularCPD::Create( domain3, nnodes3, pMD, table3 );
pCPD3->AllocMatrix(table3, matTable);
pBNet->AttachParameter(pCPD3);
//.........这里部分代码省略.........
示例4: CreateSevenNodeEx
// ----------------------------------------------------------------------------
CBNet* CreateSevenNodeEx(void)
{
// 0 1 2
// |\ \ /
// | \ \ /
// | 3
// | / \
// | 4 5
// |/
// 6
// 0, 1, 5 - continuous
// 3, 6 - softmax
// 2, 4 - discrete
const int numOfNds = 7;
int numOfNbrs[numOfNds] = { 2, 1, 1, 5, 2, 1, 2 };
int nbrs0[] = { 3, 6 };
int nbrs1[] = { 3 };
int nbrs2[] = { 3 };
int nbrs3[] = { 0, 1, 2, 4, 5 };
int nbrs4[] = { 3, 6 };
int nbrs5[] = { 3 };
int nbrs6[] = { 0, 4 };
ENeighborType nbrsTypes0[] = { ntChild, ntChild };
ENeighborType nbrsTypes1[] = { ntChild };
ENeighborType nbrsTypes2[] = { ntChild };
ENeighborType nbrsTypes3[] = { ntParent, ntParent, ntParent, ntChild, ntChild };
ENeighborType nbrsTypes4[] = { ntParent, ntChild };
ENeighborType nbrsTypes5[] = { ntParent };
ENeighborType nbrsTypes6[] = { ntParent, ntParent };
int *nbrs[] = { nbrs0, nbrs1, nbrs2, nbrs3, nbrs4, nbrs5, nbrs6 };
ENeighborType *nbrsTypes[] = { nbrsTypes0, nbrsTypes1, nbrsTypes2, nbrsTypes3, nbrsTypes4,
nbrsTypes5, nbrsTypes6
};
CGraph* pGraph = CGraph::Create( numOfNds, numOfNbrs, nbrs, nbrsTypes );
// 2) Creation of the Model Domain.
CModelDomain* pMD;
nodeTypeVector variableTypes;
int nVariableTypes = 2;
variableTypes.resize( nVariableTypes );
variableTypes[0].SetType( 0, 1 ); // continuous
variableTypes[1].SetType( 1, 2 ); // discrete, 2 states
intVector variableAssociation;
int nnodes = pGraph->GetNumberOfNodes();
variableAssociation.assign(nnodes, 1);
variableAssociation[0] = 0;
variableAssociation[1] = 0;
variableAssociation[2] = 1;
variableAssociation[3] = 1;
variableAssociation[4] = 1;
variableAssociation[5] = 0;
variableAssociation[6] = 1;
pMD = CModelDomain::Create( variableTypes, variableAssociation );
// 2) Creation base for BNet using Graph, and Model Domain
CBNet *pBNet = CBNet::Create(pGraph, pMD);
// 3)Allocation space for all factors of the model
pBNet->AllocFactors();
int nnodes0 = 1;
int domain0[] = { 0 };
float mean0 = 0.5f;
float cov0 = 1.0f;
CGaussianCPD *pCPD0 = CGaussianCPD::Create( domain0, nnodes0, pMD );
pCPD0->AllocDistribution( &mean0, &cov0, 1.0f, NULL );
pBNet->AttachFactor( pCPD0 );
int nnodes1 = 1;
int domain1[] = { 1 };
float mean1 = 0.5f;
float cov1 = 1.0f;
CGaussianCPD *pCPD1 = CGaussianCPD::Create( domain1, nnodes1, pMD );
pCPD1->AllocDistribution( &mean1, &cov1, 1.0f, NULL );
pBNet->AttachFactor( pCPD1 );
int nnodes2 = 1;
int domain2[] = { 2 };
float table2[] = { 0.3f, 0.7f};
CTabularCPD *pCPD2 = CTabularCPD::Create( domain2, nnodes2, pMD, table2 );
pCPD2->AllocMatrix(table2, matTable);
pBNet->AttachParameter(pCPD2);
int nnodes3 = 4;
int domain3[] = { 0, 1, 2, 3 };
CSoftMaxCPD *pCPD3 = CSoftMaxCPD::Create( domain3, nnodes3, pMD );
//.........这里部分代码省略.........