Package statechum.analysis.learning.rpnicore

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


    Set<List<Label>> plusStrings = buildSet(new String[][] { new String[]{"a","b"},new String[]{"c","u"} },config,converter), minusStrings = buildSet(new String[][] { new String[]{"a","u"} },config,converter);
    m.createMarkovLearner(plusStrings, minusStrings,false);
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B / A-c->B-b->C / B-u->F / T-b->T-u->T","testCheckFanoutInconsistency2",config, converter);
   
    Configuration shallowCopy = graph.config.copy();shallowCopy.setLearnerCloneGraph(false);
    LearnerGraphND Inverse_Graph = new LearnerGraphND(shallowCopy);
    AbstractPathRoutines.buildInverse(graph,LearnerGraphND.ignoreNone,Inverse_Graph)// do the inverse to the tentative graph
    Assert.assertEquals(2,m.checkFanoutInconsistency(Inverse_Graph,true,graph,graph.findVertex("B"),m.getChunkLen(), new MarkovUniversalLearner.DifferentPredictionsInconsistency(graph)));
  }
View Full Code Here


    Set<List<Label>> plusStrings = buildSet(new String[][] { new String[]{"a","b"},new String[]{"c","b"},new String[]{"c","u"} },config,converter), minusStrings = buildSet(new String[][] { new String[]{"a","u"} },config,converter);
    m.createMarkovLearner(plusStrings, minusStrings,false);
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B / A-c->B-u->C / T-b->T-u->T","testCheckFanoutInconsistency3",config, converter);
   
    Configuration shallowCopy = graph.config.copy();shallowCopy.setLearnerCloneGraph(false);
    LearnerGraphND Inverse_Graph = new LearnerGraphND(shallowCopy);
    AbstractPathRoutines.buildInverse(graph,LearnerGraphND.ignoreNone,Inverse_Graph)// do the inverse to the tentative graph
    Assert.assertEquals(1,m.checkFanoutInconsistency(Inverse_Graph,true,graph,graph.findVertex("B"),m.getChunkLen(), new MarkovUniversalLearner.DifferentPredictionsInconsistency(graph)));
  }
View Full Code Here

    Set<List<Label>> plusStrings = buildSet(new String[][] { new String[]{"a","b"},new String[]{"c","b"},new String[]{"c","u"} },config,converter), minusStrings = buildSet(new String[][] { new String[]{"a","u"} },config,converter);
    m.createMarkovLearner(plusStrings, minusStrings,false);
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->D-b->C / A-c->B-b->C / B-u->E / T-b->T-u->T","testCheckFanoutInconsistency4",config, converter);
   
    Configuration shallowCopy = graph.config.copy();shallowCopy.setLearnerCloneGraph(false);
    LearnerGraphND Inverse_Graph = new LearnerGraphND(shallowCopy);
    AbstractPathRoutines.buildInverse(graph,LearnerGraphND.ignoreNone,Inverse_Graph)// do the inverse to the tentative graph
    Assert.assertEquals(0,m.checkFanoutInconsistency(Inverse_Graph,true,graph,graph.findVertex("B"),m.getChunkLen(), new MarkovUniversalLearner.DifferentPredictionsInconsistency(graph)));// everything as expected.
    Assert.assertEquals(0,m.checkFanoutInconsistency(Inverse_Graph,true,graph,graph.findVertex("D"),m.getChunkLen(), new MarkovUniversalLearner.DifferentPredictionsInconsistency(graph)));// missing reject-transition with label u is ignored because we are only considering actual outgoing transitions
  }
