Package statechum.analysis.learning

Examples of statechum.analysis.learning.MarkovUniversalLearner


  /** Here the alphabet is limited to what is an the tentative automaton, hence nothing is added. */
  @Test
  public void testPredictTransitionsFromStatesSideways2()
  {
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B-b->C / B-u-#D / A-c->E-u->F / E-c->G","testUpdateMarkovSideways3",config, converter);
    MarkovUniversalLearner m = new MarkovUniversalLearner(2);
    m.updateMarkov(graph,false,true);
    Assert.assertTrue(m.getMarkov(true).isEmpty());
    Assert.assertEquals(9,m.getMarkov(false).size());
   
    final LearnerGraph graph2 = FsmParser.buildLearnerGraph("A-a->B","testCheckFanoutInconsistencySideways4",config, converter);
    m.constructMarkovTentative(graph2, false);
    Assert.assertNull(WMethod.checkM(graph2,m.get_extension_model()));
  }
View Full Code Here


  /** Tests that upon a label labelled as invalid, subsequent inconsistency checks are stopped. It is hence equivalent to a single incoming path. */
  @Test
  public void testPredictTransitionsFromStatesSideways3()
  {
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B-b->C / B-u-#D / A-c->E-u->F / E-c->G","testUpdateMarkovSideways3",config, converter);
    MarkovUniversalLearner m = new MarkovUniversalLearner(2);
    m.updateMarkov(graph,false,true);
    Assert.assertTrue(m.getMarkov(true).isEmpty());
    Assert.assertEquals(9,m.getMarkov(false).size());
   
    final LearnerGraph graph2 = FsmParser.buildLearnerGraph("A-a->B / T-a->T-u->T-b->T-c->T","testPredictTransitionsFromStatesSideways3",config, converter);
    m.constructMarkovTentative(graph2, false);
    Assert.assertNull(WMethod.checkM(FsmParser.buildLearnerGraph("A-a->B / A-c->F","testPredictTransitionsFromStatesForward3",config, converter), m.get_extension_model()));// FSM comparison ignores unreachable states here
    Assert.assertTrue(m.get_extension_model().findVertex("T") != null);// extended graph starts as a replica of an original one.
  }
View Full Code Here

  /** Same as {@link #testPredictTransitionsFromStatesSideways1()}, except that the path beyond is empty rather than null. */
  @Test
  public void testPredictTransitionsFromStatesWithPathBeyondCurrentState1()
  {
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B-b->C / B-u-#D / A-c->E-u->F / E-c->G","testUpdateMarkovSideways3",config, converter);
    MarkovUniversalLearner m = new MarkovUniversalLearner(2);
    m.updateMarkov(graph,false,true);
    Assert.assertTrue(m.getMarkov(true).isEmpty());
    Assert.assertEquals(9,m.getMarkov(false).size());
   
    final LearnerGraph graph2 = FsmParser.buildLearnerGraph("A-a->B / A-c->A","testCheckFanoutInconsistencySideways4",config, converter);
    Map<Trace, MarkovOutcome> markovMatrix = m.getMarkov(false);
    Map<Label, MarkovOutcome> predictions = MarkovUniversalLearner.predictTransitionsFromState(markovMatrix,graph2,false,graph2.getInit(),graph.pathroutines.computeAlphabet(),Arrays.asList(new Label[]{}),m.getChunkLen(),null);
   
    Assert.assertEquals(MarkovOutcome.positive,predictions.get(lblU));
    Assert.assertEquals(MarkovOutcome.positive,predictions.get(lblC));
    Assert.assertEquals(MarkovOutcome.positive,predictions.get(lblA));
  }
