Package statechum.analysis.learning

Examples of statechum.analysis.learning.MarkovClassifier$InconsistencyNullVsPredicted


  @Test
  public void testMarkovPerformance1()
  {
    final LearnerGraph trainingGraph = FsmParser.buildLearnerGraph("A-a->B-b->C / B-u-#D / A-c->E-u->F / E-c->G","testUpdateMarkovSideways3",config, converter);
    MarkovModel m = new MarkovModel(2,true,true);
    MarkovClassifier cl=new MarkovClassifier(m,trainingGraph);cl.updateMarkov(false);
    statechum.Pair<Double,Double> pairTraining = cl.evaluateCorrectnessOfMarkov();
    Assert.assertEquals(2./3,pairTraining.firstElem,Configuration.fpAccuracy);// reflects that transitions u and c from G are not present but predicted
    Assert.assertEquals(2./3.,pairTraining.secondElem,Configuration.fpAccuracy);// reflects that transitions a and c are not predicted but present.
   
    MarkovClassifier eval = new MarkovClassifier(m,FsmParser.buildLearnerGraph("A-t->B","testMarkovPerformance1a",config, converter));
    statechum.Pair<Double,Double> pair = eval.evaluateCorrectnessOfMarkov();
    Assert.assertEquals(0,pair.firstElem,Configuration.fpAccuracy);Assert.assertEquals(0,pair.secondElem,Configuration.fpAccuracy);

    MarkovClassifier evalB = new MarkovClassifier(m,FsmParser.buildLearnerGraph("A-a->B","testMarkovPerformance1b",config, converter));
    statechum.Pair<Double,Double> pairB = evalB.evaluateCorrectnessOfMarkov();
    Assert.assertEquals(0,pairB.firstElem,Configuration.fpAccuracy);Assert.assertEquals(0,pairB.secondElem,Configuration.fpAccuracy);
  }
View Full Code Here


  @Test
  public void testMarkovPerformance2()
  {
    final LearnerGraph trainingGraph = FsmParser.buildLearnerGraph("A-a->B-b->C / B-u-#D / A-c->E-u->F / E-c->G","testUpdateMarkovSideways3",config, converter);
    MarkovModel m = new MarkovModel(2,true,true);
    MarkovClassifier cl=new MarkovClassifier(m,trainingGraph);cl.updateMarkov(false);
   
    MarkovClassifier eval = new MarkovClassifier(m,FsmParser.buildLearnerGraph("A-a->B-u-#D / B-b->G","testMarkovPerformance2",config, converter));
    statechum.Pair<Double,Double> pair = eval.evaluateCorrectnessOfMarkov();
    Assert.assertEquals(1,pair.firstElem,Configuration.fpAccuracy);Assert.assertEquals(2./3,pair.secondElem,Configuration.fpAccuracy);// transition a is not predicted
  }
View Full Code Here

  @Test
  public void testMarkovPerformance3()
  {
    final LearnerGraph trainingGraph = FsmParser.buildLearnerGraph("A-a->B-b->C / B-u-#D / A-c->E-u->F / E-c->G","testUpdateMarkovSideways3",config, converter);
    MarkovModel m = new MarkovModel(2,true,true);
    MarkovClassifier cl=new MarkovClassifier(m,trainingGraph);cl.updateMarkov(false);
   
    MarkovClassifier eval = new MarkovClassifier(m,FsmParser.buildLearnerGraph("A-a->B-u-#D / B-b->G / B-e->Z","testMarkovPerformance3",config, converter));
    statechum.Pair<Double,Double> pair = eval.evaluateCorrectnessOfMarkov();
    Assert.assertEquals(1,pair.firstElem,Configuration.fpAccuracy);Assert.assertEquals(0.5,pair.secondElem,Configuration.fpAccuracy);// transition a is not predicted
  }
View Full Code Here

  @Test
  public void testMarkovPerformance4()
  {
    final LearnerGraph trainingGraph = FsmParser.buildLearnerGraph("A-a->B-b->C / B-u-#D / A-c->E-u->F / E-c->G","testUpdateMarkovSideways3",config, converter);
    MarkovModel m = new MarkovModel(2,true,true);
    MarkovClassifier cl=new MarkovClassifier(m,trainingGraph);cl.updateMarkov(false);
   
    MarkovClassifier eval = new MarkovClassifier(m,FsmParser.buildLearnerGraph("A-a->B-b->C-c->D-u->E","testMarkovPerformance4",config, converter));
    statechum.Pair<Double,Double> pair = eval.evaluateCorrectnessOfMarkov();
    Assert.assertEquals(3./4,pair.firstElem,Configuration.fpAccuracy);// u is predicted as negative and is indeed missing, b is correctly predicted as a positive; u after c is correctly predicted as positive and c after c is not correctly predicted.
    Assert.assertEquals(0.5,pair.secondElem,Configuration.fpAccuracy);// transition a is not predicted
  }
View Full Code Here

  @Test
  public void testMarkovPerformance5()
  {
    final LearnerGraph trainingGraph = FsmParser.buildLearnerGraph("A-a->B-b->C / B-u-#D / A-c->E-u->F / E-c->G","testUpdateMarkovSideways3",config, converter);
    MarkovModel m = new MarkovModel(2,true,true);
    MarkovClassifier cl=new MarkovClassifier(m,trainingGraph);cl.updateMarkov(false);
   
    MarkovClassifier eval = new MarkovClassifier(m,FsmParser.buildLearnerGraph("A-a->B-b->G","testMarkovPerformance5",config, converter));
    statechum.Pair<Double,Double> pair = eval.evaluateCorrectnessOfMarkov();
    Assert.assertEquals(1,pair.firstElem,Configuration.fpAccuracy);// u is predicted as negative and is indeed missing, b is correctly predicted as a positive
    Assert.assertEquals(0.5,pair.secondElem,Configuration.fpAccuracy);// transition a is not predicted
  }
