Package statechum.analysis.learning.rpnicore.GDLearnerGraph

Examples of statechum.analysis.learning.rpnicore.GDLearnerGraph.DetermineDiagonalAndRightHandSide


    config.setGdScoreComputationAlgorithm_RandomWalk_ExtraLength(0);
    LearnerGraph gr=new LearnerGraph(FsmParser.buildGraph(NDGraph, "testCount_computeGraphs"), config);
    GDLearnerGraph ndGraph = new GDLearnerGraph(gr,LearnerGraphND.ignoreRejectStates, true);
    ndGraph.computeWalkSequences(new StateBasedRandom(new Random(80)), 1);
   
    DetermineDiagonalAndRightHandSide matcher = ndGraph.new DDRH_BCR();
    getMatcherValue(gr,ndGraph,ndGraph.matrixForward, matcher,"C","D");
    Assert.assertEquals(0,matcher.getRightHandSide(),Configuration.fpAccuracy);
    Assert.assertEquals(2*2,matcher.getDiagonal(),Configuration.fpAccuracy);

    getMatcherValue(gr,ndGraph,ndGraph.matrixForward, matcher,"E","B");
    Assert.assertEquals(0.5,matcher.getRightHandSide(),Configuration.fpAccuracy);
    Assert.assertEquals(2*2,matcher.getDiagonal(),Configuration.fpAccuracy);

  }
 
View Full Code Here


    config.setGdScoreComputationAlgorithm(GDScoreComputationAlgorithmEnum.SCORE_TESTSET);
    LearnerGraph gr=new LearnerGraph(FsmParser.buildGraph(NDGraph, "testCount_computeGraphs"), config);
    GDLearnerGraph ndGraph = new GDLearnerGraph(gr,LearnerGraphND.ignoreRejectStates, true);
    ndGraph.computeWalkSequences(new StateBasedRandom(new Random(80)), 1);
   
    DetermineDiagonalAndRightHandSide matcher = ndGraph.new DDRH_BCR();
    getMatcherValue(gr,ndGraph,ndGraph.matrixForward, matcher,"C","D");
    Assert.assertEquals(1./3.,matcher.getRightHandSide(),Configuration.fpAccuracy);
    Assert.assertEquals(2*2,matcher.getDiagonal(),Configuration.fpAccuracy);

    getMatcherValue(gr,ndGraph,ndGraph.matrixForward, matcher,"E","B");
    Assert.assertEquals(1,matcher.getRightHandSide(),Configuration.fpAccuracy);
    Assert.assertEquals(2*2,matcher.getDiagonal(),Configuration.fpAccuracy);
  }
 
View Full Code Here

  {
    int size=gr.getStateNumber()*(gr.getStateNumber()+1)/2;
    DoubleMatrix1D result = DoubleFactory1D.dense.make(size);
    StatesToConsider filter = LearnerGraphND.ignoreRejectStates;
    GDLearnerGraph ndGraph = new GDLearnerGraph(gr,filter, false);
    DetermineDiagonalAndRightHandSide ddrhInstance = ndGraph.new DDRH_default();
    for(Entry<CmpVertex,Map<String,List<CmpVertex>>> entryA:ndGraph.matrixForward.transitionMatrix.entrySet())
    {
      // Now iterate through states
      Iterator<Entry<CmpVertex,Map<String,List<CmpVertex>>>> stateB_It = ndGraph.matrixForward.transitionMatrix.entrySet().iterator();
      while(stateB_It.hasNext())
      {
        Entry<CmpVertex,Map<String,List<CmpVertex>>> stateB = stateB_It.next();

        int currentStatePair = ndGraph.vertexToIntNR(stateB.getKey(),entryA.getKey());
        ddrhInstance.compute(entryA.getKey(),stateB.getKey(),entryA.getValue(),stateB.getValue());
        result.setQuick(currentStatePair, ddrhInstance.getRightHandSide());
       
        if (stateB.getKey().equals(entryA.getKey())) break; // we only process a triangular subset.
      }
    }
   
View Full Code Here

    Assert.assertEquals("right-hand side",matcher.getRightHandSide(),rightHand,Configuration.fpAccuracy);
    Assert.assertEquals("right-hand side",matcher.getDiagonal(),diag,Configuration.fpAccuracy);
   
    // Now copy the matcher and do another computation, with A and B reversed.
    DetermineDiagonalAndRightHandSide anotherMather = null;
    try {// based on http://forums.sun.com/thread.jspa?threadID=767974
      anotherMather = matcher.getClass().getDeclaredConstructor(new Class[]{GDLearnerGraph.class}).newInstance(new Object[]{gdlearnerGraph});
    } catch (Exception e) {
      Assert.fail("Unexpected exception cloning a matcher: "+e);
    }
    anotherMather.compute(gr.findVertex(B),gr.findVertex(A),
        matrixND.transitionMatrix.get(gr.findVertex(B)),matrixND.transitionMatrix.get(gr.findVertex(A)));

    Assert.assertEquals("right-hand side",anotherMather.getRightHandSide(),rightHand,Configuration.fpAccuracy);
    Assert.assertEquals("right-hand side",anotherMather.getDiagonal(),diag,Configuration.fpAccuracy);
  }
View Full Code Here

  @Test
  public final void testCountMatchingOutgoing1()
  {
    LearnerGraph gr=new LearnerGraph(FsmParser.buildGraph("A-a->B\nA-b->B\nA-c->C\nQ-a->R\nQ-b->S", "testCountMatchingOutgoing1"), Configuration.getDefaultConfiguration());
    GDLearnerGraph ndGraph = new GDLearnerGraph(gr,LearnerGraphND.ignoreRejectStates, false);
    DetermineDiagonalAndRightHandSide matcher = ndGraph.new DDRH_default();
    getMatcherValue(gr,ndGraph,ndGraph.matrixForward, matcher,"A","Q");
    Assert.assertEquals(2,matcher.getRightHandSide(),Configuration.fpAccuracy);
  }
