protected MaximizableACRF (InstanceList ilist) { logger.finest ("Initializing MaximizableACRF."); /* allocate for weights, constraints and expectations */ this.trainData = ilist; initWeights(trainData); initConstraintsExpectations(); int numInstances = trainData.size(); cachedGradient = new double[numParameters]; cachedValueStale = cachedGradientStale = true; /* if (cacheUnrolledGraphs) { unrolledGraphs = new UnrolledGraph [numInstances]; } */ logger.info("Number of training instances = " + numInstances ); logger.info("Number of parameters = " + numParameters ); logger.info("Default feature index = " + defaultFeatureIndex ); describePrior(); logger.fine("Computing constraints"); collectConstraints (trainData); }
/** * Computes the graident of the penalized log likelihood * of the ACRF, and returns it in buf[]. */ public void getValueGradient(double[] buf) { if (cachedGradientStale) { /* This will fill in the expectations */ if (cachedValueStale) getValue (); computeGradient (); cachedGradientStale = false; } if (buf.length != numParameters) throw new IllegalArgumentException ("Incorrect length buffer to getValueGradient(). Expected " + numParameters + ", received " + buf.length); System.arraycopy (cachedGradient, 0, buf, 0, cachedGradient.length); }
/** Returns the log probability of the training sequence labels */ public double getValue () { if (cachedValueStale) { cachedValue = computeLogLikelihood (); cachedValueStale = false; cachedGradientStale = true; /* if(saveNum++ % savePeriod == 0) { System.out.println ("saving ACRF ..."); ACRF.this.writeWeights(weightFile); System.out.println ("Done ...."); } */ logger.info ("getValue() (loglikelihood) = " + cachedValue); } if(Double.isNaN(cachedValue)) { logger.warning("value is NaN"); cachedValue = 0; } return cachedValue; }
resetExpectations(); collectExpectations (unrolled, inferencer); printDebugInfo (unrolled); for (int fnum = 0; fnum < weights[j].numLocations(); fnum++) { double w = weights [j].valueAtLocation (fnum); if (weightValid (w, tidx, j)) { retval += -w*w/priorDenom;
resetExpectations(); collectExpectations (unrolled, inferencer); printDebugInfo (unrolled); for (int fnum = 0; fnum < weights[j].numLocations(); fnum++) { double w = weights [j].valueAtLocation (fnum); if (weightValid (w, tidx, j)) { retval += -w*w/priorDenom;
resetExpectations(); collectExpectations (unrolled, inferencer); printDebugInfo (unrolled); for (int fnum = 0; fnum < weights[j].numLocations(); fnum++) { double w = weights [j].valueAtLocation (fnum); if (weightValid (w, tidx, j)) { retval += -w*w/priorDenom;
long stime = System.currentTimeMillis (); int numNodes = (macrf instanceof ACRF.MaximizableACRF) ? ((ACRF.MaximizableACRF) macrf).getTotalNodes () : 0; double thresh = 1e-5 * numNodes; // "early" stopping (reasonably conservative) ((MaximizableACRF) macrf).report ();
long stime = System.currentTimeMillis (); int numNodes = (macrf instanceof ACRF.MaximizableACRF) ? ((ACRF.MaximizableACRF) macrf).getTotalNodes () : 0; double thresh = 1e-5 * numNodes; // "early" stopping (reasonably conservative) ((MaximizableACRF) macrf).report ();
long stime = System.currentTimeMillis (); int numNodes = (macrf instanceof ACRF.MaximizableACRF) ? ((ACRF.MaximizableACRF) macrf).getTotalNodes () : 0; double thresh = 1e-5 * numNodes; // "early" stopping (reasonably conservative) ((MaximizableACRF) macrf).report ();
writer.close (); double[] buf = new double [getNumParameters()]; getParameters (buf); printVecs (thisFile, defaultConstraints, constraints); thisFile = new File (verboseOutputDirectory, "acrf-exp-"+gradCallNo+".txt"); printVecs (thisFile, defaultExpectations, expectations);
writer.close (); double[] buf = new double [getNumParameters()]; getParameters (buf); printVecs (thisFile, defaultConstraints, constraints); thisFile = new File (verboseOutputDirectory, "acrf-exp-"+gradCallNo+".txt"); printVecs (thisFile, defaultExpectations, expectations);
writer.close (); double[] buf = new double [getNumParameters()]; getParameters (buf); printVecs (thisFile, defaultConstraints, constraints); thisFile = new File (verboseOutputDirectory, "acrf-exp-"+gradCallNo+".txt"); printVecs (thisFile, defaultExpectations, expectations);
/** Returns the log probability of the training sequence labels */ public double getValue () { if (cachedValueStale) { cachedValue = computeLogLikelihood (); cachedValueStale = false; cachedGradientStale = true; /* if(saveNum++ % savePeriod == 0) { System.out.println ("saving ACRF ..."); ACRF.this.writeWeights(weightFile); System.out.println ("Done ...."); } */ logger.info ("getValue() (loglikelihood) = " + cachedValue); } if(Double.isNaN(cachedValue)) { logger.warning("value is NaN"); cachedValue = 0; } return cachedValue; }
protected MaximizableACRF (InstanceList ilist) { logger.finest ("Initializing MaximizableACRF."); /* allocate for weights, constraints and expectations */ this.trainData = ilist; initWeights(trainData); initConstraintsExpectations(); int numInstances = trainData.size(); cachedGradient = new double[numParameters]; cachedValueStale = cachedGradientStale = true; /* if (cacheUnrolledGraphs) { unrolledGraphs = new UnrolledGraph [numInstances]; } */ logger.info("Number of training instances = " + numInstances ); logger.info("Number of parameters = " + numParameters ); logger.info("Default feature index = " + defaultFeatureIndex ); describePrior(); logger.fine("Computing constraints"); collectConstraints (trainData); }
/** Returns the log probability of the training sequence labels */ public double getValue () { if (cachedValueStale) { cachedValue = computeLogLikelihood (); cachedValueStale = false; cachedGradientStale = true; /* if(saveNum++ % savePeriod == 0) { System.out.println ("saving ACRF ..."); ACRF.this.writeWeights(weightFile); System.out.println ("Done ...."); } */ logger.info ("getValue() (loglikelihood) = " + cachedValue); } if(Double.isNaN(cachedValue)) { logger.warning("value is NaN"); cachedValue = 0; } return cachedValue; }
protected MaximizableACRF (InstanceList ilist) { logger.finest ("Initializing MaximizableACRF."); /* allocate for weights, constraints and expectations */ this.trainData = ilist; initWeights(trainData); initConstraintsExpectations(); int numInstances = trainData.size(); cachedGradient = new double[numParameters]; cachedValueStale = cachedGradientStale = true; /* if (cacheUnrolledGraphs) { unrolledGraphs = new UnrolledGraph [numInstances]; } */ logger.info("Number of training instances = " + numInstances ); logger.info("Number of parameters = " + numParameters ); logger.info("Default feature index = " + defaultFeatureIndex ); describePrior(); logger.fine("Computing constraints"); collectConstraints (trainData); }
/** * Computes the graident of the penalized log likelihood * of the ACRF, and returns it in buf[]. */ public void getValueGradient(double[] buf) { if (cachedGradientStale) { /* This will fill in the expectations */ if (cachedValueStale) getValue (); computeGradient (); cachedGradientStale = false; } if (buf.length != numParameters) throw new IllegalArgumentException ("Incorrect length buffer to getValueGradient(). Expected " + numParameters + ", received " + buf.length); System.arraycopy (cachedGradient, 0, buf, 0, cachedGradient.length); }
/** * Computes the graident of the penalized log likelihood * of the ACRF, and returns it in buf[]. */ public void getValueGradient(double[] buf) { if (cachedGradientStale) { /* This will fill in the expectations */ if (cachedValueStale) getValue (); computeGradient (); cachedGradientStale = false; } if (buf.length != numParameters) throw new IllegalArgumentException ("Incorrect length buffer to getValueGradient(). Expected " + numParameters + ", received " + buf.length); System.arraycopy (cachedGradient, 0, buf, 0, cachedGradient.length); }
public Optimizable.ByGradientValue getMaximizable (InstanceList ilst) { return new MaximizableACRF (ilst); }
void printDebugInfo (UnrolledGraph unrolled) { print (System.err); Assignment assn = unrolled.getAssignment (); for (Iterator it = unrolled.unrolledVarSetIterator (); it.hasNext();) { UnrolledVarSet clique = (UnrolledVarSet) it.next(); System.out.println("Clique "+clique); dumpAssnForClique (assn, clique); Factor ptl = unrolled.factorOf (clique); System.out.println("Value = "+ptl.value (assn)); System.out.println(ptl); } }