/** \param N number of variables * \param M number of factors * \param k number of variables that each factor depends on * \param beta standard-deviation of Gaussian log-factor entries */ FactorGraph createHOIFG( size_t N, size_t M, size_t k, Real beta ) { vector<Var> vars; vector<Factor> factors; vars.reserve(N); for( size_t i = 0; i < N; i++ ) vars.push_back(Var(i,2)); for( size_t I = 0; I < M; I++ ) { VarSet vars; while( vars.size() < k ) { do { size_t newind = (size_t)(N * rnd_uniform()); Var newvar = Var(newind, 2); if( !vars.contains( newvar ) ) { vars |= newvar; break; } } while( 1 ); } factors.push_back( createFactorExpGauss( vars, beta ) ); } return FactorGraph( factors.begin(), factors.end(), vars.begin(), vars.end(), factors.size(), vars.size() ); }
CFactorGraph CompressInterface::createCFactorGraph() { createVarClustering(); createFacClustering(); // create lifted fg here vector<CFactor> superFacs; // clusterIdx => facIdx for (map<size_t,size_t>::iterator facIter = _facRepr.begin(); facIter != _facRepr.end(); facIter++) { VarSet superVarSet; foreach (const dai::BipartiteGraph::Neighbor &tmpVar, _cfg.nbF(facIter->second)) { Var varCluster = _varRepr[_varColorVec[tmpVar]]; if (!superVarSet.contains(varCluster)) { superVarSet |= Var(varCluster); } } CFactor superFac = CFactor(superVarSet, _cfg.factor(facIter->second).p()); superFac.sigma() = _cfg.factor(facIter->second).sigma(); superFac.position() = _cfg.factor(facIter->second).position(); superFac.counts() = createCounts(facIter->second, superVarSet); superFacs.push_back(superFac); } return CFactorGraph(superFacs); }
void MakeHOIFG( size_t N, size_t M, size_t k, Real sigma, FactorGraph &fg ) { vector<Var> vars; vector<Factor> factors; vars.reserve(N); for( size_t i = 0; i < N; i++ ) vars.push_back(Var(i,2)); for( size_t I = 0; I < M; I++ ) { VarSet vars; while( vars.size() < k ) { do { size_t newind = (size_t)(N * rnd_uniform()); Var newvar = Var(newind, 2); if( !vars.contains( newvar ) ) { vars |= newvar; break; } } while( 1 ); } factors.push_back( RandomFactor( vars, sigma ) ); } fg = FactorGraph( factors.begin(), factors.end(), vars.begin(), vars.end(), factors.size(), vars.size() ); }
void findLoopClusters( const FactorGraph & fg, std::set<VarSet> &allcl, VarSet newcl, const Var & root, size_t length, VarSet vars ) { for( VarSet::const_iterator in = vars.begin(); in != vars.end(); in++ ) { VarSet ind = fg.delta( *in ); if( (newcl.size()) >= 2 && ind.contains( root ) ) { allcl.insert( newcl | *in ); } else if( length > 1 ) findLoopClusters( fg, allcl, newcl | *in, root, length - 1, ind / newcl ); } }