Package statechum.analysis.learning.rpnicore.AbstractLearnerGraph

Examples of statechum.analysis.learning.rpnicore.AbstractLearnerGraph.StatesToConsider


  protected DoubleMatrix2D getExpectedMatrix2DSlowly(LearnerGraph gr)
  {
    int size=gr.getStateNumber()*(gr.getStateNumber()+1)/2;
    DoubleMatrix2D result = DoubleFactory2D.sparse.make(size,size,0);
    StatesToConsider filter = LearnerGraphND.ignoreRejectStates;
    GDLearnerGraph ndGraph = new GDLearnerGraph(gr,filter, false);
    for(Entry<CmpVertex,Map<Label,List<CmpVertex>>> entryA:ndGraph.matrixForward.transitionMatrix.entrySet())
    {
      // Now iterate through states
      Iterator<Entry<CmpVertex,Map<Label,List<CmpVertex>>>> stateB_It = ndGraph.matrixForward.transitionMatrix.entrySet().iterator();
View Full Code Here


 
  /** Uses computePairCompatibilityScore_general to identify incompatible pairs of states. */
  protected static Set<StatePair> buildSetOfIncompatiblePairsSlowly(final LearnerGraph gr,int ThreadNumber)
  {
    final Set<StatePair> result = Collections.synchronizedSet(new LinkedHashSet<StatePair>());
    final StatesToConsider filter = LearnerGraphND.ignoreRejectStates;
    final GDLearnerGraph ndGraph = new GDLearnerGraph(gr,filter, false);
    List<GDLearnerGraph.HandleRow<List<CmpVertex>>> handlerList = new LinkedList<GDLearnerGraph.HandleRow<List<CmpVertex>>>();
    for(int threadCnt=0;threadCnt<ThreadNumber;++threadCnt)
    handlerList.add(new GDLearnerGraph.HandleRow<List<CmpVertex>>()
    {
View Full Code Here

  }

  protected final void findIncompatibleTestHelper(LearnerGraph gr,List<StringPair> incompatibles_list)
  {
    HashSet<StatePair> incompatibles = new HashSet<StatePair>();
    StatesToConsider filter = LearnerGraphND.ignoreRejectStates;
    GDLearnerGraph ndGraph = new GDLearnerGraph(gr,filter, false);
    for(StringPair p:incompatibles_list)
    {
      incompatibles.add(new StatePair(gr.findVertex(p.firstElem),gr.findVertex(p.secondElem)));
      incompatibles.add(new StatePair(gr.findVertex(p.secondElem),gr.findVertex(p.firstElem)));
    }
    Set<StatePair> incompatiblePairs = new HashSet<StatePair>();
    for(StatePair s:buildSetOfIncompatiblePairsSlowly(gr,threadNumber))
    {
      incompatiblePairs.add(s);incompatiblePairs.add(new StatePair(s.secondElem,s.firstElem));
    }
    // incompatiblePairs these are the pairs which cannot be merged which may be a larger set than
    // the set of clearly incompatible pairs, because incompatiblePairs is computed based on
    // the outcome of computePairCompatibilityScore_general. The difference between computing incompatibility of pairs
    // and doing computePairCompatibilityScore_general is that when pairs are merged, more traces
    // are created, hence it is possible that some of those new traces will be in conflict.
    // Example: states A3 and A2 in findIncompatibleStates6()
    HashSet<StatePair> pairs_extra = new HashSet<StatePair>();pairs_extra.addAll(incompatibles);pairs_extra.removeAll(incompatiblePairs);
    Assert.assertTrue("compatible pairs included :"+pairs_extra,pairs_extra.isEmpty());// this is a check that incompatibles_list does not include any compatible pairs

    final int size=ndGraph.getPairNumber();
    final int highNumber = 10000;
    int pairs[]=new int[size];for(int i=0;i<pairs.length;++i) pairs[i]=highNumber;
   
    // reverseMap maps state pair number to the actual state pairs, we slowly build it here
    // rather then rely on getPairScore() which may have not even been written when
    // I was doing this kind of testing.
    reverseMap = new HashMap<Integer,StatePair>();
    for(CmpVertex A:gr.transitionMatrix.keySet())
      if (filter.stateToConsider(A))
        for(CmpVertex B:gr.transitionMatrix.keySet())
          if (filter.stateToConsider(B))
            reverseMap.put(ndGraph.vertexToIntNR(A, B), new StatePair(A,B));
    Assert.assertEquals(size,reverseMap.size());
   
    ndGraph.buildMatrix(threadNumber);
    ndGraph.findIncompatiblePairs(pairs,threadNumber);
View Full Code Here

  private final void TestScoreComputationWithFilters(Class<? extends StatesToConsider> filterClass)
  {
    LearnerGraph gr=buildLearnerGraph(machineCompatibility2+
        "\nB-b-#G\n","TestComputeStateCompatibility_checking_filtering2",config,converter);
    StatesToConsider filter = TestLearnerGraphND.createInstanceOfFilter(filterClass, gr);
    double score_CC=1./2,score_BB=(2+score_CC*k)/4, score_AA=(1+k*score_BB)/2;
    {
      GDLearnerGraph ndGraph = new GDLearnerGraph(gr,LearnerGraphND.ignoreNone, false);
      LSolver solver = ndGraph.buildMatrix(threadNumber);
      DoubleMatrix2D Ax=solver.toDoubleMatrix2D();
View Full Code Here

   *
   * @return an instance of filter.
   */
  public static StatesToConsider createInstanceOfFilter(Class<? extends StatesToConsider> filterClass,LearnerGraph gr)
  {
    StatesToConsider filter = null;
    try {
      java.lang.reflect.Constructor<? extends StatesToConsider> constructor = filterClass.getConstructor(new Class []{});
      filter = constructor.newInstance(new Object[]{});
    } catch (Exception e) {
      // if we failed, filter stays at null, we'll try again.
View Full Code Here

   */
  private final void checkConsideringIgnoredStates(String graph, String graphName, Class<? extends StatesToConsider> filterClass, String [] expectedToRemain)
  {
    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);
View Full Code Here

            }
            assert highState != null;
            currentWave.add(new PairScore(entryA.getKey(),highState,(int)(multiplier*scoreHigh),(int)(multiplier*scoreLow)));
          }
        });
      GDLearnerGraph.performRowTasks(handlerList, ThreadNumber, grCombined.transitionMatrix,new StatesToConsider() {
        public boolean stateToConsider(CmpVertex vert) {
          return statesOfA.contains(vert);
        }
      }, GDLearnerGraph.partitionWorkLoadLinear(ThreadNumber,statesOfA.size()));
 
View Full Code Here

  }
 
  public static void printTraceLeadingTo(LearnerGraph graph, String vert)
  {
    LearnerGraphND ptaInverse = new LearnerGraphND(graph.config);
    AbstractPathRoutines.buildInverse(graph, new StatesToConsider() {
      @Override public boolean stateToConsider(@SuppressWarnings("unused") CmpVertex v) { return true; }}
      , ptaInverse);
    CmpVertex v=ptaInverse.findVertex(vert);
    for(int i=0;i<10;++i)
    {
View Full Code Here

   *
   * @return an instance of filter.
   */
  public static StatesToConsider createInstanceOfFilter(Class<? extends StatesToConsider> filterClass,LearnerGraph gr)
  {
    StatesToConsider filter = null;
    try {
      java.lang.reflect.Constructor<? extends StatesToConsider> constructor = filterClass.getConstructor(new Class []{});
      filter = constructor.newInstance(new Object[]{});
    } catch (Exception e) {
      // if we failed, filter stays at null, we'll try again.
View Full Code Here

   */
  private final void checkConsideringIgnoredStates(String graph, String graphName, Class<? extends StatesToConsider> filterClass, String [] expectedIgnored)
  {
    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);
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.rpnicore.AbstractLearnerGraph.StatesToConsider

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.