Package statechum.model.testset

Examples of statechum.model.testset.PTASequenceEngine


    Assert.assertEquals(chunkNumber, generator.getChunkNumber());

    for(int i=0;i<chunkNumber;++i)
    {
      final PTASequenceEngine currentPTA = generator.getAllSequences(i);
      Collection<List<Label>> currentSequences = currentPTA.getData(PTASequenceEngine.truePred);
      Assert.assertEquals("chunk "+i+" (neg) should be of length "+(2*posOrNegPerChunk*(i+1))+" but it was "+currentSequences.size(),(2*posOrNegPerChunk*(i+1)), currentSequences.size());
      int positive = 0,negative=0;
      PTASequenceEngine positivePTA = currentPTA.filter(currentPTA.getFSM_filterPredicate());
      PTASequenceEngine negativePTA = currentPTA.filter(new FilterPredicate() {
        FilterPredicate origFilter = currentPTA.getFSM_filterPredicate();
       
        @Override
        public boolean shouldBeReturned(Object name) {
          return !origFilter.shouldBeReturned(name);
        }
      });
      for(List<Label> s:currentSequences)
        if(graph.paths.tracePathPrefixClosed(s) >=0)
        {
          ++negative;
          Assert.assertFalse(positivePTA.containsSequence(s));Assert.assertTrue(negativePTA.containsSequence(s));
        }
        else
        {
          ++positive;
          Assert.assertTrue(positivePTA.containsSequence(s));Assert.assertFalse(negativePTA.containsSequence(s));
        }
      Assert.assertEquals(posOrNegPerChunk*(i+1), positive);Assert.assertEquals(positive,positivePTA.getData(PTASequenceEngine.truePred).size());
      Assert.assertEquals(positive,positivePTA.getData().size());// all seq are accept ones
      Assert.assertEquals(posOrNegPerChunk*(i+1), negative);Assert.assertEquals(negative,negativePTA.getData(PTASequenceEngine.truePred).size());
      Assert.assertEquals(0,negativePTA.getData().size());// all seq are reject ones
      if (previousChunk != null) currentSequences.containsAll(previousChunk);
      previousChunk= currentSequences;
    }

    checkForCorrectException(new whatToRun() { @Override public void run() {
View Full Code Here


    checkForCorrectException(new whatToRun() { @Override public void run() {
      generator.getExtraSequences(1);
    }},IllegalArgumentException.class,"is out of range");
    Assert.assertTrue("PTA is not empty",generator.getExtraSequences(0).containsAsLeaf(labelList(new String[]{})));
    final PTASequenceEngine currentPTA = generator.getAllSequences(0);
    PTASequenceEngine positivePTA = currentPTA.filter(currentPTA.getFSM_filterPredicate());
    PTASequenceEngine negativePTA = currentPTA.filter(new FilterPredicate() {
      FilterPredicate origFilter = currentPTA.getFSM_filterPredicate();
     
      @Override
      public boolean shouldBeReturned(Object name) {
        return !origFilter.shouldBeReturned(name);
      }
    });
   
    {
      Collection<List<Label>> currentPos = positivePTA.getData(PTASequenceEngine.truePred);
      Assert.assertEquals(1,currentPos.size());
      Assert.assertEquals(labelList(new String[]{"a"}), currentPos.iterator().next());
    }
   
    {
      Collection<List<Label>> currentNeg = negativePTA.getData(PTASequenceEngine.truePred);
      Assert.assertEquals(1,currentNeg.size());
      Assert.assertEquals(labelList(new String[]{"b"}), currentNeg.iterator().next());
    }   
   
  }
View Full Code Here

  }
 
  public static PTASequenceEngine computeQS_general(final StatePair pairToMerge,
      final LearnerGraph original, final LearnerGraph learnt,final QuestionConstructor qConstructor)
  {
    final PTASequenceEngine engine = qConstructor.constructEngine(original, learnt);
   
    final SequenceSet identity = engine.new SequenceSet();identity.setIdentity();
    for(AMEquivalenceClass<CmpVertex,LearnerGraphCachedData> eq:learnt.learnerCache.getMergedStates())
      qConstructor.addQuestionsForState(eq, original, learnt, pairToMerge,
          learnt.learnerCache.stateLearnt,new MergeData(){
View Full Code Here

  {
    CmpVertex mergedRed = merged.findVertex(pair.getR().getID());
    if (mergedRed == null)
      throw new IllegalArgumentException("failed to find the red state in the merge result");
   
    PTASequenceEngine engine = new PTASequenceEngine();
    engine.init(original.new NonExistingPaths());
    PTASequenceEngine.SequenceSet paths = engine.new SequenceSet();
    PTASequenceEngine.SequenceSet initp = engine.new SequenceSet();initp.setIdentity();

    merged.pathroutines.computePathsSBetween(merged.getInit(),mergedRed, initp, paths);
   
    Collection<Label> inputsToMultWith = new LinkedList<Label>();
    for(Entry<Label,CmpVertex> loopEntry:merged.transitionMatrix.get(mergedRed).entrySet())
      if (loopEntry.getValue() == mergedRed)
      {// Note an input corresponding to any loop in temp can be followed in the original machine, since
        // a loop in temp is either due to the merge or because it was there in the first place.
        inputsToMultWith.add(loopEntry.getKey());
      }
    paths.unite(paths.crossWithSet(inputsToMultWith));// the resulting path does a "transition cover" on all transitions leaving the red state.
    merged.questions.buildQuestionsFromPair_Compatible(mergedRed, paths);
    return engine.getData();
  }
View Full Code Here

    generator.generateRandomPosNeg(posOrNegPerChunk*2,chunkNumber,false);

    Collection<List<Label>> previousChunk = null;
    for(int i=0;i<chunkNumber;++i)
    {
      final PTASequenceEngine currentPTA = generator.getAllSequences(i);
      Collection<List<Label>> currentSequences = currentPTA.getData(PTASequenceEngine.truePred);
      Assert.assertTrue(2*posOrNegPerChunk*(i+1)> currentSequences.size());
      int positive = 0,negative=0;
      PTASequenceEngine positivePTA = currentPTA.filter(currentPTA.getFSM_filterPredicate());
      PTASequenceEngine negativePTA = currentPTA.filter(new FilterPredicate() {
        FilterPredicate origFilter = currentPTA.getFSM_filterPredicate();
       
        @Override
        public boolean shouldBeReturned(Object name) {
          return !origFilter.shouldBeReturned(name);
        }
      });
      for(List<Label> s:currentSequences)
        if(graph.paths.tracePathPrefixClosed(s) >=0)
        {
          ++negative;
          Assert.assertFalse(positivePTA.containsSequence(s));Assert.assertTrue(negativePTA.containsSequence(s));
        }
        else
        {
          ++positive;
          Assert.assertTrue(positivePTA.containsSequence(s));Assert.assertFalse(negativePTA.containsSequence(s));
        }
      Assert.assertTrue(posOrNegPerChunk*(i+1) > positive);Assert.assertEquals(positive,positivePTA.getData(PTASequenceEngine.truePred).size());
      Assert.assertEquals(positive,positivePTA.getData().size());// all seq are accept ones
      Assert.assertTrue(posOrNegPerChunk*(i+1) > negative);Assert.assertEquals(negative,negativePTA.getData(PTASequenceEngine.truePred).size());
      Assert.assertEquals(0,negativePTA.getData().size());// all seq are reject ones
      if (previousChunk != null) currentSequences.containsAll(previousChunk);
      previousChunk= currentSequences;
    }
  }
View Full Code Here

  {
    CmpVertex mergedRed = merged.findVertex(pair.getR().getID());
    if (mergedRed == null)
      throw new IllegalArgumentException("failed to find the red state in the merge result");
   
    PTASequenceEngine engine = new PTASequenceEngine();
    engine.init(original.new NonExistingPaths());
    PTASequenceEngine.SequenceSet paths = engine.new SequenceSet();
    PTASequenceEngine.SequenceSet initp = engine.new SequenceSet();initp.setIdentity();

    List<Collection<Label>> sequenceOfSets = merged.paths.COMPAT_computePathsSBetween(merged.getInit(),mergedRed);
    if (sequenceOfSets == null)
      throw new IllegalArgumentException("failed to find the red state in the merge result");
    for(Collection<Label> inputsToMultWith:sequenceOfSets)
      initp = initp.crossWithSet(inputsToMultWith);
    paths.unite(initp);
    //merged.paths.computePathsSBetweenBooleanReduced(merged.init,mergedRed, initp, paths);
   
    Collection<Label> inputsToMultWith = new LinkedList<Label>();
    for(Entry<Label,CmpVertex> loopEntry:merged.transitionMatrix.get(mergedRed).entrySet())
      if (loopEntry.getValue() == mergedRed)
      {// Note an input corresponding to any loop in temp can be followed in the original machine, since
        // a loop in temp is either due to the merge or because it was there in the first place.
        inputsToMultWith.add(loopEntry.getKey());
      }
    paths.unite(paths.crossWithSet(inputsToMultWith));// the resulting path does a "transition cover" on all transitions leaving the red state.
    merged.questions.buildQuestionsFromPair_Compatible(mergedRed, paths);
    return engine.getData();
  }
View Full Code Here

  {
    CmpVertex mergedRed = merged.findVertex(pair.getR().getID());
    if (mergedRed == null)
      throw new IllegalArgumentException("failed to find the red state in the merge result");
   
    PTASequenceEngine engine = new PTASequenceEngine();
    engine.init(original.new NonExistingPaths());
    PTASequenceEngine.SequenceSet initp = engine.new SequenceSet();initp.setIdentity();
    merged.questions.buildQuestionsFromPair_Compatible(mergedRed, initp);
    return engine.getData(PTASequenceEngine.truePred);
  }
View Full Code Here

      {
        theOnlyStateReject = true;break;
      }
    final Boolean rejectAllStates = new Boolean(theOnlyStateReject);
    final AtomicBoolean statesAccept = new AtomicBoolean(true);
    PTASequenceEngine allSequences = new PTASequenceEngine();
   
    // Here we are building a PTA which consists of accept states for plusStrings and reject-states
    // for minusStrings. This way if a plus string is a prefix of a plusString, the prefix will
    // be labelled with Boolean(true) states and the suffix - with Boolean(false) states.
    // Note that the suffix may contain many states.
    allSequences.init(new PTASequenceSetAutomaton()
    {
      @Override
      public Object getTheOnlyState() {
        return statesAccept.get()?accept:reject;
      }
View Full Code Here

    try
    {
      Configuration config = Configuration.getDefaultConfiguration().copy();
      RPNIUniversalLearner l = new RPNIUniversalLearner(null,new LearnerEvaluationConfiguration(null,null,config,null,null));
      config.setLearnerIdMode(Configuration.IDMode.POSITIVE_NEGATIVE);
      PTASequenceEngine engine = buildPTA(plusStrings, minusStrings);
      checkPTAConsistency(engine, plusStrings, true);if (engine.numberOfLeafNodes()>0) checkPTAConsistency(engine, minusStrings, false);
      l.init(engine,0,0);
      actualD = l.scoreComputer.pathroutines.getGraph();
    }
    catch(IllegalArgumentException e)
    {
View Full Code Here

    try
    {
      Configuration config = Configuration.getDefaultConfiguration().copy();
      RPNIUniversalLearner l = new RPNIUniversalLearner(null,new LearnerEvaluationConfiguration(null,null,config,null,null));
      config.setLearnerIdMode(Configuration.IDMode.POSITIVE_NEGATIVE);
      PTASequenceEngine engine = buildPTA(plusStrings, minusStrings);
      checkPTAConsistency(engine, plusStrings, true);if (engine.numberOfLeafNodes()>0) checkPTAConsistency(engine, minusStrings, false);
      l.init(engine,0,0);
      actualD = l.scoreComputer.pathroutines.getGraph();
    }
    catch(IllegalArgumentException e)
    {
View Full Code Here

TOP

Related Classes of statechum.model.testset.PTASequenceEngine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.