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


Java Inferencer.lookupMarginal方法代码示例

本文整理汇总了Java中cc.mallet.grmm.inference.Inferencer.lookupMarginal方法的典型用法代码示例。如果您正苦于以下问题:Java Inferencer.lookupMarginal方法的具体用法?Java Inferencer.lookupMarginal怎么用?Java Inferencer.lookupMarginal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cc.mallet.grmm.inference.Inferencer的用法示例。


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

示例1: testBadVariable

import cc.mallet.grmm.inference.Inferencer; //导入方法依赖的package包/类
public void testBadVariable ()
{
  FactorGraph fg = createBoltzmannChain (5);
  Assignment assn = fg.sampleContinuousVars (new Randoms (23423));
  FactorGraph sliced = (FactorGraph) fg.slice (assn);
  Inferencer bp = new TRP ();
  bp.computeMarginals (sliced);

  try {
    bp.lookupMarginal (new Variable (2));
    fail ("Expected exception");
  } catch (IllegalArgumentException e) {
    // expected
    System.out.println ("OK: As expected, got exception "+e);
  }
}
 
开发者ID:mimno,项目名称:GRMM,代码行数:17,代码来源:TestAbstractBeliefPropagation.java

示例2: main

import cc.mallet.grmm.inference.Inferencer; //导入方法依赖的package包/类
public static void main (String[] args)
{

  // STEP 1: Create the graph

  Variable[] allVars = {
    new Variable (2),
    new Variable (2),
    new Variable (2),
    new Variable (2)
  };

  FactorGraph mdl = new FactorGraph (allVars);

  // Create a diamond graph, with random potentials
  Random r = new Random (42);
  for (int i = 0; i < allVars.length; i++) {
    double[] ptlarr = new double [4];
    for (int j = 0; j < ptlarr.length; j++)
      ptlarr[j] = Math.abs (r.nextDouble ());

    Variable v1 = allVars[i];
    Variable v2 = allVars[(i + 1) % allVars.length];
    mdl.addFactor (v1, v2, ptlarr);
  }

  // STEP 2: Compute marginals

  Inferencer inf = new JunctionTreeInferencer ();
  inf.computeMarginals (mdl);

  // STEP 3: Collect the results
  //   We'll just print them out

  for (int varnum = 0; varnum < allVars.length; varnum++) {
    Variable var = allVars[varnum];
    Factor ptl = inf.lookupMarginal (var);
    for (AssignmentIterator it = ptl.assignmentIterator (); it.hasNext (); it.advance()) {
      int outcome = it.indexOfCurrentAssn ();
      System.out.println (var+"  "+outcome+"   "+ptl.value (it));
    }
    System.out.println ();
  }

}
 
开发者ID:mimno,项目名称:GRMM,代码行数:46,代码来源:SimpleGraphExample.java

示例3: addWrongWrong

import cc.mallet.grmm.inference.Inferencer; //导入方法依赖的package包/类
private void addWrongWrong (InstanceList training)
    {
      allWrongWrongs = new List [training.size ()];
      int totalAdded = 0;

//      if (!acrf.isCacheUnrolledGraphs ()) {
//        throw new IllegalStateException ("Wrong-wrong won't work without caching unrolled graphs.");
//      }

      for (int i = 0; i < training.size (); i++) {
        allWrongWrongs[i] = new ArrayList ();
        int numAdded = 0;

        Instance instance = training.get (i);
        ACRF.UnrolledGraph unrolled = acrf.unroll (instance);
        if (unrolled.factors ().size () == 0) {
          System.err.println ("WARNING: FactorGraph for instance " + instance.getName () + " : no factors.");
          continue;
        }

        Inferencer inf = acrf.getInferencer ();
        inf.computeMarginals (unrolled);

        Assignment target = unrolled.getAssignment ();
        for (Iterator it = unrolled.unrolledVarSetIterator (); it.hasNext ();) {
          ACRF.UnrolledVarSet vs = (ACRF.UnrolledVarSet) it.next ();
          Factor marg = inf.lookupMarginal (vs);
          for (AssignmentIterator assnIt = vs.assignmentIterator (); assnIt.hasNext (); assnIt.advance ()) {
            if (marg.value (assnIt) > wrongWrongThreshold) {
              Assignment assn = assnIt.assignment ();
              for (int vi = 0; vi < vs.size (); vi++) {
                Variable var = vs.get (vi);
                if (isWrong2RightAssn (target, assn, var)) {
                  int assnIdx = assn.singleIndex ();
//                  System.out.println ("Computing for WW: "+vs+" idx "+assnIdx+" target "+var);
                  allWrongWrongs[i].add (new WrongWrong (unrolled, vs, var, assnIdx));
                  numAdded++;
                }
              }
            }
          }

        }

        logger.info ("WrongWrongs: Instance " + i + " : " + instance.getName () + " Num added = " + numAdded);
        totalAdded += numAdded;
      }

      resetConstraints ();
      collectConstraints (training);
      forceStale ();

      logger.info ("Total timesteps = " + totalTimesteps (training));
      logger.info ("Total WrongWrongs = " + totalAdded);
    }
 
开发者ID:mimno,项目名称:GRMM,代码行数:56,代码来源:PwplACRFTrainer.java

示例4: main

import cc.mallet.grmm.inference.Inferencer; //导入方法依赖的package包/类
public static void main (String[] args)
{

  // STEP 1: Create the graph

  Variable[] allVars = {
    new Variable (2),
    new Variable (2),
    new Variable (2),
    new Variable (2)
  };

  FactorGraph mdl = new FactorGraph (allVars);

  // Create a diamond graph, with random potentials
  Random r = new Random (42);
  for (int i = 0; i < allVars.length; i++) {
    double[] ptlarr = new double [4];
    for (int j = 0; j < ptlarr.length; j++)
      ptlarr[j] = Math.abs (r.nextDouble ());

    Variable v1 = allVars[i];
    Variable v2 = allVars[(i + 1) % allVars.length];
    mdl.addFactor (v1, v2, ptlarr);
  }

  // STEP 2: Compute marginals

  Inferencer inf = new JunctionTreeInferencer ();
  inf.computeMarginals (mdl);

  // STEP 3: Collect the results
  //   We'll just print them out

  for (int varnum = 0; varnum < allVars.length; varnum++) {
    Variable var = allVars[varnum];
    Factor ptl = inf.lookupMarginal (var);
    for (AssignmentIterator it = ptl.assignmentIterator (); it.hasNext ();) {
      int outcome = it.indexOfCurrentAssn ();
      System.out.println (var+"  "+outcome+"   "+ptl.value (it));
    }
    System.out.println ();
  }

}
 
开发者ID:shalomeir,项目名称:tctm,代码行数:46,代码来源:SimpleGraphExample.java


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