Package statechum.analysis.learning

Examples of statechum.analysis.learning.RPNIBlueFringeLearner


      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 = null;
     
      if (useAmber)
      {
        l = new RPNIBlueAmberFringeLearner(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);
          }
        };
      }
      else
      {
        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);

      RecordProgressDecorator recorder = null;
      try {
        recorder = new RecordProgressDecorator(l.getLearner(),new java.io.FileOutputStream(getFileName(FileType.LOG)),1,config,true);
        //recorder.setCompressionMethod(ZipEntry.STORED);// no compression, for speed.
      } catch (IOException e) {
        statechum.Helper.throwUnchecked("could not open log file for writing", e);
      }
      Collection<List<String>> graphTestSet = graph.wmethod.getFullTestSet(1);
      recorder.writeLearnerEvaluationData(new ProgressDecorator.LearnerEvaluationConfiguration(graph,graphTestSet,config,null));
      l.getLearner().setTopLevelListener(recorder);

      LearnerGraph learned = learn(recorder,sMinus);
      PTA_computePrecisionRecall precRec = new PTA_computePrecisionRecall(learned);
      PTASequenceEngine engine = new PTA_FSMStructure(graph);
      PosNegPrecisionRecall ptaPR = precRec.crossWith(sMinus);
      SequenceSet ptaTestSet = engine.new SequenceSet();ptaTestSet.setIdentity();
      ptaTestSet = ptaTestSet.cross(graph.wmethod.getFullTestSet(1));
      PosNegPrecisionRecall prNeg = precRec.crossWith(engine);
     
      // Columns 3 and 4
      result = result+prNeg.precision+FS+prNeg.recall;
     
      result = result + FS + questionNumber+ FS + // 5
        // Columns 6 and 7
        ptaPR.precision  + FS + ptaPR.recall + FS +
        "size:"+size+FS+ // 8
        "chunks: "+(100/percentPerChunk)+FS+ // 9
        "per chunk:"+nrPerChunk + // 10
        FS+percent+"%"+FS+ // 11
        "+:"+sPlus.getData().size()+FS+// 12
        "-:"+sMinus.getData(PTASequenceEngine.truePred).size(); // 13
/*
      try
      {
        result = result + FS+"L"+// 14
        // 15 and 16
          FS+graph.linear.getSimilarity(learned, false, 1)+FS+graph.linear.getSimilarity(learned, true, 1);
        // 17
        result = result + FS + graph.linear.getSimilarityWithNegatives(learned, 1, Linear.DDRH_highlight.class);
        // 18
        result = result + FS + graph.linear.getSimilarityWithNegatives(learned, 1, Linear.DDRH_highlight_Neg.class);
      }
      catch(IllegalArgumentException ex)
      {
        StringWriter wr = new StringWriter();ex.printStackTrace(new PrintWriter(wr));
        result = result+"\n"+"exception from linear: "+ex+
          " on graph with "+learned.getStateNumber()+" and "+learned.getStateNumber()+" transitions" +
          "\n"+wr.getBuffer().toString();
      }
  */   
      // 19 and 20
      result = result + FS + //graph.paths.getExtentOfCompleteness() + FS + learned.paths.getExtentOfCompleteness() + FS +
        l.getRestarts(); // 21
    }
View Full Code Here


        sMinus = sOrigMinus;
      else
        sMinus = sNewMinus;
     
     
      RPNIBlueFringeLearner l = null;
     
      if (useAmber)
      {
        l = new RPNIBlueAmberFringeLearner(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);
          }
        };
      }
      else
      {
        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);
          }
        };
      }
      learned = learn(l,sMinus);
      //learned = new LearnerGraph(config);
     
      PTASequenceEngine testSetEngine = new PTA_FSMStructure(graph);
      SequenceSet ptaTestSet = testSetEngine.new SequenceSet();ptaTestSet.setIdentity();
      ptaTestSet.cross(graph.wmethod.getFullTestSet(1));

      PTA_computePrecisionRecall precRec = new PTA_computePrecisionRecall(learned);
     
      PosNegPrecisionRecall ptaPR = precRec.crossWith(sMinus);
      PosNegPrecisionRecall prNeg = precRec.crossWith(testSetEngine);
     
      // Columns 3 and 4
      result = result+prNeg.precision+FS+prNeg.recall;
     
      result = result + FS + questionNumber+ FS + // 5
        // Columns 6 and 7
        ptaPR.precision  + FS + ptaPR.recall + FS;
     
      // 19 and 20
      result = result + FS + graph.paths.getExtentOfCompleteness() + FS + learned.paths.getExtentOfCompleteness() + FS +
        l.getRestarts(); // 21
    }