View Full Code Here

    {// duplicates state names found, hence use the unique names the corresponding states were given in grCombined (given via addToGraph)
      if (grCombined.config.getGdFailOnDuplicateNames()) throw new IllegalArgumentException("names of states "+duplicates+" are shared between A and B");
    }
   
    Configuration config = Configuration.getDefaultConfiguration().copy();config.setLearnerCloneGraph(false);
    final LearnerGraphND added = new LearnerGraphND(config),removed = new LearnerGraphND(config);
    added.initEmpty();removed.initEmpty();// to make sure we can handle an assignment of a reject-state to an initial state

    final Set<CmpVertex> extraVertices = new TreeSet<CmpVertex>();
   
    // Now collect the changes, where vertices to be added can cancel out with those to be removed. This is needed because
    // there could be transitions between key pairs in A such that there are transitions between vertices with the same
    // names in B that are part of other pairs. When we calculate which transitions between key pairs to add or remove,
    // it is difficult to take this into account on the fly. This is why a separate pass is done.
    new DCollector()
    {
      @Override
      public void addTransition(CmpVertex from, Label label, CmpVertex to) {
        super.addTransition(from, label, to);
        Map<Label,List<CmpVertex>> rowInAdd = added.transitionMatrix.get(from);
        if (rowInAdd == null)
        {
          rowInAdd = added.createNewRow();added.transitionMatrix.put(from, rowInAdd);
        }
        added.addTransition(rowInAdd, label, to);
      }

      @Override
      public void removeTransition(CmpVertex from, Label label, CmpVertex to) {
        super.removeTransition(from, label, to);
        Map<Label,List<CmpVertex>> rowInAdd = removed.transitionMatrix.get(from);
        if (rowInAdd == null)
        {
          rowInAdd = removed.createNewRow();removed.transitionMatrix.put(from, rowInAdd);
        }
        removed.addTransition(rowInAdd, label, to);
      }

      @Override
      public void setInitial(CmpVertex vertex) {
        graphToPatch.setInitial(vertex);
      }

      @Override
      public void addToCompatibility(CmpVertex a, CmpVertex b, JUConstants.PAIRCOMPATIBILITY value) {
        super.addToCompatibility(a,b,value);
        added.addToCompatibility(a, b, value);
      }

      @Override
      public void addVertex(CmpVertex vertex) {
        extraVertices.add(vertex);
      }

      @Override
      public void removeFromCompatibility(CmpVertex a, CmpVertex b, JUConstants.PAIRCOMPATIBILITY value) {
        super.removeFromCompatibility(a,b,value);
        removed.addToCompatibility(a, b, value);
      }

      @Override
      public void addRelabelling(VertID a, VertID b) {
        graphToPatch.addRelabelling(a, b);
      }
     
    }.computeGD();
   
    // Second phase - collect transitions that have not been cancelled out.
    // The vertex-removal phase keeps all states that are part of transitions (indirectly,
    // those that are to be added or part of associations to be added).
    // Hence we may only remove vertices from extraVertices for transitions and/or associations that are to be added.
   
    // The purpose of checkTransitionPresent and checkCompatibilityAnnotationPresent is to eliminate duplicate
    // transitions (where a transition between the same pair of states is removed and then added). This happens
    // in two cases,
    // (a) where a transition between unmatched states of A is removed and subsequently added between states of B
    // (b) where a transition between unmatched states of A is removed but these states correspond to key states of B
    // that contain a transition that is missing between the components of those keys states in A and hence is added.
    for(Entry<CmpVertex,Map<Label,List<CmpVertex>>> entry:removed.transitionMatrix.entrySet())
      for(Entry<Label,List<CmpVertex>> transition:entry.getValue().entrySet())
        for(CmpVertex target:removed.getTargets(transition.getValue()))
          if (!checkTransitionPresent(added, entry.getKey(), transition.getKey(), target))
            graphToPatch.removeTransition(entry.getKey(), transition.getKey(), target);

    for(Entry<CmpVertex,Map<Label,List<CmpVertex>>> entry:added.transitionMatrix.entrySet())
      for(Entry<Label,List<CmpVertex>> transition:entry.getValue().entrySet())
View Full Code Here

    a.pathroutines.checkConsistency(a);
    b.pathroutines.checkConsistency(b);

    ThreadNumber = threads;
    Configuration cloneConfig = argConfig.copy();cloneConfig.setLearnerCloneGraph(true);// we need to clone attributes here because after key pair identification, attributes from graph B will be copied into vertices of A, otherwise these attributes may not make it into the patch.
    grCombined = new LearnerGraphND(a,cloneConfig);// I cannot simply do Transform.addToGraph here because patch has to be relative to graph A.
    grCombined.config.setLearnerCloneGraph(false);//reset the clone attribute
    grCombined.vertNegativeID=Math.max(grCombined.vertNegativeID, b.vertNegativeID);// we aim for new vertices in grCombined to have ids different from all vertices in B.
    grCombined.vertPositiveID=Math.max(grCombined.vertPositiveID, b.vertPositiveID);
    combined_initA = grCombined.getInit();
    origToNewB = new TreeMap<CmpVertex,CmpVertex>();
