Package statechum.analysis.learning.linear

Examples of statechum.analysis.learning.linear.GDLearnerGraph$DDRH_default


  {
    Configuration conf = config.copy();conf.setTransitionMatrixImplType(STATETREE.STATETREE_SLOWTREE);
    LearnerGraph textGraph = buildLearnerGraph("A-a->A-b->B-c->C","testCheckGraphNumeric",config,converter);
    LearnerGraph numericGraph = new LearnerGraph(config);CmpVertex newInit = AbstractPathRoutines.addToGraph(numericGraph, textGraph,null);
    numericGraph = MergeStates.mergeAndDeterminize_general(numericGraph, new StatePair(newInit,numericGraph.paths.getVertex(new LinkedList<Label>())));
    GDLearnerGraph numericNDGraph = new GDLearnerGraph(numericGraph,LearnerGraphND.ignoreRejectStates,false);
    CmpVertex A = numericGraph.paths.getVertex(labelList(new String[]{})),
      B = numericGraph.paths.getVertex(labelList(new String[]{"b"})),
      C = numericGraph.paths.getVertex(labelList(new String[]{"b","c"}));
    /*  ABC
     *A 013
     *B 124
     *C 345
    */
    Assert.assertEquals(0,numericGraph.wmethod.vertexToInt(A,A));
    Assert.assertEquals(1,numericGraph.wmethod.vertexToInt(A,B));
    Assert.assertEquals(1,numericGraph.wmethod.vertexToInt(B,A));
    Assert.assertEquals(0,numericNDGraph.vertexToIntNR(A,A));
    Assert.assertEquals(1,numericNDGraph.vertexToIntNR(A,B));
    Assert.assertEquals(1,numericNDGraph.vertexToIntNR(B,A));

    Assert.assertEquals(3,numericGraph.wmethod.vertexToInt(A,C));
    Assert.assertEquals(3,numericGraph.wmethod.vertexToInt(C,A));
    Assert.assertEquals(3,numericNDGraph.vertexToIntNR(A,C));
    Assert.assertEquals(3,numericNDGraph.vertexToIntNR(C,A));

    Assert.assertEquals(2,numericGraph.wmethod.vertexToInt(B,B));
    Assert.assertEquals(2,numericNDGraph.vertexToIntNR(B,B));

    Assert.assertEquals(4,numericGraph.wmethod.vertexToInt(B,C));
    Assert.assertEquals(4,numericGraph.wmethod.vertexToInt(C,B));
    Assert.assertEquals(4,numericNDGraph.vertexToIntNR(B,C));
    Assert.assertEquals(4,numericNDGraph.vertexToIntNR(C,B));

    Assert.assertEquals(5,numericGraph.wmethod.vertexToInt(C,C));
    Assert.assertEquals(5,numericNDGraph.vertexToIntNR(C,C));
  }
 
View Full Code Here


  {
    Configuration conf = config.copy();conf.setTransitionMatrixImplType(STATETREE.STATETREE_SLOWTREE);
    LearnerGraph textGraph = buildLearnerGraph("A-a->A-b->B-c->C","testCheckGraphNumeric",config);
    LearnerGraph numericGraph = new LearnerGraph(config);CmpVertex newInit = AbstractPathRoutines.addToGraph(numericGraph, textGraph,null);
    numericGraph = MergeStates.mergeAndDeterminize_general(numericGraph, new StatePair(newInit,numericGraph.paths.getVertex(new LinkedList<Label>())));
    GDLearnerGraph numericNDGraph = new GDLearnerGraph(numericGraph,LearnerGraphND.ignoreRejectStates,false);
    CmpVertex A = numericGraph.paths.getVertex(labelList(new String[]{})),
      B = numericGraph.paths.getVertex(labelList(new String[]{"b"})),
      C = numericGraph.paths.getVertex(labelList(new String[]{"b","c"}));
    /*  ABC
     *A 013
     *B 124
     *C 345
    */
    Assert.assertEquals(0,numericGraph.wmethod.vertexToInt(A,A));
    Assert.assertEquals(1,numericGraph.wmethod.vertexToInt(A,B));
    Assert.assertEquals(1,numericGraph.wmethod.vertexToInt(B,A));
    Assert.assertEquals(0,numericNDGraph.vertexToIntNR(A,A));
    Assert.assertEquals(1,numericNDGraph.vertexToIntNR(A,B));
    Assert.assertEquals(1,numericNDGraph.vertexToIntNR(B,A));

    Assert.assertEquals(3,numericGraph.wmethod.vertexToInt(A,C));
    Assert.assertEquals(3,numericGraph.wmethod.vertexToInt(C,A));
    Assert.assertEquals(3,numericNDGraph.vertexToIntNR(A,C));
    Assert.assertEquals(3,numericNDGraph.vertexToIntNR(C,A));

    Assert.assertEquals(2,numericGraph.wmethod.vertexToInt(B,B));
    Assert.assertEquals(2,numericNDGraph.vertexToIntNR(B,B));

    Assert.assertEquals(4,numericGraph.wmethod.vertexToInt(B,C));
    Assert.assertEquals(4,numericGraph.wmethod.vertexToInt(C,B));
    Assert.assertEquals(4,numericNDGraph.vertexToIntNR(B,C));
    Assert.assertEquals(4,numericNDGraph.vertexToIntNR(C,B));

    Assert.assertEquals(5,numericGraph.wmethod.vertexToInt(C,C));
    Assert.assertEquals(5,numericNDGraph.vertexToIntNR(C,C));
  }
 
