Examples of GDLearnerGraph


Examples of statechum.analysis.learning.linear.GDLearnerGraph

public class StructuralDifferencesPaper {
  static final Configuration config = Configuration.getDefaultConfiguration();

  public static void dumpEquations()
  {
    GDLearnerGraph ndGraph = new GDLearnerGraph(buildLearnerGraph("A-a->B-a->B-b->A / B-c->C / E-a->F-a->F-d->F-b->E-c->F""dumpEquations",config),LearnerGraphND.ignoreRejectStates, false);
    final int [] incompatiblePairs = new int[ndGraph.getPairNumber()];
    final int pairsNumber = incompatiblePairs.length;
    for(int i=0;i<incompatiblePairs.length;++i) incompatiblePairs[i]=i;// emulate the behaviour or non-public part for(int i=0;i<incompatiblePairs.length;++i) incompatiblePairs[i]=PAIR_OK;final int pairsNumber = ndGraph.findIncompatiblePairs(incompatiblePairs,1);

    LSolver solver = ndGraph.buildMatrix_internal(incompatiblePairs, pairsNumber, 1,null);

    System.out.println(ndGraph.dumpEquations(solver, incompatiblePairs, null).toString())}
View Full Code Here

Examples of statechum.analysis.learning.linear.GDLearnerGraph

   * @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

Examples of statechum.analysis.learning.linear.GDLearnerGraph

   * @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

Examples of statechum.analysis.learning.linear.GDLearnerGraph

    Configuration conf = Configuration.getDefaultConfiguration().copy();conf.setTransitionMatrixImplType(STATETREE.STATETREE_SLOWTREE);
    LearnerGraph gr=buildLearnerGraph(graph,graphName,conf);
    StatesToConsider filter = createInstanceOfFilter(filterClass, gr);
    for(boolean direction:new boolean[]{false,true})
    {
      GDLearnerGraph ndGraph = new GDLearnerGraph(gr,filter, direction);
      Map<CmpVertex,Integer> state_to_int_map = new TreeMap<CmpVertex,Integer>();
      CmpVertex [] numberToStateNoReject = gr.buildStateToIntegerMap(filter,state_to_int_map);
      Assert.assertEquals(state_to_int_map.size(), numberToStateNoReject.length);
      Collection<CmpVertex> states_int = state_to_int_map.keySet();
      Assert.assertEquals(ndGraph.getStateNumber(),state_to_int_map.values().size());
      Assert.assertArrayEquals(states_int.toArray(),numberToStateNoReject);
     
      Set<CmpVertex> expectedIgnoredStates = new TreeSet<CmpVertex>();for(String st:expectedIgnored) expectedIgnoredStates.add(gr.findVertex(st));
      Assert.assertEquals(states_int,expectedIgnoredStates);
     
View Full Code Here

Examples of statechum.analysis.learning.linear.GDLearnerGraph

 
  @Test
  public final void testVertexToInt0()
  {
    LearnerGraph textGraph = buildLearnerGraph("A-a->A-b->B-c-#C","testVertexToInt0",config,converter);
    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

Examples of statechum.analysis.learning.linear.GDLearnerGraph

  }
  @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

Examples of statechum.analysis.learning.linear.GDLearnerGraph

    Configuration conf = Configuration.getDefaultConfiguration().copy();conf.setTransitionMatrixImplType(STATETREE.STATETREE_SLOWTREE);
    LearnerGraph gr=buildLearnerGraph(graph,graphName,conf,null);
    StatesToConsider filter = createInstanceOfFilter(filterClass, gr);
    for(boolean direction:new boolean[]{false,true})
    {
      GDLearnerGraph ndGraph = new GDLearnerGraph(gr,filter, direction);
      Map<CmpVertex,Integer> state_to_int_map = new TreeMap<CmpVertex,Integer>();
      CmpVertex [] numberToStateNoReject = gr.buildStateToIntegerMap(filter,state_to_int_map);
      Assert.assertEquals(state_to_int_map.size(), numberToStateNoReject.length);
      Collection<CmpVertex> states_int = state_to_int_map.keySet();
      Assert.assertEquals(ndGraph.getStateNumber(),state_to_int_map.values().size());
      Assert.assertArrayEquals(states_int.toArray(),numberToStateNoReject);
     
      Set<CmpVertex> expectedIgnoredStates = new TreeSet<CmpVertex>();for(String st:expectedToRemain) expectedIgnoredStates.add(gr.findVertex(st));
      Assert.assertEquals(states_int,expectedIgnoredStates);
     
View Full Code Here

Examples of statechum.analysis.learning.linear.GDLearnerGraph

  {
    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

Examples of statechum.analysis.learning.linear.GDLearnerGraph

 
  @Test
  public final void testVertexToInt0()
  {
    LearnerGraph textGraph = buildLearnerGraph("A-a->A-b->B-c-#C","testVertexToInt0",config,converter);
    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

Examples of statechum.analysis.learning.linear.GDLearnerGraph

  }
  @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
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.