Package statechum.analysis.learning

Examples of statechum.analysis.learning.RPNIBlueFringeLearnerTestComponentOpt


    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);
    LearnerGraph learned = new LearnerGraph(learningOutcome,config);
    PTA_computePrecisionRecall precRec = new PTA_computePrecisionRecall(learned);
    PTASequenceEngine engine = new PTA_FSMStructure(graph);
    precRec.crossWith(sMinus);
    SequenceSet ptaTestSet = engine.new SequenceSet();ptaTestSet.setIdentity();
View Full Code Here


          }
        };
      }
      else
      {
        l= new RPNIBlueFringeLearnerTestComponentOpt(null,config)
        {
          @Override
          protected Pair<Integer,String> checkWithEndUser(
              @SuppressWarnings("unused"LearnerGraph model,
              List<String> question,
View Full Code Here

    public void runTheExperiment()
    {
      buildSetsHalfNegative();
     
      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);
        }
      };
      //l.setCertaintyThreshold(10);
      config.setMinCertaintyThreshold(500000); //question threshold
      DirectedSparseGraph learningOutcome = null;
      int ptaElements = pta.numberOfLeafNodes();

      stats = stats+"Instance: "+instanceID+", learner: "+this+", pta: "+ptaElements+" tests: "+tests.size()+ "\n";
      l.init(pta, ptaElements/2,ptaElements/2);

      learningOutcome = l.learnMachine();
      result = result+l.getQuestionCounter()+FS+computeAccuracy(learningOutcome, graph.paths.getGraph(),tests);
      System.out.print(computeAccuracy(learningOutcome, graph.paths.getGraph(),tests)+",");
      //System.out.println(instanceID+","+result);
      //updateFrame(g,learningOutcome);
      l.setQuestionCounter(0);
      if (learningOutcome != null)
        stats = stats+(learningOutcome.containsUserDatumKey(JUConstants.STATS)? "\n"+learningOutcome.getUserDatum(JUConstants.STATS).toString():"");
      //System.out.println(inputFileName+" (instance "+instanceID+"), learner "+this+", "+ percent+"% terminated at "+Calendar.getInstance().getTime());
    }
View Full Code Here

          }
        };
      }
      else
      {
        l = new RPNIBlueFringeLearnerTestComponentOpt(null,config)
        {
          @Override
          protected Pair<Integer,String> checkWithEndUser(
              @SuppressWarnings("unused"LearnerGraph model,
              List<String> question,
View Full Code Here

          }
        };
      }
      else
      {
        l = new RPNIBlueFringeLearnerTestComponentOpt(null,config)
        {
          @Override
          protected Pair<Integer,String> checkWithEndUser(
              @SuppressWarnings("unused"LearnerGraph model,
              List<String> question,
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 == WMethod.tracePath(expected,Arrays.asList(path));
    for(String [] path:minus)
      assert RPNIBlueFringeLearner.USER_ACCEPTED != WMethod.tracePath(expected,Arrays.asList(path));
    RPNIBlueFringeLearnerTestComponentOpt l = new RPNIBlueFringeLearnerTestComponentOpt(null)
    {
      @Override
      public int checkWithEndUser(
          @SuppressWarnings("unused"DirectedSparseGraph model,
          List<String> question,
          @SuppressWarnings("unused"final Object [] moreOptions)
      {
        return WMethod.tracePath(new FSMStructure(model,null),question);
      }
    };
    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(expectedGraph, testSet, testConfig, null));
    DirectedSparseGraph 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);
   
    // At this point, we do not really care whether we learnt the right machine - all that matters is
    // we've got a log we can replay.
   
    //FSMStructure learntMachineNoRejects = Transform322.removeRejectStates(new FSMStructure(learntStructureA,testConfig),testConfig);
    //TestFSMAlgo.checkM(learntMachineNoRejects, expected);
   
    switch(kind)
    {
      case RECORDERTEST_SS:
      {// 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();
        TestFSMAlgo.checkM(expected, new FSMStructure(eval1.graph,null));
        Assert.assertEquals(testSet, eval1.testSet);
        LearnerEvaluationConfiguration eval2 = simulator2.readLearnerConstructionData();
        TestFSMAlgo.checkM(expected, new FSMStructure(eval2.graph,null));
        Assert.assertEquals(testSet, eval2.testSet);
       
        new Test_LearnerComparator(simulator,simulator2,false).learnMachine(buildSet(plus), buildSet(minus));
        break;
      }
     
      case RECORDERTEST_SL:
      {// now a simulator to a learner
        final LearnerSimulator simulator = new LearnerSimulator(new ByteArrayInputStream(logStream.toByteArray()),useZip);
        LearnerEvaluationConfiguration eval1 = simulator.readLearnerConstructionData();
        TestFSMAlgo.checkM(expected, new FSMStructure(eval1.graph,null));
        Assert.assertEquals(testSet, eval1.testSet);
 
        RPNIBlueFringeLearnerTestComponentOpt learner2 = new RPNIBlueFringeLearnerTestComponentOpt(null)
        {
          @Override
          public int checkWithEndUser(
              @SuppressWarnings("unused"DirectedSparseGraph model,
              List<String> question,
              @SuppressWarnings("unused"final Object [] moreOptions)
          {
            return WMethod.tracePath(new FSMStructure(model,null),question);
          }
        };
        new Test_LearnerComparator(learner2.getLearner(),simulator,false).learnMachine(buildSet(plus), buildSet(minus));
        break;
      }

      case RECORDERTEST_LL:
      {// now two learners
        RPNIBlueFringeLearnerTestComponentOpt learnerA = new RPNIBlueFringeLearnerTestComponentOpt(null)
        {
          @Override
          public int checkWithEndUser(
              @SuppressWarnings("unused"DirectedSparseGraph model,
              List<String> question,
              @SuppressWarnings("unused"final Object [] moreOptions)
          {
            return WMethod.tracePath(new FSMStructure(model,null),question);
          }
        };
        RPNIBlueFringeLearnerTestComponentOpt learnerB = new RPNIBlueFringeLearnerTestComponentOpt(null)
        {
          @Override
          public int checkWithEndUser(
              @SuppressWarnings("unused"DirectedSparseGraph model,
              List<String> question,
              @SuppressWarnings("unused"final Object [] moreOptions)
          {
            return WMethod.tracePath(new FSMStructure(model,null),question);
          }
        };
        new Test_LearnerComparator(learnerA.getLearner(),learnerB.getLearner(),false).learnMachine(buildSet(plus), buildSet(minus));
        break;
      }
    }
  }
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

      if (stdOutput != null) return stdOutput;
     
      buildSetsHalfNegative();
     
      final FSMStructure fsm = WMethod.getGraphData(graph);
      RPNIBlueFringeLearnerTestComponentOpt l = new RPNIBlueFringeLearnerTestComponentOpt(null)
      {
        @Override
        protected int checkWithEndUser(DirectedSparseGraph model,List<String> question, final Object [] moreOptions)
        {
          return tracePath(fsm, question);
        }
      };
      //l.setCertaintyThreshold(10);
      l.setMinCertaintyThreshold(500000); //question threshold
      DirectedSparseGraph learningOutcome = null;
      String result = "";
      String stats = "Instance: "+instanceID+", learner: "+this+", sPlus: "+sPlus.size()+" sMinus: "+sMinus.size()+" tests: "+tests.size()+ "\n";
      try
      {
        PTASequenceSet plusPTA = new PTASequenceSet();plusPTA.addAll(sPlus);PTASequenceSet minusPTA = new PTASequenceSet();minusPTA.addAll(sMinus);
        stats = stats + "Actual sequences, sPlus: "+plusPTA.size()+" sMinus: "+minusPTA.size()+ " ";
        changeParametersOnComputeStateScores(l.getScoreComputer());
        l.init(plusPTA, minusPTA);
        changeParametersOnLearner(l);
        learningOutcome = l.learnMachine();
        result = result+l.getQuestionCounter()+FS+computeAccuracy(learningOutcome, graph,tests);
        if(this.percent == 10)
          System.out.println();
        System.out.print(computeAccuracy(learningOutcome, graph,tests)+",");
        //System.out.println(instanceID+","+result);
        //updateFrame(g,learningOutcome);
        l.setQuestionCounter(0);
        if (learningOutcome != null)
          stats = stats+(learningOutcome.containsUserDatumKey(JUConstants.STATS)? "\n"+learningOutcome.getUserDatum(JUConstants.STATS).toString():"");
        //System.out.println(inputFileName+" (instance "+instanceID+"), learner "+this+", "+ percent+"% terminated at "+Calendar.getInstance().getTime());
        currentOutcome = OUTCOME.SUCCESS;
      }
View Full Code Here

      sPlus = new HashSet<List<String>>();
      Collection<List<String>> allPositive = rpg.getAllPaths();
      final FSMStructure fsm = WMethod.getGraphData(graph);
      WMethod wm = new WMethod(fsm,1);
      final AtomicInteger atomicInt = new AtomicInteger(0);
      RPNIBlueFringeLearnerTestComponentOpt l = new RPNIBlueFringeLearnerTestComponentOpt(null)
      {
        @Override
        protected int checkWithEndUser(
            @SuppressWarnings("unused"DirectedSparseGraph model,
            List<String> question,
            @SuppressWarnings("unused"final Object [] moreOptions)
        {
          atomicInt.addAndGet(1);
          return tracePath(fsm, question);
        }
      };
      //l.setCertaintyThreshold(3);
      l.setMinCertaintyThreshold(-1); //question threshold
      int number = size/10;
      for(int per=10;per<101;per=per+10){
        this.percent = per;atomicInt.set(0);
        sPlus = addNumberFromSamples(sPlus, allPositive, number);
        if(per!=100) // per!=30 &&
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.RPNIBlueFringeLearnerTestComponentOpt

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.