Package statechum.analysis.learning.rpnicore

Examples of statechum.analysis.learning.rpnicore.RandomPathGenerator


      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,makeEven(states*tracesAlphabet));

      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);
        final int tracesToGenerate = makeEven(traceQuantity);
        generator.generateRandomPosNeg(tracesToGenerate, 1, false, new RandomLengthGenerator() {
                   
            @Override
            public int getLength() {
              return (int)(traceLengthMultiplier*states*tracesAlphabet);
            }
   
            @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));
   
        final MarkovModel m= new MarkovModel(chunkLen,true,true);

        new MarkovClassifier(m, pta).updateMarkov(false);// construct Markov chain if asked for.
       
View Full Code Here

      for(int attempt=0;attempt<10;++attempt)
      {// try learning the same machine a few times

         LearnerGraph pta = new LearnerGraph(config);
        RandomPathGenerator generator = new RandomPathGenerator(referenceGraph,new Random(attempt),5,null);
        final int tracesToGenerate = makeEven(traceQuantity);

        generator.generateRandomPosNeg(tracesToGenerate, 1, false, new RandomLengthGenerator() {
                   
            @Override
            public int getLength() {
              return (int) traceLengthMultiplier*alphabet*states;
            }
   
            @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));

        final MarkovModel m= new MarkovModel(chunkLen,true,true, disableInconsistenciesInMergers);

        new MarkovClassifier(m, pta).updateMarkov(false);// construct Markov chain if asked for.
       
View Full Code Here

        final LearnerGraph graphReference = new LearnerGraph(learnerInitConfiguration.config);AbstractPersistence.loadGraph(GlobalConfiguration.getConfiguration().getProperty(G_PROPERTIES.RESOURCES)+File.separator+"uas_reference_automaton.xml",graphReference,labelConverter);
       final Collection<List<Label>> wMethod = graphReference.wmethod.getFullTestSet(1);
       int wPos=0;
       for(List<Label> seq:wMethod) if (graphReference.paths.tracePathPrefixClosed(seq) == AbstractOracle.USER_ACCEPTED) wPos++;
       System.out.println("before rnd: "+wMethod.size()+" sequences, "+wPos+" positives");
       RandomPathGenerator pathGen = new RandomPathGenerator(graphReference,new Random(0),5,graphReference.getInit());
       pathGen.generatePosNeg(2*(wMethod.size()-wPos), 1);
       wMethod.addAll(pathGen.getExtraSequences(0).getData());
       System.out.println("after rnd: "+wMethod.size()+" sequences");
      
      
       DrawGraphs gr = new DrawGraphs();
    final RBoxPlot<Integer>
View Full Code Here

      outcome.setValue(DOUBLE_V.ACCURACY_W, wSeq.firstElem);
    }
   
    {
      Collection<List<Label>> sequences =new LinkedHashSet<List<Label>>();
      RandomPathGenerator rpg = new RandomPathGenerator(from, new Random(0),4, from.getInit());// the seed for Random should be the same for each file
      long startTime = System.nanoTime();
      rpg.generatePosNeg((graphComplexity+1)*states , 1);
      outcome.setValue(LONG_V.DURATION_RAND,System.nanoTime()-startTime);
      sequences.addAll(rpg.getAllSequences(0).getData(PTASequenceEngine.truePred));
      sequences.addAll(rpg.getExtraSequences(0).getData(PTASequenceEngine.truePred));
      Pair<Double,Long> randSeq = compareLang(from, to, sequences);
      outcome.setValue(LONG_V.DURATION_RAND, outcome.getValue(LONG_V.DURATION_RAND)+randSeq.secondElem);
      outcome.setValue(DOUBLE_V.ACCURACY_RAND, randSeq.firstElem);
    }
   
View Full Code Here

TOP

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

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.