Package statechum.analysis.learning.rpnicore

Examples of statechum.analysis.learning.rpnicore.LearnerGraph$NonExistingPaths


  }

  @Test(expected = IllegalArgumentException.class)
  public final void testMerge_fail3()
  {
    LearnerGraph l=buildLearnerGraph(largeGraph1_invalid5,"testMerge_fail1",testConfig,getLabelConverter());
    CmpVertex
      a = l.findVertex(VertexID.parseID("A")),
      b = l.findVertex(VertexID.parseID("B"));
    StatePair pair = new StatePair(b,a);// A is red
    MergeStates.mergeAndDeterminize_general(l, pair);
  }
View Full Code Here


 
  /** Learns starting with the supplied PTA. */
  public LearnerGraph learn(LearnerGraph initPTAArg)
  {
    setInitPta(initPTAArg);
    LearnerGraph outcome = learner.learnMachine(new LinkedList<List<Label>>(), new LinkedList<List<Label>>());
    if (phantomVertex != null)
      outcome.transitionMatrix.remove(outcome.findVertex(phantomVertex));
    return outcome;
  }
View Full Code Here

      engine = positives;
    }
    else
      engine = engineArg;
   
    LearnerGraph outcome = learner.learnMachine(engine,0,0);
    if (phantomVertex != null)
      outcome.transitionMatrix.remove(outcome.findVertex(phantomVertex));
    return outcome;
  }
View Full Code Here

   * @param expectedPairs a set of pairs which has to be returned
   * @param graphName the name to give to the constructed graph
   */
  public final void testChooseStatePairs(String fsm, String [] initialReds, String [][] expectedReds, List<PairScore> expectedPairs, String graphName)
  {
    final LearnerGraph fsmAsLearnerGraph = FsmParser.buildLearnerGraph(fsm, graphName,config,getLabelConverter());
    final DirectedSparseGraph gB = fsmAsLearnerGraph.pathroutines.getGraph();
    for(PairScore pair:expectedPairs)
    {
      Assert.assertNotNull("vertex "+pair.getQ()+" is missing in the graph",fsmAsLearnerGraph.findVertex(pair.getQ()));
      Assert.assertNotNull("vertex "+pair.getR()+" is missing in the graph",fsmAsLearnerGraph.findVertex(pair.getR()));
    }
    //Visualiser.updateFrame(new LearnerGraph(gB,Configuration.getDefaultConfiguration()), null);Visualiser.waitForKey();
    // check how the reference pair selection function performs
    Configuration conf = testConfig.copy();conf.setLearnerUseStrings(false);conf.setLearnerCloneGraph(false);
    testChooseStatePairsInternal(gB,new LearnerGraph(gB, conf), initialReds, expectedReds, expectedPairs, new InterfaceChooserToTest() {
      public @Override Stack<StatePair> choosePairs() {// Here I need to convert the old type of pairs to the new one.
        Stack<OrigStatePair> pairs = chooseStatePairs(gB, new HashSet<List<Label>>(), new HashSet<List<Label>>());
        Stack<StatePair> result = new Stack<StatePair>();
        for(OrigStatePair pair:pairs) result.add(new StatePair((CmpVertex)pair.getQ(),(CmpVertex)pair.getR()));
        return result;
      }
    });

    final DirectedSparseGraph gA = FsmParser.buildLearnerGraph(fsm, graphName,config,getLabelConverter()).pathroutines.getGraph();
    // check how the revised pair selection function performs
    final LearnerGraph s = new LearnerGraph(gA, testConfig);
    testChooseStatePairsInternal(gA,s, initialReds, expectedReds, expectedPairs, new InterfaceChooserToTest() {
      public @Override Stack<? extends StatePair> choosePairs() {
        return s.pairscores.chooseStatePairs(null);
      }
    });
View Full Code Here

   * keep the spirit of BlueFringe where we look at red states closest to the initial state first.
   */
  @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);
   
View Full Code Here

    DirectedSparseGraph g = FsmParser.buildLearnerGraph(fsm, graphName,config,getLabelConverter()).pathroutines.getGraph();
    OrigStatePair pairOrig = new OrigStatePair(
        DeterministicDirectedSparseGraph.findVertex(JUConstants.LABEL, VertexID.parseID("B"), g),
        DeterministicDirectedSparseGraph.findVertex(JUConstants.LABEL, VertexID.parseID("A"), g));
   
    LearnerGraph s = new LearnerGraph(g, testConfig);
    StatePair pairNew = new StatePair(
        s.findVertex(VertexID.parseID("B")),
        s.findVertex(VertexID.parseID("A")));
    doneEdges = new HashSet<DirectedSparseEdge>();
    s.config.setLearnerScoreMode(Configuration.ScoreMode.CONVENTIONAL);s.setMaxScore(maxScoreConstant-1);
    long origScore = computeScore(g, pairOrig),
      newScoreA = s.pairscores.computeStateScore(pairNew),
      newScoreB = s.pairscores.computePairCompatibilityScore(pairNew);
    s.config.setLearnerScoreMode(Configuration.ScoreMode.COMPATIBILITY);
    long newScoreC = s.pairscores.computePairCompatibilityScore(pairNew);
