Examples of ChangesRecorder


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

  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);
    //Visualiser.updateFrame(grA,grB);Visualiser.updateFrame(gd.showGD(grA, grB, 1), null);
    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()), converter);
    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()), converter);
    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

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

  public final void testWriteAndLoad1()
  {
    LearnerGraphND graph = buildLearnerGraphND("A-a->B-a-#C\nA-d-#D\nA-c->A","testAddTransitions4",Configuration.getDefaultConfiguration());
    LearnerGraphND removed = buildLearnerGraphND("A-d-#D\nB-a-#C","testRemoveTransitions1",Configuration.getDefaultConfiguration());
    LearnerGraphND added = buildLearnerGraphND("A-d-#E\nB-a-#C","testRemoveTransitions1",Configuration.getDefaultConfiguration());
    ChangesRecorder patcher = new ChangesRecorder(removed,added,null);

    ChangesRecorder.applyGD(graph, patcher.writeGD(createDoc()));
    LearnerGraph expected = buildLearnerGraph("A-a->B-a-#C\nA-d-#E\nA-c->A","testWriteAndLoad1",Configuration.getDefaultConfiguration());
    Assert.assertNull(WMethod.checkM_and_colours(expected, graph, VERTEX_COMPARISON_KIND.DEEP));
  }
View Full Code Here

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

  public final void testWriteAndLoad2()
  {
    LearnerGraphND graph = buildLearnerGraphND("A-a->B-a-#C\nA-d-#D\nA-c->A","testAddTransitions4",Configuration.getDefaultConfiguration());
    LearnerGraphND removed = buildLearnerGraphND("A-d-#D\nA-a->B\nB-a-#C","testRemoveTransitions1",Configuration.getDefaultConfiguration());
    LearnerGraphND added = buildLearnerGraphND("A-d-#E\nB-a-#C\nB-c->B\nA-q->B","testRemoveTransitions1",Configuration.getDefaultConfiguration());
    ChangesRecorder patcher = new ChangesRecorder(removed,added,null);

    ChangesRecorder.applyGD(graph, patcher.writeGD(createDoc()));
    LearnerGraph expected = buildLearnerGraph("A-q->B-a-#C\nA-d-#E\nA-c->A\nB-c->B","testWriteAndLoad1",Configuration.getDefaultConfiguration());
    Assert.assertNull(WMethod.checkM_and_colours(expected, graph, VERTEX_COMPARISON_KIND.DEEP));
  }
View Full Code Here

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

 
  @Test
  public final void testWriteAndLoad3()
  {
    LearnerGraph graph = buildLearnerGraph("A-a->B-a-#C\nA-d-#D\nA-c->A","testAddTransitions4",Configuration.getDefaultConfiguration());
    ChangesRecorder patcher = new ChangesRecorder(null);
    patcher.addTransition(graph.findVertex("B"), AbstractLearnerGraph.generateNewLabel("c", cloneConfig), graph.findVertex("B"));
    patcher.removeTransition(graph.findVertex("A"), label_a, graph.findVertex("B"));
    patcher.addTransition(graph.findVertex("A"), label_q, graph.findVertex("B"));
    patcher.setInitial(graph.findVertex("A"));
    ChangesRecorder.applyGD(graph, patcher.writeGD(createDoc()));
    LearnerGraph expected = buildLearnerGraph("A-q->B-a-#C\nA-d-#D\nA-c->A\nB-c->B","testWriteAndLoad1",Configuration.getDefaultConfiguration());
    WMethod.checkM_and_colours(expected, graph, VERTEX_COMPARISON_KIND.DEEP);
  }
View Full Code Here

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

  /** Tests that initial state has to be assigned. */
  @Test
  public final void testWriteAndLoad4()
  {
    LearnerGraph graph = buildLearnerGraph("A-a->B-a-#C\nA-d-#D\nA-c->A","testAddTransitions4",Configuration.getDefaultConfiguration());
    final ChangesRecorder patcher = new ChangesRecorder(null);
    patcher.addTransition(graph.findVertex("B"), AbstractLearnerGraph.generateNewLabel("c", cloneConfig), graph.findVertex("B"));
    patcher.removeTransition(graph.findVertex("A"), label_a, graph.findVertex("B"));
    patcher.addTransition(graph.findVertex("A"), label_q, graph.findVertex("B"));
    checkForCorrectException(new whatToRun() { public @Override void run() {
      patcher.writeGD(createDoc());}},
    IllegalArgumentException.class,"init state is was not defined");
  }
