CCPD* CMlStaticStructLearn::CreateRandomCPD(int nfamily, const int* family, CGraphicalModel* pGrModel) { CModelDomain* pMD = pGrModel->GetModelDomain(); EDistributionType dt = pnlDetermineDistributionType( pMD, nfamily, family, NULL); CCPD* pCPD; int i; int j; // checking SoftMax distribution for( i = 0; i < nfamily; i++ ) { if( (!pMD->GetVariableType(family[i])->IsDiscrete()) && pMD->GetVariableType(family[nfamily-1])->IsDiscrete() ) { for( j = 0; j < nfamily-1; j++ ) if(pMD->GetVariableType(family[j])->IsDiscrete()) { dt = dtCondSoftMax; break; }; dt = dtSoftMax; break; } } // end of checking switch (dt) { case dtTabular : pCPD = CTabularCPD::Create(family, nfamily, pMD); pCPD->CreateAllNecessaryMatrices(1); break; case dtTree : pCPD = CTreeCPD::Create(family, nfamily, pMD); break; case dtGaussian : case dtCondGaussian : pCPD = CGaussianCPD::Create(family, nfamily, pMD); pCPD->CreateAllNecessaryMatrices(1); break; case dtSoftMax: case dtCondSoftMax: pCPD = CSoftMaxCPD::Create(family, nfamily, pMD); pCPD->CreateAllNecessaryMatrices(1); break; default: PNL_THROW(CNotImplemented, "This type of distribution has not been implemented yet"); break; } return pCPD; }
CCPD* CStaticStructLearnSEM::CreateRandomCPD(int nfamily, const int* family, CBNet* pBNet) { int child = family[nfamily-1]; CModelDomain* pMD = pBNet->GetModelDomain(); CFactor* factor = pBNet->GetFactor(child); EDistributionType dt = factor->GetDistributionType(); CCPD* pCPD; if( dt == dtTabular ) { pCPD = CTabularCPD::Create(family, nfamily, pMD); pCPD->CreateAllNecessaryMatrices(1); return pCPD; } else { if( dt == dtMixGaussian ) { floatVector data; static_cast<CMixtureGaussianCPD*>(factor)->GetProbabilities(&data); pCPD = CMixtureGaussianCPD::Create(family, nfamily, pMD, &data.front()); static_cast<CCondGaussianDistribFun*>(pCPD->GetDistribFun()) -> CreateDefaultMatrices(1); return pCPD; } else { if( (dt == dtGaussian) || (dt == dtCondGaussian) ) { pCPD = CGaussianCPD::Create(family, nfamily, pMD); pCPD->CreateAllNecessaryMatrices(1); return pCPD; } else PNL_THROW(CNotImplemented, "this type of distribution is not supported yet"); } } }