ACRF.UnrolledGraph unrolled = new ACRF.UnrolledGraph (instance, templates, fixedTmpls); long unrollEnd = System.currentTimeMillis (); unrollTime += (unrollEnd - unrollStart); if (unrolled.numVariables () == 0) continue; // Happens if all nodes are pruned. Assignment observations = unrolled.getAssignment (); double value = collectExpectationsAndValue (unrolled, observations);
graph.addClique (clique); numSkip++;
public EdgesIterator (ACRF.UnrolledGraph acrf, Assignment observed) { this.graph = acrf; this.observed = observed; cliquesByEdge = new THashMap(); for (Iterator it = acrf.unrolledVarSetIterator (); it.hasNext();) { ACRF.UnrolledVarSet clique = (ACRF.UnrolledVarSet) it.next (); for (int v1idx = 0; v1idx < clique.size(); v1idx++) { Variable v1 = clique.get(v1idx); List adjlist = graph.allFactorsContaining (v1); for (Iterator factorIt = adjlist.iterator(); factorIt.hasNext();) { Factor factor = (Factor) factorIt.next (); if (!cliquesByEdge.containsKey (factor)) { cliquesByEdge.put (factor, new ArrayList()); } List l = (List) cliquesByEdge.get (factor); if (!l.contains (clique)) { l.add (clique); } } } } cursor = cliquesByEdge.keySet().iterator (); }
if (unrolled.factors ().size () == 0) { System.err.println ("WARNING: FactorGraph for instance " + instance.getName () + " : no factors."); continue; 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);
if (unrolled.factors ().size () == 0) { System.err.println ("WARNING: FactorGraph for instance " + instance.getName () + " : no factors."); continue; 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);
if (unrolled.factors ().size () == 0) { System.err.println ("WARNING: FactorGraph for instance " + instance.getName () + " : no factors."); continue; 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 (Iterator it = currentCliqueList.iterator (); it.hasNext();) { ACRF.UnrolledVarSet clique = (ACRF.UnrolledVarSet) it.next (); Factor cliquePtl = graph.factorOf (clique); if (cliquePtl == null) throw new IllegalStateException
for (Iterator it = currentCliqueList.iterator (); it.hasNext();) { ACRF.UnrolledVarSet clique = (ACRF.UnrolledVarSet) it.next (); Factor cliquePtl = graph.factorOf (clique); if (cliquePtl == null) throw new IllegalStateException
for (Iterator it = currentCliqueList.iterator (); it.hasNext();) { ACRF.UnrolledVarSet clique = (ACRF.UnrolledVarSet) it.next (); Factor cliquePtl = graph.factorOf (clique); if (cliquePtl == null) throw new IllegalStateException
graph.addClique (clique); numSkip++;
graph.addClique (clique); numSkip++;
for (Iterator it = unrolled.unrolledVarSetIterator (); it.hasNext();) { ACRF.UnrolledVarSet clique = (ACRF.UnrolledVarSet) it.next(); int tidx = clique.getTemplate().index; if (tidx == -1) continue; Factor ptl = unrolled.factorOf (clique); double logZ = Math.log (ptl.sum ());
for (Iterator it = unrolled.unrolledVarSetIterator (); it.hasNext();) { ACRF.UnrolledVarSet clique = (ACRF.UnrolledVarSet) it.next(); int tidx = clique.getTemplate().index; if (tidx == -1) continue; Factor ptl = unrolled.factorOf (clique); double logZ = Math.log (ptl.sum ());
for (Iterator it = unrolled.unrolledVarSetIterator (); it.hasNext();) { ACRF.UnrolledVarSet clique = (ACRF.UnrolledVarSet) it.next(); int tidx = clique.getTemplate().index; if (tidx == -1) continue; Factor ptl = unrolled.factorOf (clique); double logZ = Math.log (ptl.sum ());
PwplACRFTrainer.logger.finest ("*** Collecting constraints for instance " + inum); Instance inst = ilist.get (inum); ACRF.UnrolledGraph unrolled = new ACRF.UnrolledGraph (inst, templates, null, false); for (Iterator it = unrolled.unrolledVarSetIterator (); it.hasNext ();) { ACRF.UnrolledVarSet clique = (ACRF.UnrolledVarSet) it.next (); int tidx = clique.getTemplate ().index;
PwplACRFTrainer.logger.finest ("*** Collecting constraints for instance " + inum); Instance inst = ilist.get (inum); ACRF.UnrolledGraph unrolled = new ACRF.UnrolledGraph (inst, templates, null, false); for (Iterator it = unrolled.unrolledVarSetIterator (); it.hasNext ();) { ACRF.UnrolledVarSet clique = (ACRF.UnrolledVarSet) it.next (); int tidx = clique.getTemplate ().index;
PwplACRFTrainer.logger.finest ("*** Collecting constraints for instance " + inum); Instance inst = ilist.get (inum); ACRF.UnrolledGraph unrolled = new ACRF.UnrolledGraph (inst, templates, null, false); for (Iterator it = unrolled.unrolledVarSetIterator (); it.hasNext ();) { ACRF.UnrolledVarSet clique = (ACRF.UnrolledVarSet) it.next (); int tidx = clique.getTemplate ().index;
private void checkCliqueSizeConsistent (InstanceList training) { int weight = -1; for (int i = 0; i < training.size(); i++) { Instance instance = training.get (i); UnrolledGraph unrolled = new UnrolledGraph (instance, new Template[] { this }, null, false); for (Iterator it = unrolled.unrolledVarSetIterator (); it.hasNext();) { UnrolledVarSet clique = (UnrolledVarSet) it.next (); if (clique.tmpl == this) { if (weight != clique.weight ()) { System.err.println ("Weight change for clique "+clique+" template "+this+" old = "+weight+" new "+clique.weight ()); for (int vi = 0; vi < clique.size(); vi++) { Variable var = clique.get(vi); System.err.println (var+"\t"+var.getNumOutcomes()); } if (weight == -1) { weight = clique.weight (); } else { throw new IllegalStateException ("Error on instance "+instance+": Template "+this+" clique "+clique+" error. Strange weight: was "+weight+" now is "+clique.weight()); } } } } } } private void addInCurrentWeights (BitSet[] weightsPresent)
private void checkCliqueSizeConsistent (InstanceList training) { int weight = -1; for (int i = 0; i < training.size(); i++) { Instance instance = training.get (i); UnrolledGraph unrolled = new UnrolledGraph (instance, new Template[] { this }, null, false); for (Iterator it = unrolled.unrolledVarSetIterator (); it.hasNext();) { UnrolledVarSet clique = (UnrolledVarSet) it.next (); if (clique.tmpl == this) { if (weight != clique.weight ()) { System.err.println ("Weight change for clique "+clique+" template "+this+" old = "+weight+" new "+clique.weight ()); for (int vi = 0; vi < clique.size(); vi++) { Variable var = clique.get(vi); System.err.println (var+"\t"+var.getNumOutcomes()); } if (weight == -1) { weight = clique.weight (); } else { throw new IllegalStateException ("Error on instance "+instance+": Template "+this+" clique "+clique+" error. Strange weight: was "+weight+" now is "+clique.weight()); } } } } } } private void addInCurrentWeights (BitSet[] weightsPresent)
private void checkCliqueSizeConsistent (InstanceList training) { int weight = -1; for (int i = 0; i < training.size(); i++) { Instance instance = training.get (i); UnrolledGraph unrolled = new UnrolledGraph (instance, new Template[] { this }, null, false); for (Iterator it = unrolled.unrolledVarSetIterator (); it.hasNext();) { UnrolledVarSet clique = (UnrolledVarSet) it.next (); if (clique.tmpl == this) { if (weight != clique.weight ()) { System.err.println ("Weight change for clique "+clique+" template "+this+" old = "+weight+" new "+clique.weight ()); for (int vi = 0; vi < clique.size(); vi++) { Variable var = clique.get(vi); System.err.println (var+"\t"+var.getNumOutcomes()); } if (weight == -1) { weight = clique.weight (); } else { throw new IllegalStateException ("Error on instance "+instance+": Template "+this+" clique "+clique+" error. Strange weight: was "+weight+" now is "+clique.weight()); } } } } } } private void addInCurrentWeights (BitSet[] weightsPresent)