View Full Code Here

  /** Same as {@link #testPredictTransitionsFromStatesSideways1()}, except that the path beyond is non-empty. */
  @Test
  public void testPredictTransitionsFromStatesWithPathBeyondCurrentState2()
  {
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B-b->C / B-u-#D / A-c->E-u->F / E-c->G","testUpdateMarkovSideways3",config, converter);
    final MarkovUniversalLearner m = new MarkovUniversalLearner(2);
    m.updateMarkov(graph,false,true);
    Assert.assertTrue(m.getMarkov(true).isEmpty());
    Assert.assertEquals(9,m.getMarkov(false).size());
   
    final LearnerGraph graph2 = FsmParser.buildLearnerGraph("A-a->B","testPredictTransitionsFromStatesWithPathBeyondCurrentState2",config, converter);
    final Map<Trace, MarkovOutcome> markovMatrix = m.getMarkov(false);
   
    Helper.checkForCorrectException(new whatToRun() {
      @Override
      public void run() throws NumberFormatException
      {
        MarkovUniversalLearner.predictTransitionsFromState(markovMatrix,graph2,false,graph2.getInit(),graph.pathroutines.computeAlphabet(),Arrays.asList(new Label[]{lblC}),m.getChunkLen(),null);
      }
    }, IllegalArgumentException.class, "cannot be made by extension");
  }
View Full Code Here

  /** Almost the same as {@link #testPredictTransitionsFromStatesForward2()} except that the path beyond is empty rather than null. */
  @Test
  public void testPredictTransitionsFromStatesWithPathBeyondCurrentState3()
  {
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B-b->C / B-u-#D / A-c->E-u->F / E-c->G","testUpdateMarkovSideways3",config, converter);
    MarkovUniversalLearner m = new MarkovUniversalLearner(2);
    m.updateMarkov(graph,true,true);
    Assert.assertEquals(4,m.getMarkov(true).size());
    Assert.assertTrue(m.getMarkov(false).isEmpty());
    final Map<Trace, MarkovOutcome> markovMatrix = m.getMarkov(true);
   
    final LearnerGraph graph2 = FsmParser.buildLearnerGraph("A-a->B / A-c->A/ T-u->T-b->T","testPredictTransitionsFromStatesForward2",config, converter);
    Map<Label,MarkovOutcome> outgoing_labels_probabilities=m.predictTransitionsFromState(markovMatrix,m.computeInverseGraph(graph2, true),true,graph2.findVertex("B"),graph2.getCache().getAlphabet(),Arrays.asList(new Label[]{}),m.getChunkLen(),null);
    Assert.assertEquals(2,outgoing_labels_probabilities.size());
    Assert.assertEquals(MarkovOutcome.negative,outgoing_labels_probabilities.get(lblU));
    Assert.assertEquals(MarkovOutcome.positive,outgoing_labels_probabilities.get(lblB));
  }
View Full Code Here

   */
  @Test
  public void testPredictTransitionsFromStatesWithPathBeyondCurrentState4()
  {
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B-b->C / B-u-#D / A-c->E-u->F / E-c->G","testUpdateMarkovSideways3",config, converter);
    MarkovUniversalLearner m = new MarkovUniversalLearner(2);
    m.updateMarkov(graph,true,true);
    Assert.assertEquals(4,m.getMarkov(true).size());
    Assert.assertTrue(m.getMarkov(false).isEmpty());
    final Map<Trace, MarkovOutcome> markovMatrix = m.getMarkov(true);

   
    final LearnerGraph graph2 = FsmParser.buildLearnerGraph("A-d->B / A-c->A/ T-u->T-b->T","testPredictTransitionsFromStatesForward2",config, converter);
    Map<Label,MarkovOutcome> outgoing_labels_probabilities=m.predictTransitionsFromState(markovMatrix,m.computeInverseGraph(graph2, true),true,graph2.findVertex("B"),graph2.getCache().getAlphabet(),Arrays.asList(new Label[]{lblA}),m.getChunkLen(),null);
    Assert.assertEquals(2,outgoing_labels_probabilities.size());
    Assert.assertEquals(MarkovOutcome.negative,outgoing_labels_probabilities.get(lblU));
    Assert.assertEquals(MarkovOutcome.positive,outgoing_labels_probabilities.get(lblB));
  }
