Package statechum.analysis.learning.PrecisionRecall

Examples of statechum.analysis.learning.PrecisionRecall.ConfusionMatrix


  {
    Configuration config = Configuration.getDefaultConfiguration();
    LearnerGraph from = buildLearnerGraph("A-a->A-b->B / A-c-#C","testClassify1a",config),
    to=buildLearnerGraph("A-b->A-a->B","testClassify1b",config);
   
    ConfusionMatrix matrix = DiffExperiments.classify(TestFSMAlgo.buildSet(new String[][]{
        new String[]{"a","a"} // FN
        ,new String[]{"b","b"} // FP
        ,new String[]{"c"} // TN
    },config), from, to);
    Assert.assertEquals(0.,matrix.getPrecision(),Configuration.fpAccuracy);
    Assert.assertEquals(0,matrix.getRecall(),Configuration.fpAccuracy);
    Assert.assertEquals(0.,matrix.fMeasure(),Configuration.fpAccuracy);
    Assert.assertEquals(0.5,matrix.getSpecificity(),Configuration.fpAccuracy);
    Assert.assertEquals(0.25,matrix.BCR(),Configuration.fpAccuracy);
  }
View Full Code Here


  {
    Configuration config = Configuration.getDefaultConfiguration();
    LearnerGraph from = buildLearnerGraph("A-a->A-b->B / A-c-#C","testClassify1a",config),
    to=buildLearnerGraph("A-b->A-a->B","testClassify1b",config);
   
    ConfusionMatrix matrix = DiffExperiments.classify(TestFSMAlgo.buildSet(new String[][]{
        new String[] {"a"} // TP
        ,new String[] {"b"} // TP
        ,new String[]{"b","b"} // FP
        ,new String[]{"c"} // TN
    },config), from, to);
    Assert.assertEquals(2./3.,matrix.getPrecision(),Configuration.fpAccuracy);
    Assert.assertEquals(1,matrix.getRecall(),Configuration.fpAccuracy);
    Assert.assertEquals(0.8,matrix.fMeasure(),Configuration.fpAccuracy);
    Assert.assertEquals(0.5,matrix.getSpecificity(),Configuration.fpAccuracy);
    Assert.assertEquals(0.75,matrix.BCR(),Configuration.fpAccuracy);
  }
View Full Code Here

      for(List<Label> seq:sMinus)
        pta.paths.augmentPTA(seq,false,false,null);
      pta.clearColours();
      new MarkovClassifier(m, pta).updateMarkov(false);// construct Markov chain
      // For Markov, we do not need to learn anything at all - our Markov matrix contains enough information to classify paths and hence compare it to the reference graph.
      ConfusionMatrix mat = DiffExperiments.classifyAgainstMarkov(testSet, referenceGraph, m);
      DifferenceToReferenceLanguageBCR differenceBCRMarkov = new DifferenceToReferenceLanguageBCR(mat);
     
      return new OtpErlangTuple(new OtpErlangObject[]{
          new OtpErlangDouble(differenceStructural.getValue()),new OtpErlangDouble(differenceBCRlearnt.getValue()),new OtpErlangDouble(differenceBCRMarkov.getValue())
      });
View Full Code Here

         {
          RPNIBlueFringe learner = new RPNIBlueFringe(learnerConfig,choice);
            final LearnerGraph actualAutomaton = learner.learn(collectionOfTraces.get(UAVAllSeeds).tracesForUAVandFrame.get(UAVAllSeeds).get(frame),true);
            long tmFinished = new Date().getTime();
            System.out.println("Learning complete, "+((tmFinished-tmStarted)/1000)+" sec");tmStarted = tmFinished;
            ConfusionMatrix matrix = DiffExperiments.classify(wMethod, graphReference, actualAutomaton);
            System.out.println("BCR for frame : "+frame+" = "+matrix.BCR()+", precision: "+matrix.getPrecision()+", recall: "+matrix.getRecall()+", specificity: "+matrix.getSpecificity()+", matrix: "+matrix+", log of choices: "+learner.logOfChoiceNumber);
            //Visualiser.updateFrame(actualAutomaton, graphReference);
            /*
            boolean foundSame = false;
            for(LearnerGraph g:graphs)
              if (WMethod.checkM(g, actualAutomaton) != null)
              {
                foundSame = true;break;
              }
            if (!foundSame) */graphs.add(actualAutomaton);
           
        GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData> gd = new GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData>();
        ChangesCounter<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData> counter = new ChangesCounter<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData>(graphReference, actualAutomaton, null);
        gd.computeGD(graphReference, actualAutomaton, ExperimentRunner.getCpuNumber(),counter,learnerConfig);
       
        int referenceEdges = graphReference.pathroutines.countEdges(), actualEdges = actualAutomaton.pathroutines.countEdges();
        System.out.println(counter.getRemoved()+","+counter.getAdded()+", difference is "+(((double)referenceEdges-counter.getRemoved())/referenceEdges+((double)actualEdges-counter.getAdded())/actualEdges)/2);
       
        uas_S.add(frame,matrix.BCR());
        //uas_S.drawInteractive(gr);
       }
       
        int count=0;
        for(LearnerGraph g:graphs)
