当前位置: 首页>>代码示例>>C++>>正文


C++ Factor类代码示例

本文整理汇总了C++中Factor的典型用法代码示例。如果您正苦于以下问题:C++ Factor类的具体用法?C++ Factor怎么用?C++ Factor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Factor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: var

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;
}
开发者ID:afbarnard,项目名称:libdai,代码行数:32,代码来源:lc.cpp

示例2: sendMessage

  //send the messages to all the factor nodes connected to this node
void Node::sendMessage()
{
  Link *link;
  Factor *factor;
  double cnt;
  double *msgs;
  double *outMsgs = new double[2];

  for (int lindex = 0; lindex < links_->size(); lindex++)
  {
    link = (*links_)[lindex];
    factor = link->getFactor();
    cnt = link->getCount(); (void) cnt;
      //subtract the msg recieved from this factor node
    msgs = (*msgsArr_)[lindex];
    for (int i = 0; i < 2; i++)
    {
      outMsgs[i] = msgProds_[i] - msgs[i];
    }

      //Assumes pass by value copy of the messages
    factor->receiveMessage(outMsgs, link);
  }
  delete [] outMsgs;
}
开发者ID:aduitsis,项目名称:alchemy-2,代码行数:26,代码来源:node.cpp

示例3: printActiveFactors

void
VarElim::absorveEvidence (void)
{
  if (Globals::verbosity > 2) {
    Util::printDashedLine();
    cout << "(initial factor list)" << endl;
    printActiveFactors();
  }
  const VarNodes& varNodes = fg.varNodes();
  for (size_t i = 0; i < varNodes.size(); i++) {
    if (varNodes[i]->hasEvidence()) {
      if (Globals::verbosity > 1) {
        cout << "-> aborving evidence on ";
        cout << varNodes[i]->label() << " = " ;
        cout << varNodes[i]->getEvidence() << endl;
      }
      const vector<size_t>& idxs =
          varFactors_.find (varNodes[i]->varId())->second;
      for (size_t j = 0; j < idxs.size(); j++) {
        Factor* factor = factorList_[idxs[j]];
        if (factor->nrArguments() == 1) {
          factorList_[idxs[j]] = 0;
        } else {
          factorList_[idxs[j]]->absorveEvidence (
              varNodes[i]->varId(), varNodes[i]->getEvidence());
        }
      }
    }
  }
}
开发者ID:davidvaz,项目名称:yap-cmake,代码行数:30,代码来源:VarElim.cpp

示例4: nbV

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;
}
开发者ID:afbarnard,项目名称:libdai,代码行数:29,代码来源:lc.cpp

示例5: V

// compute policy value (decomposed along different rewards)
vector<Factor> FactoredMDP::policyValueDecomp(const vector<Factor> &Pi)
{
  VarSet states = m_S_set[0] | m_Z_set[0] | m_P_set[0];
  vector<Factor> V(m_rewards.size(), Factor(states,0.0)),
    V2(m_rewards.size(), Factor(states, 0.0));

  VarSet elim_vars = allVars(m_mdp) / m_A_set;
  for (int i = 0; i < 2; i++) elim_vars /= m_S_set[i] | m_Z_set[i] | m_P_set[i];
  FactorGraph r_mdp = variableElimination(m_mdp, elim_vars);

  for (int t = m_horizon-1; t >= 0; t--) {
    if (m_verbose) cerr << "Computing policy value " << t << endl;
    for (int i = 0; i < m_rewards.size(); i++) V2[i].fill(0.0);
    for (State s(states); s.valid(); s++) {
      FactorGraph r_mdp2 = addEvidence(r_mdp, s);
      State a(m_A_set, (int)Pi[max((int)Pi.size()-m_horizon+t,0)][s]);
      
      for (int i = 0; i < m_rewards.size(); i++) {
	V2[i][s] += m_rewards[i][a(m_rewards[i].vars())+s(m_rewards[i].vars())];
      }
      
      Factor f = jointDistribution(addEvidence(r_mdp2, a));
      for (int i = 0; i < m_rewards.size(); i++) {
	V2[i][s] += (f.p() * V[i].p()).sum();
      }
    }
    for (int i = 0; i < m_rewards.size(); i++) V[i] = V2[i];
  }
  return V;
}
开发者ID:sidbatra,项目名称:factored-mdp,代码行数:31,代码来源:FactoredMDP.cpp

示例6: INFERENCE_PRINT

