Package statechum

Examples of statechum.Label


   * specific input.
   */
  protected Map<Label, Set<Label>> inputToPossibleOutputs = new TreeMap<Label, Set<Label>>();

  protected void updateInputToPossibleOutputs(Label label) {
    Label inputPortionOfLabel = stripOutput((ErlangLabel) label);
    Set<Label> outputsSeenForThisInput = inputToPossibleOutputs
        .get(inputPortionOfLabel);
    if (outputsSeenForThisInput == null) {
      outputsSeenForThisInput = new TreeSet<Label>();
      inputToPossibleOutputs.put(inputPortionOfLabel,
View Full Code Here


      // generate a collection of traces corresponding to failures
      response = new StringBuffer();
      // Erlang provides the failing element AS WELL!
      int prefixLen = outcome.answerDetails.length - 1;
      List<Label> prefix = question.subList(0, prefixLen);
      Label failedLabel = question.get(prefixLen);
      response.append("- [");
      boolean first = true;
      ErlangLabel noop = stripOutput((ErlangLabel) failedLabel);

      //assert noop.function != null : "questions do not contain function details";
View Full Code Here

      assert input instanceof ErlangLabel;
      ErlangState state = (ErlangState) currentState;

      // First of all, we check if we already have a wildcard-transition
      // recorded from this state,
      Label inputPortionOfLabel = stripOutput((ErlangLabel) input);
      if (state.rejects.contains(inputPortionOfLabel))
        return null;// failed

      // now normal input
      if (state.rejects.contains(input))
View Full Code Here

   */
  @Test
  public final void testVertexOrdering()
  {
    LearnerGraph gr = new LearnerGraph(config);
    Label a=AbstractLearnerGraph.generateNewLabel("a", config,getLabelConverter()),b=AbstractLearnerGraph.generateNewLabel("b", config,getLabelConverter());
    gr.paths.augmentPTA(Arrays.asList(new Label[]{a,a}),true,false,null);
    gr.paths.augmentPTA(Arrays.asList(new Label[]{a,b}),true,false,null);
    gr.paths.augmentPTA(Arrays.asList(new Label[]{b}),true,false,null);
   
    CmpVertex A=gr.paths.getVertex(Arrays.asList(new Label[]{})),
View Full Code Here

    PTASequenceEngine.Node currentNode = init;if (!currentNode.isAccept()) throw new IllegalArgumentException("untested on empty graphs");
    Iterator<Label> seqIt = inputSequence.iterator();
    while(seqIt.hasNext() && currentNode.isAccept())
    {
      Map<Label,PTASequenceEngine.Node> row = pta.get(currentNode);
      Label input = seqIt.next();
      if (row.containsKey(input))
        currentNode = row.get(input);
      else
        return false;// no transition with the current input
    }
View Full Code Here

    PTASequenceEngine.Node currentNode = init;
    Iterator<Label> seqIt = inputSequence.iterator();
    while(seqIt.hasNext() && currentNode.isAccept())
    {
      Map<Label,PTASequenceEngine.Node> row = pta.get(currentNode);
      Label input = seqIt.next();
      if (row.containsKey(input))
        currentNode = row.get(input);
      else
        // no transition with the current input, if this is a leaf node the current sequence will extend it.
        return currentNode != init && row.isEmpty();
View Full Code Here

  public ThreadResult call() throws Exception
  {
    final int alphabet = 2*states;
    LearnerGraph referenceGraph = null;
    ThreadResult outcome = new ThreadResult();
    Label uniqueFromInitial = null;
    final boolean pickUniqueFromInitial = true;
    MachineGenerator mg = new MachineGenerator(states, 400 , (int)Math.round((double)states/5));mg.setGenerateConnected(true);
    do
    {
      referenceGraph = mg.nextMachine(alphabet,seed, config, converter).pathroutines.buildDeterministicGraph();// reference graph has no reject-states, because we assume that undefined transitions lead to reject states.
      if (pickUniqueFromInitial)
      {
        Map<Label,CmpVertex> uniques = PairQualityLearner.uniqueFromState(referenceGraph);
        if(!uniques.isEmpty())
        {
          // some uniques are loops, hence eliminate them to match our case study
          for(Entry<Label,CmpVertex> entry:uniques.entrySet())
            if (referenceGraph.transitionMatrix.get(entry.getValue()).get(entry.getKey()) != entry.getValue())
            {
              referenceGraph.setInit(entry.getValue());uniqueFromInitial = entry.getKey();break;// found a unique of interest
            }
        }
      }
    }
    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)]);
          }
View Full Code Here

  @Test
  public void testLearnIfThen3()
  {
    Map<Label,Map<Label,Double>> outcome = PaperUAS.learnIfThen(FsmParser.buildLearnerGraph("A-a->B-a->C-b->D", "testLearnIfThen2", mainConfiguration,converter), 0,0);
    Assert.assertEquals(1,outcome.size());
    Label a= AbstractLearnerGraph.generateNewLabel("a", mainConfiguration,converter);
    Map<Label,Double> entry = outcome.get(a);Assert.assertEquals(0.5, entry.get(a),Configuration.fpAccuracy);
  }
View Full Code Here

  @Test
  public void testLearnIfThen4()
  {
    Map<Label,Map<Label,Double>> outcome = PaperUAS.learnIfThen(FsmParser.buildLearnerGraph("A-a->B-a->C-a->D-a->E", "testLearnIfThen4", mainConfiguration,converter), 0,0);
    Assert.assertEquals(1,outcome.size());
    Label a= AbstractLearnerGraph.generateNewLabel("a", mainConfiguration,converter);
    Map<Label,Double> entry = outcome.get(a);Assert.assertEquals(0.75, entry.get(a),Configuration.fpAccuracy);
  }
View Full Code Here

  @Test
  public void testLearnIfThen7()
  {
    Map<Label,Map<Label,Double>> outcome = PaperUAS.learnIfThen(FsmParser.buildLearnerGraph("A-a->B-a->C-a->D-a->E-a->A-b-#F", "testLearnIfThen6", mainConfiguration,converter), 0,0);
    Assert.assertEquals(1,outcome.size());
    Label a= AbstractLearnerGraph.generateNewLabel("a", mainConfiguration,converter),b= AbstractLearnerGraph.generateNewLabel("b", mainConfiguration,converter);
    Map<Label,Double> entryA = outcome.get(a);Assert.assertEquals(1, entryA.get(a),Configuration.fpAccuracy);Assert.assertEquals(-0.2, entryA.get(b),Configuration.fpAccuracy);
  }
View Full Code Here

TOP

Related Classes of statechum.Label

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.