本文整理汇总了C++中CFactor::AttachMatrix方法的典型用法代码示例。如果您正苦于以下问题:C++ CFactor::AttachMatrix方法的具体用法?C++ CFactor::AttachMatrix怎么用?C++ CFactor::AttachMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFactor
的用法示例。
在下文中一共展示了CFactor::AttachMatrix方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
PNL_USING
//we create very small model to start inference on it
// the model is from Kevin Murphy's BNT\examples\static\belprop_polytree_gaussain
/*
Do the example from Satnam Alag's PhD thesis, UCB ME dept 1996 p46
Make the following polytree, where all arcs point down
0 1
\ /
2
/ \
3 4
*/
int i;
//create this model
int nnodes = 5;
int numnt = 2;
CNodeType *nodeTypes = new CNodeType[numnt];
nodeTypes[0] = CNodeType(0,2);
nodeTypes[1] = CNodeType(0,1);
intVector nodeAssociation = intVector(nnodes,0);
nodeAssociation[1] = 1;
nodeAssociation[3] = 1;
int nbs0[] = { 2 };
int nbs1[] = { 2 };
int nbs2[] = { 0, 1, 3, 4 };
int nbs3[] = { 2 };
int nbs4[] = { 2 };
int *nbrs[] = { nbs0, nbs1, nbs2, nbs3, nbs4 };
int numNeighb[] = {1, 1, 4, 1, 1};
ENeighborType ori0[] = { ntChild };
ENeighborType ori1[] = { ntChild };
ENeighborType ori2[] = { ntParent, ntParent, ntChild, ntChild };
ENeighborType ori3[] = { ntParent };
ENeighborType ori4[] = { ntParent };
ENeighborType *orient[] = { ori0, ori1, ori2, ori3, ori4 };
CGraph *pGraph;
pGraph = CGraph::Create(nnodes, numNeighb, nbrs, orient);
CBNet *pBNet;
pBNet = CBNet::Create( nnodes, numnt, nodeTypes, &nodeAssociation.front(), pGraph );
//Allocation space for all factors of the model
pBNet->AllocFactors();
for( i = 0; i < nnodes; i++ )
{
//Allocation space for all matrices of CPD
pBNet->AllocFactor(i);
}
//now we need to create data for CPDs - we'll create matrices
CFactor *pCPD;
floatVector smData = floatVector(2,0.0f);
floatVector bigData = floatVector(4,1.0f);
intVector ranges = intVector(2, 1);
ranges[0] = 2;
smData[0] = 1.0f;
CNumericDenseMatrix<float> *mean0 = CNumericDenseMatrix<float>::
Create( 2, &ranges.front(), &smData.front());
bigData[0] = 4.0f;
bigData[3] = 4.0f;
ranges[1] = 2;
CNumericDenseMatrix<float> *cov0 = CNumericDenseMatrix<float>::
Create( 2, &ranges.front(), &bigData.front());
pCPD = pBNet->GetFactor(0);
pCPD->AttachMatrix(mean0, matMean);
pCPD->AttachMatrix(cov0, matCovariance);
ranges[0] = 1;
ranges[1] = 1;
float val = 1.0f;
CNumericDenseMatrix<float> *mean1 = CNumericDenseMatrix<float>::
Create( 2, &ranges.front(), &val );
CNumericDenseMatrix<float> *cov1 = CNumericDenseMatrix<float>::
Create( 2, &ranges.front(), &val );
pCPD = pBNet->GetFactor(1);
pCPD->AttachMatrix(mean1, matMean);
pCPD->AttachMatrix(cov1, matCovariance);
smData[0] = 0.0f;
smData[1] = 0.0f;
ranges[0] = 2;
CNumericDenseMatrix<float> *mean2 = CNumericDenseMatrix<float>::
Create(2, &ranges.front(), &smData.front());
smData[0] = 2.0f;
smData[1] = 1.0f;
CNumericDenseMatrix<float> *w21 = CNumericDenseMatrix<float>::
Create(2, &ranges.front(), &smData.front());
bigData[0] = 2.0f;
bigData[1] = 1.0f;
bigData[2] = 1.0f;
bigData[3] = 1.0f;
//.........这里部分代码省略.........