Examples of RandomPathGenerator


Examples of com.barrybecker4.puzzle.tantrix.model.RandomPathGenerator

     * @param board
     */
    public TantrixPath(TantrixBoard board) {

        TantrixBoard myBoard = new TantrixBoard(board.getAllTiles());
        RandomPathGenerator gen = new RandomPathGenerator(myBoard);
        TantrixPath path = gen.generateRandomPath();
        this.tiles_ = path.tiles_;
        this.primaryPathColor_ = board.getPrimaryColor();
    }
View Full Code Here

Examples of statechum.analysis.learning.experiments.RandomPathGenerator

      graphmlFile.setGraphMLFileHandler(new ExperimentGraphMLHandler());
      DirectedSparseGraph dg = new DirectedSparseGraph();
      dg.getEdgeConstraints().clear();
      dg = (DirectedSparseGraph)graphmlFile.load(wholePath+args[1]);
      int size = dg.getEdges().size()*4;
    RandomPathGenerator rpg = new RandomPathGenerator(dg, new Random(1),size, 5);
    Collection<List<String>> fullSet = rpg.getAllPaths();
    final FSMStructure expected = getGraphData(dg);
   
    RPNIBlueFringeLearnerTestComponentOpt l = new RPNIBlueFringeLearnerTestComponentOpt(null) // CHOOSE non-Opt for original version
    {
      protected int checkWithEndUser(DirectedSparseGraph model,List<String> question, final Object [] moreOptions)
View Full Code Here

Examples of statechum.analysis.learning.rpnicore.RandomPathGenerator

      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 2*states*alphabet;//(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

Examples of statechum.analysis.learning.rpnicore.RandomPathGenerator

      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));
   
        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

Examples of statechum.analysis.learning.rpnicore.RandomPathGenerator

      final Collection<List<Label>> testSet = PaperUAS.computeEvaluationSet(referenceGraph,states*3,makeEven(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);
        final int tracesToGenerate = makeEven(traceQuantity);
        generator.generateRandomPosNeg(tracesToGenerate, 1, false, new RandomLengthGenerator() {
                   
            @Override
            public int getLength() {
              return (int)(traceLengthMultiplier*states*alphabet);
            }
   
            @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));
   
        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

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

Examples of statechum.analysis.learning.rpnicore.RandomPathGenerator

      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

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

Examples of statechum.analysis.learning.rpnicore.RandomPathGenerator

   
    /** 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 learned = 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 (useOrig)
View Full Code Here

Examples of statechum.analysis.learning.rpnicore.RandomPathGenerator

            "resources/pcodaExperiments/25StatesCrowded/25Inputs_75_12.xml"
            ),config);
    }
   
    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(nrPerChunk , 100/percentPerChunk);
   
    RPNIBlueFringeLearnerTestComponentOpt l = new RPNIBlueFringeLearnerTestComponentOpt(null,config)
    {
      @Override
      protected Pair<Integer,String> checkWithEndUser(
          @SuppressWarnings("unused"LearnerGraph model,
          List<String> question,
          @SuppressWarnings("unused") final Object [] moreOptions)
      {
        return new Pair<Integer,String>(graph.paths.tracePath(question),null);
      }
    };
    PTASequenceEngine sPlus = null, sMinus = null;int percent = 10;
    sPlus = rpg.getExtraSequences(percent/10-1);sMinus = rpg.getAllSequences(percent/10-1);

    int ptaSize = sMinus.numberOfLeafNodes();
    l.init(sMinus, ptaSize,ptaSize);// our imaginary positives are prefixes of negatives.
    DirectedSparseGraph learningOutcome = l.learnMachine();
    l.setQuestionCounter(0);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.