Examples of Factor


Examples of cc.mallet.grmm.types.Factor

     */
    public void sendMessage (JunctionTree jt, VarSet from, VarSet to)
    {
//      System.err.println ("Send message "+from+" --> "+to);
      Collection sepset = jt.getSepset (from, to);
      Factor fromCpf = jt.getCPF (from);
      Factor toCpf = jt.getCPF (to);
      Factor oldSepsetPot = jt.getSepsetPot (from, to);
      Factor lambda = fromCpf.extractMax (sepset);

      lambda.normalize ();

      jt.setSepsetPot (lambda, from, to);
      toCpf = toCpf.multiply (lambda);
      toCpf.divideBy (oldSepsetPot);
      toCpf.normalize ();
View Full Code Here

Examples of cc.mallet.grmm.types.Factor

    int[] keys1 = msgs.keys1 ();
    for (int i = 0; i < keys1.length; i++) {
      int k1 = keys1[i];
      ToMsgsIterator msgIt = new ToMsgsIterator (msgs, k1);
      while (msgIt.hasNext ()) {
        Factor msg = msgIt.next ();
        int from = msgIt.currentFromIdx ();
        copy.put (k1, from, msg.duplicate ());
      }
    }
    return copy;
  }
View Full Code Here

Examples of cc.mallet.grmm.types.Factor

  }

  public void dump (PrintWriter out)
  {
    for (MessageArray.Iterator it = iterator (); it.hasNext ();) {
      Factor msg = (Factor) it.next ();
      Object from = it.from ();
      Object to = it.to ();
      out.println ("Message from " + from + " to " + to);
      out.println (msg.dumpToString ());
    }
  }
View Full Code Here

Examples of cc.mallet.grmm.types.Factor

     
    HashSet phiSet = new HashSet();     
   
    /* collect the potentials that include this variable */
    for (Iterator j = allPhi.iterator(); j.hasNext(); ) {
      Factor cpf = (Factor) j.next ();
      if (cpf.varSet().isEmpty() || cpf.containsVar (node)) {
        phiSet.add (cpf);
        j.remove ();
      }
    }

View Full Code Here

Examples of cc.mallet.grmm.types.Factor

       well. */

    /* make a copy of potentials */
    HashSet allPhi = new HashSet();
    for (Iterator i = model.factorsIterator (); i.hasNext(); ){
      Factor factor = (Factor) i.next ();
      allPhi.add(factor.duplicate());
    }

    Set nodes = model.variablesSet ();

    /* Eliminate each node in turn */
    for (Iterator i = nodes.iterator(); i.hasNext(); ) {
      Variable node = (Variable) i.next();
      if (node == query) continue; // Eliminate the query variable last!

      Factor newCPF = eliminate (allPhi, node);

      /* Extract (marginalize) over this variables */
      Factor singleCPF;
      if(newCPF.varSet().size() == 1) {
        singleCPF = newCPF;
      } else {
        singleCPF = newCPF.marginalizeOut (node);         
      }
       
      /* add it back to the list of potentials */
      allPhi.add(singleCPF);
     
    }

    /* Now, all the potentials that are left should contain only the
     * query variable.... UNLESS the graph is disconnected.  So just
     * eliminate the query var.
     */
    Factor marginal = eliminate (allPhi, query);
    assert marginal.containsVar (query);
    assert marginal.varSet().size() == 1;

    return marginal;
  }
View Full Code Here

Examples of cc.mallet.grmm.types.Factor

   */
  public double computeNormalizationFactor (FactorGraph m) {
    /* What we'll do is get the unnormalized marginal of an arbitrary
     *  node; then sum the marginal to get the normalization factor. */
    Variable var = (Variable) m.variablesSet ().iterator().next();
    Factor marginal = unnormalizedMarginal (m, var);
    return marginal.sum ();
  }
View Full Code Here

Examples of cc.mallet.grmm.types.Factor

    mdlCurrent = m;
  }

  public Factor lookupMarginal (Variable var)
  {
    Factor marginal = unnormalizedMarginal (mdlCurrent, var);
    marginal.normalize();
    return marginal;
  }
View Full Code Here

Examples of cc.mallet.grmm.types.Factor

  {
    // Send all messages in random order.
    ArrayList factors = new ArrayList (mdl.factors());
    Collections.shuffle (factors, rand);
    for (Iterator it = factors.iterator(); it.hasNext();) {
      Factor factor = (Factor) it.next();
      for (Iterator vit = factor.varSet ().iterator (); vit.hasNext ();) {
        Variable from = (Variable) vit.next ();
        sendMessage (mdl, from, factor);
      }
    }

    for (Iterator it = factors.iterator(); it.hasNext();) {
      Factor factor = (Factor) it.next();
      for (Iterator vit = factor.varSet ().iterator (); vit.hasNext ();) {
        Variable to = (Variable) vit.next ();
        sendMessage (mdl, factor, to);
      }
    }
  }
View Full Code Here

Examples of cc.mallet.grmm.types.Factor

  private void lambdaPropagation (FactorGraph mdl, Factor parent, Variable child)
  {
    logger.finer ("lambda propagation "+parent+" , "+child);
    marked.add (child);
    for (Iterator it = mdl.allFactorsContaining (child).iterator(); it.hasNext();) {
      Factor gchild = (Factor) it.next();
      if (!marked.contains (gchild)) {
        lambdaPropagation (mdl, child, gchild);
      }
    }
    if (parent != null) {
View Full Code Here

Examples of cc.mallet.grmm.types.Factor

  private void piPropagation (FactorGraph mdl, Variable var)
  {
    logger.finer ("Pi propagation from "+var);
    marked.add (var);
    for (Iterator it = mdl.allFactorsContaining (var).iterator(); it.hasNext();) {
      Factor child = (Factor) it.next();
      if (!marked.contains (child)) {
//        sendPiMessage (mdl, var, child);
        sendMessage (mdl, var, child);
        piPropagation (mdl, child);
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.