View Full Code Here

  }
 
  private void testGeneralPairScoreComputation(String machine, String graphName, int expectedScore,
      String[][] expectedSrc,String [][]incompatibles)
  {
    LearnerGraph fsm = FsmParser.buildLearnerGraph(machine, graphName,mainConfiguration,getLabelConverter());

    if (incompatibles != null)
      for(String [] incompatibleRow:incompatibles)
      {
        assert incompatibleRow.length == 2;
        fsm.addToCompatibility(fsm.findVertex(incompatibleRow[0]), fsm.findVertex(incompatibleRow[1]),JUConstants.PAIRCOMPATIBILITY.INCOMPATIBLE);
      }
    Collection<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>> result = new LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>>();
    int score = -2;
    score = fsm.pairscores.computePairCompatibilityScore_general(new StatePair(fsm.findVertex(VertexID.parseID("A")),fsm.findVertex(VertexID.parseID("B"))),null,result);
    //Visualiser.updateFrame(g, result);Visualiser.waitForKey();
    Assert.assertEquals(expectedScore, score);
    if (score >=0)
      matchCollectionsOfVertices(result, expectedSrc);
   
    result.clear();score = -2;
    score = fsm.pairscores.computePairCompatibilityScore_general(new StatePair(fsm.findVertex(VertexID.parseID("B")),fsm.findVertex(VertexID.parseID("A"))),null,result);
    Assert.assertEquals(expectedScore, score);
    if (score >=0)
      matchCollectionsOfVertices(result, expectedSrc);
  }
View Full Code Here

  }
 
  @Test
  public final void testPairCompatible_general_E()
  {
    LearnerGraph fsm = FsmParser.buildLearnerGraph("I-d->A1-a->A2-b->A3-c->A4 / I-b->B1-a->B2-b->B3 / I-c->C1-a->C2-b->C3", "testPairCompatible_general_Ea",config,getLabelConverter());
    Collection<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>> verticesToMerge = new LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>>();
    fsm.pairscores.computePairCompatibilityScore_general(null,Arrays.asList(new StatePair[]{
        new StatePair(fsm.findVertex("I"),fsm.findVertex("A1")),new StatePair(fsm.findVertex("I"),fsm.findVertex("B1")),new StatePair(fsm.findVertex("I"),fsm.findVertex("C1"))
        }), verticesToMerge);
    LearnerGraph mergeOutcome =  MergeStates.mergeCollectionOfVertices(fsm, null, verticesToMerge);
    LearnerGraph expected = FsmParser.buildLearnerGraph("I-d->I-b->I-c->I / I-a->B2-b->B3-c->C1", "testPairCompatible_general_Eb",config,getLabelConverter());
    DifferentFSMException diffEx = WMethod.checkM(expected, mergeOutcome);
    if (diffEx != null)
      throw diffEx;
  }
View Full Code Here

  @Override
  public LearnerGraph init(Collection<List<String>> plus, Collection<List<String>> minus)
  {
    sPlus = plus;
    sMinus = minus;   
    return new LearnerGraph(createAugmentedPTA(sPlus, sMinus),Configuration.getDefaultConfiguration());
  }
View Full Code Here

        questions = trimSet(questions);
        Iterator<List<String>> questionIt = questions.iterator();
        while(questionIt.hasNext()){
          List<String> question = questionIt.next();
          boolean accepted = DeterministicDirectedSparseGraph.isAccept(pair.getQ());// Q is the blue vertex
          Pair<Integer,String> response = CheckWithEndUser(new LearnerGraph(model,Configuration.getDefaultConfiguration()),question,
              AbstractOracle.USER_CANCELLED,null,new Object[0]);// zero means "yes", everything else is "no"
          pair.getQ().removeUserDatum(JUConstants.HIGHLIGHT);
          pair.getR().removeUserDatum(JUConstants.HIGHLIGHT);
          if(response.firstElem == AbstractOracle.USER_ACCEPTED){
            sPlus.add(question);
            System.out.println(question+ " <yes>");
            if(accepted == false)// KIRR: how can this be true? If it were so, there would be no questions to ask
              return learnMachine(sPlus,sMinus);
          }
          else{
            sMinus.add(question.subList(0, response.firstElem));
            System.out.println(question+ " <no>");
            if(accepted == true){// KIRR: this cannot be false either
              return learnMachine(sPlus,sMinus);
            }
          }
        }
        model = temp;
      }
      possibleMerges = chooseStatePairs(model, sPlus, sMinus);
    }
    System.out.println("finished");
    return new LearnerGraph(model,Configuration.getDefaultConfiguration());
  }
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.rpnicore.LearnerGraph$NonExistingPaths

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.