View Full Code Here

        sMinus = sOrigMinus;
      else
        sMinus = sNewMinus;
     
     
      RPNIBlueFringeLearner l = null;
     
      if (config.getLearnerToUse() == LEARNER.LEARNER_BLUEAMBER_MAY2008)
      {
        l = new RPNIBlueAmberFringeLearner(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);
          }
        };
      }
      else
      {
        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);
          }
        };
      }
      RecordProgressDecorator recorder = null;
      try {
        recorder = new RecordProgressDecorator(l.getLearner(),new java.io.FileOutputStream(getFileName(FileType.LOG)),1,config,true);
      } catch (IOException e) {
        statechum.Helper.throwUnchecked("could not open log file for writing", e);
      }
      Collection<List<String>> graphTestSet = graph.wmethod.getFullTestSet(1);
      recorder.writeLearnerEvaluationData(new ProgressDecorator.LearnerEvaluationConfiguration(graph,graphTestSet,config,null));
      l.getLearner().setTopLevelListener(recorder);
      learnt = learn(recorder,sMinus);
      //learned = new LearnerGraph(config);
     
      PTASequenceEngine testSetEngine = new PTA_FSMStructure(graph);
      SequenceSet ptaTestSet = testSetEngine.new SequenceSet();ptaTestSet.setIdentity();
      ptaTestSet.cross(graphTestSet);

      PTA_computePrecisionRecall precRec = new PTA_computePrecisionRecall(learnt);
     
      PosNegPrecisionRecall ptaPR = precRec.crossWith(sMinus);
      PosNegPrecisionRecall prNeg = precRec.crossWith(testSetEngine);
     
      // Columns 3 and 4
      result = result+prNeg.precision+FS+prNeg.recall;
     
      result = result + FS + questionNumber+ FS + // 5
        // Columns 6 and 7
        ptaPR.precision  + FS + ptaPR.recall + FS;
     
      // 19 and 20
      result = result + FS + graph.paths.getExtentOfCompleteness() + FS + learnt.paths.getExtentOfCompleteness() + FS +
        l.getRestarts(); // 21
    }