void GI_libDAI::copyLabels_MSRC(vector<std::size_t>& labels,
                                labelType* nodeLabels,
                                BP& bp,
                                FactorGraph& fg)
{
  labelType voidLabel = classIdxToLabel[0];
  labelType moutainLabel = classIdxToLabel[4161600];
  labelType horseLabel = classIdxToLabel[8323328];

  INFERENCE_PRINT("[gi_libDAI] copyLabels_MSRC void=%d, moutain=%d, horse=%d\n",
                  (int)voidLabel, (int)moutainLabel, (int)horseLabel);

  int label;
  int n = slice->getNbSupernodes();
  for(int sid = 0; sid < n; sid++) {
    label = labels[sid];

    //if(lossPerLabel == 0 && label > 20) // void label
    if(label == voidLabel || label == moutainLabel || label == horseLabel) {
      //Factor f = bp.beliefV(sid);
      Factor f = bp.belief(fg.var(sid));
      double maxProb = -1;
      for(int i = 0; i < (int)f.states(); i++) {
        if(i != voidLabel && i != moutainLabel && i != horseLabel)
          if(maxProb < f[i]) {
            maxProb = f[i];
            label = i;
          }
      }
      //INFERENCE_PRINT("label=%d\n", label);
    }
    nodeLabels[sid] = label;
  }
}
开发者ID:cjaques,项目名称:ilastik-ssvm,代码行数:34,代码来源:gi_libDAI.cpp

示例7: getAssignmentsForVariable

void BruteForceOptMatching::getMaxProbAssignments(
    const BP& ia, const FactorGraph& fg, const ConnectedFactorGraph& graph,
    McDArray<McVec2i>& pairs) {

    for (int i = 0; i < graph.variables.size(); i++) {

        McDArray<int> possibleAssignments;
        getAssignmentsForVariable(graph.variables[i], possibleAssignments);
        Factor belief =
            ia.belief(Var(graph.variables[i], possibleAssignments.size() + 1));
        float maxVal = -1 * FLT_MAX;
        int maxIdx = -1;

        for (int j = 0; j < possibleAssignments.size() + 1; j++) {
            if (belief.get(j) > maxVal) {
                maxVal = belief.get(j);
                maxIdx = j;
            }
        }
        int indexOfAssignmentInVertexList =
            mapVariableAssignmentToIndexInVertexList(graph.variables[i],
                                                     maxIdx);

        McVec2i pair =
            McVec2i(graph.variables[i], indexOfAssignmentInVertexList);

        pairs.append(pair);
    }
    outputSingleFactorValues(graph);

    //    std::vector<std::size_t> maxes= ia.findMaximum();
    //    vector<std::size_t>::iterator it=maxes.begin();
}
开发者ID:zibamira,项目名称:microtubulestitching,代码行数:33,代码来源:BruteForceOptMatching.cpp

示例8: getNumLinks

  //add the factors with appropriate counts, also add the node to the
  //corresponding factor
void Node::addFactors(Array<Factor *> * const & allFactors,
                      LinkIdToTwoWayMessageMap* const & lidToTWMsg)
{
  Factor *factor;
  Link *link;
  double cnt;
  ClauseCounter * counter = (ClauseCounter *)superPred_->getClauseCounter();
  int numFactors = counter->getNumClauses();
  const Array<double> * cnts;

  for (int findex = 0; findex < numFactors; findex++)
  {
    int fid = counter->getClauseId(findex);  
    cnts = counter->getClauseCounts(findex);
    factor = (*allFactors)[fid];
      //predIndex is the predicate index in the clause/factor
    for (int predIndex = 0; predIndex < cnts->size(); predIndex++)
    {
      cnt = (*cnts)[predIndex]; 
      if ((*cnts)[predIndex] == 0)
        continue;

        //index where this node would be stored in the list of factors
      int reverseNodeIndex = factor->getNumLinks();
        //index where this factor would be stored in the list of nodes
      int reverseFactorIndex = getNumLinks();

      link = new Link(this, factor, reverseNodeIndex, reverseFactorIndex,
                        predIndex, cnt);

        //now find the messages from parent nodes
      LinkId *lid;
      TwoWayMessage *tmsg;
      double *nodeToFactorMsgs, *factorToNodeMsgs;
      LinkIdToTwoWayMessageMap::iterator lidToTMsgItr;
      int parentSuperPredId = getParentSuperPredId();
      int parentSuperClauseId = factor->getParentSuperClauseId();

      lid = new LinkId(predId_, parentSuperPredId, parentSuperClauseId,
                       predIndex);
      lidToTMsgItr = lidToTWMsg->find(lid);
      delete lid;

      if (lidToTMsgItr != lidToTWMsg->end())
      {
        tmsg = lidToTMsgItr->second;
        nodeToFactorMsgs = tmsg->getNodeToFactorMessage();
        factorToNodeMsgs = tmsg->getFactorToNodeMessage();
      }
      else
      {
        nodeToFactorMsgs = NULL;
        factorToNodeMsgs = NULL;
      }
      this->addLink(link, nodeToFactorMsgs);
      factor->addLink(link,factorToNodeMsgs);
    }
  }
}
开发者ID:aduitsis,项目名称:alchemy-2,代码行数:61,代码来源:node.cpp

