Package statechum.analysis.learning

Examples of statechum.analysis.learning.PairScore


           
            List<CmpVertex> targetCollectionB = matrixForward.transitionMatrix.get(pair.getR()).get(targetCollectionA.getKey());
            if (targetCollectionB != null && targetCollectionB.size() == 1)
            {// matched deterministic pair
              CmpVertex targetB = targetCollectionB.get(0);
              PairScore newPair = checkAndAddIfPairIsMatched(targetA, targetB);
              if (newPair != null)
              {
                waveToAppendTo.add(newPair);
                stateAdded = true;// this means we need to iterate in order to recursively process the next pair
              }
            }
          }
        // inverse
        for(Entry<String,List<CmpVertex>> targetCollectionA:matrixInverse.transitionMatrix.get(pair.getQ()).entrySet())
          if (targetCollectionA.getValue().size() == 1)
          {
            CmpVertex targetA = targetCollectionA.getValue().get(0);
           
            List<CmpVertex> targetCollectionB = matrixInverse.transitionMatrix.get(pair.getR()).get(targetCollectionA.getKey());
            if (targetCollectionB != null && targetCollectionB.size() == 1)
            {// matched deterministic pair
              CmpVertex targetB = targetCollectionB.get(0);
              PairScore newPair = checkAndAddIfPairIsMatched(targetA, targetB);
              if (newPair != null)
              {
                waveToAppendTo.add(newPair);
                stateAdded = true;// this means we need to iterate in order to recursively process the next pair
              }
View Full Code Here


    frontWave.addAll(currentWave);currentWave.clear();
  }
 
  private PairScore checkAndAddIfPairIsMatched(CmpVertex targetA, CmpVertex targetB)
  {
    PairScore result = null;
    if (!statesInKeyPairs.contains(targetA) && !statesInKeyPairs.contains(targetB) &&
        AbstractLearnerGraph.checkCompatible(targetA, targetB, grCombined.pairCompatibility))
    {
      PairScore newPair = new PairScore(targetA,targetB,Integer.MAX_VALUE,0);
      statesInKeyPairs.add(targetA);statesInKeyPairs.add(targetB);
      currentWave.add(newPair);result = newPair;
    }
    return result;
  }
View Full Code Here

   
    for(Entry<CmpVertex,CmpVertex> pair:aTOb.entrySet())
    {
      if (initialKeyA.containsKey(pair.getKey()))
      {
        PairScore pairscore = initialKeyA.get(pair.getKey());
        renameVertex(pair.getKey().getID(),"(K "+pairscore.getScore()+","+pairscore.getAnotherScore()+"="+newBToOrig.get(pair.getValue()).getID()+")",oldVerticesToNew);
      }
      else
      {
        int scorePosition = pairScores[forward.vertexToIntNR(pair.getKey(),pair.getValue())];
        double score = scoresForward[scorePosition] + scoresInverse[scorePosition];
View Full Code Here

    List<StatePair> pairsToMerge = new LinkedList<StatePair>();
    for(Entry<CmpVertex,Map<Label,CmpVertex>> entry:merged.transitionMatrix.entrySet())
      for(Entry<Label,CmpVertex> transition:entry.getValue().entrySet())
        if (merged.transitionMatrix.get(transition.getValue()).containsKey(transition.getKey()))
        {// we have a potential loop
          PairScore p = new PairScore(entry.getKey(),transition.getValue(),0,0);
          ArrayList<PairScore> pairOfInterest = new ArrayList<PairScore>(1);pairOfInterest.add(p);
          List<PairScore> correctPairs = new ArrayList<PairScore>(1), wrongPairs = new ArrayList<PairScore>(1);
          SplitSetOfPairsIntoRightAndWrong(ptaClassifier.graph, referenceGraph, pairOfInterest, correctPairs, wrongPairs);
         
          verticesToMerge = new LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>>();
          long genScore = ptaClassifier.graph.pairscores.computePairCompatibilityScore_general(p, null, verticesToMerge);
          LearnerGraph mergedForThisPair = MergeStates.mergeCollectionOfVertices(ptaClassifier.graph, null, verticesToMerge);
          long value = MarkovClassifier.computeInconsistency(mergedForThisPair, ptaClassifier.model, checker,false);
         
          boolean decidedToMerge= (value == 0 && genScore >= genScoreThreshold);
          if (decidedToMerge)
          {
            pairsToMerge.add(p);
            ++nrOfMergers;
          }
         
          if ( !wrongPairs.isEmpty() && decidedToMerge)
              //(wrongPairs.isEmpty() && value > 0 || genScore < genScoreThreshold) ||  (!wrongPairs.isEmpty() && value == 0 && genScore >= genScoreThreshold))
          {
            System.out.println( p.toString()+(wrongPairs.isEmpty()?"valid, ":"invalid:")+value+ "(score "+genScore+")");
            System.out.println( "R: " + ptaClassifier.graph.transitionMatrix.get(p.getR())+" B: "+ptaClassifier.graph.transitionMatrix.get(p.getQ()));
          }
        }
    System.out.println("mergers identified: "+nrOfMergers);
    /*
    long genScore = graph.pairscores.computePairCompatibilityScore_general(null, pairsToMerge, verticesToMerge);
View Full Code Here

    constructPairsToMergeBasedOnSetsToMerge(graph.transitionMatrix.keySet(),verticesToMergeBasedOnInitialPTA);   
    for(CmpVertex v0:tr)
      for(CmpVertex v1:tr)
        if (v0 != v1)
        {
          PairScore p = new PairScore(v0,v1,0,0);
          ArrayList<PairScore> pairOfInterest = new ArrayList<PairScore>(1);pairOfInterest.add(p);
          List<PairScore> correctPairs = new ArrayList<PairScore>(1), wrongPairs = new ArrayList<PairScore>(1);
          SplitSetOfPairsIntoRightAndWrong(graph, referenceGraph, pairOfInterest, correctPairs, wrongPairs);
         
          verticesToMerge = new LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>>();
          genScore = graph.pairscores.computePairCompatibilityScore_general(p, null, verticesToMerge);
          LearnerGraph merged = MergeStates.mergeCollectionOfVertices(graph, null, verticesToMerge);
          long value = MarkovClassifier.computeInconsistency(merged, ptaClassifier.model, checker,false);
          if ( (wrongPairs.isEmpty() && value > 0) ||  (!wrongPairs.isEmpty() && value == 0))
          {
            System.out.println( p.toString()+(wrongPairs.isEmpty()?"valid, ":"invalid:")+value+ "(score "+genScore+")");
            System.out.println( "R: " + graph.transitionMatrix.get(p.getR())+" B: "+graph.transitionMatrix.get(p.getQ()));
          }
        }
   
    System.out.println("finished dumping inconsistencies");
  }
View Full Code Here

    for(CmpVertex A:gr.transitionMatrix.keySet())
      if (A.isAccept())
        for(CmpVertex B:gr.transitionMatrix.keySet())
          if (B.isAccept())
          {
            PairScore received1 = gr.linear.getPairScore(gr.wmethod.vertexToIntNR(A,B), 1, 2);
            Assert.assertTrue(
                received1.equals(new PairScore(A,B,1,2)) ||
                received1.equals(new PairScore(B,A,1,2))
            );
           
            PairScore received2 = gr.linear.getPairScore(gr.wmethod.vertexToIntNR(B,A), 1, 2);
            Assert.assertTrue(
                received2.equals(new PairScore(A,B,1,2)) ||
                received2.equals(new PairScore(B,A,1,2))
            );
          }
  }
View Full Code Here

          return null;// negatives can always be merged.
      }
     
      // if we are here, none of the pairs are clear candidates for mergers.

      PairScore pairBestToReturnAsRed = null;
      long worstPairScore=0;
      for(PairScore p:pairs)
      {
        /*
        long pairScore = classifyPairBasedOnUnexpectedTransitions(p,tentativeGraph,Markov);
View Full Code Here

    {
      Stack<PairScore> outcome = graph.pairscores.chooseStatePairs(LearnerMarkovPassive.this.computationOverride);
     
      if (!outcome.isEmpty())
      {
        PairScore result = null;
        result=pickPairQSMLike(outcome);
        assert result!=null;
        assert result.getScore()>=0;
/*
         List<PairScore> correctPairs = new ArrayList<PairScore>(1), wrongPairs = new ArrayList<PairScore>(1);
        List<PairScore> pairs = new ArrayList<PairScore>(1);pairs.add(result);
        SplitSetOfPairsIntoRightAndWrong(graph, referenceGraph, pairs, correctPairs, wrongPairs);
        if (!correctPairs.isEmpty())
View Full Code Here

   
    public List<PairScore> pickPairToRed(Collection<PairScore> pairs)
    {
      assert pairs != null;
      List<PairScore> bad =new ArrayList<PairScore>();
      PairScore badPair=null;
      for(PairScore P:pairs)
      {
        if(badPair == null)
          badPair=P;
        else if(P.getScore() < badPair.getScore())
          badPair=P;
      }
      bad.add(badPair);

      for(PairScore P:pairs)
      {
        if(badPair.getScore()==P.getScore() && !bad.contains(P))
        bad.add(P);
      }
      return bad;
    }
View Full Code Here

           
            @SuppressWarnings("unused")
            @Override
            public CmpVertex resolvePotentialDeadEnd(LearnerGraph gr, Collection<CmpVertex> reds, List<PairScore> pairs)
            {
              PairScore p = LearnerThatCanClassifyPairs.pickPairQSMLike(pairs);
              LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>> verticesToMerge = new LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>>();
              // constructPairsToMergeBasedOnSetsToMerge(coregraph.transitionMatrix.keySet(),verticesToMergeBasedOnInitialPTA)
              int genScore = coregraph.pairscores.computePairCompatibilityScore_general(p, null, verticesToMerge);
              assert genScore >= 0;
              LearnerGraph merged = MergeStates.mergeCollectionOfVertices(coregraph, null, verticesToMerge);
              long value = MarkovClassifier.computeInconsistency(merged, m, checker,false);
              inconsistencyFromAnEarlierIteration = value;
              return null;
            }
           
            long inconsistencyFromAnEarlierIteration = 0;
            LearnerGraph coregraph = null;
           
            LearnerGraphND inverseGraph = null;
            /** Where I have a set of paths to merge because I have identified specific states, this map is constructed that maps vertices to be merged together to the partition number that corresponds to them. */
            Map<CmpVertex,Integer> vertexToPartition = new TreeMap<CmpVertex,Integer>();
           
            @Override
            public void initComputation(LearnerGraph graph)
            {
              coregraph = graph;
              //labelStatesAwayFromRoot(coregraph,m.getChunkLen()-1);
              inverseGraph = (LearnerGraphND)MarkovClassifier.computeInverseGraph(coregraph,true);
              vertexToPartition.clear();
              int partitionNumber=0;
              for(Set<CmpVertex> set:verticesToMergeBasedOnInitialPTA)
              {
                for(CmpVertex v:set) vertexToPartition.put(v, partitionNumber);
                ++partitionNumber;
              }
            }
           
            @Override
            public long overrideScoreComputation(PairScore p)
            {
              /*
              MarkovClassifier cl = new MarkovClassifier(m, coregraph);
              long score = 0;
              Map<Label, MarkovOutcome> predictedFromRed=cl.predictTransitionsFromState(p.getR(), null, m.getChunkLen(), null);
              for(Entry<Label,MarkovOutcome> entry:cl.predictTransitionsFromState(p.getQ(), null, m.getChunkLen(), null).entrySet())
              {
                MarkovOutcome red = predictedFromRed.get(entry.getKey());
                if (red == null || red != entry.getValue())
                {
                  score = -1;break;
                }
              }
             
              if (score >= 0)
              {
                LearnerGraph extendedGraph = cl.constructMarkovTentative();
                score = extendedGraph.pairscores.computePairCompatibilityScore(p);
              }
              */

              long score = p.getScore();//computeScoreUsingMarkovFanouts(coregraph,origInverse,m,callbackAlphabet,p);
              if (score < 0)
                return score;
              long currentInconsistency = 0;
              Integer a=vertexToPartition.get(p.getR()), b = vertexToPartition.get(p.getQ());
              LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>> verticesToMerge = new LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>>();
              int genScore = coregraph.pairscores.computePairCompatibilityScore_general(p, null, verticesToMerge);
              if (genScore >= 0)
              {
                LearnerGraph merged = MergeStates.mergeCollectionOfVertices(coregraph, null, verticesToMerge);
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.PairScore

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.