Package statechum.analysis.learning.rpnicore.GD

Examples of statechum.analysis.learning.rpnicore.GD.ChangesRecorder


  public final void testComputeGD5e_RR()
  {
    Configuration config = Configuration.getDefaultConfiguration().copy();
    LearnerGraph grA = new LearnerGraph(buildGraph(A6,"testComputeGD5b"),config);
    LearnerGraph grB = convertToNumerical(new LearnerGraph(config));grB.getInit().setAccept(false);
    ChangesRecorder recorder = new ChangesRecorder(null);
    GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData> gd = new GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData>();
    gd.computeGD(grA, grB, threadNumber, recorder,config);
    LearnerGraph graph = new LearnerGraph(buildGraph(A6,"testComputeGD5b"),config);
    ChangesRecorder.applyGD(graph, recorder.writeGD(TestGD.createDoc()));
    Assert.assertNull(WMethod.checkM(graph, grB));Assert.assertEquals(grB.getStateNumber(),graph.getStateNumber());
  }
View Full Code Here


      LearnerGraph grA = new LearnerGraph(config);AbstractPersistence.loadGraph(fileA, grA);TestGD_ExistingGraphs.addColourAndIncompatiblesRandomly(grA, new Random(0));
      LearnerGraph grB = new LearnerGraph(config);AbstractPersistence.loadGraph(fileB, grB);TestGD_ExistingGraphs.addColourAndIncompatiblesRandomly(grB, new Random(1));
      GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData> gd = new GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData>();
      LearnerGraph graph = new LearnerGraph(config);AbstractPersistence.loadGraph(fileA, graph);TestGD_ExistingGraphs.addColourAndIncompatiblesRandomly(graph, new Random(0));
      LearnerGraph outcome = new LearnerGraph(config);
      ChangesRecorder patcher = new ChangesRecorder(null);
      //gd.computeGD(grA, grB, threadNumber, patcher,config);
     
      gd.init(grA, grB, threadNumber,config);
      gd.identifyKeyPairs();
      if (!gd.fallbackToInitialPair) TestGD_ExistingGraphs.addPairsRandomly(gd,pairsToAdd);
      else Assert.assertEquals(-1.,low_to_high_ratio,Configuration.fpAccuracy);
      gd.makeSteps();
      gd.computeDifference(patcher);

      ChangesRecorder.applyGD_WithRelabelling(graph, patcher.writeGD(TestGD.createDoc()),outcome);
      Assert.assertNull(testDetails(),WMethod.checkM(grB,graph));
      Assert.assertEquals(testDetails(),grB.getStateNumber(),graph.getStateNumber());
      DifferentFSMException ex= WMethod.checkM_and_colours(grB,outcome,VERTEX_COMPARISON_KIND.DEEP);
      Assert.assertNull(testDetails()+ex,WMethod.checkM_and_colours(grB,outcome,VERTEX_COMPARISON_KIND.DEEP));Assert.assertEquals(grB.getStateNumber(),graph.getStateNumber());
      Assert.assertEquals(grB,outcome);
