Package statechum.analysis.learning

Examples of statechum.analysis.learning.ErlangOracleLearner


                            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
View Full Code Here


                            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
View Full Code Here

      boolean useOutputMatching, EXPANSIONOFANY expand, long seed) {
    try {
      Random rand = new Random(seed);
      module = targetmodule;
      setupFile(file, useOutputMatching, expand);
      learner = new ErlangOracleLearner(null,
          new LearnerEvaluationConfiguration(config));

      // Make sure our copy of the module is the same object as the
      // learner's so that alphabet mods work...
      module = learner.getModule();
View Full Code Here

  public static void genComplete(ErlangModule targetmodule, File file,
      int depth, boolean useOutputMatching, EXPANSIONOFANY expand) {
    try {
      module = targetmodule;
      setupFile(file, useOutputMatching, expand);
      learner = new ErlangOracleLearner(null,
          new LearnerEvaluationConfiguration(config));

      // Make sure our copy of the module is the same object as the
      // learner's so that alphabet mods work...
      module = learner.getModule();
View Full Code Here

          // Run ErlangQSMOracle on the trace file...

          System.out.println("Learning " + m.name + "...");
          //LearnerGraph g = ErlangQSMOracle.startInference(tracefile);
          ErlangOracleVisualiser viz = new ErlangOracleVisualiser();
          ErlangOracleLearner innerLearner = ErlangQSMOracle.createLearner(viz,tracefile);
          innerLearner.addObserver(viz);
          innerLearner.setGraphNameSuffix(new File(tracefile).getName());
          innerLearner.getTentativeAutomaton().getLayoutOptions().showNegatives = false;
          LearnerGraph g = innerLearner.learnMachine();
         
          System.out.println("Produced " + g.getStateNumber() + " states");
        } catch (Exception e) {
          JOptionPane.showMessageDialog(this, e.toString());
          e.printStackTrace();
View Full Code Here

      evalConf.config = Configuration.getDefaultConfiguration().copy();
      final String moduleName = "locker";
      evalConf.config.setErlangModuleName(moduleName);
      evalConf.config.setErlangSourceFile(new File("ErlangExamples/locker",moduleName + ".erl"));
      evalConf.config.setLabelKind(LABELKIND.LABEL_ERLANG);
      final ErlangOracleLearner learner = new ErlangOracleLearner(null, evalConf);
     
      // The above loads a module, this one gets that module and subsequently updates its alphabet.
      ErlangModule mod = ErlangModule.findModule(evalConf.config.getErlangModuleName());
     
      final ErlangLabel initLabel = mod.behaviour.convertErlToMod(AbstractLearnerGraph.generateNewLabel("{"+ErlangLabel.missingFunction+",'init','AnyWibble','ok'}", evalConf.config,evalConf.getLabelConverter())),
      labelLock = mod.behaviour.convertErlToMod(AbstractLearnerGraph.generateNewLabel("{"+ErlangLabel.missingFunction+",'call','lock',{'ok','locked'}}", evalConf.config,evalConf.getLabelConverter()));
    final ErlangLabel labelInvalidRead = new ErlangLabel(labelLock.function,labelLock.callName,labelLock.input,new OtpErlangInt(88));
    statechum.Helper.checkForCorrectException(new statechum.Helper.whatToRun() {
      public @Override void run() {
        learner.askErlang(Arrays.asList(new Label[]{initLabel,labelLock,labelInvalidRead}));
      }},IllegalArgumentException.class,"does not belong");
    }
View Full Code Here

    public void testAttemptTracesWrongModule() throws IOException
    {
      GlobalConfiguration.getConfiguration().getProperty(G_PROPERTIES.TEMP);
         LearnerEvaluationConfiguration evalConf = new LearnerEvaluationConfiguration(null);
      evalConf.config = ErlangModule.setupErlangConfiguration(new File("ErlangExamples/locker/locker"+ErlangRunner.ERL.ERL.toString()));
      final ErlangOracleLearner learner = new ErlangOracleLearner(null, evalConf);
     
      // The above loads a module, this one gets that module and subsequently updates its alphabet.
      Configuration exporterConfiguration = ErlangModule.setupErlangConfiguration(new File("ErlangExamples/exporter/exporter"+ErlangRunner.ERL.ERL.toString()));
      ErlangModule.findModule(evalConf.config.getErlangModuleName());
      ErlangModule modExporter = ErlangModule.loadModule(exporterConfiguration);
     
      final ErlangLabel pushLabel = modExporter.behaviour.convertErlToMod(AbstractLearnerGraph.generateNewLabel(
          "{"+ErlangLabel.missingFunction+",'exporter:push/1',['JustAnythingA'],'ok'}", exporterConfiguration,evalConf.getLabelConverter()));
    //final ErlangLabel labelInvalidArity = new ErlangLabel(initLabel.function,initLabel.callName,initLabel.input,initLabel.expectedOutput);
    statechum.Helper.checkForCorrectException(new statechum.Helper.whatToRun() {
      public @Override void run() {
        learner.askErlang(Arrays.asList(new Label[]{pushLabel}));
      }},IllegalArgumentException.class,"but attempting to call");
    }
View Full Code Here

    {
      GlobalConfiguration.getConfiguration().getProperty(G_PROPERTIES.TEMP);
      LearnerEvaluationConfiguration evalConf = new LearnerEvaluationConfiguration(null);
      final String moduleName = "locker";
      evalConf.config = ErlangModule.setupErlangConfiguration(new File("ErlangExamples/locker",moduleName + ErlangRunner.ERL.ERL.toString()));
      ErlangOracleLearner learner = new ErlangOracleLearner(null, evalConf);
     
      // The above loads a module, this one gets that module and subsequently updates its alphabet.
      ErlangModule mod = ErlangModule.findModule(moduleName);
      Assert.assertTrue(mod.behaviour instanceof OTPGenServerBehaviour);
      Assert.assertTrue(mod.behaviour.dependencies.isEmpty());
     
      ErlangLabel initLabel = mod.behaviour.convertErlToMod(AbstractLearnerGraph.generateNewLabel("{"+ErlangLabel.missingFunction+",'init','AnyWibble','ok'}", evalConf.config,evalConf.getLabelConverter())),
        labelLock = mod.behaviour.convertErlToMod(AbstractLearnerGraph.generateNewLabel("{"+ErlangLabel.missingFunction+",'call','lock',{'ok','locked'}}", evalConf.config,evalConf.getLabelConverter())),
        labelRead = mod.behaviour.convertErlToMod(AbstractLearnerGraph.generateNewLabel("{"+ErlangLabel.missingFunction+",'call','read','AnyWibble'}", evalConf.config,evalConf.getLabelConverter())),
        labelWrite = mod.behaviour.convertErlToMod(AbstractLearnerGraph.generateNewLabel("{"+ErlangLabel.missingFunction+",'call',{'write','AnyWibble'},{'ok','AnyWibble'}}", evalConf.config,evalConf.getLabelConverter()));
      mod.behaviour.getAlphabet().add(initLabel);
      mod.behaviour.getAlphabet().add(labelLock);
      mod.behaviour.getAlphabet().add(labelRead);
      mod.behaviour.getAlphabet().add(labelWrite);
      // Attempting first trace
      List<Label> trace = Arrays.asList(new Label[]{initLabel,labelLock});
      TraceOutcome tr = learner.askErlang(trace);
      Assert.assertEquals(TRACEOUTCOME.TRACE_OK,tr.outcome);
      Assert.assertEquals("[{"+ErlangLabel.missingFunction+",'init','AnyWibble','ok'},{"+ErlangLabel.missingFunction+",'call','lock',{'ok','locked'}}]",RPNILearner.questionToString(Arrays.asList(tr.answerDetails)));
     
      tr = learner.askErlang(Arrays.asList(new Label[]{initLabel,labelLock, labelLock}));
     
         Assert.assertEquals(TRACEOUTCOME.TRACE_FAIL,tr.outcome);
      Assert.assertEquals("[{"+ErlangLabel.missingFunction+",'init','AnyWibble','ok'},{"+ErlangLabel.missingFunction+",'call','lock',{'ok','locked'}},{"+ErlangLabel.missingFunction+",'call','lock',{'ok','locked'}}]",RPNILearner.questionToString(Arrays.asList(tr.answerDetails)));
     
      tr =learner.askErlang(Arrays.asList(new Label[]{initLabel,labelLock,labelWrite, labelRead}));
     
         Assert.assertEquals(TRACEOUTCOME.TRACE_OK,tr.outcome);
      Assert.assertEquals("[{"+ErlangLabel.missingFunction+",'init','AnyWibble','ok'},{"+ErlangLabel.missingFunction+",'call','lock',{'ok','locked'}},{"+ErlangLabel.missingFunction+",'call',{'write','AnyWibble'},{'ok','AnyWibble'}},{"+ErlangLabel.missingFunction+",'call','read','AnyWibble'}]",
          RPNILearner.questionToString(Arrays.asList(tr.answerDetails)));
     
      // Now attempt a "different output" input
      ErlangLabel lbl = tr.answerDetails[3];
      tr.answerDetails[3] = new ErlangLabel(lbl.function,lbl.callName,
          lbl.input, new OtpErlangAtom("aa"));
      mod.behaviour.getAlphabet().add(tr.answerDetails[3]);
      tr =learner.askErlang(Arrays.asList(tr.answerDetails));
         Assert.assertEquals(TRACEOUTCOME.TRACE_DIFFERENTOUTPUT,tr.outcome);
      Assert.assertEquals("[{"+ErlangLabel.missingFunction+",'init','AnyWibble','ok'},{"+ErlangLabel.missingFunction+",'call','lock',{'ok','locked'}},{"+ErlangLabel.missingFunction+",'call',{'write','AnyWibble'},{'ok','AnyWibble'}},{"+ErlangLabel.missingFunction+",'call','read','AnyWibble'}]",
          RPNILearner.questionToString(Arrays.asList(tr.answerDetails)));
    }
View Full Code Here

      evalConf.config = config.copy();
      final String moduleName = "locker";
      evalConf.config.setErlangModuleName(moduleName);
      evalConf.config.setErlangSourceFile(new File(ErlangExamples+File.separator+"locker",moduleName + ".erl"));
      evalConf.config.setLabelKind(LABELKIND.LABEL_ERLANG);
      final ErlangOracleLearner learner = new ErlangOracleLearner(null, evalConf);
     
      // The above loads a module, this one gets that module and subsequently updates its alphabet.
      ErlangModule mod = ErlangModule.findModule(evalConf.config.getErlangModuleName());
     
      final ErlangLabel initLabel = mod.behaviour.convertErlToMod(AbstractLearnerGraph.generateNewLabel("{"+ErlangLabel.missingFunction+",'init','AnyWibble','ok'}", evalConf.config,evalConf.getLabelConverter())),
      labelLock = mod.behaviour.convertErlToMod(AbstractLearnerGraph.generateNewLabel("{"+ErlangLabel.missingFunction+",'call','lock',{'ok','locked'}}", evalConf.config,evalConf.getLabelConverter()));
    final ErlangLabel labelInvalidRead = new ErlangLabel(labelLock.function,labelLock.callName,labelLock.input,new OtpErlangInt(88));
    statechum.Helper.checkForCorrectException(new statechum.Helper.whatToRun() {
      public @Override void run() {
        learner.askErlang(Arrays.asList(new Label[]{initLabel,labelLock,labelInvalidRead}));
      }},IllegalArgumentException.class,"does not belong");
    }
View Full Code Here

    public void testAttemptTracesWrongModule() throws IOException
    {
      GlobalConfiguration.getConfiguration().getProperty(G_PROPERTIES.TEMP);
         LearnerEvaluationConfiguration evalConf = new LearnerEvaluationConfiguration(null);
         evalConf.config = config.copy();ErlangModule.setupErlangConfiguration(evalConf.config,new File(ErlangExamples,"locker/locker"+ErlangRunner.ERL.ERL.toString()));
      final ErlangOracleLearner learner = new ErlangOracleLearner(null, evalConf);
     
      // The above loads a module, this one gets that module and subsequently updates its alphabet.
      Configuration exporterConfiguration = config.copy();ErlangModule.setupErlangConfiguration(exporterConfiguration,new File(ErlangExamples,"exporter/exporter"+ErlangRunner.ERL.ERL.toString()));
      
      ErlangModule.findModule(evalConf.config.getErlangModuleName());
      ErlangModule modExporter = ErlangModule.loadModule(exporterConfiguration);
     
      final ErlangLabel pushLabel = modExporter.behaviour.convertErlToMod(AbstractLearnerGraph.generateNewLabel(
          "{"+ErlangLabel.missingFunction+",'exporter:push/1',['JustAnythingA'],'ok'}", exporterConfiguration,evalConf.getLabelConverter()));
    //final ErlangLabel labelInvalidArity = new ErlangLabel(initLabel.function,initLabel.callName,initLabel.input,initLabel.expectedOutput);
    statechum.Helper.checkForCorrectException(new statechum.Helper.whatToRun() {
      public @Override void run() {
        learner.askErlang(Arrays.asList(new Label[]{pushLabel}));
      }},IllegalArgumentException.class,"but attempting to call");
    }
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.ErlangOracleLearner

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.