本文整理汇总了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);
}
}
示例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 ();
}
}
示例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);
}
示例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 ();
}
}