Package statechum.analysis.learning.rpnicore

Examples of statechum.analysis.learning.rpnicore.RandomPathGenerator$StateName


   
    /** This method is executed on an executor thread. */
    public void runTheExperiment()
    {
      int sampleSize = (graph.getStateNumber()*4);
      RandomPathGenerator rpg = new RandomPathGenerator(graph, new Random(100),5);// the seed for Random should be the same for each file
      rpg.generatePosNeg(sampleSize, 2)
      Collection<List<String>> tests = rpg.getAllSequencesPercentageInterval(0).getData();
      LearnerAccuracyTracker l = new LearnerAccuracyTracker(null,config, graph, tests)
      {
        @Override
        protected Pair<Integer,String> checkWithEndUser(
            @SuppressWarnings("unused"LearnerGraph model,
            List<String> question,
            @SuppressWarnings("unused") final Object [] moreOptions)
        {
          questionNumber.addAndGet(1);
          return new Pair<Integer,String>(graph.paths.tracePath(question),null);
        }
      };
     
     
     
      sPlus = rpg.getExtraSequencesPercentageInterval(1);sMinus = rpg.getAllSequencesPercentageInterval(1);
      LearnerGraph learnt = learn(l,sMinus);

      result = result + l.resultsToString();

    }
View Full Code Here


    protected void buildSetsHalfNegative()
    {
      loadGraph();
      int size = (graph.getStateNumber()*graph.getStateNumber())/2;
        RandomPathGenerator rpg = new RandomPathGenerator(graph, new Random(100),5);// the seed for Random should be the same for each file
        rpg.generateRandomPosNeg(size/(2*experiment.getStageNumber()), experiment.getStageNumber());
      pta = rpg.getAllSequences(percent);
      tests = new ArrayList<List<String>>();
      for(List<String> test:graph.wmethod.getFullTestSet(0))
        if (!pta.containsSequence(test))
          tests.add(test);
    }
View Full Code Here

   {
     for(CmpVertex vert:referenceGraph.transitionMatrix.keySet())
       if (!vert.isAccept())
         throw new IllegalArgumentException("test set generation should not be attempted on an automaton with reject-states");
     assert numberOfSeq > 0 && seqLength > 0;
    RandomPathGenerator pathGen = new RandomPathGenerator(referenceGraph,new Random(0),seqLength,referenceGraph.getInit());
    pathGen.generateRandomPosNeg(numberOfSeq, 1, false, null, true,true,null,null);
    return  pathGen.getAllSequences(0).getData(PTASequenceEngine.truePred);
     /*
    Collection<List<Label>> evaluationTestSet = referenceGraph.wmethod.getFullTestSet(1);
   
    RandomPathGenerator pathGen = new RandomPathGenerator(referenceGraph,new Random(0),5,referenceGraph.getInit());
    int wPos=0;
View Full Code Here

   
    /** This method is executed on an executor thread. */
    public void runTheExperiment()
    {
      int size = 4*graph.getStateNumber();
      RandomPathGenerator rpg = new RandomPathGenerator(graph, new Random(100),5);// the seed for Random should be the same for each file
      int percentPerChunk = 10;
      int nrPerChunk = size/(100/percentPerChunk);nrPerChunk+=nrPerChunk % 2;// make the number even
      rpg.generatePosNeg(2*nrPerChunk , 100/percentPerChunk);// 2* reflects the fact that nrPerChunk denotes the number of elements in both chunks (positive and negative) combined.
      /*
      RPNIBlueFringeLearner l = new RPNIBlueFringeLearnerTestComponentOpt(null,config)
      {
        @Override
        protected Pair<Integer,String> checkWithEndUser(
            @SuppressWarnings("unused")  LearnerGraph model,
            List<String> question,
            @SuppressWarnings("unused") final Object [] moreOptions)
        {
          questionNumber.addAndGet(1);
          return new Pair<Integer,String>(graph.paths.tracePath(question),null);
        }
      };
      sPlus = rpg.getExtraSequences(percent/10-1);sMinus = rpg.getAllSequences(percent/10-1);
      LearnerGraph learned = learn(l,sMinus);
       */
      LearnerGraph learnt = null;
      Collection<List<String>> minusTrainingSet = null, testSet = null;
      try {
        synchronized (LearnerGraph.syncObj)
        {// ensure that the calls to Jung's vertex-creation routines do not occur on different threads.
            GraphMLFile graphmlFile = new GraphMLFile();
            graphmlFile.setGraphMLFileHandler(new ExperimentGraphMLHandler());
            final String mostOfFileName = "_"+(new File(inputFileName).getName());
            assert new File(origDir).isDirectory();
            for(String name:new File(origDir).list(new FilenameFilter(){
            public boolean accept(@SuppressWarnings("unused") File dir, String fileName) {
              return fileName.contains(mostOfFileName);
            }}))
            {
              int firstUnderscore = name.indexOf('_');assert firstUnderscore > 0;
              int currentNumber = Integer.parseInt(name.substring(0, firstUnderscore));
              if (number < 0) number = currentNumber;else assert number == currentNumber;
            }
            assert number >=0;
            /*
            learned = new LearnerGraph(graphmlFile.load(
                FileType.LEARNT.getFileName(dataDir+File.separator+number+"_"+(new File(inputFileName).getName()),"")
                ),config);
            learned.transform.invertStates();
            learned.transform.writeGraphML(getFileName(FileType.LEARNT));
            */
        }
        //computeStateScores.writeGraphML(learned, getFileName(FileType.LEARNT));
        XMLDecoder inData = new XMLDecoder(new FileInputStream(FileType.MINUS_AND_TEST.getFileName(origDir+File.separator+number+"_"+(new File(inputFileName).getName()),"")));
        minusTrainingSet = (Collection<List<String>>)inData.readObject();
        testSet = (Collection<List<String>>)inData.readObject();
        inData.close();
      } catch (IOException e) {
        StringWriter wr = new StringWriter();e.printStackTrace(new PrintWriter(wr));
        IllegalArgumentException ex = new IllegalArgumentException(e.getMessage());ex.initCause(e);
        throw ex;
      }
     
      /* Loads the original set. */
      PTASequenceEngine sOrigMinus = new PTASequenceEngine()
      {
        {
          init(graph.new FSMImplementation() {
            @Override
            public boolean shouldBeReturned(@SuppressWarnings("unused"Object elem)
            {
              return elem != null;
            }
           
          });
        }
      };
      SequenceSet minusInit = sOrigMinus.new SequenceSet();minusInit.setIdentity();minusInit.cross(minusTrainingSet);
      int totalLenOrig = 0, origNumber=0;
      for(List<String> seq:minusTrainingSet)
      {
        assert seq.size() > 1;
        assert graph.getVertex(seq) == null;// the seq is negative indeed
        assert graph.getVertex(seq.subList(0, seq.size()-1)) != null;// the -1 prefix is positive
        assert sOrigMinus.containsSequence(seq);// make sure PTA construction did not fumble.
        assert graph.paths.tracePath(seq) == seq.size()-1;// and another check that a -1 prefix is ok
        totalLenOrig+=seq.size();origNumber++;
      }
      assert sOrigMinus.getData().size() == 0;// all negatives

      /* Builds the new set. */
      PTASequenceEngine sNewMinus = rpg.getAllSequences(percent/10-1);
      int totalLenNew = 0, newNumber = 0;
      for(List<String> seq:sNewMinus.getData(PTASequenceEngine.truePred))
      {
        assert seq.size() > 1;
        assert graph.getVertex(seq) == null;
        assert graph.getVertex(seq.subList(0, seq.size()-1)) != null;
        assert graph.paths.tracePath(seq) == seq.size()-1;
        totalLenNew+=seq.size();newNumber++;
      }
      // 22,23
      String comparison = "Orig ave len: "+FS+((double)totalLenOrig)/origNumber+FS+
      // 24,25
          " new ave len: "+FS+((double)totalLenNew)/newNumber+FS+
      // 26,27
          " fudge status: "+FS+rpg.getFudgeDetails();
     
      //int numberOfMinusSequences = minusTrainingSet.size();
      assert sNewMinus.getData().size() == 0;// all negatives
     
      if (config.getLearnerToUse() == LEARNER.LEARNER_BLUEFRINGE_DEC2007)
View Full Code Here

      final Collection<List<Label>> testSet = PaperUAS.computeEvaluationSet(referenceGraph,states*3,states*alphabet);
     
      for(int attempt=0;attempt<2;++attempt)
      {// try learning the same machine a few times
        LearnerGraph pta = new LearnerGraph(config);
        RandomPathGenerator generator = new RandomPathGenerator(referenceGraph,new Random(attempt),5,null);
        // test sequences will be distributed around
        final int pathLength = generator.getPathLength();
        // The total number of elements in test sequences (alphabet*states*traceQuantity) will be distributed around (random(pathLength)+1). The total size of PTA is a product of these two.
        // For the purpose of generating long traces, we construct as many traces as there are states but these traces have to be rather long,
        // that is, length of traces will be (random(pathLength)+1)*sequencesPerChunk/states and the number of traces generated will be the same as the number of states.
        final int tracesToGenerate = makeEven(traceQuantity);
        final Random rnd = new Random(seed*31+attempt);
        generator.generateRandomPosNeg(tracesToGenerate, 1, false, new RandomLengthGenerator() {
                   
            @Override
            public int getLength() {
              return (rnd.nextInt(pathLength)+1)*lengthMultiplier;
            }
   
            @Override
            public int getPrefixLength(int len) {
              return len;
            }
          });

        if (onlyUsePositives)
          pta.paths.augmentPTA(generator.getAllSequences(0).filter(new FilterPredicate() {
            @Override
            public boolean shouldBeReturned(Object name) {
              return ((statechum.analysis.learning.rpnicore.RandomPathGenerator.StateName)name).accept;
            }
          }));
        else
          pta.paths.augmentPTA(generator.getAllSequences(0));// the PTA will have very few reject-states because we are generating few sequences and hence there will be few negative sequences.
          // In order to approximate the behaviour of our case study, we need to compute which pairs are not allowed from a reference graph and use those as if-then automata to start the inference.
        //pta.paths.augmentPTA(referenceGraph.wmethod.computeNewTestSet(referenceGraph.getInit(),1));
   
        List<List<Label>> sPlus = generator.getAllSequences(0).getData(new FilterPredicate() {
          @Override
          public boolean shouldBeReturned(Object name) {
            return ((statechum.analysis.learning.rpnicore.RandomPathGenerator.StateName)name).accept;
          }
        });
        List<List<Label>> sMinus= generator.getAllSequences(0).getData(new FilterPredicate() {
          @Override
          public boolean shouldBeReturned(Object name) {
            return !((statechum.analysis.learning.rpnicore.RandomPathGenerator.StateName)name).accept;
          }
        });
View Full Code Here

      final Collection<List<Label>> testSet = null;//PaperUAS.computeEvaluationSet(referenceGraph,states*3,states*alphabet);
     
      for(int attempt=0;attempt<2;++attempt)
      {// try learning the same machine a few times
        LearnerGraph pta = new LearnerGraph(config);
        RandomPathGenerator generator = new RandomPathGenerator(referenceGraph,new Random(attempt),5,null);
        // test sequences will be distributed around
        final int pathLength = generator.getPathLength();
        // The total number of elements in test sequences (alphabet*states*traceQuantity) will be distributed around (random(pathLength)+1). The total size of PTA is a product of these two.
        // For the purpose of generating long traces, we construct as many traces as there are states but these traces have to be rather long,
        // that is, length of traces will be (random(pathLength)+1)*sequencesPerChunk/states and the number of traces generated will be the same as the number of states.
        final int tracesToGenerate = makeEven(states*traceQuantity);
        final Random rnd = new Random(seed*31+attempt);
        generator.generateRandomPosNeg(tracesToGenerate, 1, false, new RandomLengthGenerator() {
                   
            @Override
            public int getLength() {
              return (rnd.nextInt(pathLength)+1)*lengthMultiplier;
            }
   
            @Override
            public int getPrefixLength(int len) {
              return len;
            }
          });
        /*
        for(List<Label> seq:referenceGraph.wmethod.computeNewTestSet(1))
        {
          pta.paths.augmentPTA(seq, referenceGraph.getVertex(seq) != null, false, null);
        }*/
        //pta.paths.augmentPTA(referenceGraph.wmethod.computeNewTestSet(referenceGraph.getInit(),1));// this one will not set any states as rejects because it uses shouldbereturned
        //referenceGraph.pathroutines.completeGraph(referenceGraph.nextID(false));
        if (onlyUsePositives)
          pta.paths.augmentPTA(generator.getAllSequences(0).filter(new FilterPredicate() {
            @Override
            public boolean shouldBeReturned(Object name) {
              return ((statechum.analysis.learning.rpnicore.RandomPathGenerator.StateName)name).accept;
            }
          }));
        else
          pta.paths.augmentPTA(generator.getAllSequences(0));// the PTA will have very few reject-states because we are generating few sequences and hence there will be few negative sequences.
          // In order to approximate the behaviour of our case study, we need to compute which pairs are not allowed from a reference graph and use those as if-then automata to start the inference.
         
        //pta.paths.augmentPTA(referenceGraph.wmethod.computeNewTestSet(referenceGraph.getInit(),1));
       
        pta.clearColours();
View Full Code Here

      final Collection<List<Label>> testSet = null;//PaperUAS.computeEvaluationSet(referenceGraph,states*3,states*alphabet);
     
      for(int attempt=0;attempt<2;++attempt)
      {// try learning the same machine a few times
        LearnerGraph pta = new LearnerGraph(config);
        RandomPathGenerator generator = new RandomPathGenerator(referenceGraph,new Random(attempt),5,null);
        // test sequences will be distributed around
        final int pathLength = generator.getPathLength();
        // The total number of elements in test sequences (alphabet*states*traceQuantity) will be distributed around (random(pathLength)+1). The total size of PTA is a product of these two.
        // For the purpose of generating long traces, we construct as many traces as there are states but these traces have to be rather long,
        // that is, length of traces will be (random(pathLength)+1)*sequencesPerChunk/states and the number of traces generated will be the same as the number of states.
        final int tracesToGenerate = makeEven(states*traceQuantity);
        final Random rnd = new Random(seed*31+attempt);
        generator.generateRandomPosNeg(tracesToGenerate, 1, false, new RandomLengthGenerator() {
                   
            @Override
            public int getLength() {
              return (rnd.nextInt(pathLength)+1)*lengthMultiplier;
            }
   
            @Override
            public int getPrefixLength(int len) {
              return len;
            }
          });
        /*
        for(List<Label> seq:referenceGraph.wmethod.computeNewTestSet(1))
        {
          pta.paths.augmentPTA(seq, referenceGraph.getVertex(seq) != null, false, null);
        }*/
        //pta.paths.augmentPTA(referenceGraph.wmethod.computeNewTestSet(referenceGraph.getInit(),1));// this one will not set any states as rejects because it uses shouldbereturned
        //referenceGraph.pathroutines.completeGraph(referenceGraph.nextID(false));
        if (onlyUsePositives)
          pta.paths.augmentPTA(generator.getAllSequences(0).filter(new FilterPredicate() {
            @Override
            public boolean shouldBeReturned(Object name) {
              return ((statechum.analysis.learning.rpnicore.RandomPathGenerator.StateName)name).accept;
            }
          }));
        else
          pta.paths.augmentPTA(generator.getAllSequences(0));// the PTA will have very few reject-states because we are generating few sequences and hence there will be few negative sequences.
          // In order to approximate the behaviour of our case study, we need to compute which pairs are not allowed from a reference graph and use those as if-then automata to start the inference.
         
        //pta.paths.augmentPTA(referenceGraph.wmethod.computeNewTestSet(referenceGraph.getInit(),1));
       
        pta.clearColours();
View Full Code Here

    final Collection<List<Label>> testSet = PaperUAS.computeEvaluationSet(referenceGraph,states*3,states*alphabet);
   
    for(int attempt=0;attempt<3;++attempt)
    {// try learning the same machine a few times
      LearnerGraph pta = new LearnerGraph(config);
      RandomPathGenerator generator = new RandomPathGenerator(referenceGraph,new Random(attempt),5,referenceGraph.getVertex(Arrays.asList(new Label[]{uniqueFromInitial})));
      generator.setWalksShouldLeadToInitialState();
      // test sequences will be distributed around
      final int pathLength = generator.getPathLength();
      final int sequencesPerChunk = PairQualityLearner.makeEven(alphabet*states*traceQuantity);// we are only using one chunk here but the name is unchanged.
      // Usually, the total number of elements in test sequences (alphabet*states*traceQuantity) will be distributed around (random(pathLength)+1). The total size of PTA is a product of these two.
      // For the purpose of generating long traces, we construct as many traces as there are states but these traces have to be rather long,
      // that is, length of traces will be (random(pathLength)+1)*sequencesPerChunk/states and the number of traces generated will be the same as the number of states.
      final int tracesToGenerate = 20;//PairQualityLearner.makeEven(states*traceQuantity*3);
      final Random rnd = new Random(seed*31+attempt);
     
      generator.generateRandomPosNeg(tracesToGenerate, 1, false, new RandomLengthGenerator() {
                 
          @Override
          public int getLength() {
            return  6;//10*(rnd.nextInt(pathLength)+1)*sequencesPerChunk/tracesToGenerate;
          }
 
          @Override
          public int getPrefixLength(int len) {
            return len;
          }
        },true,true,null,Arrays.asList(new Label[]{uniqueFromInitial}));
     
      //System.out.println(generator.getAllSequences(0).getData(PTASequenceEngine.truePred));
     
      /*
      for(List<Label> seq:referenceGraph.wmethod.computeNewTestSet(1))
      {
        pta.paths.augmentPTA(seq, referenceGraph.getVertex(seq) != null, false, null);
      }*/
      //pta.paths.augmentPTA(referenceGraph.wmethod.computeNewTestSet(referenceGraph.getInit(),1));// this one will not set any states as rejects because it uses shouldbereturned
      //referenceGraph.pathroutines.completeGraph(referenceGraph.nextID(false));
      if (onlyUsePositives)
        pta.paths.augmentPTA(generator.getAllSequences(0).filter(new FilterPredicate() {
          @Override
          public boolean shouldBeReturned(Object name) {
            return ((statechum.analysis.learning.rpnicore.RandomPathGenerator.StateName)name).accept;
          }
        }));
      else
        pta.paths.augmentPTA(generator.getAllSequences(0));// the PTA will have very few reject-states because we are generating few sequences and hence there will be few negative sequences.
        // In order to approximate the behaviour of our case study, we need to compute which pairs are not allowed from a reference graph and use those as if-then automata to start the inference.
       
      /*
      synchronized (AbstractLearnerGraph.syncObj) {
        PaperUAS.computePTASize(selectionID+" with unique "+uniqueFromInitial+" : ", pta, referenceGraph);
View Full Code Here

      final Collection<List<Label>> testSet = PaperUAS.computeEvaluationSet(referenceGraph,states*3,states*alphabet);
     
      for(int attempt=0;attempt<2;++attempt)
      {// try learning the same machine a few times
        LearnerGraph pta = new LearnerGraph(config);
        RandomPathGenerator generator = new RandomPathGenerator(referenceGraph,new Random(attempt),5,null);
        // test sequences will be distributed around
        final int pathLength = generator.getPathLength();
        // The total number of elements in test sequences (alphabet*states*traceQuantity) will be distributed around (random(pathLength)+1). The total size of PTA is a product of these two.
        // For the purpose of generating long traces, we construct as many traces as there are states but these traces have to be rather long,
        // that is, length of traces will be (random(pathLength)+1)*sequencesPerChunk/states and the number of traces generated will be the same as the number of states.
        final int tracesToGenerate = makeEven(traceQuantity);
        final Random rnd = new Random(seed*31+attempt);
        generator.generateRandomPosNeg(tracesToGenerate, 1, false, new RandomLengthGenerator() {
                   
            @Override
            public int getLength() {
              return (rnd.nextInt(pathLength)+1)*lengthMultiplier;
            }
   
            @Override
            public int getPrefixLength(int len) {
              return len;
            }
          });

        if (onlyUsePositives)
          pta.paths.augmentPTA(generator.getAllSequences(0).filter(new FilterPredicate() {
            @Override
            public boolean shouldBeReturned(Object name) {
              return ((statechum.analysis.learning.rpnicore.RandomPathGenerator.StateName)name).accept;
            }
          }));
        else
          pta.paths.augmentPTA(generator.getAllSequences(0));// the PTA will have very few reject-states because we are generating few sequences and hence there will be few negative sequences.
          // In order to approximate the behaviour of our case study, we need to compute which pairs are not allowed from a reference graph and use those as if-then automata to start the inference.
        //pta.paths.augmentPTA(referenceGraph.wmethod.computeNewTestSet(referenceGraph.getInit(),1));
   
        List<List<Label>> sPlus = generator.getAllSequences(0).getData(new FilterPredicate() {
          @Override
          public boolean shouldBeReturned(Object name) {
            return ((statechum.analysis.learning.rpnicore.RandomPathGenerator.StateName)name).accept;
          }
        });
        List<List<Label>> sMinus= generator.getAllSequences(0).getData(new FilterPredicate() {
          @Override
          public boolean shouldBeReturned(Object name) {
            return !((statechum.analysis.learning.rpnicore.RandomPathGenerator.StateName)name).accept;
          }
        });
View Full Code Here

              int extraLength=0;
              if (deterministicGraph.getStateNumber() == 1) extraLength=1;//where the diameter is zero (and due
              // to subset construction, we are not going to get unreachable states thus getStateNumber()
              // is the right way to determine this), we have to set extra length to 1 to ensure walks are generated.

              RandomPathGenerator randomPaths = new RandomPathGenerator(deterministicGraph,randomGenerator.getRandom(entryA.getKey()),
                  extraLength+config.getGdScoreComputationAlgorithm_RandomWalk_ExtraLength(),state,matrixForward.pathroutines.computeAlphabet());
              if (config.getGdScoreComputationAlgorithm_RandomWalk_PathLength() > 0)
                randomPaths.setPathLength(config.getGdScoreComputationAlgorithm_RandomWalk_PathLength());
              randomPaths.generateRandomPosNeg(config.getGdScoreComputationAlgorithm_RandomWalk_NumberOfSequences(), 1,false);
              graphwalk=new GraphAndWalk(deterministicGraph,randomPaths.getAllSequences(0));
            }
            break;
          case SCORE_TESTSET:
            graphwalk=new GraphAndWalk(deterministicGraph,deterministicGraph.wmethod.computeNewTestSet(state, config.getGdScoreComputationAlgorithm_TestSet_ExtraStates()));
            deterministicGraph.learnerCache.invalidate();// reduce memory footprint.
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.rpnicore.RandomPathGenerator$StateName

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.