Package statechum.analysis.learning

Examples of statechum.analysis.learning.MarkovModel.computePredictionMatrix()


  public void testUpdateMarkovSideways1d()
  {
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B-a->C / B-b->C-a-#D / B-c-#D","testUpdateMarkovSideways1c",config, converter);
    MarkovModel m = new MarkovModel(2,true,true);
    new MarkovClassifier(m,graph).updateMarkov(false);
    Map<List<Label>,MarkovOutcome> mPredictionsMatrix = m.computePredictionMatrix();
    Assert.assertEquals(7,mPredictionsMatrix.size());
    Assert.assertEquals(MarkovOutcome.failure,mPredictionsMatrix.get(Arrays.asList(new Label[]{lblA,lblA})));
    Assert.assertEquals(MarkovOutcome.positive,mPredictionsMatrix.get(Arrays.asList(new Label[]{lblA,lblB})));
    Assert.assertEquals(MarkovOutcome.negative,mPredictionsMatrix.get(Arrays.asList(new Label[]{lblA,lblC})));
    Assert.assertEquals(MarkovOutcome.negative,mPredictionsMatrix.get(Arrays.asList(new Label[]{lblB,lblA})));
View Full Code Here


   
    Set<List<Label>> plusStrings = buildSet(new String[][] {},config,converter), minusStrings = buildSet(new String[][] { new String[]{"a","a","a"},new String[]{"a","b","a"},new String[]{"a","c"} },config,converter);
    MarkovModel another = new MarkovModel(2,true,true);
    another.createMarkovLearner(plusStrings, minusStrings, false);

    Map<List<Label>,MarkovOutcome> anotherPredictionsMatrix = another.computePredictionMatrix();
    Assert.assertEquals(7,anotherPredictionsMatrix.size());
    Assert.assertEquals(MarkovOutcome.failure,anotherPredictionsMatrix.get(Arrays.asList(new Label[]{lblA,lblA})));
    Assert.assertEquals(MarkovOutcome.positive,anotherPredictionsMatrix.get(Arrays.asList(new Label[]{lblA,lblB})));
    Assert.assertEquals(MarkovOutcome.negative,anotherPredictionsMatrix.get(Arrays.asList(new Label[]{lblA,lblC})));
    Assert.assertEquals(MarkovOutcome.negative,anotherPredictionsMatrix.get(Arrays.asList(new Label[]{lblB,lblA})));
View Full Code Here

  public void testUpdateMarkovSideways2()
  {
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B-c->C / B-b-#D","testUpdateMarkovSideways2",config, converter);
    MarkovModel m = new MarkovModel(2,false,true);
    new MarkovClassifier(m,graph).updateMarkov(true);
    Map<List<Label>,MarkovOutcome> mPredictionsMatrix = m.computePredictionMatrix();
    Assert.assertEquals(3,mPredictionsMatrix.size());
    Assert.assertEquals(MarkovOutcome.positive,mPredictionsMatrix.get(Arrays.asList(new Label[]{lblA,lblA})));
    Assert.assertEquals(MarkovOutcome.negative,mPredictionsMatrix.get(Arrays.asList(new Label[]{lblC,lblB})));
    Assert.assertEquals(MarkovOutcome.positive,mPredictionsMatrix.get(Arrays.asList(new Label[]{lblC,lblC})));
  }
View Full Code Here

  public void testUpdateMarkovSideways3()
  {
    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(true);
    Map<List<Label>,MarkovOutcome> mPredictionsMatrix = m.computePredictionMatrix();
    Assert.assertEquals(9,mPredictionsMatrix.size());
    Assert.assertEquals(MarkovOutcome.positive,mPredictionsMatrix.get(Arrays.asList(new Label[]{lblA,lblA})));
    Assert.assertEquals(MarkovOutcome.positive,mPredictionsMatrix.get(Arrays.asList(new Label[]{lblA,lblC})));
    Assert.assertEquals(MarkovOutcome.positive,mPredictionsMatrix.get(Arrays.asList(new Label[]{lblC,lblA})));
   
View Full Code Here

  public void testUpdateMarkovSideways4()
  {
    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(3,false,true);
    new MarkovClassifier(m,graph).updateMarkov(true);
    Map<List<Label>,MarkovOutcome> mPredictionsMatrix = m.computePredictionMatrix();
    Assert.assertEquals(6,mPredictionsMatrix.size());
    Assert.assertEquals(MarkovOutcome.positive,mPredictionsMatrix.get(Arrays.asList(new Label[]{lblA,lblB,lblC})));
    Assert.assertEquals(MarkovOutcome.positive,mPredictionsMatrix.get(Arrays.asList(new Label[]{lblA,lblB,lblA})));
   
    Assert.assertEquals(MarkovOutcome.positive,mPredictionsMatrix.get(Arrays.asList(new Label[]{lblC,lblU,lblC})));
View Full Code Here

  public void testUpdateMarkovSideways5()
  {
    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(4,false,true);
    new MarkovClassifier(m,graph).updateMarkov(true);
    Map<List<Label>,MarkovOutcome> mPredictionsMatrix = m.computePredictionMatrix();
    Assert.assertTrue(mPredictionsMatrix.isEmpty());
  }

  @Test
  public void testPredictTransitionsSideways1()
View Full Code Here

  public void testPredictTransitionsSideways1()
  {
    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 mSideways = new MarkovModel(2,false,true), mForward = new MarkovModel(2,true,true);
    new MarkovClassifier(mSideways,graph).updateMarkov(true);
    Assert.assertEquals(9,mSideways.computePredictionMatrix().size());Assert.assertTrue(mForward.computePredictionMatrix().isEmpty());
   
    List<List<Label>> interestingPaths = new LinkedList<List<Label>>();
    // nothing in Markov matrix hence no predictions.
    Assert.assertTrue(new MarkovClassifier(mForward,graph).predictTransitionsFromState(graph.findVertex("B"),null,2,interestingPaths).isEmpty());
    Assert.assertEquals(1,interestingPaths.size());Assert.assertEquals(Arrays.asList(new Label[]{lblA}),interestingPaths.get(0));
View Full Code Here

  {
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B-b->C / B-u-#D / A-c->E-u->F / E-b->G","testUpdateMarkovSideways3",config, converter);
    MarkovModel m = new MarkovModel(2,false,true);
    new MarkovClassifier(m,graph).updateMarkov(true);
   
    Map<List<Label>,MarkovOutcome> mPredictionsMatrix = m.computePredictionMatrix();
    Assert.assertEquals(8,mPredictionsMatrix.size());
   
    Assert.assertEquals(MarkovOutcome.failure,mPredictionsMatrix.get(Arrays.asList(new Label[]{lblB,lblU})));
   
    Assert.assertEquals(MarkovOutcome.positive,mPredictionsMatrix.get(Arrays.asList(new Label[]{lblA,lblA})));
View Full Code Here

  {
    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 / A-c->A / T-u->T-b->T","testCheckFanoutInconsistencySideways4",config, converter);// T is there to ensure that graph2's alphabet is the same as that of graph.
    Map<Label, MarkovOutcome> predictions = new MarkovClassifier(m,graph2).predictTransitionsFromState(graph2.getInit(),null,m.getChunkLen(),null);
   
    Assert.assertEquals(MarkovOutcome.positive,predictions.get(lblU));
View Full Code Here

 
  @Test
  public void testPredictTransitionsFromStatesForward1()
  {
    MarkovModel m = new MarkovModel(2,true,true);
    Assert.assertTrue(m.computePredictionMatrix().isEmpty());
   
    final LearnerGraph graph2 = FsmParser.buildLearnerGraph("A-a->B / A-c->A","testCheckFanoutInconsistencySideways4",config, converter);
    Map<CmpVertex, Map<Label, MarkovOutcome>> predictions = new MarkovClassifier(m, graph2).predictTransitions();
    Assert.assertTrue(predictions.isEmpty());// empty Markov means no predictions.
  }
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.