public static void main(String[] args) { TestMEMM tm = new TestMEMM (""); tm.doTestSpacePrediction (true); return; /* TestSuite theSuite; if (args.length > 0) { theSuite = new TestSuite(); for (int i = 0; i < args.length; i++) { theSuite.addTest (new TestMEMM (args [i])); } } else { theSuite = (TestSuite) suite(); } junit.textui.TestRunner.run (theSuite); */ }
public void disabledtestAddOrderNStates () Pipe p = makeSpacePredictionPipe (); double lik1 = getLikelihood (memmt1, lists[0]); double lik2 = getLikelihood (memmt2, lists[0]); double lik3 = getLikelihood (memmt3, lists[0]); assertTrue ("Final zero-order likelihood <"+lik1+"> greater than first-order <"+lik2+">", lik1 < lik2); assertTrue ("Final defaults-only likelihood <"+lik2+"> greater than full first-order <"+lik3+">", lik2 < lik3); assertEquals (-167.335971702, lik1, 0.0001); assertEquals (-166.212235389, lik2, 0.0001); assertEquals ( -90.386005741, lik3, 0.0001);
boolean useSparseWeights) Pipe p = makeSpacePredictionPipe (); System.out.println("Testing Accuracy after saving = " + postTestAcc); assertEquals(postTrainAcc, preTrainAcc, 0.0001); assertEquals(postTestAcc, preTestAcc, 0.0001);
public void disabledtestDenseTrain () { doTestSpacePrediction (false, false, false); }
public void testSpaceViewer () throws FileNotFoundException { Pipe pipe = TestMEMM.makeSpacePredictionPipe (); String[] data0 = { TestCRF.data[0] }; String[] data1 = { TestCRF.data[1] }; InstanceList training = new InstanceList (pipe); training.addThruPipe (new ArrayIterator (data0)); InstanceList testing = new InstanceList (pipe); testing.addThruPipe (new ArrayIterator (data1)); CRF crf = new CRF (pipe, null); crf.addFullyConnectedStatesForLabels (); CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood (crf); crft.trainIncremental (training); CRFExtractor extor = hackCrfExtor (crf); Extraction extration = extor.extract (new ArrayIterator (data1)); PrintStream out = new PrintStream (new FileOutputStream (htmlFile)); LatticeViewer.extraction2html (extration, extor, out); out.close(); out = new PrintStream (new FileOutputStream (latticeFile)); LatticeViewer.extraction2html (extration, extor, out, true); out.close(); }
+ " minGrad=" + minimizableGradientNorm); assertEquals (true, Math.abs (minimizableCost - 35770) < 0.001); assertEquals (true, Math.abs (minimizableGradientNorm - 520) < 0.001);
public void disabledtestAddOrderNStates () Pipe p = makeSpacePredictionPipe (); double lik1 = getLikelihood (memmt1, lists[0]); double lik2 = getLikelihood (memmt2, lists[0]); double lik3 = getLikelihood (memmt3, lists[0]); assertTrue ("Final zero-order likelihood <"+lik1+"> greater than first-order <"+lik2+">", lik1 < lik2); assertTrue ("Final defaults-only likelihood <"+lik2+"> greater than full first-order <"+lik3+">", lik2 < lik3); assertEquals (-167.335971702, lik1, 0.0001); assertEquals (-166.212235389, lik2, 0.0001); assertEquals ( -90.386005741, lik3, 0.0001);
boolean useSparseWeights) Pipe p = makeSpacePredictionPipe (); System.out.println("Testing Accuracy after saving = " + postTestAcc); assertEquals(postTrainAcc, preTrainAcc, 0.0001); assertEquals(postTestAcc, preTestAcc, 0.0001);
public void disabledtestValueGradient() { doTestSpacePrediction(true); }
public void testSpaceViewer () throws FileNotFoundException { Pipe pipe = TestMEMM.makeSpacePredictionPipe (); String[] data0 = { TestCRF.data[0] }; String[] data1 = { TestCRF.data[1] }; InstanceList training = new InstanceList (pipe); training.addThruPipe (new ArrayIterator (data0)); InstanceList testing = new InstanceList (pipe); testing.addThruPipe (new ArrayIterator (data1)); CRF crf = new CRF (pipe, null); crf.addFullyConnectedStatesForLabels (); CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood (crf); crft.trainIncremental (training); CRFExtractor extor = hackCrfExtor (crf); Extraction extration = extor.extract (new ArrayIterator (data1)); PrintStream out = new PrintStream (new FileOutputStream (htmlFile)); LatticeViewer.extraction2html (extration, extor, out); out.close(); out = new PrintStream (new FileOutputStream (latticeFile)); LatticeViewer.extraction2html (extration, extor, out, true); out.close(); }
+ " minGrad=" + minimizableGradientNorm); assertEquals (true, Math.abs (minimizableCost - 35770) < 0.001); assertEquals (true, Math.abs (minimizableGradientNorm - 520) < 0.001);
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 disabledtestSerialization() { doTestSpacePrediction(false, true, true); }
public void doTestSpacePrediction(boolean testValueAndGradient) Pipe p = makeSpacePredictionPipe (); Pipe p2 = new TestMEMM2String();
public static void main(String[] args) { TestMEMM tm = new TestMEMM (""); tm.doTestSpacePrediction (true); return; /* TestSuite theSuite; if (args.length > 0) { theSuite = new TestSuite(); for (int i = 0; i < args.length; i++) { theSuite.addTest (new TestMEMM (args [i])); } } else { theSuite = (TestSuite) suite(); } junit.textui.TestRunner.run (theSuite); */ }
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 disabledtestDenseTrain () { doTestSpacePrediction (false, false, false); }
public void doTestSpacePrediction(boolean testValueAndGradient) Pipe p = makeSpacePredictionPipe (); Pipe p2 = new TestMEMM2String();
public void disabledtestSerialization() { doTestSpacePrediction(false, true, true); }
public void testSpaceViewer () throws IOException { Pipe pipe = TestMEMM.makeSpacePredictionPipe (); String[] data0 = { TestCRF.data[0] }; String[] data1 = { TestCRF.data[1] }; InstanceList training = new InstanceList (pipe); training.addThruPipe (new ArrayIterator (data0)); InstanceList testing = new InstanceList (pipe); testing.addThruPipe (new ArrayIterator (data1)); CRF crf = new CRF (pipe, null); crf.addFullyConnectedStatesForLabels (); CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood (crf); crft.trainIncremental (training); CRFExtractor extor = TestLatticeViewer.hackCrfExtor (crf); Extraction extraction = extor.extract (new ArrayIterator (data1)); if (!outputDir.exists ()) outputDir.mkdir (); DocumentViewer.writeExtraction (outputDir, extraction); }