View Full Code Here

    final LearnerSimulator simulator = new LearnerSimulator(new java.io.FileInputStream(logFileName),true);
    final LearnerEvaluationConfiguration eval1 = simulator.readLearnerConstructionData();
    final org.w3c.dom.Element nextElement = simulator.expectNextElement(ELEM_KINDS.ELEM_INIT.name());
    final ProgressDecorator.InitialData initial = simulator.readInitialData(nextElement);
    simulator.setNextElement(nextElement);
    RPNIBlueFringeLearner learner2 = new RPNIBlueFringeLearnerTestComponentOpt(null,eval1.config)
    {
      @Override
      public Pair<Integer,String> checkWithEndUser(
          @SuppressWarnings("unused"LearnerGraph model,
          List<String> question,
          @SuppressWarnings("unused"final Object [] moreOptions)
      {
        return new Pair<Integer,String>(eval1.graph.paths.tracePath(question),null);
      }
    };
   
    /*
    RecordProgressDecorator recorder = null;
    java.io.FileOutputStream out = null;
    try {
      out = new java.io.FileOutputStream("resources/tmp.xml");
      recorder = new RecordProgressDecorator(learner2.getLearner(),out,1,eval1.config,true);
    } catch (IOException e) {
      statechum.Helper.throwUnchecked("could not open log file for writing", e);
    }
    recorder.writeLearnerEvaluationData(eval1);
    learner2.getLearner().setTopLevelListener(recorder);
    recorder.learnMachine(initial.plus, initial.minus);
    try {
      out.close();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    //WMethod.checkM(initial.graph, learner2.getLearner().init(initial.plus, initial.minus));
    
     */
    new Test_LearnerComparator(learner2.getLearner(),simulator).learnMachine(initial.plus, initial.minus);
  }
View Full Code Here

    // now sanity checking on the plus and minus sets
    for(String [] path:plus)
      assert RPNIBlueFringeLearner.USER_ACCEPTED == expected.paths.tracePath(Arrays.asList(path));
    for(String [] path:minus)
      assert RPNIBlueFringeLearner.USER_ACCEPTED != expected.paths.tracePath(Arrays.asList(path));
    RPNIBlueFringeLearner l = new RPNIBlueFringeLearnerTestComponentOpt(null,testConfig)
    {
      @Override
      public Pair<Integer,String> checkWithEndUser(
          @SuppressWarnings("unused"LearnerGraph model,
          List<String> question,
          @SuppressWarnings("unused"final Object [] moreOptions)
      {
        return new Pair<Integer,String>(expected.paths.tracePath(question),null);
      }
    };
    testConfig.setLearnerIdMode(IDMode.POSITIVE_NEGATIVE);
    ByteArrayOutputStream logStream = new ByteArrayOutputStream();
    RecordProgressDecorator recorder = new RecordProgressDecorator(l.getLearner(),logStream,1,testConfig,useZip);
    Collection<List<String>> testSet = new LinkedList<List<String>>();
    recorder.writeLearnerEvaluationData(new ProgressDecorator.LearnerEvaluationConfiguration(expected, testSet, testConfig, null));
    LearnerGraph learntStructureA = recorder.learnMachine(buildSet(plus), buildSet(minus));
   
    //System.out.println("compression rate: "+recorder.getCompressionRate());
    //System.out.println(logStream.toString()+"============");
    //System.out.println(logStream.toByteArray().length);
    LearnerGraph learntMachineNoRejects = Transform322.removeRejectStates(learntStructureA,testConfig);
    WMethod.checkM(learntMachineNoRejects, expected);
   
    {// matching two simulators
      final LearnerSimulator
        simulator = new LearnerSimulator(new ByteArrayInputStream(logStream.toByteArray()),useZip),
        simulator2 = new LearnerSimulator(new ByteArrayInputStream(logStream.toByteArray()),useZip);
     
      LearnerEvaluationConfiguration eval1 = simulator.readLearnerConstructionData();
      WMethod.checkM(expected, eval1.graph);
      Assert.assertEquals(testSet, eval1.testSet);
      Assert.assertEquals(expected.config, testConfig);
      LearnerEvaluationConfiguration eval2 = simulator2.readLearnerConstructionData();
      WMethod.checkM(expected, eval2.graph);
      Assert.assertEquals(testSet, eval2.testSet);
      Assert.assertEquals(expected.config, testConfig);
     
      new Test_LearnerComparator(simulator,simulator2).learnMachine(buildSet(plus), buildSet(minus));
    }

    {// now a simulator to a learner
      final LearnerSimulator simulator = new LearnerSimulator(new ByteArrayInputStream(logStream.toByteArray()),useZip);
      LearnerEvaluationConfiguration eval1 = simulator.readLearnerConstructionData();
      WMethod.checkM(expected, eval1.graph);
      Assert.assertEquals(testSet, eval1.testSet);
      Assert.assertEquals(expected.config, testConfig);

      RPNIBlueFringeLearner learner2 = new RPNIBlueFringeLearnerTestComponentOpt(null,expected.config)
      {
        @Override
        public Pair<Integer,String> checkWithEndUser(
            @SuppressWarnings("unused"LearnerGraph model,
            List<String> question,
            @SuppressWarnings("unused"final Object [] moreOptions)
        {
          return new Pair<Integer,String>(expected.paths.tracePath(question),null);
        }
      };
      new Test_LearnerComparator(learner2.getLearner(),simulator).learnMachine(buildSet(plus), buildSet(minus));
    }


    {// now two learners
      RPNIBlueFringeLearner learnerA = new RPNIBlueFringeLearnerTestComponentOpt(null,testConfig)
      {
        @Override
        public Pair<Integer,String> checkWithEndUser(
            @SuppressWarnings("unused"LearnerGraph model,
            List<String> question,
            @SuppressWarnings("unused"final Object [] moreOptions)
        {
          return new Pair<Integer,String>(expected.paths.tracePath(question),null);
        }
      };
      RPNIBlueFringeLearner learnerB = new RPNIBlueFringeLearnerTestComponentOpt(null,testConfig)
      {
        @Override
        public Pair<Integer,String> checkWithEndUser(
            @SuppressWarnings("unused"LearnerGraph model,
            List<String> question,
            @SuppressWarnings("unused"final Object [] moreOptions)
        {
          return new Pair<Integer,String>(expected.paths.tracePath(question),null);
        }
      };
      new Test_LearnerComparator(learnerA.getLearner(),learnerB.getLearner()).learnMachine(buildSet(plus), buildSet(minus));
    }

  }
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.RPNIBlueFringeLearner

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.