Package statechum.analysis.learning.TestFSMAlgo

Examples of statechum.analysis.learning.TestFSMAlgo.FSMStructure


  protected void checkLearner(String fsmString, String [][] plus, String [][] minus)
  {
    final DirectedSparseGraph g = TestFSMAlgo.buildGraph(fsmString, "sample FSM");
    final DirectedSparseGraph completedGraph = (DirectedSparseGraph)g.copy();TestFSMAlgo.completeGraph(completedGraph, "REJECT");
    final FSMStructure expected = WMethod.getGraphData(g);
   
    //updateFrame(g, g);

    // 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(visFrame)
    {
      @Override
      protected int checkWithEndUser(DirectedSparseGraph model,List<String> question, final Object [] moreOptions)
      {
        return checkPath(expected, g, question, moreOptions);
      }
    };
    l.setDebugMode(false);
    //l.setPairsMergedPerHypothesis(0);
    //l.setGeneralisationThreshold(1);
    //l.setCertaintyThreshold(5);
    if (visFrame != null) l.addObserver(visFrame);
    l.getScoreComputer().setMode(IDMode.POSITIVE_NEGATIVE);
    l.init(buildSet(plus), buildSet(minus));
    DirectedSparseGraph learningOutcomeA = l.learnMachine();
    //updateFrame(learningOutcome,g);
    FSMStructure learntStructureA = WMethod.getGraphData(learningOutcomeA);

    // Now do the same with ptasets instead of real sets
    PTASequenceSet plusPTA = new PTASequenceSet();plusPTA.addAll(buildSet(plus));PTASequenceSet minusPTA = new PTASequenceSet();minusPTA.addAll(buildSet(minus));
    l.init(plusPTA, minusPTA);
    DirectedSparseGraph learningOutcomeB = l.learnMachine();
    FSMStructure learntStructureB = WMethod.getGraphData(learningOutcomeB);
   
    TestFSMAlgo.checkMBoolean(learntStructureA, learntStructureB, learntStructureA.init, learntStructureB.init);
    //TestFSMAlgo.checkM(learntStructure,completedGraph,learntStructure.init,expected.init);
  }
View Full Code Here


   
    //setDebugMode(true);updateFrame(g, computeStateScores.mergeAndDeterminize(new computeStateScores(g,"SINK"),pair).getGraph());

    // Now check that computeStateScores properly does  mergeAndDeterminize
    // (on the test data we are dealing with in these tests, there are separate tests for mergeAndDeterminize)
    FSMStructure tempG = WMethod.getGraphData(temp), tempBG = WMethod.getGraphData(tempB);
    Assert.assertEquals(false, WMethod.checkUnreachableStates(tempG));Assert.assertEquals(false, WMethod.checkUnreachableStates(tempBG));
    Assert.assertEquals(true, TestFSMAlgo.checkMBoolean(tempG, tempBG, tempG.init, tempBG.init));
   
    doneEdges = new HashSet();
    int origScore = computeScore(g, pair),
View Full Code Here

  @Test
  public final void testCopyGraph1()
  {
    DirectedSparseGraph g=TestFSMAlgo.buildGraph("S-a->S1", "testCopyGraph");
    DirectedSparseGraph copy=computeStateScores.copy(g);
    FSMStructure gS = WMethod.getGraphData(g),gC = WMethod.getGraphData(copy);
   
    Assert.assertTrue(gS.equals(gC));
  }
View Full Code Here

  @Test
  public final void testCopyGraph2()
  {
    DirectedSparseGraph g=TestFSMAlgo.buildGraph("S-a->S1-b->"+"A-a->A1-a-#ARej\nA1-d->A2-d->A3\nA1-c->A2-c->A3"+PTA3, "testCopyGraph");
    DirectedSparseGraph copy=computeStateScores.copy(g);
    FSMStructure gS = WMethod.getGraphData(g),gCopy = WMethod.getGraphData(copy);
   
    Assert.assertTrue(gS.equals(gCopy));
   
    // now test if all clones are faithful
    for(Edge e:(Set<Edge>)g.getEdges())
      ((Set<String>)e.getUserDatum(JUConstants.LABEL)).add("junk");
   
    FSMStructure gS_Modified = WMethod.getGraphData(copy);
   
    Assert.assertTrue(gS_Modified.equals(gCopy));
  }