View Full Code Here

   */
  @Test
  public void testPredictTransitionsFromStatesWithPathBeyondCurrentState5()
  {
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B-b->C / B-u-#D / A-c->E-u->F / E-c->G","testUpdateMarkovSideways3",config, converter);
    final MarkovUniversalLearner m = new MarkovUniversalLearner(2);
    m.updateMarkov(graph,true,true);
    Assert.assertEquals(4,m.getMarkov(true).size());
    Assert.assertTrue(m.getMarkov(false).isEmpty());
    final Map<Trace, MarkovOutcome> markovMatrix = m.getMarkov(true);

   
    final LearnerGraph graph2 = FsmParser.buildLearnerGraph("A-d->B / A-c->A/ T-u->T-b->T","testPredictTransitionsFromStatesForward2",config, converter);
    Helper.checkForCorrectException(new whatToRun() {
      @Override
      public void run() throws NumberFormatException
      {
        m.predictTransitionsFromState(markovMatrix,m.computeInverseGraph(graph2, true),true,graph2.findVertex("B"),graph2.getCache().getAlphabet(),Arrays.asList(new Label[]{lblA,lblB}),m.getChunkLen(),null);
      }
    }, IllegalArgumentException.class, "supplied path");
  }
View Full Code Here

 
  @Test
  public void testUpdateMarkovSideways1a()
  {
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B-a->C / B-b->C","testUpdateMarkovSideways1",config, converter);
    MarkovUniversalLearner m = new MarkovUniversalLearner(2);
    m.updateMarkov(graph,false,true);
    Assert.assertTrue(m.getMarkov(true).isEmpty());Assert.assertEquals(4,m.getMarkov(false).size());
    Assert.assertTrue(m.getOccurrence(true).isEmpty());Assert.assertEquals(4,m.getOccurrence(false).size());
    Assert.assertEquals(MarkovOutcome.positive,m.getMarkov(false).get(new Trace(Arrays.asList(new Label[]{lblA,lblA}),true)));Assert.assertEquals(new UpdatablePairInteger(2, 0),m.getOccurrence(false).get(new Trace(Arrays.asList(new Label[]{lblA,lblA}),true)));
    Assert.assertEquals(MarkovOutcome.positive,m.getMarkov(false).get(new Trace(Arrays.asList(new Label[]{lblA,lblB}),true)));Assert.assertEquals(new UpdatablePairInteger(1, 0),m.getOccurrence(false).get(new Trace(Arrays.asList(new Label[]{lblA,lblB}),true)));
    Assert.assertEquals(MarkovOutcome.positive,m.getMarkov(false).get(new Trace(Arrays.asList(new Label[]{lblB,lblA}),true)));Assert.assertEquals(new UpdatablePairInteger(1, 0),m.getOccurrence(false).get(new Trace(Arrays.asList(new Label[]{lblB,lblA}),true)));
    Assert.assertEquals(MarkovOutcome.positive,m.getMarkov(false).get(new Trace(Arrays.asList(new Label[]{lblB,lblB}),true)));Assert.assertEquals(new UpdatablePairInteger(1, 0),m.getOccurrence(false).get(new Trace(Arrays.asList(new Label[]{lblB,lblB}),true)));
  }
