Package statechum.analysis.learning.MarkovModel

Examples of statechum.analysis.learning.MarkovModel.UpdatablePairInteger


      {
        if(vert.isAccept() )
            {
            final Map<Label,UpdatablePairDouble> outgoing_labels_probabilities=new HashMap<Label,UpdatablePairDouble>();
            final Map<Label,UpdatablePairInteger> outgoing_labels_occurrences=new HashMap<Label,UpdatablePairInteger>();
            final UpdatablePairInteger sum=new UpdatablePairInteger(0,0);
            WalkThroughAllPathsOfSpecificLength(graphToUseForPrediction,vert,model.getPredictionLen(),new ForEachCollectionOfPaths()
            {
          @Override
          public void handlePath(List<Label> pathToNewState)
          {
              Trace path_chunk_minus_one=new Trace(pathToNewState,true);
              for(Label label:allElementsOfAlphabet)
              {
                Trace Predicted_trace= new Trace();Predicted_trace.getList().addAll(path_chunk_minus_one.getList());
                if (predictionGraphInverted)
                  Collections.reverse(Predicted_trace.getList());
                Predicted_trace.add(label);

                UpdatablePairInteger occurrence_of_label_predicted_form_Markov=model.occurrenceMatrix.get(Predicted_trace);

                if(outgoing_labels_occurrences.containsKey(label))
                {
                  UpdatablePairInteger labels_occurence= outgoing_labels_occurrences.get(label);
                  sum.add(labels_occurence);
                  labels_occurence.add(occurrence_of_label_predicted_form_Markov);                      
                }
                else
                {
                  outgoing_labels_occurrences.put(label, occurrence_of_label_predicted_form_Markov);
                  sum.add(occurrence_of_label_predicted_form_Markov);
View Full Code Here


            predictedTrace.getList().addAll(pathToUseWithMarkovToPredictOutgoing);
          }
          predictedTrace.add(lbl);
         
          MarkovOutcome newValue = null;
          UpdatablePairInteger p=model.occurrenceMatrix.get(predictedTrace);if (p == null) { p=new UpdatablePairInteger(0, 0);model.occurrenceMatrix.put(predictedTrace,p); }

          boolean foundAccept = false, foundReject = false;
          for(Object vObj:graphToCheckForConsistency.getTargets(targets))
          {
            if ( ((CmpVertex)vObj).isAccept() ) foundAccept = true;
            if ( !((CmpVertex)vObj).isAccept() ) foundReject = true;
          }
         
          // By construction of an inverse graph and its immutability, it is either accept, reject, or both. getTargets will never be empty.
         
          if (foundAccept && foundReject)
            throw new IllegalArgumentException("inconsistent inverse graph: path "+predictedTrace.getList()+" is both accepted and rejected");
         
          if (foundAccept)
          {
            newValue=MarkovOutcome.positive;p.add(1, 0);
          }
          else
          {
            newValue=MarkovOutcome.negative;p.add(0, 1);
          }
         
          model.predictionsMatrix.put(predictedTrace, MarkovOutcome.reconcileOpinions_PosNeg_Overrides_Null(model.predictionsMatrix.get(predictedTrace),newValue));
          }
      }
View Full Code Here

      {
        if(vert.isAccept() )
            {
            final Map<Label,UpdatablePairDouble> outgoing_labels_probabilities=new HashMap<Label,UpdatablePairDouble>();
            final Map<Label,UpdatablePairInteger> outgoing_labels_occurrences=new HashMap<Label,UpdatablePairInteger>();
            final UpdatablePairInteger sum=new UpdatablePairInteger(0,0);
            WalkThroughAllPathsOfSpecificLength(graphToUseForPrediction,vert,model.getPredictionLen(),new ForEachCollectionOfPaths()
            {
          @Override
          public void handlePath(List<Label> pathToNewState)
          {
              List<Label> partOfTraceUsedInMarkovPredictions=new ArrayList<Label>(pathToNewState.size());partOfTraceUsedInMarkovPredictions.addAll(pathToNewState);
              if (predictionGraphInverted)
                Collections.reverse(partOfTraceUsedInMarkovPredictions);
              Map<Label,PTASequenceEngine.Node> lastElementToPrediction = model.markovMatrix.getMapFromLabelsToPredictions(partOfTraceUsedInMarkovPredictions);
              for(Label label:allElementsOfAlphabet)
              {
                PredictionForSequence prediction = MarkovMatrixEngine.getPredictionIfExists(lastElementToPrediction,label);

                UpdatablePairInteger occurrence_of_label_predicted_form_Markov=prediction == null?null:prediction.occurrence;

                if(outgoing_labels_occurrences.containsKey(label))
                {
                  UpdatablePairInteger labels_occurence= outgoing_labels_occurrences.get(label);
                  sum.add(labels_occurence);
                  labels_occurence.add(occurrence_of_label_predicted_form_Markov);                      
                }
                else
                {
                  outgoing_labels_occurrences.put(label, occurrence_of_label_predicted_form_Markov);
                  sum.add(occurrence_of_label_predicted_form_Markov);
View Full Code Here

    MarkovModel mOther = new MarkovModel(2,true,true);
    new MarkovClassifier(mOther,graph).updateMarkov(false);
    Assert.assertEquals(m.predictionsMatrix,mOther.predictionsMatrix);
   
    // Workaround around a deficiency in the calculation of occurrences of prefixes by the PTA-based construction of Markov model.
    Assert.assertEquals(new UpdatablePairInteger(2, 0), m.occurrenceMatrix.get(new Trace(Arrays.asList(new Label[]{lblA}),true)));
    Assert.assertEquals(new UpdatablePairInteger(1, 0), mOther.occurrenceMatrix.get(new Trace(Arrays.asList(new Label[]{lblA}),true)));
   
    m.occurrenceMatrix.remove(new Trace(Arrays.asList(new Label[]{lblA}),true));mOther.occurrenceMatrix.remove(new Trace(Arrays.asList(new Label[]{lblA}),true));
    Assert.assertEquals(m.occurrenceMatrix,mOther.occurrenceMatrix);
  }
View Full Code Here

    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B-a->C / B-b->C","testUpdateMarkovSideways1",config, converter);
    MarkovModel m = new MarkovModel(2,false,true);
    new MarkovClassifier(m,graph).updateMarkov(true);
    Assert.assertEquals(4,m.predictionsMatrix.size());
    Assert.assertEquals(4,m.occurrenceMatrix.size());
    Assert.assertEquals(MarkovOutcome.positive,m.predictionsMatrix.get(new Trace(Arrays.asList(new Label[]{lblA,lblA}),true)));Assert.assertEquals(new UpdatablePairInteger(2, 0),m.occurrenceMatrix.get(new Trace(Arrays.asList(new Label[]{lblA,lblA}),true)));
    Assert.assertEquals(MarkovOutcome.positive,m.predictionsMatrix.get(new Trace(Arrays.asList(new Label[]{lblA,lblB}),true)));Assert.assertEquals(new UpdatablePairInteger(1, 0),m.occurrenceMatrix.get(new Trace(Arrays.asList(new Label[]{lblA,lblB}),true)));
    Assert.assertEquals(MarkovOutcome.positive,m.predictionsMatrix.get(new Trace(Arrays.asList(new Label[]{lblB,lblA}),true)));Assert.assertEquals(new UpdatablePairInteger(1, 0),m.occurrenceMatrix.get(new Trace(Arrays.asList(new Label[]{lblB,lblA}),true)));
    Assert.assertEquals(MarkovOutcome.positive,m.predictionsMatrix.get(new Trace(Arrays.asList(new Label[]{lblB,lblB}),true)));Assert.assertEquals(new UpdatablePairInteger(1, 0),m.occurrenceMatrix.get(new Trace(Arrays.asList(new Label[]{lblB,lblB}),true)));
  }
View Full Code Here

  {
    final LearnerGraph graph = FsmParser.buildLearnerGraph("A-a->B-a->C / B-b->C","testUpdateMarkovSideways1",config, converter);
    MarkovModel m = new MarkovModel(2,false,true);
    new MarkovClassifier(m,graph).updateMarkov(false);
    Assert.assertEquals(6,m.predictionsMatrix.size());
    Assert.assertEquals(MarkovOutcome.positive,m.predictionsMatrix.get(new Trace(Arrays.asList(new Label[]{lblA,lblA}),true)));Assert.assertEquals(new UpdatablePairInteger(2, 0),m.occurrenceMatrix.get(new Trace(Arrays.asList(new Label[]{lblA,lblA}),true)));
    Assert.assertEquals(MarkovOutcome.positive,m.predictionsMatrix.get(new Trace(Arrays.asList(new Label[]{lblA,lblB}),true)));Assert.assertEquals(new UpdatablePairInteger(1, 0),m.occurrenceMatrix.get(new Trace(Arrays.asList(new Label[]{lblA,lblB}),true)));
    Assert.assertEquals(MarkovOutcome.positive,m.predictionsMatrix.get(new Trace(Arrays.asList(new Label[]{lblB,lblA}),true)));Assert.assertEquals(new UpdatablePairInteger(1, 0),m.occurrenceMatrix.get(new Trace(Arrays.asList(new Label[]{lblB,lblA}),true)));
    Assert.assertEquals(MarkovOutcome.positive,m.predictionsMatrix.get(new Trace(Arrays.asList(new Label[]{lblB,lblB}),true)));Assert.assertEquals(new UpdatablePairInteger(1, 0),m.occurrenceMatrix.get(new Trace(Arrays.asList(new Label[]{lblB,lblB}),true)));

    Assert.assertEquals(MarkovOutcome.positive,m.predictionsMatrix.get(new Trace(Arrays.asList(new Label[]{lblA}),true)));Assert.assertEquals(new UpdatablePairInteger(2, 0),m.occurrenceMatrix.get(new Trace(Arrays.asList(new Label[]{lblA}),true)));
    Assert.assertEquals(MarkovOutcome.positive,m.predictionsMatrix.get(new Trace(Arrays.asList(new Label[]{lblB}),true)));Assert.assertEquals(new UpdatablePairInteger(1, 0),m.occurrenceMatrix.get(new Trace(Arrays.asList(new Label[]{lblB}),true)));
  }
View Full Code Here

      {
        if(vert.isAccept() )
            {
            final Map<Label,UpdatablePairDouble> outgoing_labels_probabilities=new HashMap<Label,UpdatablePairDouble>();
            final Map<Label,UpdatablePairInteger> outgoing_labels_occurrences=new HashMap<Label,UpdatablePairInteger>();
            final UpdatablePairInteger sum=new UpdatablePairInteger(0,0);
            WalkThroughAllPathsOfSpecificLength(graphToUseForPrediction,vert,model.getPredictionLen(),new ForEachCollectionOfPaths()
            {
          @Override
          public void handlePath(List<Label> pathToNewState)
          {
              Trace path_chunk_minus_one=new Trace(pathToNewState,true);
              for(Label label:allElementsOfAlphabet)
              {
                Trace Predicted_trace= new Trace();Predicted_trace.getList().addAll(path_chunk_minus_one.getList());
                if (predictionGraphInverted)
                  Collections.reverse(Predicted_trace.getList());
                Predicted_trace.add(label);

                UpdatablePairInteger occurrence_of_label_predicted_form_Markov=model.occurrenceMatrix.get(Predicted_trace);

                if(outgoing_labels_occurrences.containsKey(label))
                {
                  UpdatablePairInteger labels_occurence= outgoing_labels_occurrences.get(label);
                  sum.add(labels_occurence);
                  labels_occurence.add(occurrence_of_label_predicted_form_Markov);                      
                }
                else
                {
                  outgoing_labels_occurrences.put(label, occurrence_of_label_predicted_form_Markov);
                  sum.add(occurrence_of_label_predicted_form_Markov);
View Full Code Here

            predictedTrace.getList().addAll(pathToUseWithMarkovToPredictOutgoing);
          }
          predictedTrace.add(lbl);
         
          MarkovOutcome newValue = null;
          UpdatablePairInteger p=model.occurrenceMatrix.get(predictedTrace);if (p == null) { p=new UpdatablePairInteger(0, 0);model.occurrenceMatrix.put(predictedTrace,p); }

          boolean foundAccept = false, foundReject = false;
          for(Object vObj:graphToCheckForConsistency.getTargets(targets))
          {
            if ( ((CmpVertex)vObj).isAccept() ) foundAccept = true;
            if ( !((CmpVertex)vObj).isAccept() ) foundReject = true;
          }
         
          // By construction of an inverse graph and its immutability, it is either accept, reject, or both. getTargets will never be empty.
         
          if (foundAccept && foundReject)
            throw new IllegalArgumentException("inconsistent inverse graph: path "+predictedTrace.getList()+" is both accepted and rejected");
         
          if (foundAccept)
          {
            newValue=MarkovOutcome.positive;p.add(1, 0);
          }
          else
          {
            newValue=MarkovOutcome.negative;p.add(0, 1);
          }
         
          model.predictionsMatrix.put(predictedTrace, MarkovOutcome.reconcileOpinions_PosNeg_Overrides_Null(model.predictionsMatrix.get(predictedTrace),newValue));
          }
      }
View Full Code Here

      {
        if(vert.isAccept() )
            {
            final Map<Label,UpdatablePairDouble> outgoing_labels_probabilities=new HashMap<Label,UpdatablePairDouble>();
            final Map<Label,UpdatablePairInteger> outgoing_labels_occurrences=new HashMap<Label,UpdatablePairInteger>();
            final UpdatablePairInteger sum=new UpdatablePairInteger(0,0);
            WalkThroughAllPathsOfSpecificLength(graphToUseForPrediction,vert,model.getPredictionLen(),new ForEachCollectionOfPaths()
            {
          @Override
          public void handlePath(List<Label> pathToNewState)
          {
              List<Label> partOfTraceUsedInMarkovPredictions=new ArrayList<Label>(pathToNewState.size());partOfTraceUsedInMarkovPredictions.addAll(pathToNewState);
              if (predictionGraphInverted)
                Collections.reverse(partOfTraceUsedInMarkovPredictions);
              Map<Label,PTASequenceEngine.Node> lastElementToPrediction = model.markovMatrix.getMapFromLabelsToPredictions(partOfTraceUsedInMarkovPredictions);
              for(Label label:allElementsOfAlphabet)
              {
                PredictionForSequence prediction = MarkovMatrixEngine.getPredictionIfExists(lastElementToPrediction,label);

                UpdatablePairInteger occurrence_of_label_predicted_form_Markov=prediction == null?null:prediction.occurrence;

                if(outgoing_labels_occurrences.containsKey(label))
                {
                  UpdatablePairInteger labels_occurence= outgoing_labels_occurrences.get(label);
                  sum.add(labels_occurence);
                  labels_occurence.add(occurrence_of_label_predicted_form_Markov);                      
                }
                else
                {
                  outgoing_labels_occurrences.put(label, occurrence_of_label_predicted_form_Markov);
                  sum.add(occurrence_of_label_predicted_form_Markov);
View Full Code Here

    MarkovModel mOther = new MarkovModel(2,true,true);
    new MarkovClassifier(mOther,graph).updateMarkov(false);
    Assert.assertEquals(m.computePredictionMatrix(),mOther.computePredictionMatrix());
   
    // Workaround around a deficiency in the calculation of occurrences of prefixes by the PTA-based construction of Markov model.
    Assert.assertEquals(new UpdatablePairInteger(2, 0), m.computeOccurrenceMatrix().get(Arrays.asList(new Label[]{lblA})));
    Assert.assertEquals(new UpdatablePairInteger(1, 0), mOther.computeOccurrenceMatrix().get(Arrays.asList(new Label[]{lblA})));

    Map<List<Label>,UpdatablePairInteger> mOccurrenceMatrix = m.computeOccurrenceMatrix(), mOtherOccurrenceMatrix = mOther.computeOccurrenceMatrix();
    mOccurrenceMatrix.remove(Arrays.asList(new Label[]{lblA}));mOtherOccurrenceMatrix.remove(Arrays.asList(new Label[]{lblA}));
    Assert.assertEquals(mOccurrenceMatrix,mOtherOccurrenceMatrix);
  }
View Full Code Here

TOP

Related Classes of statechum.analysis.learning.MarkovModel.UpdatablePairInteger

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.