本文整理汇总了C++中Factor::normalize方法的典型用法代码示例。如果您正苦于以下问题:C++ Factor::normalize方法的具体用法?C++ Factor::normalize怎么用?C++ Factor::normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Factor
的用法示例。
在下文中一共展示了Factor::normalize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NewPancake
Factor LC::NewPancake (size_t i, size_t _I, bool & hasNaNs) {
size_t I = nbV(i)[_I];
Factor piet = _pancakes[i];
// recalculate _pancake[i]
VarSet Ivars = factor(I).vars();
Factor A_I;
for( VarSet::const_iterator k = Ivars.begin(); k != Ivars.end(); k++ )
if( var(i) != *k )
A_I *= (_pancakes[findVar(*k)] * factor(I).inverse()).marginal( Ivars / var(i), false );
if( Ivars.size() > 1 )
A_I ^= (1.0 / (Ivars.size() - 1));
Factor A_Ii = (_pancakes[i] * factor(I).inverse() * _phis[i][_I].inverse()).marginal( Ivars / var(i), false );
Factor quot = A_I / A_Ii;
if( props.damping != 0.0 )
quot = (quot^(1.0 - props.damping)) * (_phis[i][_I]^props.damping);
piet *= quot / _phis[i][_I].normalized();
_phis[i][_I] = quot.normalized();
piet.normalize();
if( piet.hasNaNs() ) {
cerr << name() << "::NewPancake(" << i << ", " << _I << "): has NaNs!" << endl;
hasNaNs = true;
}
return piet;
}
示例2: res
Params
BeliefProp::getFactorJoint (
FacNode* fn,
const VarIds& jointVarIds)
{
if (runned_ == false) {
runSolver();
}
Factor res (fn->factor());
const BpLinks& links = getLinks( fn);
for (size_t i = 0; i < links.size(); i++) {
Factor msg ({links[i]->varNode()->varId()},
{links[i]->varNode()->range()},
getVarToFactorMsg (links[i]));
res.multiply (msg);
}
res.sumOutAllExcept (jointVarIds);
res.reorderArguments (jointVarIds);
res.normalize();
Params jointDist = res.params();
if (Globals::logDomain) {
Util::exp (jointDist);
}
return jointDist;
}
示例3: CalcCavityDist
Real LC::CalcCavityDist (size_t i, const std::string &name, const PropertySet &opts) {
Factor Bi;
Real maxdiff = 0;
if( props.verbose >= 2 )
cerr << "Initing cavity " << var(i) << "(" << delta(i).size() << " vars, " << delta(i).nrStates() << " states)" << endl;
if( props.cavity == Properties::CavityType::UNIFORM )
Bi = Factor(delta(i));
else {
InfAlg *cav = newInfAlg( name, *this, opts );
cav->makeCavity( i );
if( props.cavity == Properties::CavityType::FULL )
Bi = calcMarginal( *cav, cav->fg().delta(i), props.reinit );
else if( props.cavity == Properties::CavityType::PAIR ) {
vector<Factor> pairbeliefs = calcPairBeliefs( *cav, cav->fg().delta(i), props.reinit, false );
for( size_t ij = 0; ij < pairbeliefs.size(); ij++ )
Bi *= pairbeliefs[ij];
} else if( props.cavity == Properties::CavityType::PAIR2 ) {
vector<Factor> pairbeliefs = calcPairBeliefs( *cav, cav->fg().delta(i), props.reinit, true );
for( size_t ij = 0; ij < pairbeliefs.size(); ij++ )
Bi *= pairbeliefs[ij];
}
maxdiff = cav->maxDiff();
delete cav;
}
Bi.normalize();
_cavitydists[i] = Bi;
return maxdiff;
}
示例4: printActiveFactors
void
VarElim::processFactorList (const VarIds& vids)
{
totalFactorSize_ = 0;
largestFactorSize_ = 0;
for (size_t i = 0; i < elimOrder_.size(); i++) {
if (Globals::verbosity >= 2) {
if (Globals::verbosity >= 3) {
Util::printDashedLine();
printActiveFactors();
}
cout << "-> summing out " ;
cout << fg.getVarNode (elimOrder_[i])->label() << endl;
}
eliminate (elimOrder_[i]);
}
Factor* finalFactor = new Factor();
for (size_t i = 0; i < factorList_.size(); i++) {
if (factorList_[i]) {
finalFactor->multiply (*factorList_[i]);
delete factorList_[i];
factorList_[i] = 0;
}
}
VarIds unobservedVids;
for (size_t i = 0; i < vids.size(); i++) {
if (fg.getVarNode (vids[i])->hasEvidence() == false) {
unobservedVids.push_back (vids[i]);
}
}
finalFactor->reorderArguments (unobservedVids);
finalFactor->normalize();
factorList_.push_back (finalFactor);
if (Globals::verbosity > 0) {
cout << "total factor size: " << totalFactorSize_ << endl;
cout << "largest factor size: " << largestFactorSize_ << endl;
cout << endl;
}
}