View Full Code Here

 
  @Test
  public void testUpdateMarkovSideways1b()
  {
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B-a->C / B-b->C","testUpdateMarkovSideways1",config, converter);
    MarkovUniversalLearner m = new MarkovUniversalLearner(2);
    m.updateMarkov(graph,false,false);
    Assert.assertTrue(m.getMarkov(true).isEmpty());Assert.assertEquals(6,m.getMarkov(false).size());
    Assert.assertEquals(MarkovOutcome.positive,m.getMarkov(false).get(new Trace(Arrays.asList(new Label[]{lblA,lblA}),true)));Assert.assertEquals(new UpdatablePairInteger(2, 0),m.getOccurrence(false).get(new Trace(Arrays.asList(new Label[]{lblA,lblA}),true)));
    Assert.assertEquals(MarkovOutcome.positive,m.getMarkov(false).get(new Trace(Arrays.asList(new Label[]{lblA,lblB}),true)));Assert.assertEquals(new UpdatablePairInteger(1, 0),m.getOccurrence(false).get(new Trace(Arrays.asList(new Label[]{lblA,lblB}),true)));
    Assert.assertEquals(MarkovOutcome.positive,m.getMarkov(false).get(new Trace(Arrays.asList(new Label[]{lblB,lblA}),true)));Assert.assertEquals(new UpdatablePairInteger(1, 0),m.getOccurrence(false).get(new Trace(Arrays.asList(new Label[]{lblB,lblA}),true)));
    Assert.assertEquals(MarkovOutcome.positive,m.getMarkov(false).get(new Trace(Arrays.asList(new Label[]{lblB,lblB}),true)));Assert.assertEquals(new UpdatablePairInteger(1, 0),m.getOccurrence(false).get(new Trace(Arrays.asList(new Label[]{lblB,lblB}),true)));

    Assert.assertEquals(MarkovOutcome.positive,m.getMarkov(false).get(new Trace(Arrays.asList(new Label[]{lblA}),true)));Assert.assertEquals(new UpdatablePairInteger(2, 0),m.getOccurrence(false).get(new Trace(Arrays.asList(new Label[]{lblA}),true)));
    Assert.assertEquals(MarkovOutcome.positive,m.getMarkov(false).get(new Trace(Arrays.asList(new Label[]{lblB}),true)));Assert.assertEquals(new UpdatablePairInteger(1, 0),m.getOccurrence(false).get(new Trace(Arrays.asList(new Label[]{lblB}),true)));
  }
View Full Code Here

  /** This one is similar to the {@link #testUpdateMarkovSideways1b}, except that there are a few additional negative transitions. */
  @Test
  public void testUpdateMarkovSideways1c()
  {
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B-a->C / B-b->C-a-#D / B-c-#D","testUpdateMarkovSideways1c",config, converter);
    MarkovUniversalLearner m = new MarkovUniversalLearner(2);
    m.updateMarkov(graph,false,false);
    Assert.assertTrue(m.getMarkov(true).isEmpty());Assert.assertEquals(9,m.getMarkov(false).size());
    Assert.assertEquals(MarkovOutcome.positive,m.getMarkov(false).get(new Trace(Arrays.asList(new Label[]{lblA,lblA}),true)));
    Assert.assertEquals(MarkovOutcome.positive,m.getMarkov(false).get(new Trace(Arrays.asList(new Label[]{lblA,lblB}),true)));
    Assert.assertEquals(MarkovOutcome.positive,m.getMarkov(false).get(new Trace(Arrays.asList(new Label[]{lblB,lblA}),true)));
    Assert.assertEquals(MarkovOutcome.positive,m.getMarkov(false).get(new Trace(Arrays.asList(new Label[]{lblB,lblB}),true)));
    Assert.assertEquals(MarkovOutcome.negative,m.getMarkov(false).get(new Trace(Arrays.asList(new Label[]{lblA,lblC}),true)));
    Assert.assertEquals(MarkovOutcome.negative,m.getMarkov(false).get(new Trace(Arrays.asList(new Label[]{lblB,lblC}),true)));

    Assert.assertEquals(MarkovOutcome.failure,m.getMarkov(false).get(new Trace(Arrays.asList(new Label[]{lblA}),true)));
    Assert.assertEquals(MarkovOutcome.positive,m.getMarkov(false).get(new Trace(Arrays.asList(new Label[]{lblB}),true)));
    Assert.assertEquals(MarkovOutcome.negative,m.getMarkov(false).get(new Trace(Arrays.asList(new Label[]{lblC}),true)));
  }
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.MarkovUniversalLearner

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.