/** Returns the log probability of the training sequence labels and the prior over parameters. */ public double getValue () { if (crf.weightsValueChangeStamp != cachedValueWeightsStamp) { // The cached value is not up to date; it was calculated for a different set of CRF weights. long startingTime = System.currentTimeMillis(); cachedValue = 0; for (int i = 0; i < opts.length; i++) cachedValue += opts[i].getValue(); cachedValueWeightsStamp = crf.weightsValueChangeStamp; // cachedValue is now no longer stale logger.info ("getValue() (loglikelihood) = "+cachedValue); logger.fine ("Inference milliseconds = "+(System.currentTimeMillis() - startingTime)); } return cachedValue; }
/** Returns the log probability of the training sequence labels and the prior over parameters. */ public double getValue () { if (crf.weightsValueChangeStamp != cachedValueWeightsStamp) { // The cached value is not up to date; it was calculated for a different set of CRF weights. long startingTime = System.currentTimeMillis(); cachedValue = 0; for (int i = 0; i < opts.length; i++) cachedValue += opts[i].getValue(); cachedValueWeightsStamp = crf.weightsValueChangeStamp; // cachedValue is now no longer stale logger.info ("getValue() (loglikelihood) = "+cachedValue); logger.fine ("Inference milliseconds = "+(System.currentTimeMillis() - startingTime)); } return cachedValue; }
/** Returns the log probability of the training sequence labels and the prior over parameters. */ public double getValue () { if (crf.weightsValueChangeStamp != cachedValueWeightsStamp) { // The cached value is not up to date; it was calculated for a different set of CRF weights. long startingTime = System.currentTimeMillis(); cachedValue = 0; for (int i = 0; i < opts.length; i++) cachedValue += opts[i].getValue(); cachedValueWeightsStamp = crf.weightsValueChangeStamp; // cachedValue is now no longer stale logger.info ("getValue() (loglikelihood) = "+cachedValue); logger.fine ("Inference milliseconds = "+(System.currentTimeMillis() - startingTime)); } return cachedValue; }
public void testStartState() { Pipe p = new SerialPipes(new Pipe[] { new LineGroupString2TokenSequence(), new TokenSequenceMatchDataAndTarget(Pattern .compile("^(\\S+) (.*)"), 2, 1), new TokenSequenceParseFeatureString(false), new TokenText(), new TokenSequence2FeatureVectorSequence(true, false), new Target2LabelSequence(), new PrintInputAndTarget(), }); InstanceList data = new InstanceList(p); data.addThruPipe(new LineGroupIterator(new StringReader(toy), Pattern .compile("\n"), true)); CRF crf = new CRF(p, null); crf.print(); crf.addStatesForLabelsConnectedAsIn(data); crf.addStartState(); CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood(crf); Optimizable.ByGradientValue maxable = crft.getOptimizableCRF(data); assertEquals(-1.3862, maxable.getValue(), 1e-4); crf = new CRF(p, null); crf .addOrderNStates(data, new int[] { 1 }, null, "A", null, null, false); crf.print(); crft = new CRFTrainerByLabelLikelihood(crf); maxable = crft.getOptimizableCRF(data); assertEquals(-3.09104245335831, maxable.getValue(), 1e-4); }
public void testStartState() { Pipe p = new SerialPipes(new Pipe[] { new LineGroupString2TokenSequence(), new TokenSequenceMatchDataAndTarget(Pattern .compile("^(\\S+) (.*)"), 2, 1), new TokenSequenceParseFeatureString(false), new TokenText(), new TokenSequence2FeatureVectorSequence(true, false), new Target2LabelSequence(), new PrintInputAndTarget(), }); InstanceList data = new InstanceList(p); data.addThruPipe(new LineGroupIterator(new StringReader(toy), Pattern .compile("\n"), true)); CRF crf = new CRF(p, null); crf.print(); crf.addStatesForLabelsConnectedAsIn(data); crf.addStartState(); CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood(crf); Optimizable.ByGradientValue maxable = crft.getOptimizableCRF(data); assertEquals(-1.3862, maxable.getValue(), 1e-4); crf = new CRF(p, null); crf .addOrderNStates(data, new int[] { 1 }, null, "A", null, null, false); crf.print(); crft = new CRFTrainerByLabelLikelihood(crf); maxable = crft.getOptimizableCRF(data); assertEquals(-3.09104245335831, maxable.getValue(), 1e-4); }
public void testSpaceSerializable () throws IOException, ClassNotFoundException { Pipe p = makeSpacePredictionPipe (); InstanceList training = new InstanceList (p); training.addThruPipe (new ArrayIterator (data)); MEMM memm = new MEMM (p, null); memm.addFullyConnectedStatesForLabels (); memm.addStartState(); memm.setWeightsDimensionAsIn(training); MEMMTrainer memmt = new MEMMTrainer (memm); memmt.train (training, 10); MEMM memm2 = (MEMM) TestSerializable.cloneViaSerialization (memm); Optimizable.ByGradientValue mcrf1 = memmt.getOptimizableMEMM(training); double val1 = mcrf1.getValue (); Optimizable.ByGradientValue mcrf2 = memmt.getOptimizableMEMM(training); double val2 = mcrf2.getValue (); assertEquals (val1, val2, 1e-5); }
public void testSpaceSerializable () throws IOException, ClassNotFoundException { Pipe p = makeSpacePredictionPipe (); InstanceList training = new InstanceList (p); training.addThruPipe (new ArrayIterator (data)); MEMM memm = new MEMM (p, null); memm.addFullyConnectedStatesForLabels (); memm.addStartState(); memm.setWeightsDimensionAsIn(training); MEMMTrainer memmt = new MEMMTrainer (memm); memmt.train (training, 10); MEMM memm2 = (MEMM) TestSerializable.cloneViaSerialization (memm); Optimizable.ByGradientValue mcrf1 = memmt.getOptimizableMEMM(training); double val1 = mcrf1.getValue (); Optimizable.ByGradientValue mcrf2 = memmt.getOptimizableMEMM(training); double val2 = mcrf2.getValue (); assertEquals (val1, val2, 1e-5); }
/** * Evaluate value. Make it a minimization problem. */ private double evalL1() { double val = -optimizable.getValue(); double sumAbsWt = 0; if (l1Weight > 0) { for (double param : parameters) { if (Double.isInfinite(param)) continue; sumAbsWt += Math.abs(param) * l1Weight; } } logger.info("getValue() (" + optName + ".getValue() = " + val + " + |w|=" + sumAbsWt + ") = " + (val + sumAbsWt)); return val + sumAbsWt; }
/** * Evaluate value. Make it a minimization problem. */ private double evalL1() { double val = -optimizable.getValue(); double sumAbsWt = 0; if (l1Weight > 0) { for (double param : parameters) { if (Double.isInfinite(param)) continue; sumAbsWt += Math.abs(param) * l1Weight; } } logger.info("getValue() (" + optName + ".getValue() = " + val + " + |w|=" + sumAbsWt + ") = " + (val + sumAbsWt)); return val + sumAbsWt; }
/** * Evaluate value. Make it a minimization problem. */ private double evalL1() { double val = -optimizable.getValue(); double sumAbsWt = 0; if (l1Weight > 0) { for (double param : parameters) { if (Double.isInfinite(param)) continue; sumAbsWt += Math.abs(param) * l1Weight; } } logger.info("getValue() (" + optName + ".getValue() = " + val + " + |w|=" + sumAbsWt + ") = " + (val + sumAbsWt)); return val + sumAbsWt; }
double getLikelihood (MEMMTrainer memmt, InstanceList data) { Optimizable.ByGradientValue mcrf = memmt.getOptimizableMEMM(data); // Do this elaborate thing so that crf.cachedValueStale is forced true double[] params = new double [mcrf.getNumParameters()]; mcrf.getParameters (params); mcrf.setParameters (params); return mcrf.getValue (); }
public double getValue () { double ret = 0; for (Optimizable.ByGradientValue o : optimizables) ret += o.getValue(); return ret; }
double getLikelihood(CRF crf, InstanceList data) { CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood(crf); Optimizable.ByGradientValue mcrf = crft.getOptimizableCRF(data); // Do this elaborate thing so that crf.cachedValueStale is forced true double[] params = new double[mcrf.getNumParameters()]; mcrf.getParameters(params); mcrf.setParameters(params); return mcrf.getValue(); }
/** Returns the log probability of the training sequence labels and the prior over parameters. */ public double getValue () { if (crf.weightsValueChangeStamp != cachedValueWeightsStamp) { // The cached value is not up to date; it was calculated for a different set of CRF weights. cachedValue = 0; for (int i = 0; i < optimizables.length; i++) cachedValue += optimizables[i].getValue(); cachedValueWeightsStamp = crf.weightsValueChangeStamp; // cachedValue is now no longer stale logger.info ("getValue() = "+cachedValue); } return cachedValue; }
double getLikelihood (MEMMTrainer memmt, InstanceList data) { Optimizable.ByGradientValue mcrf = memmt.getOptimizableMEMM(data); // Do this elaborate thing so that crf.cachedValueStale is forced true double[] params = new double [mcrf.getNumParameters()]; mcrf.getParameters (params); mcrf.setParameters (params); return mcrf.getValue (); }
public double getValue () { double ret = 0; for (Optimizable.ByGradientValue o : optimizables) ret += o.getValue(); return ret; }
double getLikelihood(CRF crf, InstanceList data) { CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood(crf); Optimizable.ByGradientValue mcrf = crft.getOptimizableCRF(data); // Do this elaborate thing so that crf.cachedValueStale is forced true double[] params = new double[mcrf.getNumParameters()]; mcrf.getParameters(params); mcrf.setParameters(params); return mcrf.getValue(); }
/** Returns the log probability of the training sequence labels and the prior over parameters. */ public double getValue () { if (crf.weightsValueChangeStamp != cachedValueWeightsStamp) { // The cached value is not up to date; it was calculated for a different set of CRF weights. cachedValue = 0; for (int i = 0; i < optimizables.length; i++) cachedValue += optimizables[i].getValue(); cachedValueWeightsStamp = crf.weightsValueChangeStamp; // cachedValue is now no longer stale logger.info ("getValue() = "+cachedValue); } return cachedValue; }
public double getValue () { double ret = 0; for (Optimizable.ByGradientValue o : optimizables) ret += o.getValue(); return ret; }
/** Returns the log probability of the training sequence labels and the prior over parameters. */ public double getValue () { if (crf.weightsValueChangeStamp != cachedValueWeightsStamp) { // The cached value is not up to date; it was calculated for a different set of CRF weights. cachedValue = 0; for (int i = 0; i < optimizables.length; i++) cachedValue += optimizables[i].getValue(); cachedValueWeightsStamp = crf.weightsValueChangeStamp; // cachedValue is now no longer stale logger.info ("getValue() = "+cachedValue); } return cachedValue; }