View Full Code Here

  private LearnerGraphND runTest(LearnerGraphND grA, LearnerGraphND grB, String secondStateInKeyPair, String [] duplicatesExpectedString)
  {
    Configuration config = Configuration.getDefaultConfiguration().copy();config.setGdFailOnDuplicateNames(false);config.setGdKeyPairThreshold(.1);
    GD<List<CmpVertex>,List<CmpVertex>,LearnerGraphNDCachedData,LearnerGraphNDCachedData> gd = new GD<List<CmpVertex>,List<CmpVertex>,LearnerGraphNDCachedData,LearnerGraphNDCachedData>();
    gd.init(grA, grB, threadNumber,config);gd.identifyKeyPairs();
    ChangesRecorder recorder = new ChangesRecorder(null);
    gd.makeSteps();gd.computeDifference(recorder);

    Assert.assertEquals(2,gd.aTOb.size());
    Set<CmpVertex> keyPairsLeft = new TreeSet<CmpVertex>(),keyPairsRight = new TreeSet<CmpVertex>();
    keyPairsLeft.addAll(Arrays.asList(new CmpVertex[]{grA.findVertex(VertexID.parseID("A")),grA.findVertex(VertexID.parseID("C"))}));
    keyPairsRight.addAll(Arrays.asList(new CmpVertex[]{gd.origToNewB.get(grB.findVertex(VertexID.parseID("B"))),gd.origToNewB.get(grB.findVertex(VertexID.parseID(secondStateInKeyPair)))}));
    Assert.assertEquals(keyPairsLeft, gd.aTOb.keySet());
    Set<CmpVertex> actual = new TreeSet<CmpVertex>();actual.addAll(gd.aTOb.values());Assert.assertEquals(keyPairsRight, actual);
    Set<CmpVertex> duplicatesExpected = new TreeSet<CmpVertex>();
    for(String dup:duplicatesExpectedString) duplicatesExpected.add(gd.origToNewB.get(grB.findVertex(VertexID.parseID(dup))));
   
    Assert.assertEquals(duplicatesExpected,gd.duplicates);
    Configuration cloneConfig = config.copy();cloneConfig.setLearnerCloneGraph(true);
    LearnerGraphND graph = new LearnerGraphND(cloneConfig);AbstractLearnerGraph.copyGraphs(grA, graph);
    ChangesRecorder.applyGD(graph, recorder.writeGD(TestGD.createDoc()));
    LearnerGraphND outcome = new LearnerGraphND(config);AbstractLearnerGraph.copyGraphs(graph, outcome);
    Assert.assertNull(WMethod.checkM(grB, graph));

    // Now do the same as above, but renumber states to match grB
    AbstractLearnerGraph.copyGraphs(grA, graph);
    Configuration configMut = Configuration.getDefaultConfiguration().copy();config.setLearnerCloneGraph(false);
    LearnerGraphMutator<List<CmpVertex>,LearnerGraphNDCachedData> graphPatcher = new LearnerGraphMutator<List<CmpVertex>,LearnerGraphNDCachedData>(graph,configMut,null);
    ChangesRecorder.loadDiff(graphPatcher, recorder.writeGD(TestGD.createDoc()));
    graphPatcher.removeDanglingStates();
    LearnerGraphND result = new LearnerGraphND(configMut);
    graphPatcher.relabel(result);
    Assert.assertNull(WMethod.checkM_and_colours(grB, result,VERTEX_COMPARISON_KIND.DEEP));
    return outcome;
View Full Code Here

      {
        LearnerGraphND loadedA1 = new LearnerGraphND(config);AbstractPersistence.loadGraph(fileA1, loadedA1);
        LearnerGraph loadedA2 = new LearnerGraph(config);AbstractPersistence.loadGraph(fileA2, loadedA2);
        graph = LearnerGraphND.UniteTransitionMatrices(loadedA1,loadedA2);TestGD_ExistingGraphs.addColourAndTransitionsRandomly(graph, new Random(0));
      }
      ChangesRecorder patcher = new ChangesRecorder(null);
      //gd.computeGD(grA, grB, threadNumber, patcher,config);
      gd.init(grA, grB, threadNumber,config);
      gd.identifyKeyPairs();
      if (!gd.fallbackToInitialPair) TestGD_ExistingGraphs.addPairsRandomly(gd,pairsToAdd);
      else Assert.assertEquals(-1.,low_to_high_ratio,Configuration.fpAccuracy);
      gd.makeSteps();
      gd.computeDifference(patcher);

      LearnerGraphND outcome = new LearnerGraphND(config);
      ChangesRecorder.applyGD_WithRelabelling(graph, patcher.writeGD(TestGD.createDoc()),outcome);
      Assert.assertNull(testDetails(),WMethod.checkM(grB,graph));
      Assert.assertEquals(testDetails(),grB.getStateNumber(),graph.getStateNumber());
      Assert.assertEquals(grB,outcome);
     
      // Cannot do checkM_and_colours here because merged vertices may change their colours and other attributes.
View Full Code Here

    GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData> gd = new GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData>();
    Configuration config = Configuration.getDefaultConfiguration().copy();config.setGdPropagateDet(true);
    gd.init(graphA, graphB, threadNumber,config);
    Assert.assertTrue(gd.identifyKeyPairs());
    //TestGD.printListOfPairs(gd.frontWave, gd.newToOrig);
    ChangesRecorder recorder = new ChangesRecorder(null);
    gd.makeSteps();gd.computeDifference(recorder);
    //printListOfPairs(gd,allKeyPairs);
    for(Entry<CmpVertex,CmpVertex> pair:gd.aTOb.entrySet())
    {
      CmpVertex A=pair.getKey(), B=gd.newBToOrig.get(pair.getValue());
View Full Code Here

    GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData> gd = new GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData>();
    Configuration config = Configuration.getDefaultConfiguration().copy();config.setGdPropagateDet(false);
    gd.init(graphA, graphB, threadNumber,config);
    Assert.assertTrue(gd.identifyKeyPairs());
    //TestGD.printListOfPairs(gd.frontWave, gd.newToOrig);
    ChangesRecorder recorder = new ChangesRecorder(null);
    gd.makeSteps();gd.computeDifference(recorder);
    //printListOfPairs(gd,allKeyPairs);
    for(Entry<CmpVertex,CmpVertex> pair:gd.aTOb.entrySet())
    {
      CmpVertex A=pair.getKey(), B=gd.newBToOrig.get(pair.getValue());
View Full Code Here

    GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData> gd = new GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData>();
    gd.init(grA, grB, threadNumber,config);
    gd.identifyKeyPairs();
    //printListOfPairs(gd, gd.currentWave);
    //printListOfPairs(gd, gd.frontWave);
    ChangesRecorder recorder = new ChangesRecorder(null);
    gd.makeSteps();gd.computeDifference(recorder);
    //printListOfPairs(gd, allKeyPairs);
    Assert.assertEquals(expectedMatchedPairs,gd.aTOb.size());
    LearnerGraph graph = new LearnerGraph(buildGraph(graphA,name+"A"),config);
    ChangesRecorder.applyGD(graph, recorder.writeGD(TestGD.createDoc()));
    Assert.assertNull(WMethod.checkM(graph, grB));Assert.assertEquals(grB.getStateNumber(),graph.getStateNumber());
  }
View Full Code Here

    Configuration config = argConfig;if (config == null) config = Configuration.getDefaultConfiguration();
    LearnerGraph grA = new LearnerGraph(buildGraph(graphA,name+"A"),config);
    LearnerGraph grB = new LearnerGraph(buildGraph(graphB,name+"B"),config);

    GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData> gd = new GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData>();
    ChangesRecorder rec1 =   new ChangesRecorder(null);
    ChangesDisplay  rec2 = new ChangesDisplay(rec1);
    ChangesCounter<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData> rec3 = new ChangesCounter<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData>(grA,grB,rec2);
    ChangesRecorder rec4 =   new ChangesRecorder(rec3);
    ChangesDisplay  rec5 = new ChangesDisplay(rec4);
    ChangesCounter<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData>  rec6 = new ChangesCounter<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData>(grA,grB,rec5);
    ChangesRecorder rec7 =   new ChangesRecorder(rec6);
    ChangesDisplay  rec8 = new ChangesDisplay(rec7);
    ChangesCounter<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData>  rec9 = new ChangesCounter<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData>(grA,grB,rec8);
    {// compute GD and check that changes recorded by rec9 are correct.
      LearnerGraph graph1 = new LearnerGraph(buildGraph(graphA,name+"A"),config);
      ChangesRecorder.applyGD(graph1, gd.computeGDToXML(grA, grB, threadNumber, TestGD.createDoc(), rec9,Configuration.getDefaultConfiguration()));
      Assert.assertNull(WMethod.checkM(graph1, grB));Assert.assertEquals(grB.getStateNumber(),graph1.getStateNumber());
    }
    {// check that changes propagated to rec7 are correct.
      LearnerGraph graph2 = new LearnerGraph(buildGraph(graphA,name+"A"),config);
      ChangesRecorder.applyGD(graph2, rec7.writeGD(TestGD.createDoc()));
      Assert.assertNull(WMethod.checkM(graph2, grB));Assert.assertEquals(grB.getStateNumber(),graph2.getStateNumber());
    }
    {// check that changes propagated to rec4 are correct.
      LearnerGraph graph3 = new LearnerGraph(buildGraph(graphA,name+"A"),config);
      ChangesRecorder.applyGD(graph3, rec4.writeGD(TestGD.createDoc()));
View Full Code Here

  public final void testComputeGD5b_RA()
  {
    Configuration config = Configuration.getDefaultConfiguration().copy();config.setGdFailOnDuplicateNames(false);
    LearnerGraph grA = new LearnerGraph(config);grA.getInit().setAccept(false);
    LearnerGraph grB = convertToNumerical(new LearnerGraph(config));
    ChangesRecorder recorder = new ChangesRecorder(null);
    GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData> gd = new GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData>();
    gd.computeGD(grA, grB, threadNumber, recorder,config);
    LearnerGraph graph = new LearnerGraph(config);graph.setInit(null);graph.transitionMatrix.clear();
    ChangesRecorder.applyGD(graph, recorder.writeGD(TestGD.createDoc()));
    Assert.assertNull(WMethod.checkM(graph, grB));Assert.assertEquals(grB.getStateNumber(),graph.getStateNumber());
  }
View Full Code Here

  public final void testComputeGD5b_AR()
  {
    Configuration config = Configuration.getDefaultConfiguration().copy();config.setGdFailOnDuplicateNames(false);
    LearnerGraph grA = new LearnerGraph(config);
    LearnerGraph grB = convertToNumerical(new LearnerGraph(config));grB.getInit().setAccept(false);
    ChangesRecorder recorder = new ChangesRecorder(null);
    GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData> gd = new GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData>();
    gd.computeGD(grA, grB, threadNumber, recorder,config);
    LearnerGraph graph = new LearnerGraph(config);graph.setInit(null);graph.transitionMatrix.clear();
    ChangesRecorder.applyGD(graph, recorder.writeGD(TestGD.createDoc()));
    Assert.assertNull(WMethod.checkM(graph, grB));Assert.assertEquals(grB.getStateNumber(),graph.getStateNumber());
  }
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.rpnicore.GD.ChangesRecorder

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.