Package cc.mallet.grmm.types

Examples of cc.mallet.grmm.types.Variable


  public static UndirectedGraph mdlToGraph (FactorGraph fg)
  {
    UndirectedGraph g = new SimpleGraph ();

    for (Iterator it = fg.variablesIterator (); it.hasNext ();) {
      Variable var = (Variable) it.next ();
      g.addVertex (var);
    }

    for (Iterator it = fg.factorsIterator (); it.hasNext ();) {
      Factor factor = (Factor) it.next ();
View Full Code Here


      Region parent = new Region (ptl);

      // Now add appropriate edges to region graph
      for (Iterator childIt = ptl.varSet().iterator (); childIt.hasNext();) {
        Variable var = (Variable) childIt.next ();
        Factor childPtl = mdl.factorOf (var);
        Region child = rg.findRegion (childPtl, true);

        //add node potential to parent if necessary
        if (childPtl != null) {
View Full Code Here

          // Create region for 4-clique
          Region fourSquare = new Region (vars, edges);

          // Create 1-clique region
          for (int i = 0; i < 4; i++) {
            Variable var = vars[i];
            Factor ptl = mdl.factorOf (var);
            if (ptl != null) {
              fourSquare.factors.add (ptl);
            }
          }

          // Finally create edge regions, and connect to everyone else
          for (int i = 0; i < 4; i++) {
            Factor edgePtl = edges[i];
            Region edgeRgn = rg.findRegion (edgePtl, true);
            rg.add (fourSquare, edgeRgn);

            Variable v1 = (Variable) edgeRgn.vars.get (0);
            Region nodeRgn = createVarRegion (rg, mdl, v1);
            edgeRgn.factors.addAll (nodeRgn.factors);
            rg.add (edgeRgn, nodeRgn);

            Variable v2 = (Variable) edgeRgn.vars.get (1);
            nodeRgn = createVarRegion (rg, mdl, v2);
            edgeRgn.factors.addAll (nodeRgn.factors);

            rg.add (edgeRgn, nodeRgn);
          }
View Full Code Here

  {
    // No display of factors
    StringBuffer buf = new StringBuffer ();
    buf.append ("REGION[");
    for (Iterator it = vars.iterator (); it.hasNext ();) {
      Variable var = (Variable) it.next ();
      buf.append (var);
      if (it.hasNext ())
        buf.append (" ");
    }
    buf.append ("] nf:");
View Full Code Here

        for (int j = i + 1; j < N; j++) {

          TokenInfo info1 = (TokenInfo) infoList.get (i);
          TokenInfo info2 = (TokenInfo) infoList.get (j);

          Variable v1 = lblseq.varOfIndex (info1.pos, factor);
          Variable v2 = lblseq.varOfIndex (info2.pos, factor);

          if (excludeAdjacent && (Math.abs(info1.pos - info2.pos) <= 1)) continue;

          Variable[] vars = new Variable[]{v1, v2};
          assert v1 != null : "Couldn't get label factor " + factor + " time " + i;
View Full Code Here

    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 */
 
View Full Code Here

   * Computes the normalization constant for a model.
   */
  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

    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

    for (int t = 0; t < lblseq.size (); t++) {
      Labels lbls = lblseq.getLabels (t);
      idx2var[t] = new Variable [lbls.size ()];
      for (int j = 0; j < lbls.size (); j++) {
        Label lbl = lbls.get (j);
        Variable var = new Variable (lbl.getLabelAlphabet ());
        var.setLabel ("I"+id+"_VAR[f=" + j + "][tm=" + t + "]");
        idx2var[t][j] = var;
        var2label.put (var, lbl);
      }
    }
  }
View Full Code Here

    int maxTime = maxTime ();
    Labels[] lbls = new Labels [maxTime];
    for (int t = 0; t < maxTime; t++) {
      Label[] theseLabels = new Label [numFactors];
      for (int i = 0; i < numFactors; i++) {
        Variable var = varOfIndex (t, i);
        int maxidx;

        if (var != null) {
          maxidx = assn.get (var);
        } else {
View Full Code Here

TOP

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

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.