Package statechum.analysis.learning.TestFSMAlgo

Examples of statechum.analysis.learning.TestFSMAlgo.FSMStructure


   * @param minus value loaded from XML
   */
  public synchronized DirectedSparseGraph init(Collection<List<String>> plus,  Collection<List<String>> minus)
  {
    DirectedSparseGraph result = null;
    FSMStructure copyOfResult = null;
    // First, we call the expected method
    if (Thread.currentThread() == secondThread)
    {
      result = whatToCompareWith.init(plus, minus);
      copyOfResult = new FSMStructure(result,null);
      iGraph = copyOfResult;
    }
    else
    {
      result = decoratedLearner.init(plus, minus);
      copyOfResult = new FSMStructure(result,null);
    }
    checkCall(KIND_OF_METHOD.M_INIT);

    if (Thread.currentThread() != secondThread)
    {// second thread, checking.
View Full Code Here


  protected void checkLearnerProgressRecording(String fsmString, String name,final String [][] plus, final String [][] minus)
  {
    Configuration testConfig = Configuration.getDefaultConfiguration().copy();
    testConfig.setGdFailOnDuplicateNames(false);
    final DirectedSparseGraph expectedGraph = TestFSMAlgo.buildGraph(fsmString, "sample FSM");
    final FSMStructure expected = new FSMStructure(expectedGraph,testConfig);
   
    // 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

    graphML_end;
 
  @Test(expected=IllegalArgumentException.class)
  public final void testGraphMLwriter_fail() throws IOException
  {
    FSMStructure fsm = new FSMStructure(TestFSMAlgo.buildGraph(relabelFSM.replaceAll("A", Transform322.Initial+"_str"), "testRelabel1"),Configuration.getDefaultConfiguration());
    StringWriter writer = new StringWriter();
    fsm.transform322.writeGraphML(writer);
  }
View Full Code Here

  }
 
  @Test
  public final void testGraphMLwriter1() throws IOException
  {
    FSMStructure fsm = new FSMStructure(TestFSMAlgo.buildGraph(relabelFSM, "testRelabel1"),Configuration.getDefaultConfiguration());
    StringWriter writer = new StringWriter();
    fsm.transform322.writeGraphML(writer);
    Assert.assertEquals(removeWhiteSpace(graphml_beginning+"VERTEX=\"B\" "+graphml_ending),
        removeWhiteSpace(writer.toString()));
  }
View Full Code Here

  }
 
  @Test
  public final void testGraphMLwriter2() throws IOException
  {
    FSMStructure fsm = new FSMStructure(TestFSMAlgo.buildGraph(relabelFSM, "testRelabel1"),Configuration.getDefaultConfiguration());
    StringWriter writer = new StringWriter();
    fsm.accept.put(fsm.findVertex("B"),false);
    fsm.transform322.writeGraphML(writer);
    Assert.assertEquals(removeWhiteSpace(graphml_beginning+
        "VERTEX=\"B\" "+JUConstants.ACCEPTED+"=\"false\""+
        graphml_ending),
        removeWhiteSpace(writer.toString()));
View Full Code Here

  }
 
  @Test
  public final void testGraphMLwriter_loadnode1() throws IOException
  {
    FSMStructure fsm = new FSMStructure(TestFSMAlgo.buildGraph(relabelFSM, "testRelabel1"),Configuration.getDefaultConfiguration());
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    Document doc = null;
    try
    {
      factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);factory.setXIncludeAware(false);
      factory.setExpandEntityReferences(false);factory.setValidating(false);// we do not have a schema to validate against-this does not seem necessary for the simple data format we are considering here.
      doc = factory.newDocumentBuilder().newDocument();
    }
    catch(ParserConfigurationException ex)
    {
      IOException parserEx = new IOException("configuration exception: "+ex);parserEx.initCause(ex);throw parserEx;
    }
    FSMStructure actual = new FSMStructure(Transform322.loadGraph(fsm.transform322.createGraphMLNode(doc)),Configuration.getDefaultConfiguration());
    Assert.assertNull(checkM(fsm,fsm.init,actual,actual.init));
    Assert.assertEquals(fsm.init, actual.init);
  }
View Full Code Here

  }
 
  @Test
  public final void testGraphMLwriter_loadnode2() throws IOException
  {
    FSMStructure fsm = new FSMStructure(TestFSMAlgo.buildGraph(relabelFSM, "testRelabel1"),Configuration.getDefaultConfiguration());
    fsm.findVertex("B");fsm.findVertex("B");fsm.accept.put(fsm.findVertex("B"),false);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    Document doc = null;
    try
    {
      factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);factory.setXIncludeAware(false);
      factory.setExpandEntityReferences(false);factory.setValidating(false);// we do not have a schema to validate against-this does not seem necessary for the simple data format we are considering here.
      doc = factory.newDocumentBuilder().newDocument();
    }
    catch(ParserConfigurationException ex)
    {
      IOException parserEx = new IOException("configuration exception: "+ex);parserEx.initCause(ex);throw parserEx;
    }
    FSMStructure actual = new FSMStructure(Transform322.loadGraph(fsm.transform322.createGraphMLNode(doc)),Configuration.getDefaultConfiguration());
    Assert.assertNull(checkM(fsm,fsm.init,actual,actual.init));
    Assert.assertEquals(fsm.init, actual.init);
  }
View Full Code Here

  /** No graph element. */
  @Test
  public final void testGraphMLwriter_loadnode_fail2a() throws IOException
  {
    FSMStructure fsm = new FSMStructure(TestFSMAlgo.buildGraph(relabelFSM, "testRelabel1"),Configuration.getDefaultConfiguration());
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    Document doc = null;
    try
    {
      factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);factory.setXIncludeAware(false);
View Full Code Here

 
  /** No graph element. */
  @Test
  public final void testGraphMLwriter_loadnode_fail2b() throws IOException
  {
    FSMStructure fsm = new FSMStructure(TestFSMAlgo.buildGraph(relabelFSM, "testRelabel1"),Configuration.getDefaultConfiguration());
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    Document doc = null;
    try
    {
      factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);factory.setXIncludeAware(false);
View Full Code Here

 
  /** Duplicate graph elements. */
  @Test
  public final void testGraphMLwriter_loadnode_fail2c() throws IOException
  {
    FSMStructure fsm = new FSMStructure(TestFSMAlgo.buildGraph(relabelFSM, "testRelabel1"),Configuration.getDefaultConfiguration());
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    Document doc = null;
    try
    {
      factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);factory.setXIncludeAware(false);
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.TestFSMAlgo.FSMStructure

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.