Package statechum.analysis.learning

Examples of statechum.analysis.learning.PairScore


      if (!outcome.isEmpty())
      {
        dataCollector.updateDatasetWithPairs(outcome, graph, referenceGraph);// we learn from the whole range of pairs, not just the filtered ones
        List<PairScore> filteredPairs = filterPairsBasedOnMandatoryMerge(outcome,graph);
        assert !outcome.isEmpty() : "no feasible pairs left for a choice by QSM, this case should have been handled by resolvePotentialDeadEnd";
        PairScore chosenPair = pickCorrectPair(filteredPairs, graph);
        outcome.clear();outcome.push(chosenPair);
      }
     
      return outcome;
    }   
View Full Code Here


        dataCollector.buildSetsForComparatorsThatDoNotDependOnFiltering(pairs,tentativeGraph);
        for(PairScore p:pairs)
        {
          assert p.getScore() >= 0;
          if (!p.getQ().isAccept() || !p.getR().isAccept()) // if any are rejects, add with a score of zero, these will always work because accept-reject pairs will not get here and all rejects can be merged.
            possibleResults.add(new PairScore(p.getQ(), p.getR(), p.getScore(), 0));
          else
            nonNegPairs.add(p);// meaningful pairs, will check with the classifier
        }
       
        for(PairScore p:nonNegPairs)
        {
          try
          {
            int []comparisonResults = new int[dataCollector.getInstanceLength()];
            dataCollector.fillInPairDetails(comparisonResults,p, nonNegPairs);
            Instance instance = dataCollector.constructInstance(comparisonResults, true);
            double distribution[]=classifier.distributionForInstance(instance);
            long quality = obtainMeasureOfQualityFromDistribution(distribution,classTrue);
            if ( quality >= 0 )// && p.getScore() > 0)
            {
              possibleResults.add(new PairScore(p.getQ(), p.getR(), p.getScore(), quality));
            }
          }
          catch(Exception ex)
          {
            ex.printStackTrace();
View Full Code Here

     
      // if we are here, none of the pairs are clear candidates for mergers.
     
      dataCollector.buildSetsForComparatorsThatDoNotDependOnFiltering(pairs,tentativeGraph);

      PairScore pairBestToReturnAsRed = null;
      LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>> verticesToMerge = new LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>>();
      List<StatePair> pairsList = buildVerticesToMerge(tentativeGraph,labelsLeadingToStatesToBeMerged,labelsLeadingFromStatesToBeMerged);
     
      for(PairScore p:pairs)
      {
        if (!pairsList.isEmpty() && tentativeGraph.pairscores.computePairCompatibilityScore_general(p, pairsList, verticesToMerge) < 0)
        // This pair cannot be merged, return as red. Note that this computation is deferred to this stage from computePairScores in order to consider
        // only a small subset of pairs that are apparently compatible but will be incompatible once the mandatory merge conditions are taken into account.
          return p;
       
        // potentially meaningful pair, check with the classifier
        try
        {
          int []comparisonResults = new int[dataCollector.getInstanceLength()];
          dataCollector.fillInPairDetails(comparisonResults,p, pairs);
          Instance instance = dataCollector.constructInstance(comparisonResults, true);
          double distribution[]=classifier.distributionForInstance(instance);
          long quality = obtainMeasureOfQualityFromDistribution(distribution,classFalse);
          if ( quality > 0 )
          {
            if (pairBestToReturnAsRed == null || quality >pairBestToReturnAsRed.getAnotherScore())
              pairBestToReturnAsRed = new PairScore(p.getQ(), p.getR(), p.getScore(), quality);// this is the pair to return.
          }
          else // we are here because Weka was not confident that this pair should not be merged, hence check the score and if zero, consider blocking the merge.
          if (blacklistZeroScoringPairs && p.getScore() == 0)
          {// blacklisting pairs with zero score
            if (pairBestToReturnAsRed == null || pairBestToReturnAsRed.getAnotherScore() == 0)
              pairBestToReturnAsRed = new PairScore(p.getQ(), p.getR(), p.getScore(), 0);// this is the pair that may be mergeable but the score is zero and we hence blacklist it.
          }
          else
            return null;// this pair seems a plausible merge candidate.
        }
        catch(Exception ex)
View Full Code Here

          if (filteredPairs.isEmpty())
            stateToLabelRed = pairs.get(0).getQ();// if mandatory merge rules out all mergers, return any of the states to be marked red
          else
            if (classifierToChooseWhereNoMergeIsAppropriate)
            {
              PairScore worstPair = getPairToBeLabelledRed(filteredPairs,coregraph);
              if (worstPair != null)
              {
                stateToLabelRed = worstPair.getQ();
  /*
                long highestScore=-1;
                for(PairScore p:pairs)
                  if (p.getScore() > highestScore) highestScore = p.getScore();
                {
                  List<PairScore> pairOfInterest = Arrays.asList(new PairScore[]{worstPair});
                  List<PairScore> correctPairs = new ArrayList<PairScore>(pairOfInterest.size()), wrongPairs = new ArrayList<PairScore>(pairOfInterest.size());
                  SplitSetOfPairsIntoRightAndWrong(coregraph, referenceGraph, pairOfInterest, correctPairs, wrongPairs);
                  // this one is checking that wrong pairs because we aim to check that the pair chosen is not the right one to merge
                  System.out.println("resolvePotentialDeadEnd: pair forced red: "+stateToLabelRed+" pair: "+worstPair+" max score: "+highestScore+(wrongPairs.isEmpty()?" THAT IS INCORRECT":""));
                }
                */
              }
              //System.out.println("resolvePotentialDeadEnd: number of states considered = "+pairs.size()+" number of reds: "+reds.size()+(worstPair != null?(" pair chosen as the worst: "+worstPair):""));
            }
          return stateToLabelRed;// resolution depends on whether Weka has successfully guessed that all pairs are wrong.
        }
       
        @Override
        public void initComputation(@SuppressWarnings("unused") LearnerGraph gr) {
          // dummy
        }

        @Override
        public long overrideScoreComputation(PairScore p) {
          return p.getScore();// dummy
        }});
      if (!outcome.isEmpty())
      {
        List<PairScore> filteredPairs = filterPairsBasedOnMandatoryMerge(outcome,graph);
        assert !outcome.isEmpty() : "no feasible pairs left for a choice by QSM, this case should have been handled by resolvePotentialDeadEnd";

        //System.out.println("classifyPairs: number of states considered = "+filteredPairs.size()+" number of reds: "+graph.getRedStateNumber()+" ( before filtering "+outcome.size()+")");
        ArrayList<PairScore> possibleResults = classifyPairs(filteredPairs,graph);
        updateStatistics(pairQuality, graph,referenceGraph, filteredPairs);

        if (possibleResults.isEmpty())
        {
          possibleResults.add(pickPairQSMLike(filteredPairs));// no pairs have been provided by the modified algorithm, hence using the default one.
          //System.out.println("no suitable pair was found");
        }
        PairScore result = possibleResults.iterator().next();
        outcome.clear();outcome.push(result);
/*
        {
          List<PairScore> correctPairs = new ArrayList<PairScore>(outcome.size()), wrongPairs = new ArrayList<PairScore>(outcome.size());
          SplitSetOfPairsIntoRightAndWrong(graph, referenceGraph, outcome, correctPairs, wrongPairs);
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

    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

    public static int countChoices(Stack<PairScore> stack)
    {
      if (stack.isEmpty())
        return 0;
      int outcome = 1;
      PairScore top = stack.peek();
     
      int i=stack.size()-2;
      while(i>=0)
      {
        PairScore curr = stack.get(i);--i;
        if (curr.getScore() != top.getScore() || curr.getR() != top.getR() )
          break;
        ++outcome;
      }
      return outcome;
    }
View Full Code Here

   
   
    /** Returns the pair corresponding to the smallest or largest machine for one of the pairs with the same score at the top of the stack. */
    public static PairScore selectPairMinMax(LearnerGraph graph, Stack<PairScore> stack, int pairChoice)
    {
      PairScore top = stack.peek();
      int value = MergeStates.mergeAndDeterminize(graph, top).getStateNumber();
      int i=stack.size()-2;
      while(i>=0)
      {
        PairScore pair = stack.get(i);--i;
        if (pair.getScore() != top.getScore()) break;
        int stateNumber = MergeStates.mergeAndDeterminize(graph, pair).getStateNumber();
        switch(pairChoice)
        {
        case pairchoiceMIN:
          if (stateNumber < value)
View Full Code Here

    }
   
    /** Picks a pair at the top of the stack at random. */
    public static PairScore selectPairAtRandom(Stack<PairScore> stack, Random rnd)
    {
      PairScore top = stack.get(stack.size()-1-rnd.nextInt(countChoices(stack)));
      assert top.getScore() == stack.peek().getScore();
      return top;
    }
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.