Package statechum.analysis.learning

Examples of statechum.analysis.learning.PairScore


           
            @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


          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

    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

            CmpVertex currentBlueState = BlueEntry.getValue();
           
            int numberOfCompatiblePairs = 0;
            for(CmpVertex oldRed:reds)
            {
              PairScore pair = obtainPair(currentBlueState,oldRed,decisionProcedure);
              if (pair.getScore() >= coregraph.config.getGeneralisationThreshold())
              {
                coregraph.pairsAndScores.add(pair);
                ++numberOfCompatiblePairs;
                if (GlobalConfiguration.getConfiguration().isAssertEnabled() && coregraph.config.getDebugMode()) PathRoutines.checkPTAConsistency(coregraph, currentBlueState);
              }
View Full Code Here

  public PairScore obtainPair(CmpVertex blue, CmpVertex red, ScoreComputationCallback scoreComputationOverride)
  {
    long computedScore = -1, compatibilityScore =-1;StatePair pairToComputeFrom = new StatePair(blue,red);
    if (coregraph.config.getLearnerScoreMode() == Configuration.ScoreMode.ONLYOVERRIDE)
    {
      computedScore = scoreComputationOverride.overrideScoreComputation(new PairScore(blue,red,0, 0));compatibilityScore=computedScore;
      return new PairScore(blue,red,computedScore, compatibilityScore);
    }
    else   
    if (coregraph.config.getLearnerScoreMode() == Configuration.ScoreMode.COMPATIBILITY)
    {
      computedScore = computePairCompatibilityScore(pairToComputeFrom);compatibilityScore=computedScore;
    }
    else   
    if (coregraph.config.getLearnerScoreMode() == Configuration.ScoreMode.GENERAL)
    {
      Collection<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>> collectionOfVerticesToMerge = new ArrayList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>>();
      computedScore = computePairCompatibilityScore_general(pairToComputeFrom,null,collectionOfVerticesToMerge);compatibilityScore=computedScore;
    }
    if (coregraph.config.getLearnerScoreMode()==Configuration.ScoreMode.KTAILS)
    {
      computedScore = coregraph.pairscores.computeStateScore(pairToComputeFrom);
      if (computedScore >= 0)
        computedScore = coregraph.pairscores.computeStateScoreKTails(pairToComputeFrom,false);
    }
    else
      if (coregraph.config.getLearnerScoreMode()==Configuration.ScoreMode.KTAILS_ANY)
      {
        computedScore = coregraph.pairscores.computeStateScore(pairToComputeFrom);
        if (computedScore >= 0)
          computedScore = coregraph.pairscores.computeStateScoreKTails(pairToComputeFrom,true);
      }
      else
      {
        computedScore = coregraph.pairscores.computeStateScore(pairToComputeFrom);
        if (computedScore >= 0)
        {
          compatibilityScore=  computePairCompatibilityScore(pairToComputeFrom);
          if (compatibilityScore < 0)
            computedScore = -1;
        }
       
        else
        if (GlobalConfiguration.getConfiguration().isAssertEnabled())
        {
          int compatScore = computePairCompatibilityScore(pairToComputeFrom);
          assert compatScore <= computedScore;
        }
      }

    if (blue.isAccept() && computedScore < coregraph.config.getRejectPositivePairsWithScoresLessThan())
      computedScore = -1;
   
    if (computedScore >= 0 && scoreComputationOverride != null)
      computedScore = scoreComputationOverride.overrideScoreComputation(new PairScore(blue,red,computedScore, compatibilityScore));
    return new PairScore(blue,red,computedScore, compatibilityScore);
  }
View Full Code Here

                int score = 0;

                if (!AbstractLearnerGraph.checkCompatible(stateB.getKey(),entryA.getKey(),coregraph.pairCompatibility)) score=GDLearnerGraph.PAIR_INCOMPATIBLE;

                if (score>threshold)
                  resultsPerThread[threadNo].add(new PairScore(entryA.getKey(),stateB.getKey(),(int)(scale*score),0));

                if (stateB.getKey().equals(entryA.getKey())) break; // we only process a triangular subset.
              }
            }// B-loop
          }
View Full Code Here

            score = -1;
          return score;
        }});
      if (!outcome.isEmpty())
      {
        PairScore chosenPair = pickPairQSMLike(outcome);
        outcome.clear();outcome.push(chosenPair);
      }
     
      return outcome;
    }   
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.