View Full Code Here

  @Test
  public final void testCountMatchingOutgoing2()
  {
    LearnerGraph gr=new LearnerGraph(FsmParser.buildGraph("A-a->B\nA-b->B\nA-c->C\nQ-a->R\nQ-b->S", "testCountMatchingOutgoing1"), Configuration.getDefaultConfiguration());
    GDLearnerGraph ndGraph = new GDLearnerGraph(gr,LearnerGraphND.ignoreRejectStates, false);
    DetermineDiagonalAndRightHandSide matcher = ndGraph.new DDRH_default();
    getMatcherValue(gr,ndGraph,ndGraph.matrixForward, matcher,"A","A");
    Assert.assertEquals(3,matcher.getRightHandSide(),Configuration.fpAccuracy);
  }
View Full Code Here

  @Test
  public final void testCountMatchingOutgoing3a()
  {
    LearnerGraph gr=new LearnerGraph(FsmParser.buildGraph("A-a-#B\nA-b->B1\nA-c->C\nQ-a->R-a->R\nQ-b->S", "testCountMatchingOutgoing3a"), Configuration.getDefaultConfiguration());
    GDLearnerGraph ndGraph = new GDLearnerGraph(gr,LearnerGraphND.ignoreRejectStates, false);
    DetermineDiagonalAndRightHandSide matcher = ndGraph.new DDRH_default();
    getMatcherValue(gr,ndGraph,ndGraph.matrixForward, matcher ,"A","Q");
    // A and Q have 3 outgoing transitions, 2 are matched.
    // target pair B1-S has a score of 0, B-R has a score of -1.
    Assert.assertEquals(2,matcher.getRightHandSide(),Configuration.fpAccuracy);
    Assert.assertEquals(3*2,matcher.getDiagonal(),Configuration.fpAccuracy);
    getMatcherValue(gr,ndGraph,ndGraph.matrixForward, matcher ,"B","R");
    Assert.assertEquals(PAIR_INCOMPATIBLE,matcher.getRightHandSide(),Configuration.fpAccuracy);
    Assert.assertEquals(1*2,matcher.getDiagonal(),Configuration.fpAccuracy);
  }
 
View Full Code Here

  @Test
  public final void testCountMatchingOutgoing3b()
  {
    LearnerGraph gr=new LearnerGraph(FsmParser.buildGraph("A-a-#B\nA-b->B1\nA-c->C\nQ-a->R\nQ-b->S", "testCountMatchingOutgoing3b"), Configuration.getDefaultConfiguration());
    GDLearnerGraph ndGraph = new GDLearnerGraph(gr,LearnerGraphND.ignoreNone, false);
    DetermineDiagonalAndRightHandSide matcher = ndGraph.new DDRH_default();
    getMatcherValue(gr,ndGraph,ndGraph.matrixForward, matcher ,"A","B");
    Assert.assertEquals(matcher.getDiagonal()*PAIR_INCOMPATIBLE,matcher.getRightHandSide()*2,Configuration.fpAccuracy);
    Assert.assertEquals(3*2,matcher.getDiagonal(),Configuration.fpAccuracy);
  }
 
View Full Code Here

  {
    Configuration config = Configuration.getDefaultConfiguration().copy();
    LearnerGraph gr=new LearnerGraph(FsmParser.buildGraph("A-a-#B\nA-b->B1\nA-c->C\nQ-a->R\nQ-b->S", "testCountMatchingOutgoing3c"), config);
    gr.linear.moveRejectToHighlight();
    GDLearnerGraph ndGraph = new GDLearnerGraph(gr,LearnerGraphND.ignoreRejectStates, false);
    DetermineDiagonalAndRightHandSide matcher = ndGraph.new DDRH_default();
    getMatcherValue(gr,ndGraph,ndGraph.matrixForward, matcher,"A","Q");
    // A and Q have 3 outgoing and 2 matched.
    // the score for the first pair is -1, for another one it is 1, hence the outcome is zero
    Assert.assertEquals(2,matcher.getRightHandSide(),Configuration.fpAccuracy);
    Assert.assertEquals(3*2,matcher.getDiagonal(),Configuration.fpAccuracy);
  }
 
View Full Code Here

  {
    Configuration config = Configuration.getDefaultConfiguration().copy();
    LearnerGraph gr=new LearnerGraph(FsmParser.buildGraph("A-a->B\nA-b->B1\nA-c->C\nQ-a->R\nQ-b->Q-c->S", "testCountMatchingOutgoing3d"), config);
    gr.linear.moveRejectToHighlight();
    GDLearnerGraph ndGraph = new GDLearnerGraph(gr,LearnerGraphND.ignoreRejectStates, false);
    DetermineDiagonalAndRightHandSide matcher = ndGraph.new DDRH_default();
    getMatcherValue(gr,ndGraph,ndGraph.matrixForward, matcher,"A","Q");
    // A and Q have 3 outgoing and 3 matched.
    // the score for the first pair is -1, for the other ones it is 1, hence the outcome is 1
    Assert.assertEquals(3,matcher.getRightHandSide(),Configuration.fpAccuracy);
    Assert.assertEquals(3*2,matcher.getDiagonal(),Configuration.fpAccuracy);
  }
 
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.rpnicore.GDLearnerGraph.DetermineDiagonalAndRightHandSide

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.