本文整理汇总了Java中cc.mallet.grmm.types.Variable类的典型用法代码示例。如果您正苦于以下问题:Java Variable类的具体用法?Java Variable怎么用?Java Variable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Variable类属于cc.mallet.grmm.types包,在下文中一共展示了Variable类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: lookupMarginal
import cc.mallet.grmm.types.Variable; //导入依赖的package包/类
public Factor lookupMarginal (JunctionTree jt, Variable var)
{
if (jt == null) { throw new IllegalStateException ("Call computeMarginals() first."); }
VarSet parent = jt.findParentCluster (var);
Factor cpf = jt.getCPF (parent);
if (logger.isLoggable (Level.FINER)) {
logger.finer ("Lookup jt marginal: var " + var + " cluster " + parent);
logger.finest (" cpf " + cpf);
}
Factor marginal = strategy.extractBelief (cpf, new HashVarSet (new Variable[] { var }));
marginal.normalize ();
return marginal;
}
示例2: computeBaseRegions
import cc.mallet.grmm.types.Variable; //导入依赖的package包/类
public List computeBaseRegions (FactorGraph mdl)
{
List regions = new ArrayList ();
UndirectedGrid grid = (UndirectedGrid) mdl;
for (int x = 0; x < grid.getWidth() - 1; x++) {
for (int y = 0; y < grid.getHeight() - 1; y++) {
Variable[] vars = new Variable[] {
grid.get (x, y),
grid.get (x, y+1),
grid.get (x+1, y+1),
grid.get (x+1, y),
};
regions.add (new Region (vars, new Factor[0]));
}
}
addAllFactors (mdl, regions);
return regions;
}
示例3: mdlToGraph
import cc.mallet.grmm.types.Variable; //导入依赖的package包/类
/**
* Converts a FactorGraph into a plain graph where each Variable is a vertex,
* and two Variables are connected by an edge if they are arguments to the same factor.
* (Essentially converts an fg into an MRF structure, minus the factors.)
* @param fg
* @return a Graph
*/
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 ();
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));
}
}
}
return g;
}
示例4: setupLabel2Var
import cc.mallet.grmm.types.Variable; //导入依赖的package包/类
private void setupLabel2Var ()
{
idx2var = new Variable [lblseq.size ()][];
var2label = new THashMap ();
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);
}
}
}
示例5: toLabelsSequence
import cc.mallet.grmm.types.Variable; //导入依赖的package包/类
public LabelsSequence toLabelsSequence (Assignment assn)
{
int numFactors = numSlices ();
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 {
maxidx = 0;
}
LabelAlphabet dict = labelOfVar (var).getLabelAlphabet ();
theseLabels[i] = dict.lookupLabel (maxidx);
}
lbls[t] = new Labels (theseLabels);
}
return new LabelsSequence (lbls);
}
示例6: testInitialAssignment
import cc.mallet.grmm.types.Variable; //导入依赖的package包/类
public void testInitialAssignment ()
{
Variable[] vars = new Variable[] { new Variable (3), new Variable (3), new Variable (3) };
Variable[] vars1 = new Variable[]{ vars[0], vars[1] };
double[] vals1 = new double[] { 0, 0.2, 0.8, 0, 0.7, 0.3, 0, 0.5, 0.5 };
Factor tbl1 = new TableFactor (vars1, vals1);
Variable[] vars2 = new Variable[]{ vars[1], vars[2] };
double[] vals2 = new double[] { 0.2, 0.2, 0.8, 0.7, 0, 0.7, 0.3, 0, 0.5 };
Factor tbl2 = new TableFactor (vars2, vals2);
FactorGraph fg = new FactorGraph ();
fg.multiplyBy (tbl1);
fg.multiplyBy (tbl2);
System.out.println (fg.dumpToString ());
GibbsSampler gs = new GibbsSampler (new Randoms (324123), 10);
gs.sample (fg, 10); // assert no exception
}
示例7: mdlToGraph
import cc.mallet.grmm.types.Variable; //导入依赖的package包/类
/**
* Converts a FactorGraph into a plain graph where each Variable is a vertex,
* and two Variables are connected by an edge if they are arguments to the same factor.
* (Essentially converts an fg into an MRF structure, minus the factors.)
* @param fg
* @return a Graph
*/
public static UndirectedGraph mdlToGraph (FactorGraph fg)
{
UndirectedGraph g = new SimpleGraph(DefaultEdge.class);
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 ();
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));
}
}
}
return g;
}
示例8: setupLabel2Var
import cc.mallet.grmm.types.Variable; //导入依赖的package包/类
private void setupLabel2Var ()
{
idx2var = new Variable [lblseq.size ()][];
var2label = new THashMap();
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);
}
}
}
示例9: setupLabel2Var
import cc.mallet.grmm.types.Variable; //导入依赖的package包/类
private void setupLabel2Var ()
{
idx2var = new Variable [lblseq.size ()][];
var2label = new HashMap();
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);
}
}
}