Examples of PairScore


Examples of statechum.analysis.learning.PairScore

          LearnerAbortedException.throwExceptionIfTooManyReds(coregraph);
          return super.overrideScoreComputation(p);
        }});
      if (!outcome.isEmpty())
      {
        PairScore chosenPair = pickPairQSMLike(outcome);
        outcome.clear();outcome.push(chosenPair);
      }
     
      return outcome;
    }   
View Full Code Here

Examples of statechum.analysis.learning.PairScore

      if (pairs.size() != pairsAndScores.size())
        throw new IllegalArgumentException("different sizes of ChooseStatePairs collections of pairs, \n"+pairs+" v.s. \n"+pairsAndScores);
      Iterator<PairScore> ps1 = pairs.iterator(), ps2=pairsAndScores.iterator();
      while(ps1.hasNext())
      {
        PairScore p1 = ps1.next(),p2=ps2.next();
        if (!p1.getQ().getID().equals(p2.getQ().getID()) || !p1.getR().getID().equals(p2.getR().getID()) ||
            p1.getScore() != p2.getScore() || p1.getAnotherScore() != p2.getAnotherScore())
          throw new IllegalArgumentException("different ChooseStatePairs pairs, "+p1+" v.s. "+p2);
      }
     
      pairs =null;// reset stored data
    }
View Full Code Here

Examples of statechum.analysis.learning.PairScore

          return null;// dummy, ignored if null.
        }
      });
      if (!outcome.isEmpty())
      {
        PairScore chosenPair = pickPairQSMLike(outcome);
        updateStatistics(pairQuality, graph,referenceGraph, outcome);
        outcome.clear();outcome.push(chosenPair);
      }
     
      return outcome;
View Full Code Here

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

Examples of statechum.analysis.learning.PairScore

        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

Examples of statechum.analysis.learning.PairScore

     
      // 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

Examples of statechum.analysis.learning.PairScore

          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
        }

        @Override
        public Collection<Entry<Label, CmpVertex>> getSurroundingTransitions(@SuppressWarnings("unused") CmpVertex currentRed)
        {
          return null;// dummy, ignored if null.
        }
      });
      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

Examples of statechum.analysis.learning.PairScore

            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

Examples of statechum.analysis.learning.PairScore

  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

Examples of statechum.analysis.learning.PairScore

                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
TOP
Copyright © 2018 www.massapi.com. 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.