return outcome;
}
public static LearnerGraph buildFirstOrderMarkovGraph(MarkovClassifier ptaClassifier, LearnerGraph referenceGraph)
{
LearnerGraph outcome = new LearnerGraph(ptaClassifier.graph.config);
if (ptaClassifier.model.getChunkLen() < 2)
throw new IllegalArgumentException("not enough data for a first-order Markov model");
LearnerGraph trimmedReference = trimUncoveredTransitions(ptaClassifier.graph,referenceGraph);
ptaClassifier.updateMarkov(false);
Map<Label,CmpVertex> states = new TreeMap<Label,CmpVertex>();
for(Label l:ptaClassifier.graph.getCache().getAlphabet())
{
CmpVertex state = AbstractLearnerGraph.generateNewCmpVertex(VertexID.parseID(l.toString()), ptaClassifier.graph.config);states.put(l,state);
outcome.transitionMatrix.put(state, outcome.createNewRow());
}
for(Entry<Label,CmpVertex> state:states.entrySet())
{
for(Label label:ptaClassifier.graph.getCache().getAlphabet())
{
MarkovOutcome transition = ptaClassifier.model.predictionsMatrix.get(new Trace(Arrays.asList(new Label[]{state.getKey(),label}),true));
if (transition != null)
if (transition == MarkovOutcome.positive) outcome.transitionMatrix.get(state.getValue()).put(label,states.get(label));
}
}
List<List<Label>> uniqueSequences = new LinkedList<List<Label>>();
for(Label l1:ptaClassifier.graph.getCache().getAlphabet())
{
boolean nonUnique = false;
Label unique = null;
for(Label lbl:ptaClassifier.graph.getCache().getAlphabet())
{
if (ptaClassifier.model.predictionsMatrix.containsKey(new Trace(Arrays.asList(new Label[]{l1,lbl}),true)))
{
if (unique == null)
unique = lbl;
else
{
nonUnique = true;break;
}
}
}
if (unique != null && !nonUnique)
uniqueSequences.add(Arrays.asList(new Label[]{l1,unique}));
}
List<List<Label>> sequencesUnique2=new LinkedList<List<Label>>();
for(List<Label> prefix:uniqueSequences)
{
boolean nonUnique = false;
List<Label> unique = null;
for(Label lbl:ptaClassifier.graph.getCache().getAlphabet())
{
List<Label> seq = new LinkedList<Label>(prefix);seq.add(lbl);
if (ptaClassifier.model.predictionsMatrix.containsKey(new Trace(seq,true)))
{
if (unique == null)
unique = seq;
else
{
nonUnique = true;break;
}
}
}
if (nonUnique == false && unique!= null)
sequencesUnique2.add(unique);
}
for(List<Label> seq:sequencesUnique2)
{
System.out.println(seq);
for(CmpVertex vert:trimmedReference.transitionMatrix.keySet())
{
CmpVertex target=trimmedReference.getVertex(vert,seq);
if (target != null)
{
System.out.println("\t -> "+target);
CmpVertex stateOfInterest = trimmedReference.getVertex(vert,seq.subList(0, 2));
System.out.println("\t "+trimmedReference.transitionMatrix.get(stateOfInterest));
}
}
}