Package statechum.analysis.learning

Examples of statechum.analysis.learning.PairScore


  public LearnerGraph MergeAndDeterminize(LearnerGraph original, StatePair pair)
  {
    LearnerGraph result = decoratedLearner.MergeAndDeterminize(original, pair);
    Element mergedGraph = series.writeGraph(result);
    Element mergeNode = doc.createElement(StatechumXML.ELEM_MERGEANDDETERMINIZE.name());
    mergeNode.appendChild(mergedGraph);mergeNode.appendChild(writePair(new PairScore(pair.getQ(),pair.getR(),0,0),doc));
    writeElement(mergeNode);
    return result;
  }
View Full Code Here


          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

      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
        }

        @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

          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

    {
      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;

        outcome.clear();outcome.push(result);
     
      return outcome;
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() )
                     if (curr.getScore() != top.getScore())

                           break;
                   ++outcome;
           }
           return outcome;
View Full Code Here

       public static int countChoicesOther(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() )
                     if (curr.getAnotherScore() != top.getAnotherScore())

                           break;
                   ++outcome;
           }
           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.