protected void checkLearnerProgressRecording(String fsmString, String name,final String [][] plus, final String [][] minus)
{
Configuration testConfig = Configuration.getDefaultConfiguration().copy();
testConfig.setGdFailOnDuplicateNames(false);
final DirectedSparseGraph expectedGraph = TestFSMAlgo.buildGraph(fsmString, "sample FSM");
final FSMStructure expected = new FSMStructure(expectedGraph,testConfig);
// now sanity checking on the plus and minus sets
for(String [] path:plus)
assert RPNIBlueFringeLearner.USER_ACCEPTED == WMethod.tracePath(expected,Arrays.asList(path));
for(String [] path:minus)
assert RPNIBlueFringeLearner.USER_ACCEPTED != WMethod.tracePath(expected,Arrays.asList(path));
RPNIBlueFringeLearnerTestComponentOpt l = new RPNIBlueFringeLearnerTestComponentOpt(null)
{
@Override
public int checkWithEndUser(
@SuppressWarnings("unused") DirectedSparseGraph model,
List<String> question,
@SuppressWarnings("unused") final Object [] moreOptions)
{
return WMethod.tracePath(new FSMStructure(model,null),question);
}
};
testConfig.setLearnerIdMode(IDMode.POSITIVE_NEGATIVE);
ByteArrayOutputStream logStream = new ByteArrayOutputStream();
RecordProgressDecorator recorder = new RecordProgressDecorator(l.getLearner(),logStream,1,testConfig,useZip);
Collection<List<String>> testSet = new LinkedList<List<String>>();
recorder.writeLearnerEvaluationData(new ProgressDecorator.LearnerEvaluationConfiguration(expectedGraph, testSet, testConfig, null));
DirectedSparseGraph learntStructureA = recorder.learnMachine(buildSet(plus), buildSet(minus));
//System.out.println("compression rate: "+recorder.getCompressionRate());
//System.out.println(logStream.toString()+"============");
//System.out.println(logStream.toByteArray().length);
// At this point, we do not really care whether we learnt the right machine - all that matters is
// we've got a log we can replay.
//FSMStructure learntMachineNoRejects = Transform322.removeRejectStates(new FSMStructure(learntStructureA,testConfig),testConfig);
//TestFSMAlgo.checkM(learntMachineNoRejects, expected);
switch(kind)
{
case RECORDERTEST_SS:
{// matching two simulators
final LearnerSimulator
simulator = new LearnerSimulator(new ByteArrayInputStream(logStream.toByteArray()),useZip),
simulator2 = new LearnerSimulator(new ByteArrayInputStream(logStream.toByteArray()),useZip);
LearnerEvaluationConfiguration eval1 = simulator.readLearnerConstructionData();
TestFSMAlgo.checkM(expected, new FSMStructure(eval1.graph,null));
Assert.assertEquals(testSet, eval1.testSet);
LearnerEvaluationConfiguration eval2 = simulator2.readLearnerConstructionData();
TestFSMAlgo.checkM(expected, new FSMStructure(eval2.graph,null));
Assert.assertEquals(testSet, eval2.testSet);
new Test_LearnerComparator(simulator,simulator2,false).learnMachine(buildSet(plus), buildSet(minus));
break;
}
case RECORDERTEST_SL:
{// now a simulator to a learner
final LearnerSimulator simulator = new LearnerSimulator(new ByteArrayInputStream(logStream.toByteArray()),useZip);
LearnerEvaluationConfiguration eval1 = simulator.readLearnerConstructionData();
TestFSMAlgo.checkM(expected, new FSMStructure(eval1.graph,null));
Assert.assertEquals(testSet, eval1.testSet);
RPNIBlueFringeLearnerTestComponentOpt learner2 = new RPNIBlueFringeLearnerTestComponentOpt(null)
{
@Override
public int checkWithEndUser(
@SuppressWarnings("unused") DirectedSparseGraph model,
List<String> question,
@SuppressWarnings("unused") final Object [] moreOptions)
{
return WMethod.tracePath(new FSMStructure(model,null),question);
}
};
new Test_LearnerComparator(learner2.getLearner(),simulator,false).learnMachine(buildSet(plus), buildSet(minus));
break;
}
case RECORDERTEST_LL:
{// now two learners
RPNIBlueFringeLearnerTestComponentOpt learnerA = new RPNIBlueFringeLearnerTestComponentOpt(null)
{
@Override
public int checkWithEndUser(
@SuppressWarnings("unused") DirectedSparseGraph model,
List<String> question,
@SuppressWarnings("unused") final Object [] moreOptions)
{
return WMethod.tracePath(new FSMStructure(model,null),question);
}
};
RPNIBlueFringeLearnerTestComponentOpt learnerB = new RPNIBlueFringeLearnerTestComponentOpt(null)
{
@Override
public int checkWithEndUser(
@SuppressWarnings("unused") DirectedSparseGraph model,
List<String> question,
@SuppressWarnings("unused") final Object [] moreOptions)
{
return WMethod.tracePath(new FSMStructure(model,null),question);
}
};
new Test_LearnerComparator(learnerA.getLearner(),learnerB.getLearner(),false).learnMachine(buildSet(plus), buildSet(minus));
break;
}