View Full Code Here

 
            @Override
            public void run() {
              for(int choice:SelectionChoices)
              {
                ConfusionMatrix matrix = DiffExperiments.classify(wMethod, graphReference,
                    new RPNIBlueFringe(learnerConfig,choice).learn(collectionOfTraces.get(UAVAllSeeds).tracesForUAVandFrame.get(UAVAllSeeds).get(frame),true));
                uas_outcome.add(new Pair<Integer,String>(frame,"S"),matrix.BCR());
                uas_S.add(frame,matrix.BCR());
              }
            }
           
          };
          if (threadNumber > 1) outcomes.add(executorService.submit(interactiveRunner));else interactiveRunner.run();
        }
       
        for(final String seed:collectionOfTraces.keySet())
          if (!seed.equals(UAVAllSeeds))
          {// Just for all frames of the a single seed
            Runnable interactiveRunner = new Runnable() {

              @Override
              public void run() {
                TracesForSeed tracesForThisSeed = collectionOfTraces.get(seed);
               
                for(int choice:SelectionChoices)
                {
                  ConfusionMatrix matrix = DiffExperiments.classify(wMethod, graphReference,
                      new RPNIBlueFringe(learnerConfig,choice).learn(tracesForThisSeed.tracesForUAVandFrame.get(UAVAll).get(frame),true));
                  uas_outcome.add(new Pair<Integer,String>(frame,"A"),matrix.BCR());
                  uas_A.add(frame,matrix.BCR());
                }
              }
             
            };
            if (threadNumber > 1) outcomes.add(executorService.submit(interactiveRunner));else interactiveRunner.run();
          }
        for(final String UAV:collectionOfTraces.get(UAVAllSeeds).tracesForUAVandFrame.keySet())
          if (!UAV.equals(UAVAllSeeds) && !UAV.equals(UAVAll))
            for(final String seed:collectionOfTraces.keySet())
              if (!seed.equals(UAVAllSeeds))
              {
                Runnable interactiveRunner = new Runnable() {

                  @Override
                  public void run() {
                    for(int choice:SelectionChoices)
                    {
                      ConfusionMatrix matrix = DiffExperiments.classify(wMethod, graphReference,
                          new RPNIBlueFringe(learnerConfig,choice).learn(collectionOfTraces.get(seed).tracesForUAVandFrame.get(UAV).get(frame),true));
                      uas_outcome.add(new Pair<Integer,String>(frame,"U"),matrix.BCR());
                      uas_U.add(frame,matrix.BCR());
                    }
                  }
                 
                };
                if (threadNumber > 1) outcomes.add(executorService.submit(interactiveRunner));else interactiveRunner.run();
              }
       
        if (threadNumber <= 1)
        {/*
          uas_outcome.drawInteractive(gr);
          uas_A.drawInteractive(gr);
          uas_S.drawInteractive(gr);
          uas_U.drawInteractive(gr);
          */
          progress.next();
        }
      }
     
      for(int i=0;i<5;++i)
      {
        final int arg=i;
        Runnable interactiveRunner = new Runnable() {

          @Override
          public void run() {
            for(int choice:SelectionChoices)
            {
              Configuration tmpConf = learnerConfig.copy();tmpConf.setGeneralisationThreshold(arg);
              ConfusionMatrix matrix = DiffExperiments.classify(wMethod, graphReference,new RPNIBlueFringe(tmpConf,choice).learn(collectionOfTraces.get(UAVAllSeeds).tracesForUAVandFrame.get(UAVAllSeeds).get(maxFrameNumber),false));
              uas_threshold.add(arg, matrix.BCR());
            }
          }
         
        };
        if (threadNumber > 1)
View Full Code Here

  private Pair<Double,Long> compareLang(LearnerGraph from, LearnerGraph to,
      Collection<List<Label>> sequences)
  {
   
    final long startTime = System.nanoTime();
    ConfusionMatrix matrix = classify(sequences, from,to);
    final long duration = System.nanoTime() - startTime;
    double result = matrix.fMeasure();
    assert !Double.isNaN(result);
    return new Pair<Double,Long>(result,duration);
  }
View Full Code Here

      else if(!inTarget && inMutated)
        fp++;
      else if(!inTarget && !inMutated)
        tn++;
    }
    return new ConfusionMatrix(tp,tn,fp,fn);
  }
View Full Code Here

    set.clear();
    set.addAll(expected);
    set.removeAll(detected);
    fn = set.size();
   
    ConfusionMatrix conf = new ConfusionMatrix(tp, tn, fp, fn);
    return conf.fMeasure();
  }
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.PrecisionRecall.ConfusionMatrix

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.