Package cc.mallet.grmm.types

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


  }

  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

     
    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

       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

   */
  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

    mdlCurrent = m;
  }

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

  {
    // 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

  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

  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

      for (Iterator it = unrolled.unrolledVarSetIterator (); it.hasNext();) {
        ACRF.UnrolledVarSet clique = (ACRF.UnrolledVarSet) it.next();
        int tidx = clique.getTemplate().index;
        if (tidx == -1) continue;

        Factor ptl = unrolled.factorOf (clique);
        double logZ = Math.log (ptl.sum ());

        // for each assigment to the clique
        //  xxx SLOW this will need to be sparsified
        AssignmentIterator assnIt = clique.assignmentIterator ();
        int i = 0;
        while (assnIt.hasNext ()) {
          double marginal = Math.exp (ptl.logValue (assnIt) - logZ);
          expectations [tidx][i].plusEqualsSparse (clique.getFv (), marginal);
          if (defaultExpectations[tidx].location (i) != -1)
            defaultExpectations [tidx].incrementValue (i, marginal);
          assnIt.advance (); i++;
        }

        value += (ptl.logValue (observations) - logZ);
      }
      return value;
    }
View Full Code Here

TOP

Related Classes of cc.mallet.grmm.types.Factor

Copyright © 2018 www.massapicom. 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.