View Full Code Here

    Configuration gdConfig = a.config.copy();gdConfig.setGdFailOnDuplicateNames(false);gdConfig.setTransitionMatrixImplType(STATETREE.STATETREE_SLOWTREE);
    init(a,b, threads,gdConfig);
    identifyKeyPairs();
    final List<PairScore> initialKeyPairs = new LinkedList<PairScore>();initialKeyPairs.addAll(frontWave);
    final Map<VertID,VertID> oldVerticesToNew = new TreeMap<VertID,VertID>();
    final LearnerGraphND outcome = new LearnerGraphND(a,gdConfig);outcome.setName(outcome.getName()+"_diff");
    final LearnerGraphMutator<List<CmpVertex>,LearnerGraphNDCachedData> mutator =
      new LearnerGraphMutator<List<CmpVertex>,LearnerGraphNDCachedData>(outcome,gdConfig,null);

    final EdgeAnnotation transitionAnnotation = new EdgeAnnotation();
    final Map<StatePair,TransitionChanges> pairToNumberOfChanges = new TreeMap<StatePair,TransitionChanges>();
    for(Entry<CmpVertex,Map<Label,TARGET_A_TYPE>> entry:a.transitionMatrix.entrySet())
      for(Entry<Label,TARGET_A_TYPE> transition:entry.getValue().entrySet())
        for(CmpVertex target:a.getTargets(transition.getValue()))
        {
          TransitionChanges changes = pairToNumberOfChanges.get(new StatePair(entry.getKey(), target));
          if (changes == null)
          {
            changes = new TransitionChanges();pairToNumberOfChanges.put(new StatePair(entry.getKey(), target),changes);
          }
          changes.orig++;// we populate our map with the existing transitions
         
        }
    makeSteps();
    computeDifference(new PatchGraph() {
      protected Label copyVertexWithPrefix(String prefix, Label origLabel)
      {
        Label result = null;
        if (origLabel instanceof StringLabel)
          result = new StringLabel(prefix+origLabel);
        else
        if (origLabel instanceof ErlangLabel)
        {
          ErlangLabel oErl = (ErlangLabel)origLabel;
          result = new ErlangLabel(oErl.function,prefix+oErl.callName,
              oErl.input, oErl.expectedOutput);
        }
        else
          assert false;
       
        return result;
      }
     
      @Override
      public void addTransition(CmpVertex from, Label origLabel, CmpVertex to)
      {
        Label label = copyVertexWithPrefix("ADD_",origLabel);
        mutator.addTransition(from, label, to);
        TransitionChanges changes = pairToNumberOfChanges.get(new StatePair(from,to));
        if (changes == null)
        {
          changes = new TransitionChanges();pairToNumberOfChanges.put(new StatePair(from,to),changes);
        }
        changes.added++;
      }

      @Override
      public void removeTransition(CmpVertex from, Label origLabel, CmpVertex to)
      {
        Label label = copyVertexWithPrefix("REM_",origLabel);
        mutator.removeTransition(from, origLabel, to);// remove the original transition
        mutator.addTransition(from, label, to);// and add the renamed one
        TransitionChanges changes = pairToNumberOfChanges.get(new StatePair(from,to));
        if (changes == null)
        {
          changes = new TransitionChanges();pairToNumberOfChanges.put(new StatePair(from,to),changes);
        }
        changes.removed++;
      }

      @Override
      public void setInitial(CmpVertex vertex)
      {
        mutator.setInitial(vertex);
      }

      @Override
      public void addToCompatibility(@SuppressWarnings("unused") CmpVertex astate,
          @SuppressWarnings("unused") CmpVertex bstate, @SuppressWarnings("unused") JUConstants.PAIRCOMPATIBILITY value) {
        // does not do anything
      }

      @Override
      public void addRelabelling(VertID astate, VertID bstate) {
        renameVertex(astate, "["+bstate+"] ",oldVerticesToNew);
      }

      @Override
      public void addVertex(CmpVertex vertex) {
        mutator.addNewVertex(vertex);
      }

      @SuppressWarnings("unused")
      @Override
      public void removeFromCompatibility(CmpVertex astate, CmpVertex bstate, JUConstants.PAIRCOMPATIBILITY value) {
        // does not do anything
      }
    });

    for(Entry<StatePair,TransitionChanges> pc:pairToNumberOfChanges.entrySet())
    {
      CmpVertex from = pc.getKey().getQ(), to = pc.getKey().getR();
      Map<Label,Map<String,Color>> lbl = transitionAnnotation.get(from.getStringId());
      if (lbl == null)
      {
        lbl = new TreeMap<Label,Map<String,Color>>();transitionAnnotation.put(from.getStringId(), lbl);
      }
      for(Entry<Label,List<CmpVertex>> transition:outcome.transitionMatrix.get(from).entrySet())
        for(CmpVertex target:outcome.getTargets(transition.getValue()))
          if (to.equals(target))
          {
            Map<String,Color> targetToColour = lbl.get(transition.getKey());
            if (targetToColour == null)
            {// this is the first annotation for the specific target state
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

  {
    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().copy());
    vertices = new ArrayList<CmpVertex>();
    generator  = new MersenneTwister(seed);
    this.alphabet = alphabetArg;
    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

        {
          ExperimentResult outcome = new ExperimentResult();
          while(!outcome.experimentValid)
          {
            int mutations = mutationsPerStage * (mutationStage+1);
            LearnerGraphND origGraph = mg.nextMachine(alphabet, experiment,config);
            GraphMutator<List<CmpVertex>,LearnerGraphNDCachedData> mutator = new GraphMutator<List<CmpVertex>,LearnerGraphNDCachedData>(origGraph,r);
            mutator.mutate(mutations);
            LearnerGraphND origAfterRenaming = new LearnerGraphND(origGraph.config);
            Map<CmpVertex,CmpVertex> origToNew = copyStatesAndTransitions(origGraph,origAfterRenaming);
            LearnerGraphND mutated = (LearnerGraphND)mutator.getMutated();
            Set<Transition> appliedMutations = new HashSet<Transition>();
            for(Transition tr:mutator.getDiff())
            {
              CmpVertex renamedFrom = origToNew.get(tr.getFrom());if (renamedFrom == null) renamedFrom = tr.getFrom();
              CmpVertex renamedTo = origToNew.get(tr.getTo());if (renamedTo == null) renamedTo = tr.getTo();
View Full Code Here

TOP

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

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.