Package statechum.analysis.learning.rpnicore

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


                        if (command.equals(msgComputeDiff) && message.arity() == 4)
                        {
                          OtpErlangObject outcome = null;
                          try
                          {
                            LearnerGraphND grA = new LearnerGraphND(learnerInitConfiguration.config), grB = new LearnerGraphND(learnerInitConfiguration.config);
                            Synapse.StatechumProcess.parseStatemachine(message.elementAt(2),grA,null,true);
                            Synapse.StatechumProcess.parseStatemachine(message.elementAt(3),grB,null,true);
                            OtpErlangObject difference  = DifferenceVisualiser.ChangesToGraph.computeGD(grA, grB, learnerInitConfiguration.config);
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgOk,difference});
                          }
                          catch(Throwable ex)
                          {
                            ex.printStackTrace();
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgFailure,new OtpErlangList(ex.getMessage())});
                          }
                          mbox.send(erlangPartner,outcome);
                        }
                        else
                        // Args: Ref,learn, pid
                        // pid is optional, where provided, progress messages are reported in a form of {Ref,'status',step}
                        // in the course of learning, the learner is receptive to messages directed at its normal PID, a {Ref,terminate} command will kill it and the response will be {Ref,terminate}.
                        // Response: Ref,ok,fsm
                        // on error: Ref,failure,text_of_the_error (as string)
                        if (command.equals(msgLearnEDSM) && message.arity() >= 2)
                        {
                          OtpErlangObject outcome = null;
                          try
                          {
                            final AtomicLong counter = new AtomicLong();
                            RPNIUniversalLearner learner = new RPNIUniversalLearner(null, learnerInitConfiguration) {

                              @Override
                              public Stack<PairScore> ChooseStatePairs(LearnerGraph graph)
                              {
                                // send the notification if necessary
                                if (message.arity() > 2 && message.elementAt(2) instanceof OtpErlangPid)
                                  sendProgress((OtpErlangPid)message.elementAt(2), ref, graph, null, counter);
                               
                                // check if we were asked to terminate
                                try {
                                  OtpErlangObject messageReceived = mbox.receive(0);// do not wait, return null if anything received
                                  if (messageReceived != null && messageReceived instanceof OtpErlangTuple && ((OtpErlangTuple)messageReceived).arity() == 2)
                                  {
                                    OtpErlangTuple cmd = ((OtpErlangTuple)messageReceived);
                                    if (cmd.elementAt(0).equals(ref) && cmd.elementAt(1).equals(msgStop))
                                      throw new AskedToTerminateException();
                                  }
                                } catch (OtpErlangExit e) {
                                  Helper.throwUnchecked("node exited", e);
                                } catch (OtpErlangDecodeException e) {
                                  Helper.throwUnchecked("decode exception", e);
                                }
                                // resume learning.
                                return super.ChooseStatePairs(graph);
                              }

                              @Override
                              public Pair<Integer, String> CheckWithEndUser(
                                  LearnerGraph model,
                                  List<Label> question,
                                  int expectedForNoRestart,
                                  List<Boolean> consistentFacts,
                                  PairScore pairBeingMerged,
                                  Object[] moreOptions) {

                                return super.CheckWithEndUser(model, question, expectedForNoRestart,
                                    consistentFacts, pairBeingMerged, moreOptions);
                              }
                             
                            };
                            learner.init(sPlus, sMinus);
                            if (learnerInitConfiguration.graph != null)
                            {
                              learnerInitConfiguration.graph.clearColours();learnerInitConfiguration.graph.getInit().setColour(JUConstants.RED);
                              LearnerGraph.copyGraphs(learnerInitConfiguration.graph,learner.getTentativeAutomaton());
                            }
                            LearnerGraph graphLearnt = learner.learnMachine();
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgOk,  constructFSM(graphLearnt)});
                          }
                          catch(AskedToTerminateException e)
                          {
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgTerminate});
                          }
                          catch(Throwable ex)
                          {
                            ex.printStackTrace();
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgFailure,new OtpErlangList(ex.getMessage())});
                          }
                          mbox.send(erlangPartner,outcome);
                         
                        }
                        else
                        // Args: Ref,learn, pid
                        // pid is optional, where provided, progress messages are reported in a form of {Ref,'status',step}
                        // in the course of learning, the learner is receptive to messages directed at its normal PID, a {Ref,terminate} command will kill it and the response will be {Ref,terminate}.
                        // Response: Ref,ok,fsm
                        // on error: Ref,failure,text_of_the_error (as string)
                        if (command.equals(msgLearnEDSMMARKOV) && message.arity() >= 2)
                        {
                          OtpErlangObject outcome = null;
                          try
                          {
                            final AtomicLong counter = new AtomicLong();
                            learnerInitConfiguration.config.setLearnerScoreMode(ScoreMode.ONLYOVERRIDE);
                            LearnerGraph pta=new LearnerGraph(learnerInitConfiguration.config);
                            for(List<Label> seq:sPlus)
                              pta.paths.augmentPTA(seq,true,false,null);
                            for(List<Label> seq:sMinus)
                              pta.paths.augmentPTA(seq,false,false,null);
                            final MarkovModel m= new MarkovModel(3,true,true);

                            new MarkovClassifier(m, pta).updateMarkov(false);// construct Markov chain if asked for.
                            final ConsistencyChecker checker = new MarkovClassifier.DifferentPredictionsInconsistencyNoBlacklistingIncludeMissingPrefixes();
                         
                            pta.clearColours();
                            EDSM_MarkovLearner learner = new EDSM_MarkovLearner(learnerInitConfiguration,pta,0) {

                              @Override
                              public Stack<PairScore> ChooseStatePairs(LearnerGraph graph)
                              {
                                // send the notification if necessary
                                if (message.arity() > 2 && message.elementAt(2) instanceof OtpErlangPid)
                                  sendProgress((OtpErlangPid)message.elementAt(2), ref, graph, null, counter);
                               
                                // check if we were asked to terminate
                                try {
                                  OtpErlangObject messageReceived = mbox.receive(0);// do not wait, return null if anything received
                                  if (messageReceived != null && messageReceived instanceof OtpErlangTuple && ((OtpErlangTuple)messageReceived).arity() == 2)
                                  {
                                    OtpErlangTuple cmd = ((OtpErlangTuple)messageReceived);
                                    if (cmd.elementAt(0).equals(ref) && cmd.elementAt(1).equals(msgStop))
                                      throw new AskedToTerminateException();
                                  }
                                } catch (OtpErlangExit e) {
                                  Helper.throwUnchecked("node exited", e);
                                } catch (OtpErlangDecodeException e) {
                                  Helper.throwUnchecked("decode exception", e);
                                }
                                // resume learning.
                                return super.ChooseStatePairs(graph);
                              }

                              @Override
                              public Pair<Integer, String> CheckWithEndUser(
                                  LearnerGraph model,
                                  List<Label> question,
                                  int expectedForNoRestart,
                                  List<Boolean> consistentFacts,
                                  PairScore pairBeingMerged,
                                  Object[] moreOptions) {

                                return super.CheckWithEndUser(model, question, expectedForNoRestart,
                                    consistentFacts, pairBeingMerged, moreOptions);
                              }
                             
                            };
                            learner.setMarkov(m);learner.setChecker(checker);
                            learner.setUseNewScoreNearRoot(false);learner.setUseClassifyPairs(false);
                            learner.setDisableInconsistenciesInMergers(false);
                           
                            if (learnerInitConfiguration.graph != null)
                            {
                              learnerInitConfiguration.graph.clearColours();learnerInitConfiguration.graph.getInit().setColour(JUConstants.RED);
                              LearnerGraph.copyGraphs(learnerInitConfiguration.graph,learner.getTentativeAutomaton());
                            }
                            LearnerGraph graphLearnt = learner.learnMachine(new LinkedList<List<Label>>(),new LinkedList<List<Label>>());
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgOk,  constructFSM(graphLearnt)});
                          }
                          catch(AskedToTerminateException e)
                          {
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgTerminate});
                          }
                          catch(Throwable ex)
                          {
                            ex.printStackTrace();
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgFailure,new OtpErlangList(ex.getMessage())});
                          }
                          mbox.send(erlangPartner,outcome);
                         
                        }
                        else
                        // Args: Ref,addTypeInformation,list of pairs containing method names and types.
                        if (command.equals(msgAddTypeInformation) && message.arity() >= 3)
                        {
                          OtpErlangObject outcome = null;
                          try
                          {
                            updateFrom((OtpErlangList)message.elementAt(2), overrides);
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgOk,  typeMapToList(overrides)});
                          }
                          catch(Throwable ex)
                          {
                            ex.printStackTrace();
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgFailure,new OtpErlangList(ex.getMessage())});
                          }
                          mbox.send(erlangPartner,outcome);
                        }
                        else
                        // Args: Ref,purgeModuleInformation
                        // Since using addTypeInformation followed by learnErlang causes changes to the alphabet modules we are dealing with, independence of tests requires the collection of loaded modules to be purged. This is the purpose of this function.
                        if (command.equals(msgPurgeModuleInformation) && message.arity() >= 2)
                        {
                          OtpErlangObject outcome = null;
                          try
                          {
                            ErlangModule.flushRegistry();
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgOk});
                          }
                          catch(Throwable ex)
                          {
                            ex.printStackTrace();
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgFailure,new OtpErlangList(ex.getMessage())});
                          }
                          mbox.send(erlangPartner,outcome);
                        }
                        else
                        // Args: Ref,extractTypeInformation,moduleFileFullPath.
                        // Returns a list of pairs of method names and types.
                        if (command.equals(msgExtractTypeInformation) && message.arity() >= 3)
                        {
                          OtpErlangObject outcome = null;
                          try
                          {
                            ErlangModule.setupErlangConfiguration(learnerInitConfiguration.config, new File(((OtpErlangAtom)message.elementAt(2)).atomValue()));
                           
                            // we start a separate Erlang node to run the questions
                            ErlangRunner erlangRunner = ErlangRuntime.getDefaultRuntime().createNewRunner();
                            learnerInitConfiguration.config.setErlangMboxName(erlangRunner.getRunnerName());
                            final ErlangModule mod = ErlangModule.loadModule(learnerInitConfiguration.config);
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgOk,  typeMapToList(mod.sigTypes)});
                          }
                          catch(Throwable ex)
                          {
                            ex.printStackTrace();
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgFailure,new OtpErlangList(ex.getMessage())});
                          }
                          mbox.send(erlangPartner,outcome);
                        }
                        else
                        // Args: Ref,learnErlang,moduleFileFullPath, pid
                        // pid is optional, where provided, progress messages are reported in a form of {Ref,'status',step}
                        // in the course of learning, the learner is receptive to messages directed at its normal PID, a {Ref,terminate} command will kill it and the response will be {Ref,terminate}.
                        // Response: Ref,ok,fsm
                        // on error: Ref,failure,text_of_the_error (as string)
                        if (command.equals(msgLearnErlang) && message.arity() >= 3)
                        {
                          OtpErlangObject outcome = null;
                          try
                          {
                            ErlangModule.setupErlangConfiguration(learnerInitConfiguration.config, new File(((OtpErlangAtom)message.elementAt(2)).atomValue()));
                           
                            // we start a separate Erlang node to run the questions
                            ErlangRunner erlangRunner = ErlangRuntime.getDefaultRuntime().createNewRunner();
                            learnerInitConfiguration.config.setErlangMboxName(erlangRunner.getRunnerName());
                            final AtomicLong counter = new AtomicLong();
                            final ErlangModule mod = ErlangModule.loadModule(learnerInitConfiguration.config);
                            mod.rebuildSigs(learnerInitConfiguration.config, overrides);mod.behaviour.generateAlphabet(learnerInitConfiguration.config);
                           
                            ErlangOracleLearner learner = new ErlangOracleLearner(null, learnerInitConfiguration) {

                              @Override
                              public Stack<PairScore> ChooseStatePairs(LearnerGraph graph)
                              {
                                // check if we were asked to terminate
                                try {
                                  if (message.arity() > 3 && message.elementAt(3) instanceof OtpErlangPid)
                                    // send the notification if necessary
                                    sendProgress((OtpErlangPid)message.elementAt(3), ref, graph, mod, counter);

                                  OtpErlangObject messageReceived = mbox.receive(0);// do not wait, return null if anything received
                                  if (messageReceived != null && messageReceived instanceof OtpErlangTuple && ((OtpErlangTuple)messageReceived).arity() == 2)
                                  {
                                    OtpErlangTuple cmd = ((OtpErlangTuple)messageReceived);
                                    if (cmd.elementAt(0).equals(ref) && cmd.elementAt(1).equals(msgStop))
                                      throw new AskedToTerminateException();
                                  }
                                } catch (OtpErlangExit e) {
                                  Helper.throwUnchecked("node exited", e);
                                } catch (OtpErlangDecodeException e) {
                                  Helper.throwUnchecked("decode exception", e);
                                }
                               
                                // resume learning.
                                return super.ChooseStatePairs(graph);
                              }

                              @Override
                              public Pair<Integer, String> CheckWithEndUser(
                                  LearnerGraph model,
                                  List<Label> question,
                                  int expectedForNoRestart,
                                  List<Boolean> consistentFacts,
                                  PairScore pairBeingMerged,
                                  Object[] moreOptions) {
                                return super.CheckWithEndUser(model, question, expectedForNoRestart,consistentFacts, pairBeingMerged, moreOptions);
                              }
                             
                            };
                            if (learnerInitConfiguration.config.getAskQuestions()) // only generate initial traces if we are permited to ask questions.
                              learner.init(learner.GenerateInitialTraces(learnerInitConfiguration.config.getErlangInitialTraceLength()),0,0);
                            System.out.println("random trace generation complete");
                            LearnerGraph graphLearnt = learner.learnMachine(),
                                graphWithTrimmedLabels = new LearnerGraph(learnerInitConfiguration.config);
                           
                            if (learnerInitConfiguration.config.getErlangStripModuleNamesFromFunctionsInNonGenModules())
                              convertLabelsToStrings(graphLearnt,graphWithTrimmedLabels);
                            else
                              AbstractLearnerGraph.interpretLabelsOnGraph(graphLearnt,graphWithTrimmedLabels,mod.behaviour.new ConverterModToErl());
                           
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgOk,  constructFSM(graphWithTrimmedLabels)});
                            erlangRunner.close();
                          }
                          catch(AskedToTerminateException e)
                          {
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgTerminate});
                          }
                          catch(Throwable ex)
                          {
                            ex.printStackTrace();
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgFailure,new OtpErlangList(ex.getMessage())});
                          }
                          mbox.send(erlangPartner,outcome);
                         
                        }
                        else
                        if (command.equals(msgTestDiffParsing) && message.arity() == 4) // this one computes a graph reflecting the differences and returns the labelling part of it as a string. Inputs are one of the original machines and the differences.
                        {
                          OtpErlangObject outcome = null;
                          try
                          {
                            DirectedSparseGraph diff = DifferenceVisualiser.ChangesToGraph.computeVisualisationParameters(message.elementAt(2), message.elementAt(3));
                            StringBuffer textOfTheOutcome = new StringBuffer();
                            boolean first = true;
                            for(Object obj:diff.getEdges())
                            {
                              if (!first) textOfTheOutcome.append(",");else first = false;
                             
                              textOfTheOutcome.append(obj.toString());textOfTheOutcome.append(":");textOfTheOutcome.append( ((Edge)obj).getUserDatum(JUConstants.DIFF) );
                            }
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgOk,new OtpErlangAtom(textOfTheOutcome.toString())});
                          }
                          catch(Throwable ex)
                          {
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgFailure,new OtpErlangList(ex.getMessage())});
                          }
                          mbox.send(erlangPartner,outcome);
                        }
                        else
                         
                        // Arguments: Ref, 'displayDiff', first graph, diff, atom with the name of the difference and (optional) list of states (as atoms) to ignore.
                        // Upon error, no notifications are sent and instead an error is reported.
                        // Note: if the difference name is an empty sequence, no graph is displayed but notifications are provided (for testing).
                        if (command.equals(msgDisplayDiff) && message.arity() >= 5)
                        {
                          OtpErlangObject outcome = null;
                          try
                          {
                            DirectedSparseGraph diff = DifferenceVisualiser.ChangesToGraph.computeVisualisationParameters(message.elementAt(2), message.elementAt(3));
                            int windowNumber = setOptions(message,4,diff);
                            if (windowNumber >= 0)
                              Visualiser.updateFrameWithPos(diff,windowNumber);

                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgOk});
                          }
                          catch(Throwable ex)
                          {
                            outcome = new OtpErlangTuple(new OtpErlangObject[]{ref,msgFailure,new OtpErlangList(ex.getMessage())});
                          }
                          mbox.send(erlangPartner,outcome);
                        }
                        else
                          // Arguments: Ref, 'displayFSM', graph, atom with the name of the difference and (optional) list of states (as atoms) to ignore.
                          // Upon error, no notifications are sent and instead an error is reported.
                          // Note: if the difference name is an empty sequence, no graph is displayed but notifications are provided (for testing).
                          if (command.equals(msgDisplayFSM) && message.arity() >= 4)
                          {
                            OtpErlangObject outcome = null;
                            try
                            {
                              Configuration config = Configuration.getDefaultConfiguration().copy();
                              LearnerGraphND machine = new LearnerGraphND(config);Synapse.StatechumProcess.parseStatemachine(message.elementAt(2),machine,null,true);
                              DirectedSparseGraph fsmPicture = machine.pathroutines.getGraph();
                              if (!fsmPicture.containsUserDatumKey(JUConstants.LAYOUTOPTIONS))
                                fsmPicture.addUserDatum(JUConstants.LAYOUTOPTIONS,new LayoutOptions(), UserData.SHARED);
                              int windowNumber = setOptions(message,3,fsmPicture);
                              if (windowNumber >= 0)
View Full Code Here


  public static void main(String[] args) throws IOException{
    //File graphDir = new File(args[0]);//new File(System.getProperty("user.dir")+System.getProperty("file.separator")+"resources"+
    //System.getProperty("file.separator")+"TestGraphs"+System.getProperty("file.separator") +args[0]);
    //String wholePath = graphDir.getAbsolutePath()+File.separator;
    LearnerGraphND graph0 = new LearnerGraphND(Configuration.getDefaultConfiguration().copy()),graph1 = null;
    AbstractPersistence.loadGraph(args[0], graph0,null);
    if (args.length > 1)
    {
      graph1 = new LearnerGraphND(Configuration.getDefaultConfiguration().copy());;
      AbstractPersistence.loadGraph(args[1], graph1,null);
    }
    Visualiser.updateFrame(graph0, graph1);Visualiser.waitForKey();
  }
View Full Code Here

  public static DirectedSparseGraph obtainDifferenceGraph(String graphA, String graphB,int counter,boolean display, Configuration config)
  {
    GD<List<CmpVertex>,List<CmpVertex>,LearnerGraphNDCachedData,LearnerGraphNDCachedData> gd =
      new GD<List<CmpVertex>,List<CmpVertex>,LearnerGraphNDCachedData,LearnerGraphNDCachedData>();

    LearnerGraphND grA=buildLearnerGraphND(graphA, "labellingDemo_A_"+counter,config,null),
        grB=buildLearnerGraphND(graphB, "labellingDemo_B_"+counter,config,null);
    DirectedSparseGraph gr = gd.showGD(
        grA,grB,
        ExperimentRunner.getCpuNumber());
    if (display)
View Full Code Here

     * @return graph with colouring to reflect the changes.
     */
    public static DirectedSparseGraph computeVisualisationParameters(OtpErlangObject origMachineObject, OtpErlangObject differences)
    {
      Configuration config = Configuration.getDefaultConfiguration().copy();
      LearnerGraphND origMachine = new LearnerGraphND(config);Synapse.StatechumProcess.parseStatemachine(origMachineObject,origMachine,null,true);
     
      ChangesToGraph recorder=load(differences);
      return recorder.getDifferenceGraph(origMachine.pathroutines.getGraph());
    }
View Full Code Here

 
      ChangesToGraph recorder = new ChangesToGraph();
      gd.computeGD(grA, grB, ExperimentRunner.getCpuNumber(),recorder,config);
     
     
      LearnerGraphND origMachine = new LearnerGraphND(grA,config), finalMachineWithoutRelabelling = new LearnerGraphND(grA,config);
      //Synapse.StatechumProcess.parseStatemachine(origMachineObject,origMachine,null,true);
      //Synapse.StatechumProcess.parseStatemachine(origMachineObject,finalMachineWithoutRelabelling,null,true);
     
      // now we apply the patch to the graph, the outcome will be in terms of the original vertices which is why it is easiest to apply a patch rather than use the second graph and figure out the relationship between the vertices.
      recorder.applyDiff(finalMachineWithoutRelabelling,config);
View Full Code Here

  /** Tests non-deterministic case of {@link MarkovClassifier#tracePath}, deterministic case is tested with {@link TestPathTracing}. */
  @Test
  public void testTracePath1()
  {
    final LearnerGraph fsm = FsmParser.buildLearnerGraph("A-a->B-b->C", "testTracePath1",config,converter);
    LearnerGraphND ndFSM = new LearnerGraphND(fsm,config);
    synchronized(AbstractLearnerGraph.syncObj)
    {
      ndFSM.addVertex(ndFSM.addVertex(fsm.findVertex("A"), true, lblA),true,lblA);
    }
    Assert.assertTrue(MarkovClassifier.tracePath(ndFSM,AbstractLearnerGraph.buildList(Arrays.asList(new String[]{}),config,converter),fsm.findVertex("A")));
    Assert.assertTrue(MarkovClassifier.tracePath(ndFSM,AbstractLearnerGraph.buildList(Arrays.asList(new String[]{"a","b"}),config,converter),fsm.findVertex("A")));
    Assert.assertTrue(MarkovClassifier.tracePath(ndFSM,AbstractLearnerGraph.buildList(Arrays.asList(new String[]{"a","a"}),config,converter),fsm.findVertex("A")));
  }
View Full Code Here

  {
    Configuration config = Configuration.getDefaultConfiguration().copy();config.setTransitionMatrixImplType(STATETREE.STATETREE_SLOWTREE);
    config.setGdKeyPairThreshold(1);config.setGdLowToHighRatio(1);
    String name = "testVisual5";
    String common = "A-a->B-p->B\nA-a->C-q->C\nA-a->D-r->D\nS-a-#T";
    LearnerGraphND grA = FsmParser.buildLearnerGraphND("A-a->E-s->E\nA-a->F-v->F\nU-a-#V\n"+common,name+"A",config);
    LearnerGraphND grB = FsmParser.buildLearnerGraphND("A-a->G-u->G\nA-a->H-t->H\n"+common,name+"B",config);
    LearnerGraphND grA_reduced = new LearnerGraphND(config), grB_reduced = new LearnerGraphND(config);
    AbstractPathRoutines.removeRejectStates(grA, grA_reduced);
    AbstractPathRoutines.removeRejectStates(grB, grB_reduced);
    GD<List<CmpVertex>,List<CmpVertex>,LearnerGraphNDCachedData,LearnerGraphNDCachedData> gd =
      new GD<List<CmpVertex>,List<CmpVertex>,LearnerGraphNDCachedData,LearnerGraphNDCachedData>();
    DirectedSparseGraph graph = gd.showGD(grA_reduced,grB_reduced,  ExperimentRunner.getCpuNumber());
View Full Code Here

  /** Tests non-deterministic case of {@link MarkovClassifier#tracePath}, deterministic case is tested with {@link TestPathTracing}. */
  @Test
  public void testTracePath2()
  {
    final LearnerGraph fsm = FsmParser.buildLearnerGraph("A-a->B-b->C", "testTracePath1",config,converter);
    LearnerGraphND ndFSM = new LearnerGraphND(fsm,config);
    synchronized(AbstractLearnerGraph.syncObj)
    {
      CmpVertex AA=ndFSM.addVertex(ndFSM.addVertex(fsm.findVertex("A"), true, lblA),true,lblA);
      ndFSM.addVertex(AA, true, lblA);ndFSM.addVertex(AA, true, lblC);
    }
    Assert.assertEquals(7,ndFSM.getStateNumber());
    Assert.assertTrue(MarkovClassifier.tracePath(ndFSM,AbstractLearnerGraph.buildList(Arrays.asList(new String[]{"a","a","c"}),config,converter),fsm.findVertex("A")));
    Assert.assertTrue(MarkovClassifier.tracePath(ndFSM,AbstractLearnerGraph.buildList(Arrays.asList(new String[]{"a","a","a"}),config,converter),fsm.findVertex("A")));
    Assert.assertFalse(MarkovClassifier.tracePath(ndFSM,AbstractLearnerGraph.buildList(Arrays.asList(new String[]{"a","a","b"}),config,converter),fsm.findVertex("A")));
    Assert.assertFalse(MarkovClassifier.tracePath(ndFSM,AbstractLearnerGraph.buildList(Arrays.asList(new String[]{"a","a","a","a"}),config,converter),fsm.findVertex("A")));
  }
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 conv label converter, ignored if null.
     */
    static public void loadDiff(PatchGraph graphPatcher, Element elem,final ConvertALabel conv)
    {
      Configuration config = Configuration.getDefaultConfiguration().copy();config.setLearnerCloneGraph(false);
      LearnerGraphND gr = new LearnerGraphND(config);AbstractPersistence.loadGraph(getGraphElement(elem, StatechumXML.gdRemoved.toString(),false,true),gr,conv);
      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(Entry<CmpVertex,PAIRCOMPATIBILITY> target:incompatibles.getValue().entrySet())
          graphPatcher.removeFromCompatibility(incompatibles.getKey(), target.getKey(), target.getValue());
     
      AbstractPersistence.loadGraph(getGraphElement(elem, StatechumXML.gdAdded.toString(),false,true),gr,conv);
     
      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(), pair.getR());
          }
      }
      graphPatcher.setInitial(gr.getInit());
    }
View Full Code Here

TOP

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

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.