Package cc.mallet.grmm.types

Examples of cc.mallet.grmm.types.Factor


      Variable var = (Variable) it.next ();
      g.addVertex (var);
    }

    for (Iterator it = fg.factorsIterator (); it.hasNext ();) {
      Factor factor = (Factor) it.next ();
      VarSet varSet = factor.varSet ();
      int nv = varSet.size ();
      for (int i = 0; i < nv; i++) {
        for (int j = i + 1; j < nv; j++) {
          g.addEdge (varSet.get (i), varSet.get (j));
        }
View Full Code Here


    // check no exceptions thrown when asking for all marginals,
    //  and check that at least one factors' belief has changed
    //  from the choice at zero iterations.
    for (Iterator it = grid.factorsIterator (); it.hasNext();) {
      Factor f = (Factor) it.next ();
      Factor marg = trp.lookupMarginal (f.varSet ());// test no exception thrown
      if (!marg.almostEquals (f.duplicate ().normalize ())) {
        oneIsDifferent = true;
      }
    }

    assertTrue (oneIsDifferent);
View Full Code Here

  public RegionGraph constructRegionGraph (FactorGraph mdl)
  {
    RegionGraph rg = new RegionGraph ();
    for (Iterator it = mdl.factorsIterator (); it.hasNext();) {
      Factor ptl = (Factor) it.next ();
      if (ptl.varSet ().size() == 1) continue// Single-node potentials handled separately

      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) {
          parent.addFactor (childPtl);
View Full Code Here

  public FactorizedRegion (List factors)
  {
    super (varsForFactors (factors), factors);
    subMdl = new FactorGraph ((Variable[]) vars.toArray (new Variable[0]));
    for (Iterator it = factors.iterator (); it.hasNext ();) {
      Factor factor = (Factor) it.next ();
      subMdl.addFactor (factor);
    }
  }
View Full Code Here

  private static Collection varsForFactors (List factors)
  {
    Set vars = new THashSet ();
    for (Iterator it = factors.iterator (); it.hasNext ();) {
      Factor ptl = (Factor) it.next ();
      vars.addAll (ptl.varSet ());
    }
    return vars;
  }
View Full Code Here

          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);
View Full Code Here

    }
  }

  private Region createVarRegion (RegionGraph rg, FactorGraph mdl, Variable v1)
  {
    Factor ptl = mdl.factorOf (v1);
    if (ptl == null) {
      return rg.findRegion (v1, true);
    } else {
      return rg.findRegion (ptl, true);
    }
View Full Code Here

    return newMessages;
  }

  Factor msgProduct (RegionEdge edge)
  {
    Factor product = new LogTableFactor (edge.from.vars);

    for (Iterator it = edge.neighboringParents.iterator (); it.hasNext ();) {
      RegionEdge otherEdge = (RegionEdge) it.next ();
      Factor otherMsg = oldMessages.getMessage (otherEdge.from, otherEdge.to);

      product.multiplyBy (otherMsg);
    }

    for (Iterator it = edge.loopingMessages.iterator (); it.hasNext ();) {
      RegionEdge otherEdge = (RegionEdge) it.next ();
      Factor otherMsg = newMessages.getMessage (otherEdge.from, otherEdge.to);
      product.divideBy (otherMsg);
    }

    return product;
  }
View Full Code Here

     * underflow.
     */
    public void sendMessage (JunctionTree jt, VarSet from, VarSet 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.marginalize (sepset);

      lambda.normalize ();

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

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

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.