Package statechum.analysis.learning.rpnicore

Examples of statechum.analysis.learning.rpnicore.LearnerGraphND$ignoreZeroClass


        }
        if(!found)
          throw new RuntimeException();//adjustArtificialTargetSize();
      }
     
      LearnerGraphND outcome = new LearnerGraphND(machine.config);AbstractLearnerGraph.copyGraphs(machine,outcome);
      return outcome;
    }
View Full Code Here


  {
    this.forwards = argForward;this.backwards = argBackward;selfLoop=argSelfloop;
    if(!(argForward > 0 && argForward < 1) || !(argBackward > 0 && argBackward <= 1))
      throw new IllegalArgumentException("invalid scopes for backwards or forwards");
    visited = new HashSet<CmpVertex>();
    machine = new LearnerGraphND(Configuration.getDefaultConfiguration());
    vertices = new ArrayList<CmpVertex>();
    generator  = new MersenneTwister(seed);
    this.alphabet = alphabet;
    boolGenerator = new Random(seed);
    CmpVertex v= AbstractLearnerGraph.generateNewCmpVertex(new VertexID(VertexID.VertKind.NEUTRAL,0), Configuration.getDefaultConfiguration())//new ();
View Full Code Here

  protected LearnerGraphND buildMachine(int size)
  {
    buildGraph(size);
    Configuration conf = Configuration.getDefaultConfiguration();
    //conf.setAllowedToCloneNonCmpVertex(true);
    return new LearnerGraphND(machine,conf);
  }
View Full Code Here

    GDLearnerGraph(AbstractLearnerGraph<TARGET_A_TYPE,CACHE_A_TYPE> coregraph,
    StatesToConsider stateFilter,
    boolean direction)
  {
    alphabet = coregraph.learnerCache.getAlphabet();config=coregraph.config;filter=stateFilter;
    matrixInverse = new LearnerGraphND(config);matrixInverse.initEmpty();
    matrixForward = new LearnerGraphND(config);matrixForward.initEmpty();
    pairCompatibility = coregraph.pairCompatibility;
   
    stateToNumberMap = new TreeMap<CmpVertex,Integer>();
    numberToStateArray = coregraph.buildStateToIntegerMap(filter,stateToNumberMap);
    assert numberToStateArray.length == stateToNumberMap.size();
View Full Code Here

    public ChangesRecorder(PatchGraph nextInStack)
    {
      next = nextInStack;
      Configuration config = Configuration.getDefaultConfiguration().copy();config.setLearnerCloneGraph(false);
      added = new LearnerGraphND(config);removed = new LearnerGraphND(config);removed.initEmpty();
      added.setInit(null);added.initEmpty();// to make sure we can handle an assignment of a reject-state to an initial state
      addedPatcher = new LearnerGraphMutator<List<CmpVertex>,LearnerGraphNDCachedData>(added, config,null);
      removedPatcher = new LearnerGraphMutator<List<CmpVertex>,LearnerGraphNDCachedData>(removed,config,null);
    }
View Full Code Here

     * @param elem element containing the difference.
     */
    static public void loadDiff(PatchGraph graphPatcher, Element elem)
    {
      Configuration config = Configuration.getDefaultConfiguration().copy();config.setLearnerCloneGraph(false);
      LearnerGraphND gr = new LearnerGraphND(config);AbstractPersistence.loadGraph(getGraphElement(elem, StatechumXML.gdRemoved.toString(),false,true),gr);
      //System.out.println("removed: "+gr.transitionMatrix.keySet());
      for(Entry<CmpVertex,Map<Label,List<CmpVertex>>> entry:gr.transitionMatrix.entrySet())
        for(Entry<Label,List<CmpVertex>> transition:entry.getValue().entrySet())
          for(CmpVertex target:gr.getTargets(transition.getValue()))
            graphPatcher.removeTransition(entry.getKey(), transition.getKey(), target);
         
      for(Entry<CmpVertex,Map<CmpVertex,JUConstants.PAIRCOMPATIBILITY>> incompatibles:gr.pairCompatibility.compatibility.entrySet())
        for(CmpVertex target:incompatibles.getValue().keySet())
          graphPatcher.removeFromCompatibility(incompatibles.getKey(), target);
     
      AbstractPersistence.loadGraph(getGraphElement(elem, StatechumXML.gdAdded.toString(),false,true),gr);
      //System.out.println("added: "+gr.transitionMatrix.keySet()+"\n with incompatibles : "+gr.pairCompatibility.keySet());
     
      for(Entry<CmpVertex,Map<Label,List<CmpVertex>>> entry:gr.transitionMatrix.entrySet())
      {
        if (entry.getValue().isEmpty())
          graphPatcher.addVertex(entry.getKey());
        else
          for(Entry<Label,List<CmpVertex>> transition:entry.getValue().entrySet())
            for(CmpVertex target:gr.getTargets(transition.getValue()))
              graphPatcher.addTransition(entry.getKey(), transition.getKey(), target);
      }
      for(Entry<CmpVertex,Map<CmpVertex,JUConstants.PAIRCOMPATIBILITY>> incompatibles:gr.pairCompatibility.compatibility.entrySet())
        for(Entry<CmpVertex,JUConstants.PAIRCOMPATIBILITY> targetEntry:incompatibles.getValue().entrySet())
          graphPatcher.addToCompatibility(incompatibles.getKey(), targetEntry.getKey(), targetEntry.getValue());
     
      NodeList relabellingElementList=  StatechumXML.getChildWithTag(elem,StatechumXML.gdRelabelling.toString());
      if (relabellingElementList.getLength() > 0)
      {// load the relabelling if present.
        getGraphElement(elem, StatechumXML.gdRelabelling.toString(),true,false);// check that XML structure is consistent and there are pairs stored - will throw otherwise
        Element relabellingElement = (Element)relabellingElementList.item(0);
        NodeList children = relabellingElement.getChildNodes();
        for(int childNum=0;childNum<children.getLength();++childNum)
          if (children.item(childNum).getNodeType() == Node.ELEMENT_NODE)
          {
            PairScore pair=ProgressDecorator.readPair(gr, (Element)children.item(childNum));
            graphPatcher.addRelabelling(pair.getQ().getID(), pair.getR().getID());
          }
      }
      graphPatcher.setInitial(gr.getInit());
    }
View Full Code Here

            fileA1 = files[fileNum],
            fileA2 = files[(fileNum+1)%files.length],
            fileB1 = files[(fileNum+2)%files.length],
            fileB2 = files[(fileNum+3)%files.length];
       
          LearnerGraphND grA = null, grB = null;
          {
            LearnerGraphND loadedA1 = new LearnerGraphND(config);AbstractPersistence.loadGraph(fileA1, loadedA1);
            LearnerGraph loadedA2 = new LearnerGraph(config);AbstractPersistence.loadGraph(fileA2, loadedA2);
            grA = LearnerGraphND.UniteTransitionMatrices(loadedA1,loadedA2);
            addColourAndTransitionsRandomly(grA, new Random(0));
          }
         
          {
            LearnerGraphND loadedB1 = new LearnerGraphND(config);AbstractPersistence.loadGraph(fileB1, loadedB1);
            LearnerGraph loadedB2 = new LearnerGraph(config);AbstractPersistence.loadGraph(fileB2, loadedB2);
            grB = LearnerGraphND.UniteTransitionMatrices(loadedB1,loadedB2);
            addColourAndTransitionsRandomly(grB, new Random(1));
          }
         
View Full Code Here

  static void linearDiff(LearnerGraph cvsGraphD, LearnerGraphND otherGraph)
  {
    //GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData> gd = new GD<CmpVertex,CmpVertex,LearnerGraphCachedData,LearnerGraphCachedData>();
    GD<List<CmpVertex>,List<CmpVertex>,LearnerGraphNDCachedData,LearnerGraphNDCachedData> gd = new GD<List<CmpVertex>,List<CmpVertex>,LearnerGraphNDCachedData,LearnerGraphNDCachedData>();
    LearnerGraphND cvsGraph = new LearnerGraphND(cvsGraphD,config);
    ChangesCounter<List<CmpVertex>,List<CmpVertex>,LearnerGraphNDCachedData,LearnerGraphNDCachedData>  rec3 = new ChangesCounter<List<CmpVertex>,List<CmpVertex>,LearnerGraphNDCachedData,LearnerGraphNDCachedData>(cvsGraph,otherGraph,null);
    gd.computeGD(cvsGraph, otherGraph, 1, rec3, config);
    int intersection = cvsGraph.pathroutines.countEdges()-rec3.getRemoved();
    assert otherGraph.pathroutines.countEdges() == intersection+rec3.getAdded();
    System.out.println(otherGraph.getName()+": precision = "+((double)intersection/otherGraph.pathroutines.countEdges())+" recall = "+((double)intersection/cvsGraph.pathroutines.countEdges()));
View Full Code Here

        "q10-appendfile->q11 /" +
        "q13-retrievefile->q13","sd_cvs",config,null),
        markovD = buildLearnerGraphND(markovString.replace("PART2", "a").replace("PART3", "a"),"sd_markovD",config,null).pathroutines.buildDeterministicGraph(),
        edsm = buildLearnerGraph("a-initialise->b-connect->c-login->d-storefile->e-changedir->d-listfiles->e-retrievefile->e-logout->i-disconnect->l\nd-delete->d-makedir->d-changedir->f-listnames->d-logout->g-disconnect->j\nd-setfiletype->h-storefile->k-appendfile->m-setfiletype->n-rename->o-storefile->m\nd-appendfile->o-logout->p-disconnect->q","sd_edsm",config,null)
        ;
    LearnerGraphND
      markov = buildLearnerGraphND(markovString,"sd_markov",config,null);
    markovD.setName("sd_markovD");

    Set<Label> origAlphabet = cvsGraph.pathroutines.computeAlphabet();
    assert origAlphabet.equals(markov.pathroutines.computeAlphabet());
    assert origAlphabet.equals(markovD.pathroutines.computeAlphabet());
    assert origAlphabet.equals(edsm.pathroutines.computeAlphabet());
    final RandomPathGenerator generator = new RandomPathGenerator(cvsGraph,new Random(0),5,null);
    final int posOrNegPerChunk = 50;
    generator.generateRandomPosNeg(posOrNegPerChunk*2,1);
    Collection<List<Label>> sequences = cvsGraph.wmethod.getFullTestSet(1);//generator.getAllSequences(0).getData(PTASequenceEngine.truePred);

    PTASequenceEngine walkEngine = new PTA_FSMStructure(cvsGraph,null);
    SequenceSet ptaWalk = walkEngine.new SequenceSet();ptaWalk.setIdentity();
    ptaWalk = ptaWalk.cross(sequences);
   
   
   
    PTA_computePrecisionRecall precRec = null;
   
    {
      precRec = new PTA_computePrecisionRecall(markovD);
      precRec.crossWith(walkEngine);PosNegPrecisionRecall result = precRec.getPosNegPrecisionRecallNum();
      final String name = "Markov";
      System.out.println(name+": +precision "+result.getPosprecision()+" +recall: "+result.getPosrecall());
      System.out.println(name+": -precision "+result.getNegprecision()+" -recall: "+result.getNegrecall());
      System.out.println(name+": =precision "+result.getPrecision()+" =recall: "+result.getRecall());
    }

    {
      precRec = new PTA_computePrecisionRecall(edsm);
      precRec.crossWith(walkEngine);PosNegPrecisionRecall result = precRec.getPosNegPrecisionRecallNum();
      final String name = "EDSM";
      System.out.println(name+": +precision "+result.getPosprecision()+" +recall: "+result.getPosrecall());
      System.out.println(name+": -precision "+result.getNegprecision()+" -recall: "+result.getNegrecall());
      System.out.println(name+": =precision "+result.getPrecision()+" =recall: "+result.getRecall());
    }
   
    linearDiff(cvsGraph, markov);
    linearDiff(cvsGraph, new LearnerGraphND(edsm,config));
  }
View Full Code Here

  }

  static void linearDiff(LearnerGraph cvsGraphD, LearnerGraphND otherGraph)
  {
    GD<List<CmpVertex>,List<CmpVertex>,LearnerGraphNDCachedData,LearnerGraphNDCachedData> gd = new GD<List<CmpVertex>,List<CmpVertex>,LearnerGraphNDCachedData,LearnerGraphNDCachedData>();
    LearnerGraphND cvsGraph = new LearnerGraphND(cvsGraphD,config);
    ChangesCounter<List<CmpVertex>,List<CmpVertex>,LearnerGraphNDCachedData,LearnerGraphNDCachedData>  rec3 = new ChangesCounter<List<CmpVertex>,List<CmpVertex>,LearnerGraphNDCachedData,LearnerGraphNDCachedData>(cvsGraph,otherGraph,null);
    gd.computeGD(cvsGraph, otherGraph, 1, rec3, config);
    int intersection = cvsGraph.pathroutines.countEdges()-rec3.getRemoved();
    assert otherGraph.pathroutines.countEdges() == intersection+rec3.getAdded();
    System.out.println("PLTSDIFF, "+otherGraph.getName()+": precision = "+((double)intersection/otherGraph.pathroutines.countEdges())+" recall = "+((double)intersection/cvsGraph.pathroutines.countEdges()))
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.rpnicore.LearnerGraphND$ignoreZeroClass

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.