Package statechum.analysis.learning

Examples of statechum.analysis.learning.MarkovClassifier


        //System.out.println("Inconsistency of trimmed reference : "+inconsistencyForTheReferenceGraph);
       
        //if (inconsistencyForTheReferenceGraph != 53)
        //  break;// ignore automata where we get good results.
         
        MarkovClassifier ptaClassifier = new MarkovClassifier(m,pta);
        final List<List<Label>> pathsToMerge=ptaClassifier.identifyPathsToMerge(checker);
        final Collection<Set<CmpVertex>> verticesToMergeBasedOnInitialPTA=ptaClassifier.buildVerticesToMergeForPaths(pathsToMerge);

        /*
        List<StatePair> pairsListInitialMerge = ptaClassifier.buildVerticesToMergeForPath(pathsToMerge);
        LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>> verticesToMergeInitialMerge = new LinkedList<AMEquivalenceClass<CmpVertex,LearnerGraphCachedData>>();
        int scoreInitialMerge = pta.pairscores.computePairCompatibilityScore_general(null, pairsListInitialMerge, verticesToMergeInitialMerge);
View Full Code Here


          //    m.computeMMScoreImproved(p, tentativeGraph, l);
          //if(d > 0.0)
          //  possibleResults.add(new PairScoreWithDistance(p, d));
         
          //long score = computeScoreBasedOnMarkov(tentativeGraph,p,Markov,0);
          double d = MarkovScoreComputation.computeMMScoreImproved(p, new MarkovClassifier(Markov,tentativeGraph));
          if(d > 0.0)
            possibleResults.add(new PairScoreWithDistance(p, d));
          /*long pairScore = classifyPairBasedOnUnexpectedTransitions(p,tentativeGraph,Markov);
          if (pairScore >= 0)
            possibleResults.add(p);
View Full Code Here

        /*
        long pairScore = classifyPairBasedOnUnexpectedTransitions(p,tentativeGraph,Markov);
        if (pairScore >= 0)
          return null;
        */
        double d=MarkovScoreComputation.computeMMScoreImproved(p, new MarkovClassifier(Markov,tentativeGraph));
        if (d>0)
          return null;
        return p;
        /*
//        double d=m.get_extension_model().pairscores.computePairCompatibilityScore(p);
View Full Code Here

      ArrayList<PairScoreWithDistance>  WrongPairs= new ArrayList<PairScoreWithDistance>();
      for(PairScore p:pairs)
      { 
        if(p.firstElem.isAccept()==true && p.secondElem.isAccept()==true)
        {
          double d=MarkovScoreComputation.computeMMScoreImproved(p, new MarkovClassifier(Markov,graph));
          if(d == MarkovClassifier.fREJECT)
          {
            WrongPairs.add(new PairScoreWithDistance(p, d));
           }
        }
View Full Code Here

    /*
    m.updateMarkov(merged,predictForwardOrSideways,false);// now we construct sideways learner ...
    m.constructMarkovTentative(graph,predictForwardOrSideways);// ... and use it to add more transitions.
    */
    MarkovModel inverseModel = new MarkovModel(ptaClassifier.model.getChunkLen(),true,!ptaClassifier.model.directionForwardOrInverse);
    MarkovClassifier cl = new MarkovClassifier(inverseModel,ptaClassifier.graph);cl.updateMarkov(false);
    Collection<Set<CmpVertex>> verticesToMergeUsingSideways=cl.buildVerticesToMergeForPaths(pathsOfInterest);
    return verticesToMergeUsingSideways;
  }
