/** * Tests that parameters set by setParameters can be retrieved by * getParameters. * @param maxable Instance of a Maximizable that should be tested. * Its current parameters will be overwritten. */ public static boolean testGetSetParameters (Optimizable maxable) { System.out.println ("TestMaximizable testGetSetParameters"); // Set all the parameters to unique values using setParameters() double[] parameters = new double [maxable.getNumParameters()]; maxable.getParameters (parameters); for (int i = 0; i < parameters.length; i++) parameters[i] = (double)i; maxable.setParameters (parameters); // Test to make sure those parameters are there MatrixOps.setAll (parameters, 0.0); maxable.getParameters (parameters); for (int i = 0; i < parameters.length; i++) assertTrue (parameters[i] == (double)i); return true; }
public void testPrint() { Pipe p = new SerialPipes(new Pipe[] { new CharSequence2TokenSequence("."), new TokenText(), new TestCRFTokenSequenceRemoveSpaces(), new TokenSequence2FeatureVectorSequence(), new PrintInputAndTarget(), }); InstanceList one = new InstanceList(p); String[] data = new String[] { "ABCDE", }; one.addThruPipe(new ArrayIterator(data)); CRF crf = new CRF(p, null); crf.addFullyConnectedStatesForThreeQuarterLabels(one); CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood(crf); crf.setWeightsDimensionAsIn(one, false); Optimizable mcrf = crft.getOptimizableCRF(one); double[] params = new double[mcrf.getNumParameters()]; for (int i = 0; i < params.length; i++) { params[i] = i; } mcrf.setParameters(params); crf.print(); }
public void testPrint() { Pipe p = new SerialPipes(new Pipe[] { new CharSequence2TokenSequence("."), new TokenText(), new TestCRFTokenSequenceRemoveSpaces(), new TokenSequence2FeatureVectorSequence(), new PrintInputAndTarget(), }); InstanceList one = new InstanceList(p); String[] data = new String[] { "ABCDE", }; one.addThruPipe(new ArrayIterator(data)); CRF crf = new CRF(p, null); crf.addFullyConnectedStatesForThreeQuarterLabels(one); CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood(crf); crf.setWeightsDimensionAsIn(one, false); Optimizable mcrf = crft.getOptimizableCRF(one); double[] params = new double[mcrf.getNumParameters()]; for (int i = 0; i < params.length; i++) { params[i] = i; } mcrf.setParameters(params); crf.print(); }
/** * Tests that parameters set by setParameters can be retrieved by * getParameters. * @param maxable Instance of a Maximizable that should be tested. * Its current parameters will be overwritten. */ public static boolean testGetSetParameters (Optimizable maxable) { System.out.println ("TestMaximizable testGetSetParameters"); // Set all the parameters to unique values using setParameters() double[] parameters = new double [maxable.getNumParameters()]; maxable.getParameters (parameters); for (int i = 0; i < parameters.length; i++) parameters[i] = (double)i; maxable.setParameters (parameters); // Test to make sure those parameters are there MatrixOps.setAll (parameters, 0.0); maxable.getParameters (parameters); for (int i = 0; i < parameters.length; i++) assertTrue (parameters[i] == (double)i); return true; }