/** This method is executed on an executor thread. */
public void runTheExperiment()
{
int size = 4*graph.getStateNumber();
RandomPathGenerator rpg = new RandomPathGenerator(graph, new Random(100),5);// the seed for Random should be the same for each file
int percentPerChunk = 10;
int nrPerChunk = size/(100/percentPerChunk);nrPerChunk+=nrPerChunk % 2;// make the number even
rpg.generatePosNeg(2*nrPerChunk , 100/percentPerChunk);// 2* reflects the fact that nrPerChunk denotes the number of elements in both chunks (positive and negative) combined.
/*
RPNIBlueFringeLearner l = new RPNIBlueFringeLearnerTestComponentOpt(null,config)
{
@Override
protected Pair<Integer,String> checkWithEndUser(
@SuppressWarnings("unused") LearnerGraph model,
List<String> question,
@SuppressWarnings("unused") final Object [] moreOptions)
{
questionNumber.addAndGet(1);
return new Pair<Integer,String>(graph.paths.tracePath(question),null);
}
};
sPlus = rpg.getExtraSequences(percent/10-1);sMinus = rpg.getAllSequences(percent/10-1);
LearnerGraph learned = learn(l,sMinus);
*/
LearnerGraph learned = null;
Collection<List<String>> minusTrainingSet = null, testSet = null;
try {
synchronized (LearnerGraph.syncObj)
{// ensure that the calls to Jung's vertex-creation routines do not occur on different threads.
GraphMLFile graphmlFile = new GraphMLFile();
graphmlFile.setGraphMLFileHandler(new ExperimentGraphMLHandler());
final String mostOfFileName = "_"+(new File(inputFileName).getName());
assert new File(origDir).isDirectory();
for(String name:new File(origDir).list(new FilenameFilter(){
public boolean accept(@SuppressWarnings("unused") File dir, String fileName) {
return fileName.contains(mostOfFileName);
}}))
{
int firstUnderscore = name.indexOf('_');assert firstUnderscore > 0;
int currentNumber = Integer.parseInt(name.substring(0, firstUnderscore));
if (number < 0) number = currentNumber;else assert number == currentNumber;
}
assert number >=0;
/*
learned = new LearnerGraph(graphmlFile.load(
FileType.LEARNT.getFileName(dataDir+File.separator+number+"_"+(new File(inputFileName).getName()),"")
),config);
learned.transform.invertStates();
learned.transform.writeGraphML(getFileName(FileType.LEARNT));
*/
}
//computeStateScores.writeGraphML(learned, getFileName(FileType.LEARNT));
XMLDecoder inData = new XMLDecoder(new FileInputStream(FileType.MINUS_AND_TEST.getFileName(origDir+File.separator+number+"_"+(new File(inputFileName).getName()),"")));
minusTrainingSet = (Collection<List<String>>)inData.readObject();
testSet = (Collection<List<String>>)inData.readObject();
inData.close();
} catch (IOException e) {
StringWriter wr = new StringWriter();e.printStackTrace(new PrintWriter(wr));
IllegalArgumentException ex = new IllegalArgumentException(e.getMessage());ex.initCause(e);
throw ex;
}
/* Loads the original set. */
PTASequenceEngine sOrigMinus = new PTASequenceEngine()
{
{
init(graph.new FSMImplementation() {
@Override
public boolean shouldBeReturned(@SuppressWarnings("unused") Object elem)
{
return elem != null;
}
});
}
};
SequenceSet minusInit = sOrigMinus.new SequenceSet();minusInit.setIdentity();minusInit.cross(minusTrainingSet);
int totalLenOrig = 0, origNumber=0;
for(List<String> seq:minusTrainingSet)
{
assert seq.size() > 1;
assert graph.getVertex(seq) == null;// the seq is negative indeed
assert graph.getVertex(seq.subList(0, seq.size()-1)) != null;// the -1 prefix is positive
assert sOrigMinus.containsSequence(seq);// make sure PTA construction did not fumble.
assert graph.paths.tracePath(seq) == seq.size()-1;// and another check that a -1 prefix is ok
totalLenOrig+=seq.size();origNumber++;
}
assert sOrigMinus.getData().size() == 0;// all negatives
/* Builds the new set. */
PTASequenceEngine sNewMinus = rpg.getAllSequences(percent/10-1);
int totalLenNew = 0, newNumber = 0;
for(List<String> seq:sNewMinus.getData(PTASequenceEngine.truePred))
{
assert seq.size() > 1;
assert graph.getVertex(seq) == null;
assert graph.getVertex(seq.subList(0, seq.size()-1)) != null;
assert graph.paths.tracePath(seq) == seq.size()-1;
totalLenNew+=seq.size();newNumber++;
}
// 22,23
String comparison = "Orig ave len: "+FS+((double)totalLenOrig)/origNumber+FS+
// 24,25
" new ave len: "+FS+((double)totalLenNew)/newNumber+FS+
// 26,27
" fudge status: "+FS+rpg.getFudgeDetails();
//int numberOfMinusSequences = minusTrainingSet.size();
assert sNewMinus.getData().size() == 0;// all negatives
if (useOrig)