示例9: while

/**
 * Free all ressources.
 */
Constraint::~Constraint(void) {
	Factor *fact = facts;
	while(fact) {
		Factor *next = fact->next();
		delete fact;
		fact = next;
	}
	sys->removeConstraint(this);
}
开发者ID:t-crest,项目名称:patmos-otawa,代码行数:12,代码来源:lp_solve5.cpp

示例10: ASSERT

// Overload
double Constraint::coefficient(ilp::Var *var) const {
	ASSERT(var);
	Var *lvar = sys->getVar(var);
	ASSERT(lvar);
	for(Factor *fact = facts; fact; fact = fact->next())
		if(fact->variable() == lvar)
			return fact->coefficient();
	ASSERT(false);
}
开发者ID:alexjordan,项目名称:otawa,代码行数:10,代码来源:lp_solve_Constraint.cpp

示例11: appendFactor

/* appending a factor to a Term is a multiplication by the Factor */
void Term::appendFactor(const Factor& x) {
    Term::map_iter_t it = factors.find(x.getId());
    if (it == factors.end()) {
        // Don't use operator[] -- it requires a default constructor on Factor
        // which doesn't exist. A Factor does not have a logical default value.
        factors.insert(map<string, Factor>::value_type(x.getId(), x));
    } else {
        it->second.getPower() += x.getPower();
    }
}
开发者ID:pglass,项目名称:cpp_maths,代码行数:11,代码来源:Poly.hpp

示例12: collectSufficientStatistics

void SharedParameters::collectSufficientStatistics( InfAlg &alg ) {
    for( std::map< FactorIndex, Permute >::iterator i = _perms.begin(); i != _perms.end(); ++i ) {
        Permute &perm = i->second;
        VarSet &vs = _varsets[i->first];

        Factor b = alg.belief(vs);
        Prob p( b.states(), 0.0 );
        for( size_t entry = 0; entry < b.states(); ++entry )
            p[entry] = b[perm.convertLinearIndex(entry)]; // apply inverse permutation
        _estimation->addSufficientStatistics( p );
    }
}
开发者ID:alucchi,项目名称:structured_prediction_for_segmentation,代码行数:12,代码来源:emalg.cpp

示例13: collectExpectations

void SharedParameters::collectExpectations( InfAlg &alg ) {
    for( std::map< FactorIndex, Permute >::iterator i = _perms.begin(); i != _perms.end(); ++i ) {
        Permute &perm = i->second;
        VarSet &vs = _varsets[i->first];

        Factor b = alg.belief(vs);
        Prob p( b.nrStates(), 0.0 );
        for( size_t entry = 0; entry < b.nrStates(); ++entry )
            p.set( entry, b[perm.convertLinearIndex(entry)] ); // apply inverse permutation
        (*_expectations) += p;
    }
}
开发者ID:AndrewNguyenF3,项目名称:libdai,代码行数:12,代码来源:emalg.cpp

示例14: daiforeach

Factor MF::calcNewBelief( size_t i ) {
    Factor result;
    daiforeach( const Neighbor &I, nbV(i) ) {
        Factor henk;
        daiforeach( const Neighbor &j, nbF(I) ) // for all j in I \ i
            if( j != i )
                henk *= _beliefs[j];
        Factor piet = factor(I).log(true);
        piet *= henk;
        piet = piet.marginal(var(i), false);
        piet = piet.exp();
        result *= piet;
    }
开发者ID:alucchi,项目名称:structured_prediction_for_segmentation,代码行数:13,代码来源:mf.cpp

示例15: while

Scalar::Term::ProductOfFactors::Node* Scalar::Term::FindTermOfFactorType( Factor::Type factorType )
{
	ProductOfFactors::Node* node = productOfFactors.Head();
	while( node )
	{
		Factor* factor = node->data;
		if( factor->ReturnType() == factorType )
			break;

		node = node->Next();
	}

	return node;
}
开发者ID:mapleyustat,项目名称:GACompute,代码行数:14,代码来源:Scalar.cpp


注:本文中的Factor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。