Package statechum.analysis.learning

Examples of statechum.analysis.learning.StatePair


  @Test
  public final void testVertexToInt2()
  {
    LearnerGraph textGraph = new LearnerGraph(buildGraph("A-a->A-b->B-c->C","testCheckGraphNumeric"),config);
    LearnerGraph numericGraph = new LearnerGraph(config);CmpVertex newInit = Transform.addToGraph(numericGraph, textGraph);
    numericGraph = MergeStates.mergeAndDeterminize_general(numericGraph, new StatePair(newInit,numericGraph.paths.getVertex(new LinkedList<String>())));
    CmpVertex A = numericGraph.paths.getVertex(Arrays.asList(new String[]{})),
      B = numericGraph.paths.getVertex(Arrays.asList(new String[]{"b"})),
      C = numericGraph.paths.getVertex(Arrays.asList(new String[]{"b","c"}));
    /*  ABC
     *A 013
View Full Code Here


            }
        }
      }
      if (statesIntersect)
      {
        System.err.println("bumped score for "+new StatePair(pair.firstElem, pair.secondElem));
        graph.pairsAndScores.set(i, new PairScore(pair.firstElem, pair.secondElem,
            pair.getScore()+1,pair.getAnotherScore()));
      }
      else
        System.err.println("no bump for "+new StatePair(pair.firstElem, pair.secondElem));
    }
    return graph.pairscores.getSortedPairsAndScoresStackFromUnsorted();
  }
View Full Code Here

                    synchronized (currentExplorationBoundary)
                    {
                      if (!sourceData.contains(sourcePair))
                      {
                        sourceData.add(sourcePair);
                        currentExplorationBoundary.add(new StatePair(srcB,srcA));
                      }
                    }
                  }
              }
            }
          }// if intersects
          else
            if (incompatiblePairs[currentStatePair] != PAIR_INCOMPATIBLE) // it is not possible for this loop to set this -
              // we are going through the vertices sequentially, but it could have been set by whoever called us.
            incompatiblePairs[currentStatePair]=PAIR_OK;// potentially compatible pair

          if (stateB.getKey().equals(entryA.getKey())) break; // we only process a triangular subset.
        }// B-loop
      }
    });
    performRowTasks(handlerList, ThreadNumber, matrixForward.transitionMatrix, filter,
        GDLearnerGraph.partitionWorkLoadTriangular(ThreadNumber,matrixForward.transitionMatrix.size()));
    //inputsAccepted=null;inputsRejected=null;
   
    // At this point, we've marked all clearly incompatible pairs of states and need to propagate
    // this information further, to states which have transitions leading to the currently considered set of states.
    // This part is not run in parallel on multiple CPUs (we expect it to do little most of the time),
    // hence no need to split the processing and/or lock currentExplorationBoundary
    while(!currentExplorationBoundary.isEmpty())
    {
      StatePair pair = currentExplorationBoundary.remove();
     
      int currentStatePair = vertexToIntNR(pair.firstElem,pair.secondElem);
      incompatiblePairs[currentStatePair]=PAIR_INCOMPATIBLE;

      Map<Label,List<CmpVertex>> rowB = matrixInverse.transitionMatrix.get(pair.secondElem);
     
      for(Entry<Label,List<CmpVertex>> outLabel:matrixInverse.transitionMatrix.get(pair.firstElem).entrySet())
      {
        List<CmpVertex> to = rowB.get(outLabel.getKey());
        if (to != null)
        {// matched pair of transitions, now we need to build a cross-product
         // of the states leading to the current pair of states, that is,
         // to (entryA.getKey(),stateB)
          for(CmpVertex srcA:outLabel.getValue())
            for(CmpVertex srcB:to)
            {
              // It is possible that for the same inputs (srcA,srcB)=(A,B) and (B,A)
              // in this case, we have to avoid including (B,A) in the list, but
              // it is not known in advance if any such case occurs, so we have to store
              // the pairs we encountered and eliminate them. Happily, this is handled by
              // incompatiblePairs[sourcePair]=PAIR_INCOMPATIBLE
              int sourcePair = vertexToIntNR(srcA, srcB);
              if (incompatiblePairs[sourcePair] == PAIR_OK)
              {
                currentExplorationBoundary.offer(new StatePair(srcA,srcB)); // append to the list
                incompatiblePairs[sourcePair]=PAIR_INCOMPATIBLE;
              }
            }
        }
      }
View Full Code Here

    return new PairScore(aV,bV, score,score);
  }

  static protected void checkLess(String a, String b, int abS, String c, String d, int cdS, Configuration config)
  {
    StatePair p = constructPairScore(a,b,abS,config),
        q=constructPairScore(c,d,cdS,config);
    assertFalse(p.equals(q));
    assertTrue(p.compareTo(q)<0);
    assertTrue(q.compareTo(p)>0);
    assertFalse(p.hashCode() == q.hashCode());
    assertEquals(0,p.compareTo(p));
    assertEquals(0,q.compareTo(q));
  }
View Full Code Here

  }

  @Test
  public void testPairScoreEquality()
  {
    StatePair p = constructPairScore("a","b",4,testConfig), q=constructPairScore("a","b",4,testConfig);
    assertTrue(p.equals(p));
    assertTrue(p.equals(q));
    assertFalse(p.equals(null));
    assertFalse(p.equals("test"));
    assertFalse(p.equals(constructPairScore("a","c",4,testConfig)));
    assertFalse(p.equals(constructPairScore("a","b",6,testConfig)));
    assertFalse(p.equals(constructPairScore("b","b",4,testConfig)));
  }
View Full Code Here

        for(Entry<Label,List<CmpVertex>> transition:entry.getValue().entrySet())
          for(CmpVertex target:transition.getValue())
          {
            DeterministicVertex targetVertex = DeterministicDirectedSparseGraph.findVertexNamed(target,graphToUpdate);
            if (targetVertex == null) targetVertex = addVertex(graphToUpdate, target);
            DeterministicEdge e = pairsToNewEdges.get(new StatePair(from,target));
            if (e == null)
            {
                e = new DeterministicEdge(fromVertex,targetVertex);
                Set<Label> labels = new TreeSet<Label>();labels.add(transition.getKey());
                e.addUserDatum(JUConstants.LABEL, labels, UserData.CLONE);e.addUserDatum(JUConstants.DIFF, color, UserData.SHARED);
                graphToUpdate.addEdge(e);
                pairsToNewEdges.put(new StatePair(from,target),e);
            }
            else
              ((Set<Label>)e.getUserDatum(JUConstants.LABEL)).add(transition.getKey());
           
View Full Code Here

   
    // Here P is a singleton and R is empty, hence they are ignored.
    List<StatePair> outcome = PairQualityLearner.collectionOfSetsToPairs(collectionOfSets);
    // three pairs, here we have a hardwired expected response that unfortunately depends on the implementation of collectionOfSetsToPairs.
    Assert.assertEquals(3,outcome.size());
    Assert.assertTrue(outcome.contains(new StatePair(gr.findVertex("B"),gr.findVertex("C"))));
    Assert.assertTrue(outcome.contains(new StatePair(gr.findVertex("C"),gr.findVertex("D"))));
    Assert.assertTrue(outcome.contains(new StatePair(gr.findVertex("D"),gr.findVertex("E"))));
  }
View Full Code Here

    final Map<StatePair,TransitionChanges> pairToNumberOfChanges = new TreeMap<StatePair,TransitionChanges>();
    for(Entry<CmpVertex,Map<Label,TARGET_A_TYPE>> entry:a.transitionMatrix.entrySet())
      for(Entry<Label,TARGET_A_TYPE> transition:entry.getValue().entrySet())
        for(CmpVertex target:a.getTargets(transition.getValue()))
        {
          TransitionChanges changes = pairToNumberOfChanges.get(new StatePair(entry.getKey(), target));
          if (changes == null)
          {
            changes = new TransitionChanges();pairToNumberOfChanges.put(new StatePair(entry.getKey(), target),changes);
          }
          changes.orig++;// we populate our map with the existing transitions
         
        }
    makeSteps();
    computeDifference(new PatchGraph() {
      protected Label copyVertexWithPrefix(String prefix, Label origLabel)
      {
        Label result = null;
        if (origLabel instanceof StringLabel)
          result = new StringLabel(prefix+origLabel);
        else
        if (origLabel instanceof ErlangLabel)
        {
          ErlangLabel oErl = (ErlangLabel)origLabel;
          result = new ErlangLabel(oErl.function,prefix+oErl.callName,
              oErl.input, oErl.expectedOutput);
        }
        else
          assert false;
       
        return result;
      }
     
      @Override
      public void addTransition(CmpVertex from, Label origLabel, CmpVertex to)
      {
        Label label = copyVertexWithPrefix("ADD_",origLabel);
        mutator.addTransition(from, label, to);
        TransitionChanges changes = pairToNumberOfChanges.get(new StatePair(from,to));
        if (changes == null)
        {
          changes = new TransitionChanges();pairToNumberOfChanges.put(new StatePair(from,to),changes);
        }
        changes.added++;
      }

      @Override
      public void removeTransition(CmpVertex from, Label origLabel, CmpVertex to)
      {
        Label label = copyVertexWithPrefix("REM_",origLabel);
        mutator.removeTransition(from, origLabel, to);// remove the original transition
        mutator.addTransition(from, label, to);// and add the renamed one
        TransitionChanges changes = pairToNumberOfChanges.get(new StatePair(from,to));
        if (changes == null)
        {
          changes = new TransitionChanges();pairToNumberOfChanges.put(new StatePair(from,to),changes);
        }
        changes.removed++;
      }

      @Override
View Full Code Here

   
    // Here P is a singleton and R is empty, hence they are ignored.
    List<StatePair> outcome = MarkovClassifier.collectionOfSetsToPairs(collectionOfSets);
    // three pairs, here we have a hardwired expected response that unfortunately depends on the implementation of collectionOfSetsToPairs.
    Assert.assertEquals(3,outcome.size());
    Assert.assertTrue(outcome.contains(new StatePair(gr.findVertex("B"),gr.findVertex("C"))));
    Assert.assertTrue(outcome.contains(new StatePair(gr.findVertex("C"),gr.findVertex("D"))));
    Assert.assertTrue(outcome.contains(new StatePair(gr.findVertex("D"),gr.findVertex("E"))));
  }
View Full Code Here

  }
 
  protected PairScore obtainPair(CmpVertex blue, CmpVertex red)
  {
    if (coregraph.learnerCache.maxScore < 0) coregraph.learnerCache.maxScore = coregraph.transitionMatrix.size()*coregraph.wmethod.computeAlphabet().size();
    int computedScore = -1, compatibilityScore =-1;StatePair pairToComputeFrom = new StatePair(blue,red);
    if (coregraph.config.getLearnerScoreMode() == Configuration.ScoreMode.COMPATIBILITY)
    {
      computedScore = computePairCompatibilityScore(pairToComputeFrom);compatibilityScore=computedScore;
    }
    else
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.StatePair

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.