本文整理汇总了C++中CFactor::GetModelDomain方法的典型用法代码示例。如果您正苦于以下问题:C++ CFactor::GetModelDomain方法的具体用法?C++ CFactor::GetModelDomain怎么用?C++ CFactor::GetModelDomain使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFactor
的用法示例。
在下文中一共展示了CFactor::GetModelDomain方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _LearnPotentials
float CMlLearningEngine::_LearnPotentials()
{
int iteration = 1;
float log_lik = 0.0f;
CStaticGraphicalModel *grmodel = this->GetStaticModel();
CFactor *parameter = NULL;
float epsilon = m_precisionIPF;
const CPotential *joint_prob = NULL;
CPotential *clique_jpd = NULL;
CMatrix<float> *itogMatrix;
CInfEngine *m_pInfEngine =
CNaiveInfEngine::Create(grmodel);
intVector obsNodes(0);
valueVector obsValues(0);
CEvidence *emptyEvidence = CEvidence::Create(grmodel->GetModelDomain(), obsNodes, obsValues);
m_pInfEngine -> EnterEvidence( emptyEvidence );
int querySize = grmodel->GetNumberOfNodes();
int *query;
query = new int [querySize];
int i;
for( i = 0; i < querySize; i++ )
{
query[i] = i;
}
m_pInfEngine -> MarginalNodes( query, querySize );
joint_prob = m_pInfEngine->GetQueryJPD();
CPotential *itog_joint_prob =
static_cast<CPotential *>(joint_prob ->Marginalize(query, querySize));
int DomainSize;
const int *domain;
potsPVector learn_factors;
CPotential *tmp_factor;
for (i = 0; i < grmodel -> GetNumberOfFactors(); i++)
{
factor = grmodel -> GetFactor(i);
factor -> GetDomain( &DomainSize, &domain );
CDistribFun *correspData= factor -> GetDistribFun();
CMatrix<float> *learnMatrix = correspData ->
GetStatisticalMatrix(stMatTable);
CPotential *factor = CTabularPotential::Create( domain, DomainSize,
parameter->GetModelDomain());
learn_factors.push_back(factor);
learn_factors[i] -> AttachMatrix(learnMatrix->NormalizeAll(), matTable);
}
int data_length;
float *old_itog_data = NULL;
const float *itog_data;
delete [] query;
int convergence = 0;
while( !convergence && (iteration <= m_maxIterIPF))
{
iteration++;
itogMatrix = (itog_joint_prob->GetDistribFun())
-> GetMatrix(matTable);
static_cast<CNumericDenseMatrix<float>*>(itogMatrix)->
GetRawData(&data_length, &itog_data);
old_itog_data = new float[data_length];
for( i = 0; i < data_length; i++)
{
old_itog_data[i] = itog_data[i];
}
for( int clique = 0; clique < grmodel->GetNumberOfFactors(); clique++)
{
factor = grmodel -> GetFactor(clique);
factor -> GetDomain( &DomainSize, &domain );
clique_jpd = static_cast<CPotential *>
(itog_joint_prob -> Marginalize( domain, DomainSize ));
tmp_factor = itog_joint_prob -> Multiply(learn_factors[clique]);
delete (itog_joint_prob);
itog_joint_prob = tmp_factor;
tmp_factor = itog_joint_prob -> Divide(clique_jpd);
delete (itog_joint_prob);
delete (clique_jpd);
itog_joint_prob = tmp_factor;
}
itogMatrix = (itog_joint_prob->GetDistribFun())
-> GetMatrix(matTable);
static_cast<CNumericDenseMatrix<float>*>(itogMatrix)->
GetRawData(&data_length, &itog_data);
convergence = true;
for (int j = 0; j < data_length; j++)
{
if( fabs( itog_data[j] - old_itog_data[j] ) > epsilon)
{
//.........这里部分代码省略.........