View Full Code Here

          @Override
          public void initComputation(LearnerGraph graph)
          {
            coregraph = graph;

            cl = new MarkovClassifier(m, coregraph);
              extendedGraph = cl.constructMarkovTentative();
          }
         
          @Override
          public long overrideScoreComputation(PairScore p)
          {

            long pairScore = p.getScore();
           
            if (pairScore >= 0)
              pairScore = MarkovScoreComputation.computenewscore(p, extendedGraph);
           
            return pairScore;
          }

          /** This one returns a set of transitions in all directions. */
          @SuppressWarnings("unused")
          @Override
          public Collection<Entry<Label, CmpVertex>> getSurroundingTransitions(CmpVertex currentRed)
          {
            return null;
          }

        });
        actualAutomaton = learnerOfPairs.learnMachine(new LinkedList<List<Label>>(),new LinkedList<List<Label>>());
       
        SampleData dataSample = new SampleData(null,null);
        //dataSample.difference = new DifferenceToReferenceDiff(0, 0);
        //dataSample.differenceForReferenceLearner = new DifferenceToReferenceDiff(0, 0);
       
        VertID rejectVertexID = null;
        for(CmpVertex v:actualAutomaton.transitionMatrix.keySet())
          if (!v.isAccept())
          {
            assert rejectVertexID == null : "multiple reject vertices in learnt automaton, such as "+rejectVertexID+" and "+v;
            rejectVertexID = v;break;
          }
        if (rejectVertexID == null)
          rejectVertexID = actualAutomaton.nextID(false);
        actualAutomaton.pathroutines.completeGraphPossiblyUsingExistingVertex(rejectVertexID);// we need to complete the graph, otherwise we are not matching it with the original one that has been completed.
        dataSample.actualLearner = estimateDifference(referenceGraph,actualAutomaton,testSet);
        dataSample.actualLearner.inconsistency = MarkovClassifier.computeInconsistency(actualAutomaton, m, checker,false);
        dataSample.referenceLearner = zeroScore;
        LearnerGraph outcomeOfReferenceLearner = new LearnerGraph(config);
        try
        {
          outcomeOfReferenceLearner = //new ReferenceLearnerUsingSiccoScoring(learnerEval,ptaCopy,false).learnMachine(new LinkedList<List<Label>>(),new LinkedList<List<Label>>());
              new EDSMReferenceLearner(learnerEval,ptaCopy,2).learnMachine(new LinkedList<List<Label>>(),new LinkedList<List<Label>>());
          dataSample.referenceLearner = estimateDifference(referenceGraph, outcomeOfReferenceLearner,testSet);
          dataSample.referenceLearner.inconsistency = MarkovClassifier.computeInconsistency(outcomeOfReferenceLearner, m, checker,false);
        }
        catch(LearnerAbortedException ex)
        {// the exception is thrown because the learner failed to learn anything completely. Ignore it because the default score is zero assigned via zeroScore.
        }       
        dataSample.fractionOfStatesIdentifiedBySingletons=Math.round(100*MarkovClassifier.calculateFractionOfStatesIdentifiedBySingletons(referenceGraph));
        dataSample.stateNumber = referenceGraph.getStateNumber();
        dataSample.transitionsSampled = Math.round(100*trimmedReference.pathroutines.countEdges()/referenceGraph.pathroutines.countEdges());
        statechum.Pair<Double,Double> correctnessOfMarkov = new MarkovClassifier(m, referenceGraph).evaluateCorrectnessOfMarkov();
        dataSample.markovPrecision = Math.round(100*correctnessOfMarkov.firstElem);dataSample.markovRecall = Math.round(100*correctnessOfMarkov.secondElem);
        Collection<List<Label>> wset=WMethod.computeWSet_reducedw(referenceGraph);
        int wSeqLen=0;
        for(List<Label> seq:wset)
        {
View Full Code Here

                              pta.paths.augmentPTA(seq,true,false,null);
                            for(List<Label> seq:sMinus)
                              pta.paths.augmentPTA(seq,false,false,null);
                            final MarkovModel m= new MarkovModel(3,true,true,false);

                            new MarkovClassifier(m, pta).updateMarkov(false);// construct Markov chain if asked for.
                            final ConsistencyChecker checker = new MarkovClassifier.DifferentPredictionsInconsistencyNoBlacklistingIncludeMissingPrefixes();
                         
                            pta.clearColours();
                            EDSM_MarkovLearner learner = new EDSM_MarkovLearner(learnerInitConfiguration,pta,0) {
View Full Code Here

  {
    MarkovModel m = new MarkovModel(2,true,true);
    Set<List<Label>> plusStrings = buildSet(new String[][] { new String[]{"a","p"} },config,converter), minusStrings = buildSet(new String[][] { new String[]{"a","u"} },config,converter);
    m.createMarkovLearner(plusStrings, minusStrings,false);
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-u->B-p->B","testConstructExtendedGraph1",config, converter);
    MarkovClassifier cl = new MarkovClassifier(m,graph);
    Map<CmpVertex, Map<Label, MarkovOutcome>> newTransitions = cl.predictTransitions();
    Assert.assertTrue(newTransitions.isEmpty());// not enough evidence to update, hence nothing should be recorded.
    final LearnerGraph expected = FsmParser.buildLearnerGraph("A-u->B-p->B","testConstructExtendedGraph1",config, converter);
    LearnerGraph actual = cl.constructMarkovTentative();
    DifferentFSMException ex = WMethod.checkM(expected, actual);
    if (ex != null)
      throw ex;
    Assert.assertNotSame(graph, actual);
  }
View Full Code Here

  {
    MarkovModel m = new MarkovModel(2,true,true);
    Set<List<Label>> plusStrings = buildSet(new String[][] { new String[]{"a","p"} },config,converter), minusStrings = buildSet(new String[][] { new String[]{"a","u"} },config,converter);
    m.createMarkovLearner(plusStrings, minusStrings,false);
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B","testConstructExtendedGraph2",config, converter);
    MarkovClassifier cl = new MarkovClassifier(m,graph);
    Map<CmpVertex, Map<Label, MarkovOutcome>> newTransitions = cl.predictTransitions();
    Assert.assertTrue(newTransitions.isEmpty());// not enough evidence to update, hence nothing should be recorded.
    final LearnerGraph expected = FsmParser.buildLearnerGraph("A-a->B","testConstructExtendedGraph2",config, converter);
    LearnerGraph actual = cl.constructMarkovTentative();
    DifferentFSMException ex = WMethod.checkM(expected, actual);
    if (ex != null)
      throw ex;
    Assert.assertNotSame(graph, actual);
  }
View Full Code Here

  {
    MarkovModel m = new MarkovModel(2,true,true);
    Set<List<Label>> plusStrings = buildSet(new String[][] { new String[]{"a","b"} },config,converter), minusStrings = buildSet(new String[][] { new String[]{"a","u"} },config,converter);
    m.createMarkovLearner(plusStrings, minusStrings,false);
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B / T-b->T-u->T","testConstructExtendedGraph3a",config, converter);
    MarkovClassifier cl = new MarkovClassifier(m,graph);
    Map<CmpVertex, Map<Label, MarkovOutcome>> newTransitions = cl.predictTransitions();
    Assert.assertEquals(1,newTransitions.size());// not enough evidence to update, hence nothing should be recorded.

    Assert.assertSame(MarkovOutcome.negative, newTransitions.get(graph.findVertex("B")).get(lblU));
   
    Assert.assertSame(MarkovOutcome.positive, newTransitions.get(graph.findVertex("B")).get(lblB));

    final LearnerGraph expected = FsmParser.buildLearnerGraph("A-a->B-b->C / B-u-#D / T-b->T-u->T","testConstructExtendedGraph3b",config, converter);
    LearnerGraph actual = cl.constructMarkovTentative();
    DifferentFSMException ex = WMethod.checkM(expected, actual);
    if (ex != null)
      throw ex;
    Assert.assertNotSame(graph, actual);
  }
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.MarkovClassifier

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.