View Full Code Here

    Assert.assertNotNull("state "+stateRed+" was not found", a);
    Assert.assertNotNull("state "+stateBlue+" was not found", b);
   
    StatePair pair = new StatePair(b,a);
   
    FSMStructure
      mergeResultA = WMethod.getGraphData(new RPNIBlueFringeLearner(null).mergeAndDeterminize(g, pair)),
      mergeResultB = WMethod.getGraphData(computeStateScores.mergeAndDeterminize(g2, pair)),
      mergeResultC = WMethod.getGraphData(computeStateScores.mergeAndDeterminize(new computeStateScores(g,"SINK"), pair).getGraph()),
      expectedMachine = WMethod.getGraphData(TestFSMAlgo.buildGraph(expectedFSM, "expected machine"));
View Full Code Here

    DirectedSparseGraph g=TestFSMAlgo.buildGraph("S-p->A-a->S\nA-b->S\nA-c->D\nA-b->D\nA-d->E\nS-n->U", "testMerge");
    Vertex
      s = RPNIBlueFringeLearner.findVertex(JUConstants.LABEL, "S", g),
      d = RPNIBlueFringeLearner.findVertex(JUConstants.LABEL, "U", g);
    StatePair pair = new StatePair(d,s);
    FSMStructure
      mergeResultA = WMethod.getGraphData(new RPNIBlueFringeLearner(null).mergeAndDeterminize(g, pair)),
      expectedResult = WMethod.getGraphData(TestFSMAlgo.buildGraph("S-p->A-a->S\nA-b->S\nA-c->S\nA-d->E\nS-n->S", "expected"));
    Assert.assertTrue(expectedResult.equals(mergeResultA));
  }
View Full Code Here

   * @return the recorded XML element
   */
  public Element writeLearnerEvaluationConfiguration(LearnerEvaluationConfiguration cnf)
  {
    Element evaluationData = doc.createElement(ELEM_KINDS.ELEM_EVALUATIONDATA.name());
    evaluationData.appendChild(new FSMStructure(cnf.graph,null).transform322.createGraphMLNode(doc));
    Element sequenceListElement = writeSequenceList(ELEM_KINDS.ATTR_TESTSET.name(), cnf.testSet);
    evaluationData.appendChild(Transform322.endl(doc));
    evaluationData.appendChild(sequenceListElement);evaluationData.appendChild(Transform322.endl(doc));
    evaluationData.appendChild(cnf.config.writeXML(doc));evaluationData.appendChild(Transform322.endl(doc));
    if (cnf.ltlSequences != null)
View Full Code Here

  protected Element writeInitialData(InitialData initialData)
  {
    Element elemInit = doc.createElement(ELEM_KINDS.ELEM_INIT.name());
    Element positive = writeSequenceList(ELEM_KINDS.ATTR_POSITIVE_SEQUENCES.name(), initialData.plus);positive.setAttribute(ELEM_KINDS.ATTR_POSITIVE_SIZE.name(), Integer.toString(initialData.plusSize));
    Element negative = writeSequenceList(ELEM_KINDS.ATTR_NEGATIVE_SEQUENCES.name(), initialData.minus);negative.setAttribute(ELEM_KINDS.ATTR_NEGATIVE_SIZE.name(), Integer.toString(initialData.minusSize));
    elemInit.appendChild(new FSMStructure(initialData.graph,null).transform322.createGraphMLNode(doc));elemInit.appendChild(Transform322.endl(doc));
    elemInit.appendChild(positive);elemInit.appendChild(Transform322.endl(doc));
    elemInit.appendChild(negative);elemInit.appendChild(Transform322.endl(doc));
    return elemInit;
  }
View Full Code Here

 
  protected void checkGraphEquality(DirectedSparseGraph what, DirectedSparseGraph with)
  {
    try
    {
      TestFSMAlgo.checkM(new FSMStructure(what,null), new FSMStructure(with,null));
    }
    catch(DifferentFSMException ex)
    {
      if (failureCode == null) failureCode = ex;
    }
View Full Code Here

   * @return graph loaded from XML file.
   */
  public synchronized computeStateScores MergeAndDeterminize(computeStateScores original, StatePair pair)
  {
    computeStateScores result = null;
    FSMStructure copyOfResult = null;
    // First, we call the expected method
    if (Thread.currentThread() == secondThread)
    {
      result = whatToCompareWith.MergeAndDeterminize(original, pair);
      copyOfResult = new FSMStructure(result.getGraph(),null);// since a tread which produced result may exit and modify the graph, we have to take a copy of it.
      mPair = pair;mGraph = copyOfResult;
    }
    else
    {
      result = decoratedLearner.MergeAndDeterminize(original, pair);
      copyOfResult = new FSMStructure(result.getGraph(),null);
    }
    checkCall(KIND_OF_METHOD.M_MERGEANDDETERMINIZE);

    if (Thread.currentThread() != secondThread)
    {// checking, considering that acceptance conditions are not stored in XML.
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.