View Full Code Here

   * @param randomWalkGenerator random number generator to be used in walk generation.
   */
  public void chooseStatePairs_internal(double threshold, double scale, int ThreadNumber,
      final Class<? extends DetermineDiagonalAndRightHandSideInterface> ddrh, StatesToConsider filter, StateBasedRandom randomWalkGenerator)
  {
    GDLearnerGraph ndGraph = new GDLearnerGraph(coregraph, filter, false);
    switch(coregraph.config.getGdScoreComputationAlgorithm())
    {
    case SCORE_RANDOMPATHS:
    case SCORE_TESTSET:
      // build (1) deterministic machines for each state and (2) walks from each state.
      ndGraph.computeWalkSequences(randomWalkGenerator, ThreadNumber);
      break;
    case SCORE_LINEAR:
      break;
    default:
      throw new IllegalArgumentException("computation algorithm "+coregraph.config.getGdScoreComputationAlgorithm()+" is not currently supported");
    }
   
    final int [] incompatiblePairs = new int[ndGraph.getStateNumber()*(ndGraph.getStateNumber()+1)/2];for(int i=0;i<incompatiblePairs.length;++i) incompatiblePairs[i]=GDLearnerGraph.PAIR_OK;
    final int pairsNumber = ndGraph.findIncompatiblePairs(incompatiblePairs,ThreadNumber);
    LSolver solver = ndGraph.buildMatrix_internal(incompatiblePairs, pairsNumber, ThreadNumber,ddrh);
    solver.solve(ThreadNumber);
    solver.freeAllButResult();// deallocate memory before creating a large array.
    coregraph.pairsAndScores.clear();
    // now fill in the scores in the array.
    for(int i=0;i<incompatiblePairs.length;++i)
    {
      int index = incompatiblePairs[i];
      if (index >= 0)
      {
        double value = solver.j_x[incompatiblePairs[i]];
        if (value > threshold) coregraph.pairsAndScores.add(ndGraph.getPairScore(i, (int)(scale*value), 0));
      }
      else // PAIR_INCOMPATIBLE
        if (threshold < GDLearnerGraph.PAIR_INCOMPATIBLE) coregraph.pairsAndScores.add(ndGraph.getPairScore(i, (int)(scale*GDLearnerGraph.PAIR_INCOMPATIBLE), 0));
    }
  }
View Full Code Here

 
  @Test
  public final void testVertexToInt0()
  {
    LearnerGraph textGraph = buildLearnerGraph("A-a->A-b->B-c-#C","testVertexToInt0",config);
    GDLearnerGraph ndGraph = new GDLearnerGraph(textGraph,LearnerGraphND.ignoreRejectStates,false);
    Assert.assertTrue(ndGraph.getStatesToNumber().containsKey(textGraph.findVertex("A")));
    Assert.assertTrue(ndGraph.getStatesToNumber().containsKey(textGraph.findVertex("B")));
    Assert.assertFalse(ndGraph.getStatesToNumber().containsKey(textGraph.findVertex("C")));
  }
View Full Code Here

  }
  @Test
  public final void testVertexToInt1()
  {
    LearnerGraph textGraph = new LearnerGraph(config);
    GDLearnerGraph ndGraph = new GDLearnerGraph(textGraph,LearnerGraphND.ignoreRejectStates,false);
    CmpVertex A = textGraph.paths.getVertex(labelList(new String[]{}));
    Assert.assertEquals(0,textGraph.wmethod.vertexToInt(A,A));
    Assert.assertEquals(0,ndGraph.vertexToIntNR(A,A));
  }
