Package statechum.analysis.learning.rpnicore

Examples of statechum.analysis.learning.rpnicore.LearnerGraph


     // not to get this one wrong and the way to do it is to be cautious.
     // At present, we seem to be getting around 10% of these wrong.
      whatToMerge = thresholdToInconsistency.entrySet().iterator().next().getValue();
      List<StatePair> pairsList = buildVerticesToMergeForPath(whatToMerge);
      scoreAfterBigMerge = dREJECT;
      LearnerGraph merged = null;
      if (//thresholdToInconsistency.entrySet().iterator().next().getKey() == 0 &&
          !pairsList.isEmpty())
      {
        LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>> verticesToMerge = new LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>>();
        int score = graph.pairscores.computePairCompatibilityScore_general(null, pairsList, verticesToMerge);
View Full Code Here


  /** A match. */
  @Test
  public final void testKtails6()
  {
    testConfig.setKlimit(2);
    LearnerGraph fsm = FsmParser.buildLearnerGraph("A-a->B-b->C-a->D-d->E / B-c->F-a->G-e->H / M-b->N-a->Q / M-c->P-a->S", "testKtails6",testConfig,getLabelConverter());
    Assert.assertEquals(0,fsm.pairscores.computeStateScoreKTails(new StatePair(fsm.findVertex("M"),fsm.findVertex("B")), true));
    Assert.assertEquals(0,fsm.pairscores.computeStateScoreKTails(new StatePair(fsm.findVertex("M"),fsm.findVertex("B")), false));
    Assert.assertEquals(0,fsm.pairscores.computeStateScoreKTails(new StatePair(fsm.findVertex("B"),fsm.findVertex("M")), true));
    Assert.assertEquals(0,fsm.pairscores.computeStateScoreKTails(new StatePair(fsm.findVertex("B"),fsm.findVertex("M")), false));
 
View Full Code Here

  /** Only matches for any path. */
  @Test
  public final void testKtails7()
  {
    testConfig.setKlimit(2);
    LearnerGraph fsm = FsmParser.buildLearnerGraph("A-a->B-b->C-a->D-d->E / B-c->F-a->G-e->H / M-b->N-a->Q / M-c->P-a->S / N-b->R", "testKtails7",testConfig,getLabelConverter());
    Assert.assertEquals(0,fsm.pairscores.computeStateScoreKTails(new StatePair(fsm.findVertex("M"),fsm.findVertex("B")), true));
    Assert.assertEquals(-1,fsm.pairscores.computeStateScoreKTails(new StatePair(fsm.findVertex("M"),fsm.findVertex("B")), false));
    Assert.assertEquals(0,fsm.pairscores.computeStateScoreKTails(new StatePair(fsm.findVertex("B"),fsm.findVertex("M")), true));
    Assert.assertEquals(-1,fsm.pairscores.computeStateScoreKTails(new StatePair(fsm.findVertex("B"),fsm.findVertex("M")), false));
 
View Full Code Here

  /** Only matches for any path. */
  @Test
  public final void testKtails8()
  {
    testConfig.setKlimit(2);
    LearnerGraph fsm = FsmParser.buildLearnerGraph("A-a->B-b->C-a->D-d->E / B-c->F-a->G-e->H / M-b->N-a->Q / M-c->P-a->S / P-b->R", "testKtails8",testConfig,getLabelConverter());
    Assert.assertEquals(0,fsm.pairscores.computeStateScoreKTails(new StatePair(fsm.findVertex("M"),fsm.findVertex("B")), true));
    Assert.assertEquals(-1,fsm.pairscores.computeStateScoreKTails(new StatePair(fsm.findVertex("M"),fsm.findVertex("B")), false));
    Assert.assertEquals(0,fsm.pairscores.computeStateScoreKTails(new StatePair(fsm.findVertex("B"),fsm.findVertex("M")), true));
    Assert.assertEquals(-1,fsm.pairscores.computeStateScoreKTails(new StatePair(fsm.findVertex("B"),fsm.findVertex("M")), false));
 
View Full Code Here

  /** Only matches for any path. */
  @Test
  public final void testKtails9()
  {
    testConfig.setKlimit(2);
    LearnerGraph fsm = FsmParser.buildLearnerGraph("A-a->B-b->C-a->D-d->E / B-c->F-a->G-e->H / M-b-#N / M-c->P-a->S", "testKtails9",testConfig,getLabelConverter());
    Assert.assertEquals(-1,fsm.pairscores.computeStateScoreKTails(new StatePair(fsm.findVertex("M"),fsm.findVertex("B")), true));
    Assert.assertEquals(-1,fsm.pairscores.computeStateScoreKTails(new StatePair(fsm.findVertex("M"),fsm.findVertex("B")), false));
    Assert.assertEquals(-1,fsm.pairscores.computeStateScoreKTails(new StatePair(fsm.findVertex("B"),fsm.findVertex("M")), true));
    Assert.assertEquals(-1,fsm.pairscores.computeStateScoreKTails(new StatePair(fsm.findVertex("B"),fsm.findVertex("M")), false));
 
View Full Code Here

        innerLearner.addObserver(PickNegativesVisualiser.this);
        Learner mainDecorator = new AutoAnswers(innerLearner);
        if (conf.labelDetails != null)
          mainDecorator = new SmtLearnerDecorator(mainDecorator,conf.labelDetails);
            if (whomToNotify != null) whomToNotify.threadStarted();
            LearnerGraph graph = mainDecorator.learnMachine(sPlus, sMinus);
            if (graph != null)
            {
              DirectedSparseGraph learnt = graph.pathroutines.getGraph();
              if(conf.config.isGenerateTextOutput())
                OutputUtil.generateTextOutput(learnt,"textOutput.txt");
View Full Code Here

  /** Only matches for any path. */
  @Test
  public final void testKtails10()
  {
    testConfig.setKlimit(2);
    LearnerGraph fsm = FsmParser.buildLearnerGraph("A-a->B-b->C-a->D-d->E / B-c->F-a->G-e->H / M-b->N-a-#Q / M-c->P-a->S / P-b->R", "testKtails10",testConfig,getLabelConverter());
    Assert.assertEquals(-1,fsm.pairscores.computeStateScoreKTails(new StatePair(fsm.findVertex("M"),fsm.findVertex("B")), true));
    Assert.assertEquals(-1,fsm.pairscores.computeStateScoreKTails(new StatePair(fsm.findVertex("M"),fsm.findVertex("B")), false));
    Assert.assertEquals(-1,fsm.pairscores.computeStateScoreKTails(new StatePair(fsm.findVertex("B"),fsm.findVertex("M")), true));
    Assert.assertEquals(-1,fsm.pairscores.computeStateScoreKTails(new StatePair(fsm.findVertex("B"),fsm.findVertex("M")), false));
 
View Full Code Here

    DirectedSparseGraph g=FsmParser.buildLearnerGraphND("S-p->A-a->S\nA-b->S\nA-c->D\nA-b->D\nA-d->E\nS-n->U", "testMerge1a",config,getLabelConverter()).pathroutines.getGraph();
    Vertex
      s = DeterministicDirectedSparseGraph.findVertex(JUConstants.LABEL, VertexID.parseID("S"), g),
      d = DeterministicDirectedSparseGraph.findVertex(JUConstants.LABEL, VertexID.parseID("U"), g);
    OrigStatePair pair = new OrigStatePair(d,s);
    LearnerGraph
      mergeResultA = new LearnerGraph(Test_Orig_RPNIBlueFringeLearner.mergeAndDeterminize(g, pair),testConfig),
      expectedResult = buildLearnerGraph("S-p->A-a->S\nA-b->S\nA-c->S\nA-d->E\nS-n->S", "expected",testConfig,getLabelConverter());
    Assert.assertTrue(expectedResult.equals(mergeResultA));
  }
View Full Code Here

  }
   
  @Test(expected = IllegalArgumentException.class)
  public final void testMerge_fail2()
  {
    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(l, pair);
  }
View Full Code Here

    {
     
      @Override
      public LearnerGraph MergeAndDeterminize(LearnerGraph original, StatePair pair)
      {
        LearnerGraph outcome = null;
        int extraPhantomVertices = 0;
        if (useOptimizedMerge)
        {
          // Use the old and limited version to compute the merge because the general one is too slow on large graphs and we do not need either to merge arbitrary states or to handle "incompatibles".
          outcome = MergeStates.mergeAndDeterminize(original, pair);outcome.pathroutines.updateDepthLabelling();
        }
        else
        {
          Collection<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>> mergedVertices = new ArrayList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>>();
          long score = original.pairscores.computePairCompatibilityScore_general(pair,null,mergedVertices);
          outcome = MergeStates.mergeCollectionOfVertices(original,pair.getR(),mergedVertices);
         
          if (score != original.getStateNumber()-outcome.getStateNumber())
          {// This is either a bug somewhere in the merger or (most likely) that the phantomVertex has been removed by the generalised learner.
           // We are checking which of these two has happened in the code below.
           // The computation below is expensive on large graphs but only needs to be done once.
            LinkedHashSet<CmpVertex> removedStates = new LinkedHashSet<CmpVertex>();removedStates.addAll(original.transitionMatrix.keySet());
            removedStates.removeAll(outcome.transitionMatrix.keySet());removedStates.remove(pair.getQ());removedStates.remove(pair.getR());
            Assert.assertEquals(1,removedStates.size());// if it were a phantom vertex, there would only be one of them.
            CmpVertex tentativePhantom = removedStates.iterator().next();
            Set<Label> alphabetUsedOnPhantom = new TreeSet<Label>();alphabetUsedOnPhantom.addAll(original.pathroutines.computeAlphabet());
            for(Entry<Label,CmpVertex> transition:original.transitionMatrix.get(tentativePhantom).entrySet())
            {
              Assert.assertSame(tentativePhantom,transition.getValue());alphabetUsedOnPhantom.remove(transition.getKey());
            }
            Assert.assertEquals(0, alphabetUsedOnPhantom.size());
            extraPhantomVertices = 1;// now certain it was indeed a phantom vertex added when the PTA was initially built.
          }
         
          Assert.assertEquals(score+extraPhantomVertices,original.getStateNumber()-outcome.getStateNumber());
        }
        ScoreMode origScore = original.config.getLearnerScoreMode();original.config.setLearnerScoreMode(ScoreMode.COMPATIBILITY);
        long compatibilityScore = original.pairscores.computePairCompatibilityScore(pair);
        original.config.setLearnerScoreMode(origScore);
       
        Assert.assertEquals(compatibilityScore+1+extraPhantomVertices,original.getStateNumber()-outcome.getStateNumber());
        return outcome;
      }

      @Override
      public Stack<PairScore> ChooseStatePairs(LearnerGraph graph)
      {
        Stack<PairScore> outcome = graph.pairscores.chooseStatePairs(new PairScoreComputation.RedNodeSelectionProcedure(){

          @Override
          public CmpVertex selectRedNode(LearnerGraph coregraph,  @SuppressWarnings("unused") Collection<CmpVertex> reds, Collection<CmpVertex> tentativeRedNodes)
          {
            CmpVertex redVertex = null;
            if (listOfPairsToWrite != null)
            {
              redVertex = tentativeRedNodes.iterator().next();
              listOfPairsToWrite.add(new PairOfPaths(coregraph, new PairScore(null, redVertex, 0, 0)));
            }
           
            if(listOfPairsToCheckAgainstIterator != null)
            {
              PairOfPaths pair = listOfPairsToCheckAgainstIterator.next();
              Assert.assertNull(pair.getQ());
              redVertex = coregraph.getVertex(pair.getR());
            }
            return redVertex;
          }

          @SuppressWarnings("unused")
          @Override
          public CmpVertex resolvePotentialDeadEnd(LearnerGraph coregraph, Collection<CmpVertex> reds, List<PairScore> pairs) {
            return null;// do not resolve in any way
          }

          @Override
          public void initComputation(@SuppressWarnings("unused") LearnerGraph gr) {
            // dummy
          }

          @Override
          public long overrideScoreComputation(PairScore p) {
            return p.getScore();// dummy
          }

          @Override
          public Collection<Entry<Label, CmpVertex>> getSurroundingTransitions(@SuppressWarnings("unused") CmpVertex currentRed)
          {
            return null;// dummy, ignored if null.
          }
        });
       
        if (!outcome.isEmpty())
        {
          if (listOfPairsToWrite != null)
          {
            //System.out.println("Optimized: "+useOptimizedMerge+", matrix: "+graph.config.getTransitionMatrixImplType()+", pair : "+outcome.peek());
            listOfPairsToWrite.add(new PairOfPaths(graph, outcome.peek()));
          }
         
          if(listOfPairsToCheckAgainstIterator != null)
          {
            PairOfPaths pair = listOfPairsToCheckAgainstIterator.next();
            while(pair.getQ() == null)
              pair = listOfPairsToCheckAgainstIterator.next();// skip red pairs, we are no longer checking with selectRedNode collections of reds where there there is only one choice.
            //System.out.println("Choosing "+pair+" from "+outcome);
            //System.out.println("chosen "+outcome.peek()+", expected "+new PairScore(graph.getVertex(pair.getQ()),graph.getVertex(pair.getR()),0,0));
            pair.rebuildStack(graph, outcome);
          }
        }
       
        return outcome;
      }
   
      @Override
      public LearnerGraph init(Collection<List<Label>> plus,  Collection<List<Label>> minus)
      {
        if (initPta != null)
        {
          LearnerGraph graph = decoratedLearner.init(plus,minus);
          LearnerGraph.copyGraphs(initPta, graph);
          return initPta;
        }
        throw new IllegalArgumentException("should not be called");
      }
     
      @Override
      public LearnerGraph init(PTASequenceEngine engine, int plusSize, int minusSize)
      {
        LearnerGraph graph = decoratedLearner.init(engine,plusSize,minusSize);

        if (initPta != null)
        {
          LearnerGraph.copyGraphs(initPta, graph);
        }
View Full Code Here

TOP

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

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.