Package statechum.analysis.learning

Examples of statechum.analysis.learning.PairScore


  static public PairScore constructPairScore(String a,String b, int score, Configuration config)
  {
    CmpVertex aV = LearnerGraph.generateNewCmpVertex(new VertexID(a), config),
      bV = LearnerGraph.generateNewCmpVertex(new VertexID(b),config);
    return new PairScore(aV,bV, score,score);
  }
View Full Code Here


  public static Set<PairScore> addAllPermutations(Collection<PairScore> scores)
  {
    Set<PairScore> pairsSet = new TreeSet<PairScore>();
    for(PairScore p:scores)
    {
      pairsSet.add(p);pairsSet.add(new PairScore(p.secondElem,p.firstElem,p.getScore(),0));
    }
    return pairsSet;
  }
View Full Code Here

  {
    LearnerGraph gr = new LearnerGraph(buildGraph(machineCompatibility1,"TestComputeStateCompatibility1"),config);
   
    Set<PairScore> pairsSet = addAllPermutations(gr.linear.chooseStatePairs(PAIR_INCOMPATIBLE,10,ThreadNumber,null));
    Set<PairScore> expected = addAllPermutations(Arrays.asList(new PairScore[]{
        new PairScore(gr.findVertex("A"),gr.findVertex("A"),(int)(10*(1+k)),1),
        new PairScore(gr.findVertex("A"),gr.findVertex("B"),10,1),
        new PairScore(gr.findVertex("B"),gr.findVertex("B"),10,1),
        new PairScore(gr.findVertex("A"),gr.findVertex("C"),0,1),
        new PairScore(gr.findVertex("B"),gr.findVertex("C"),0,1),
        new PairScore(gr.findVertex("C"),gr.findVertex("C"),0,1)
    }));
    Assert.assertEquals(expected, pairsSet);
 
View Full Code Here

  public final void TestComputeStateCompatibility2b()
  {
    LearnerGraph gr=new LearnerGraph(buildGraph(machineCompatibility2,"TestComputeStateCompatibility1"),config);
    Set<PairScore> pairsSet = addAllPermutations(gr.linear.chooseStatePairs(PAIR_INCOMPATIBLE*2,10,ThreadNumber,null));
    Set<PairScore> exp = addAllPermutations(Arrays.asList(new PairScore[]{
        new PairScore(gr.findVertex("A"),gr.findVertex("A"),(int)(10*(1+k)),1),
        new PairScore(gr.findVertex("A"),gr.findVertex("B"),10*PAIR_INCOMPATIBLE,1),
        new PairScore(gr.findVertex("B"),gr.findVertex("B"),10,1),
        new PairScore(gr.findVertex("A"),gr.findVertex("C"),10*PAIR_INCOMPATIBLE,1),
        new PairScore(gr.findVertex("B"),gr.findVertex("C"),10*PAIR_INCOMPATIBLE,1),
        new PairScore(gr.findVertex("C"),gr.findVertex("C"),0,1)
    }));
    Assert.assertEquals(exp, pairsSet);
  }
View Full Code Here

  public final void TestComputeStateCompatibility2c()
  {
    LearnerGraph gr=new LearnerGraph(buildGraph(machineCompatibility2,"TestComputeStateCompatibility1"),config);
    Set<PairScore> pairsSet = addAllPermutations(gr.linear.chooseStatePairs(PAIR_INCOMPATIBLE,10,ThreadNumber,null));
    Set<PairScore> exp = addAllPermutations(Arrays.asList(new PairScore[]{
        new PairScore(gr.findVertex("A"),gr.findVertex("A"),(int)(10*(1+k)),1),
        new PairScore(gr.findVertex("B"),gr.findVertex("B"),10,1),
        new PairScore(gr.findVertex("C"),gr.findVertex("C"),0,1)
    }));
    Assert.assertEquals(exp, pairsSet);
  }
View Full Code Here

  public final void TestComputeStateCompatibility2d()
  {
    LearnerGraph gr=new LearnerGraph(buildGraph(machineCompatibility2,"TestComputeStateCompatibility1"),config);
    Set<PairScore> pairsSet = addAllPermutations(gr.linear.chooseStatePairs(1,10,ThreadNumber,null));
    Set<PairScore> exp = addAllPermutations(Arrays.asList(new PairScore[]{
        new PairScore(gr.findVertex("A"),gr.findVertex("A"),(int)(10*(1+k)),1)
    }));
    Assert.assertEquals(exp, pairsSet);
  }
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

                if (!fallbackToInitialPair)
                {
                  int scorePosition = pairScores[forward.vertexToIntNR(targetStateA,targetStateB)];
                  score = scoresForward[scorePosition] + scoresInverse[scorePosition];
                }
                currentWave.add(new PairScore(targetStateA,targetStateB,(int)(multiplier*score),0));
               
              }
        }
      }
    }
 
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.