Package statechum.analysis.learning.observers.ProgressDecorator

Examples of statechum.analysis.learning.observers.ProgressDecorator.LearnerEvaluationConfiguration


  @Test
  public final void testLearnerEvaluation8()
  {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    RecordProgressDecorator dumper = new RecordProgressDecorator(null,output,1,Configuration.getDefaultConfiguration(),false);
    Element learnerConfig = dumper.writeLearnerEvaluationConfiguration(new LearnerEvaluationConfiguration(graph,testData,anotherconfig,ltl));
    learnerConfig.appendChild(anotherconfig.writeXML(dumper.doc));
    dumper.topElement.appendChild(learnerConfig);dumper.close();xmlData = output.toString();
   
    final LearnerSimulator loader = new LearnerSimulator(new ByteArrayInputStream(xmlData.getBytes()),false);
    checkForCorrectException(new whatToRun() { public void run() {
View Full Code Here


  }
 
  @Test
  public void TestConstructIfThenForUniques1()
  {
    LearnerEvaluationConfiguration evaluationConfiguration = new LearnerEvaluationConfiguration(mainConfiguration);
    LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B-c->B-b->A / B-a-#C", "testSplitFSM", mainConfiguration,converter);
    Map<Label,Pair<CmpVertex,CmpVertex>> map=PairQualityLearner.uniqueIntoState(graph);
    Assert.assertNull(evaluationConfiguration.ifthenSequences);
    PairQualityLearner.addIfThenForMandatoryMerge(evaluationConfiguration, map.keySet());
    Assert.assertEquals(2,evaluationConfiguration.ifthenSequences.size());
View Full Code Here

          }
        }
      }
      while(pickUniqueFromInitial && uniqueFromInitial == null);
     
      LearnerEvaluationConfiguration learnerEval = new LearnerEvaluationConfiguration(config);learnerEval.setLabelConverter(converter);
      final Collection<List<Label>> testSet = PaperUAS.computeEvaluationSet(referenceGraph,states*3,states*alphabet);
     
      for(int attempt=0;attempt<2;++attempt)
      {// try learning the same machine a few times
        LearnerGraph pta = new LearnerGraph(config);
View Full Code Here

  }

  @Test
  public void TestConstructIfThenForUniques2()
  {
    LearnerEvaluationConfiguration evaluationConfiguration = new LearnerEvaluationConfiguration(mainConfiguration);
    LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B-c->B-b->A / B-a-#C", "testSplitFSM", mainConfiguration,converter);
    Map<Label,Pair<CmpVertex,CmpVertex>> map=PairQualityLearner.uniqueIntoState(graph);
    evaluationConfiguration.ifthenSequences = new LinkedList<String>();evaluationConfiguration.ifthenSequences.add("junk");
    PairQualityLearner.addIfThenForMandatoryMerge(evaluationConfiguration, map.keySet());
    Assert.assertEquals(3,evaluationConfiguration.ifthenSequences.size());
View Full Code Here

  }
 
  @Test
  public void TestConstructIfThenForUniques3()
  {
    LearnerEvaluationConfiguration evaluationConfiguration = new LearnerEvaluationConfiguration(mainConfiguration);
    LearnerGraph graph = new LearnerGraph(mainConfiguration);
    Map<Label,Pair<CmpVertex,CmpVertex>> map=PairQualityLearner.uniqueIntoState(graph);
    evaluationConfiguration.ifthenSequences = new LinkedList<String>();evaluationConfiguration.ifthenSequences.add("junk");
    PairQualityLearner.addIfThenForMandatoryMerge(evaluationConfiguration, map.keySet());
    Assert.assertEquals(1,evaluationConfiguration.ifthenSequences.size());
View Full Code Here

 
  @Test
  public void TestConstructIfThenForInfeasible0()
  {
    LearnerGraph graph = new LearnerGraph(mainConfiguration);
    LearnerEvaluationConfiguration evaluationConfiguration = new LearnerEvaluationConfiguration(mainConfiguration);
    PairQualityLearner.addIfThenForPairwiseConstraints(evaluationConfiguration, PairQualityLearner.computeInfeasiblePairs(graph));
    Assert.assertTrue(evaluationConfiguration.ifthenSequences.isEmpty());
  }
View Full Code Here

 
  @Test
  public void TestConstructIfThenForInfeasible1()
  {
    LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B-c->B-b->A / B-a-#C", "testSplitFSM", mainConfiguration,converter);
    LearnerEvaluationConfiguration evaluationConfiguration = new LearnerEvaluationConfiguration(mainConfiguration);
    evaluationConfiguration.ifthenSequences = new LinkedList<String>();evaluationConfiguration.ifthenSequences.add("junk");
    PairQualityLearner.addIfThenForPairwiseConstraints(evaluationConfiguration, PairQualityLearner.computeInfeasiblePairs(graph));
    Assert.assertEquals(2,evaluationConfiguration.ifthenSequences.size());
    Iterator<String> ifthenIterator = evaluationConfiguration.ifthenSequences.iterator();
    Assert.assertEquals("junk",ifthenIterator.next());
View Full Code Here

          }
        }
      }
      while(pickUniqueFromInitial && uniqueFromInitial == null);
     
      LearnerEvaluationConfiguration learnerEval = new LearnerEvaluationConfiguration(config);learnerEval.setLabelConverter(converter);
      final Collection<List<Label>> testSet = null;//PaperUAS.computeEvaluationSet(referenceGraph,states*3,states*alphabet);
     
      for(int attempt=0;attempt<2;++attempt)
      {// try learning the same machine a few times
        LearnerGraph pta = new LearnerGraph(config);
View Full Code Here

    for(String [] path:plus)
      assert AbstractOracle.USER_ACCEPTED == expected.paths.tracePathPrefixClosed(AbstractLearnerGraph.buildList(Arrays.asList(path),config,getLabelConverter()));
    for(String [] path:minus)
      assert AbstractOracle.USER_ACCEPTED != expected.paths.tracePathPrefixClosed(AbstractLearnerGraph.buildList(Arrays.asList(path),config,getLabelConverter()));
    // Visualiser.getVisualiser()
    Learner l = new RPNIUniversalLearner(null,new LearnerEvaluationConfiguration(null,null,testConfig,null,null))
    {
      @Override
      public LearnerGraph MergeAndDeterminize(LearnerGraph original, StatePair pair)
      {
        // Check that compatibility score computation gives the same response as if we did merge and computed a difference between the number of states.
View Full Code Here

        }
      }
    }
    while(pickUniqueFromInitial && uniqueFromInitial == null);
   
    LearnerEvaluationConfiguration learnerEval = new LearnerEvaluationConfiguration(config);learnerEval.setLabelConverter(converter);
    final Collection<List<Label>> testSet = PaperUAS.computeEvaluationSet(referenceGraph,states*3,states*alphabet);
   
    for(int attempt=0;attempt<3;++attempt)
    {// try learning the same machine a few times
      LearnerGraph pta = new LearnerGraph(config);
      RandomPathGenerator generator = new RandomPathGenerator(referenceGraph,new Random(attempt),5,referenceGraph.getVertex(Arrays.asList(new Label[]{uniqueFromInitial})));
      generator.setWalksShouldLeadToInitialState();
      // test sequences will be distributed around
      final int pathLength = generator.getPathLength();
      final int sequencesPerChunk = PairQualityLearner.makeEven(alphabet*states*traceQuantity);// we are only using one chunk here but the name is unchanged.
      // Usually, the total number of elements in test sequences (alphabet*states*traceQuantity) will be distributed around (random(pathLength)+1). The total size of PTA is a product of these two.
      // For the purpose of generating long traces, we construct as many traces as there are states but these traces have to be rather long,
      // that is, length of traces will be (random(pathLength)+1)*sequencesPerChunk/states and the number of traces generated will be the same as the number of states.
      final int tracesToGenerate = 20;//PairQualityLearner.makeEven(states*traceQuantity*3);
      final Random rnd = new Random(seed*31+attempt);
     
      generator.generateRandomPosNeg(tracesToGenerate, 1, false, new RandomLengthGenerator() {
                 
          @Override
          public int getLength() {
            return  6;//10*(rnd.nextInt(pathLength)+1)*sequencesPerChunk/tracesToGenerate;
          }
 
          @Override
          public int getPrefixLength(int len) {
            return len;
          }
        },true,true,null,Arrays.asList(new Label[]{uniqueFromInitial}));
     
      //System.out.println(generator.getAllSequences(0).getData(PTASequenceEngine.truePred));
     
      /*
      for(List<Label> seq:referenceGraph.wmethod.computeNewTestSet(1))
      {
        pta.paths.augmentPTA(seq, referenceGraph.getVertex(seq) != null, false, null);
      }*/
      //pta.paths.augmentPTA(referenceGraph.wmethod.computeNewTestSet(referenceGraph.getInit(),1));// this one will not set any states as rejects because it uses shouldbereturned
      //referenceGraph.pathroutines.completeGraph(referenceGraph.nextID(false));
      if (onlyUsePositives)
        pta.paths.augmentPTA(generator.getAllSequences(0).filter(new FilterPredicate() {
          @Override
          public boolean shouldBeReturned(Object name) {
            return ((statechum.analysis.learning.rpnicore.RandomPathGenerator.StateName)name).accept;
          }
        }));
      else
        pta.paths.augmentPTA(generator.getAllSequences(0));// the PTA will have very few reject-states because we are generating few sequences and hence there will be few negative sequences.
        // In order to approximate the behaviour of our case study, we need to compute which pairs are not allowed from a reference graph and use those as if-then automata to start the inference.
       
      /*
      synchronized (AbstractLearnerGraph.syncObj) {
        PaperUAS.computePTASize(selectionID+" with unique "+uniqueFromInitial+" : ", pta, referenceGraph);
      }*/
      //Visualiser.updateFrame(referenceGraph, pta);
      //Visualiser.waitForKey();
     
      pta.clearColours();
     
      if (!onlyUsePositives)
      {
        assert pta.getStateNumber() > pta.getAcceptStateNumber() : "graph with only accept states but onlyUsePositives is not set";
        Map<Label,Set<Label>> infeasiblePairs = PairQualityLearner.computeInfeasiblePairs(referenceGraph);
        Map<Label,Set<Label>> subsetOfPairs = new TreeMap<Label,Set<Label>>();
        for(Entry<Label,Set<Label>> entry:infeasiblePairs.entrySet())
        {
          Set<Label> value = new TreeSet<Label>();
          if (!entry.getValue().isEmpty())
          {
            Label possibleLabels[]=entry.getValue().toArray(new Label[]{});
            if (possibleLabels.length == 1)
              value.add(possibleLabels[0]);
            else
              value.add(possibleLabels[rnd.nextInt(possibleLabels.length)]);
          }
          subsetOfPairs.put(entry.getKey(),value);
        }
        PairQualityLearner.addIfThenForPairwiseConstraints(learnerEval,subsetOfPairs);
        LearnerGraph [] ifthenAutomata = Transform.buildIfThenAutomata(learnerEval.ifthenSequences, null, referenceGraph, learnerEval.config, learnerEval.getLabelConverter()).toArray(new LearnerGraph[0]);
        learnerEval.config.setUseConstraints(false);// do not use if-then during learning (refer to the explanation above)
        int statesToAdd = 1;// we are adding pairwise constraints hence only one has to be added.
        //System.out.println(new Date().toString()+" Graph loaded: "+pta.getStateNumber()+" states ("+pta.getAcceptStateNumber()+" accept states), adding at most "+ statesToAdd+" if-then states");
        Transform.augmentFromIfThenAutomaton(pta, null, ifthenAutomata, statesToAdd);// we only need  to augment our PTA once (refer to the explanation above).
        //System.out.println(new Date().toString()+" Graph augmented: "+pta.getStateNumber()+" states ("+pta.getAcceptStateNumber()+" accept states)");
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.observers.ProgressDecorator.LearnerEvaluationConfiguration

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.