View Full Code Here

   * @param randomWalkGenerator random number generator to be used in walk generation.
   */
  public void chooseStatePairs_internal(double threshold, double scale, int ThreadNumber,
      final Class<? extends DetermineDiagonalAndRightHandSideInterface> ddrh, StatesToConsider filter, StateBasedRandom randomWalkGenerator)
  {
    GDLearnerGraph ndGraph = new GDLearnerGraph(coregraph, filter, false);
    switch(coregraph.config.getGdScoreComputationAlgorithm())
    {
    case SCORE_RANDOMPATHS:
    case SCORE_TESTSET:
      // build (1) deterministic machines for each state and (2) walks from each state.
      ndGraph.computeWalkSequences(randomWalkGenerator, ThreadNumber);
      break;
    case SCORE_LINEAR:
      break;
    default:
      throw new IllegalArgumentException("computation algorithm "+coregraph.config.getGdScoreComputationAlgorithm()+" is not currently supported");
    }
   
    final int [] incompatiblePairs = new int[ndGraph.getStateNumber()*(ndGraph.getStateNumber()+1)/2];for(int i=0;i<incompatiblePairs.length;++i) incompatiblePairs[i]=GDLearnerGraph.PAIR_OK;
    final int pairsNumber = ndGraph.findIncompatiblePairs(incompatiblePairs,ThreadNumber);
    LSolver solver = ndGraph.buildMatrix_internal(incompatiblePairs, pairsNumber, ThreadNumber,ddrh);
    solver.solve(ThreadNumber);
    solver.freeAllButResult();// deallocate memory before creating a large array.
    coregraph.pairsAndScores.clear();
    // now fill in the scores in the array.
    for(int i=0;i<incompatiblePairs.length;++i)
    {
      int index = incompatiblePairs[i];
      if (index >= 0)
      {
        double value = solver.j_x[incompatiblePairs[i]];
        if (value > threshold) coregraph.pairsAndScores.add(ndGraph.getPairScore(i, (int)(scale*value), 0));
      }
      else // PAIR_INCOMPATIBLE
        if (threshold < GDLearnerGraph.PAIR_INCOMPATIBLE) coregraph.pairsAndScores.add(ndGraph.getPairScore(i, (int)(scale*GDLearnerGraph.PAIR_INCOMPATIBLE), 0));
    }
  }
View Full Code Here

   * @param randomWalkGenerator random number generator to be used in walk generation.
   */
  public void chooseStatePairs_internal(double threshold, double scale, int ThreadNumber,
      final Class<? extends DetermineDiagonalAndRightHandSideInterface> ddrh, StatesToConsider filter, StateBasedRandom randomWalkGenerator)
  {
    GDLearnerGraph ndGraph = new GDLearnerGraph(coregraph, filter, false);
    switch(coregraph.config.getGdScoreComputationAlgorithm())
    {
    case SCORE_RANDOMPATHS:
    case SCORE_TESTSET:
      // build (1) deterministic machines for each state and (2) walks from each state.
      ndGraph.computeWalkSequences(randomWalkGenerator, ThreadNumber);
      break;
    case SCORE_LINEAR:
      break;
    default:
      throw new IllegalArgumentException("computation algorithm "+coregraph.config.getGdScoreComputationAlgorithm()+" is not currently supported");
    }
   
    final int [] incompatiblePairs = new int[ndGraph.getStateNumber()*(ndGraph.getStateNumber()+1)/2];for(int i=0;i<incompatiblePairs.length;++i) incompatiblePairs[i]=GDLearnerGraph.PAIR_OK;
    final int pairsNumber = ndGraph.findIncompatiblePairs(incompatiblePairs,ThreadNumber);
    LSolver solver = ndGraph.buildMatrix_internal(incompatiblePairs, pairsNumber, ThreadNumber,ddrh);
    solver.solve(ThreadNumber);
    solver.freeAllButResult();// deallocate memory before creating a large array.
    coregraph.pairsAndScores.clear();
    // now fill in the scores in the array.
    for(int i=0;i<incompatiblePairs.length;++i)
    {
      int index = incompatiblePairs[i];
      if (index >= 0)
      {
        double value = solver.j_x[incompatiblePairs[i]];
        if (value > threshold) coregraph.pairsAndScores.add(ndGraph.getPairScore(i, (int)(scale*value), 0));
      }
      else // PAIR_INCOMPATIBLE
        if (threshold < GDLearnerGraph.PAIR_INCOMPATIBLE) coregraph.pairsAndScores.add(ndGraph.getPairScore(i, (int)(scale*GDLearnerGraph.PAIR_INCOMPATIBLE), 0));
    }
  }
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.linear.GDLearnerGraph$DDRH_default

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.