View Full Code Here

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

  {
    LearnerGraphND graph = buildLearnerGraphND("A-a->B-a-#C\nA-d-#D\nA-c->A\nA-a->S-a->S","testWriteAndLoad5",Configuration.getDefaultConfiguration());
    graph.findVertex("B").setDepth(5);graph.findVertex("D").setColour(JUConstants.AMBER);
   
    graph.addToCompatibility(graph.findVertex("A"), graph.findVertex("B"),JUConstants.PAIRCOMPATIBILITY.INCOMPATIBLE);
    ChangesRecorder patcher = new ChangesRecorder(null);
    patcher.addTransition(graph.findVertex("B"), AbstractLearnerGraph.generateNewLabel("c", cloneConfig), graph.findVertex("B"));
    patcher.removeTransition(graph.findVertex("A"), label_a, graph.findVertex("B"));
    patcher.removeFromCompatibility(graph.findVertex("B"), graph.findVertex("A"));
    patcher.addToCompatibility(graph.findVertex("B"), graph.findVertex("S"),JUConstants.PAIRCOMPATIBILITY.INCOMPATIBLE);
    patcher.addTransition(graph.findVertex("A"), label_q, graph.findVertex("B"));
    patcher.setInitial(graph.findVertex("A"));
    patcher.addRelabelling(VertexID.parseID("A"), VertexID.parseID("U"));
    patcher.addRelabelling(VertexID.parseID("C"), VertexID.parseID("R"));
   
    CmpVertex danglingVertex = AbstractLearnerGraph.generateNewCmpVertex(VertexID.parseID("TEST"), cloneConfig);
    danglingVertex.setColour(JUConstants.BLUE);
    patcher.addVertex(danglingVertex);
    Configuration config = Configuration.getDefaultConfiguration().copy();config.setLearnerCloneGraph(false);
    LearnerGraphMutator<List<CmpVertex>,LearnerGraphNDCachedData> graphPatcher = new LearnerGraphMutator<List<CmpVertex>,LearnerGraphNDCachedData>(graph,config,null);
    ChangesRecorder.loadDiff(graphPatcher, patcher.writeGD(createDoc()));
    graphPatcher.removeDanglingStates();
    LearnerGraphND result = new LearnerGraphND(Configuration.getDefaultConfiguration());
    graphPatcher.relabel(result);
   
    LearnerGraphND expected = buildLearnerGraphND("U-q->B-a-#R\nU-d-#D\nU-c->U\nB-c->B\nU-a->S-a->S","testWriteAndLoad1",Configuration.getDefaultConfiguration());
View Full Code Here

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

    LearnerGraph grB = buildLearnerGraph("B-a->B","testKeyPairLeadingToNoOutgoingTransitions_with_attribute_change_b",config);
    CmpVertex F=AbstractLearnerGraph.generateNewCmpVertex(VertexID.parseID("F"), config);
    grB.transitionMatrix.put(F,grB.createNewRow());
    GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData> gd = new GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData>();
    LearnerGraph outcome = new LearnerGraph(config);
    ChangesRecorder patcher = new ChangesRecorder(null);
    //gd.computeGD(grA, grB, threadNumber, patcher,config);
   
    gd.init(grA, grB, 1,config);
    gd.identifyKeyPairs();
    Assert.assertFalse(gd.fallbackToInitialPair);
    CmpVertex newF = gd.origToNewB.get(F);
    CmpVertex C = gd.grCombined.findVertex(VertexID.parseID("C"));

    gd.frontWave.add(new PairScore(C,newF,1,0));
    gd.statesInKeyPairs.add(C);gd.statesInKeyPairs.add(newF);

    gd.makeSteps();
    gd.computeDifference(patcher);
   
    ChangesRecorder.applyGD_WithRelabelling(graph, patcher.writeGD(TestGD.createDoc()),outcome);
    Assert.assertNull(WMethod.checkM(grB,graph));
    Assert.assertEquals(grB.getStateNumber(),graph.getStateNumber());
    Assert.assertEquals(JUConstants.AMBER,grA.findVertex(VertexID.parseID("C")).getColour());
  }
View Full Code Here

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

      {
        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

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

      LearnerGraph grA = new LearnerGraph(config);AbstractPersistence.loadGraph(fileA, grA);addColourAndIncompatiblesRandomly(grA, new Random(0));
      LearnerGraph grB = new LearnerGraph(config);AbstractPersistence.loadGraph(fileB, grB);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);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);
      if (checkScores) scoresLogger.check(parametersToString(threadNumber,pairsToAdd,low_to_high_ratio,fileA,fileB), gd.serialiseScores());
      gd.identifyKeyPairs();
      if (!gd.fallbackToInitialPair) 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

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

  public final void testWriteAndLoad1()
  {
    LearnerGraphND graph = buildLearnerGraphND("A-a->B-a-#C\nA-d-#D\nA-c->A","testAddTransitions4",Configuration.getDefaultConfiguration(), converter);
    LearnerGraphND removed = buildLearnerGraphND("A-d-#D\nB-a-#C","testRemoveTransitions1",Configuration.getDefaultConfiguration(), converter);
    LearnerGraphND added = buildLearnerGraphND("A-d-#E\nB-a-#C","testRemoveTransitions1",Configuration.getDefaultConfiguration(), converter);
    ChangesRecorder patcher = new ChangesRecorder(removed,added,null);

    ChangesRecorder.applyGD(graph, patcher.writeGD(createDoc()), converter);
    LearnerGraph expected = buildLearnerGraph("A-a->B-a-#C\nA-d-#E\nA-c->A","testWriteAndLoad1",Configuration.getDefaultConfiguration(),converter);
    Assert.assertNull(WMethod.checkM_and_colours(expected, graph, VERTEX_COMPARISON_KIND.DEEP));
  }
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.