View Full Code Here

    // mapping map to store all paths leave each state in different length
    double tentativeScore=0;
    @SuppressWarnings("rawtypes")
    ConsistencyChecker checker = new MarkovClassifier.InconsistencyNullVsPredicted();
    MarkovClassifier resultClassifier = new MarkovClassifier(cl.model,result);
    for(Entry<CmpVertex,Collection<Label>> entry:labelsAdded.entrySet())
      if (!entry.getValue().isEmpty())
      {
        double numberOfInconsistencies = resultClassifier.checkFanoutInconsistency(entry.getKey(),checker,false);
        tentativeScore-=numberOfInconsistencies;
      }

    return (long)tentativeScore;
  }
View Full Code Here

    /*
    m.updateMarkov(merged,predictForwardOrSideways,false);// now we construct sideways learner ...
    m.constructMarkovTentative(graph,predictForwardOrSideways);// ... and use it to add more transitions.
    */
    MarkovModel inverseModel = new MarkovModel(ptaClassifier.model.getChunkLen(),true,!ptaClassifier.model.directionForwardOrInverse);
    MarkovClassifier cl = new MarkovClassifier(inverseModel,ptaClassifier.graph);cl.updateMarkov(false);
    Collection<Set<CmpVertex>> verticesToMergeUsingSideways=cl.buildVerticesToMergeForPaths(pathsOfInterest);
    return verticesToMergeUsingSideways;
  }
View Full Code Here

        //System.out.println("Inconsistency of trimmed reference : "+inconsistencyForTheReferenceGraph);
       
        //if (inconsistencyForTheReferenceGraph != 53)
        //  break;// ignore automata where we get good results.
         
        MarkovClassifier ptaClassifier = new MarkovClassifier(m,pta);
        final List<List<Label>> pathsToMerge=ptaClassifier.identifyPathsToMerge(checker);
        final Collection<Set<CmpVertex>> verticesToMergeBasedOnInitialPTA=ptaClassifier.buildVerticesToMergeForPaths(pathsToMerge);

        /*
        List<StatePair> pairsListInitialMerge = ptaClassifier.buildVerticesToMergeForPath(pathsToMerge);
        LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>> verticesToMergeInitialMerge = new LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>>();
        int scoreInitialMerge = pta.pairscores.computePairCompatibilityScore_general(null, pairsListInitialMerge, verticesToMergeInitialMerge);
View Full Code Here

  {
    MarkovModel m = new MarkovModel(2,true,true);
    Set<List<Label>> plusStrings = buildSet(new String[][] { new String[]{"a","b"},new String[]{"c","u"} },config,converter), minusStrings = buildSet(new String[][] { new String[]{"a","u"} },config,converter);
    m.createMarkovLearner(plusStrings, minusStrings,false);
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B / A-c->B-c->Z / T-b->T-u->T","testConstructExtendedGraph7a",config, converter);
    MarkovClassifier cl = new MarkovClassifier(m,graph);
    Map<CmpVertex, Map<Label, MarkovOutcome>> newTransitions = cl.predictTransitions();
   
    Assert.assertEquals(2,newTransitions.size());

    Assert.assertEquals(1,newTransitions.get(graph.findVertex("B")).size());
    Assert.assertEquals(1,newTransitions.get(graph.findVertex("Z")).size());
   
    Assert.assertSame(MarkovOutcome.positive, newTransitions.get(graph.findVertex("B")).get(lblB));
    Assert.assertSame(MarkovOutcome.positive, newTransitions.get(graph.findVertex("Z")).get(lblU));

    final LearnerGraph expected = FsmParser.buildLearnerGraph("A-a->B / A-c->B-c->Z-u->Y / B-b->C / T-b->T-u->T","testConstructExtendedGraph7b",config, converter);
    LearnerGraph actual = cl.constructMarkovTentative();
    DifferentFSMException ex = WMethod.checkM(expected, actual);
    if (ex != null)
      throw ex;
    Assert.assertNotSame(graph, actual);
  }
View Full Code Here

  @Test
  public void testCheckFanoutInconsistencySideways1_a()
  {
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B-b->C / B-u-#D / A-c->E-u->F / E-c->G","testUpdateMarkovSideways3",config, converter);
    MarkovModel m = new MarkovModel(2,false,true);
    new MarkovClassifier(m,graph).updateMarkov(false);
    Assert.assertEquals(9+graph.getCache().getAlphabet().size(),m.computePredictionMatrix().size());
   
    final LearnerGraph graph2 = FsmParser.buildLearnerGraph("A-a->B","testCheckFanoutInconsistencySideways1",config, converter);
    final AtomicInteger counterA=new AtomicInteger(0),counterB=new AtomicInteger(0);
    Assert.assertEquals(0,new MarkovClassifier(m, graph2).checkFanoutInconsistency(graph2.getInit(),new MarkovClassifier.ConsistencyChecker(){

      @Override
      public boolean consistent(MarkovOutcome actual,MarkovOutcome predicted) {
        Assert.assertEquals(MarkovOutcome.positive,actual);Assert.assertNotNull(predicted);
        counterA.addAndGet(1);
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.MarkovClassifier$InconsistencyNullVsPredicted

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.