Package statechum

Examples of statechum.Trace


            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))
                {
View Full Code Here


        for(Label label:graph.getCache().getAlphabet())
        {
          if (!failureLabels.contains(label))
          {// if the labels is not already recorded as being inconsistently predicted
            MarkovOutcome predictedFromEalierTrace = outgoing_labels_probabilities.get(label);
              Trace Predicted_trace = new Trace();
              if (predictionGraphInverted)
              {
                for(int i=pathToNewState.size()-1;i>=0;--i) Predicted_trace.add(pathToNewState.get(i));if (pathBeyondCurrentState != null) Predicted_trace.getList().addAll(pathBeyondCurrentState);
              }
              else
              {
                Predicted_trace.getList().addAll(pathToNewState);
              }
              Predicted_trace.add(label);
             
              MarkovOutcome predicted_from_Markov=model.predictionsMatrix.get(Predicted_trace);
            MarkovOutcome outcome = MarkovOutcome.reconcileOpinions_PosNeg_Overrides_Null(predictedFromEalierTrace, predicted_from_Markov);
            if (outcome != predictedFromEalierTrace)
            {// we learnt something new, be it a new value (or a non-null value) or a failure, record it
View Full Code Here

        @SuppressWarnings("rawtypes")
      Object targets = ((Map)graphToCheckForConsistency.transitionMatrix.get(vert)).get(lbl);
        if (targets != null) // there are transitions with the considered label, hence update Markov
          for(List<Label> pathToUseWithMarkovToPredictOutgoing:markovPathsToUpdate)
          {
            Trace predictedTrace= new Trace();
          if (model.predictForwardOrSideways)
          {
            for(int i=pathToUseWithMarkovToPredictOutgoing.size()-1;i>=0;--i) predictedTrace.add(pathToUseWithMarkovToPredictOutgoing.get(i));
          }
          else
          {
            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);
          }
View Full Code Here

        else
        {
          encounteredPartOfTrace.addAll(pathToNewState);
        }
        //System.out.println(vert.toString()+" : "+encounteredPartOfTrace+" outgoing: "+outgoingLabels);
        if (model.occurrenceMatrix.containsKey(new Trace(encounteredPartOfTrace, true))) // we skip everything where a path was not seen in PTA.
            for(Label label:outgoingLabels)
            {
            MarkovOutcome labels_occurrence= outgoing_labels_value.get(label);
            if (labels_occurrence != MarkovOutcome.failure)
            {
                Trace traceToCheck = new Trace();traceToCheck.getList().addAll(encounteredPartOfTrace);
                traceToCheck.add(label);

                MarkovOutcome predicted_from_Markov=model.predictionsMatrix.get(traceToCheck);
                if (predicted_from_Markov != MarkovOutcome.failure)
                {// if training data does not lead to a consistent outcome for this label because chunk length is too small, not much we can do, but otherwise we are here and can make use of the data
                  if (!checker.consistent(labels_occurrence, predicted_from_Markov))
View Full Code Here

   
    // going through all positive traces
    //and partitioning each positive traces into a list of events ( a list of labels based on the chunk length)
    for(List<Label> positive_trace:pos)
    {
      Trace current_positive_trace=new Trace(positive_trace, true);
      for(int i=onlyLongest?chunk_Length-1:0;i<chunk_Length;i++)
      {
        List<Trace> List_traces=splitTrace(current_positive_trace,i+1);
        for (Trace tracePos:List_traces)
          updateOccurrenceMatrix(tracePos,true);
      }
    }
   
    // from negative traces initialize the Markov matrix
    for(List<Label> negative_trace:neg)
    {
      for(int i=onlyLongest?chunk_Length-1:0; i<chunk_Length; i++)
      {
        Trace trace=new Trace(negative_trace,true);
        List<Trace> List_traces=splitTrace(trace,i+1);
        int chunkNumber = List_traces.size();
        if (chunkNumber >= 1)
        {
          Trace traceNeg=List_traces.get(chunkNumber-1);
          updateOccurrenceMatrix(traceNeg,false);
          for (Trace tracePos:List_traces)
            if (tracePos != traceNeg)
              updateOccurrenceMatrix(tracePos,true);
        }
View Full Code Here

    List<Trace> chunks=new ArrayList<Trace>();
       for(int f=0; f < t.size(); f++)
      {
         if(f < (t.size()-chunkLen+1))
         {
           Trace traceToMarkov=new Trace(t.getList().subList(f, f+chunkLen), true); // get trace from the path
           chunks.add(traceToMarkov);
         }
      }
       return chunks;
  }
View Full Code Here

    }
    for(Entry<Label,CmpVertex> state:states.entrySet())
    {
      for(Label label:ptaClassifier.graph.getCache().getAlphabet())
      {
        MarkovOutcome transition = ptaClassifier.model.predictionsMatrix.get(new Trace(Arrays.asList(new Label[]{state.getKey(),label}),true));
        if (transition != null)
          if (transition == MarkovOutcome.positive) outcome.transitionMatrix.get(state.getValue()).put(label,states.get(label));
      }
    }   

    List<List<Label>> uniqueSequences = new LinkedList<List<Label>>();
    for(Label l1:ptaClassifier.graph.getCache().getAlphabet())
    {
      boolean nonUnique = false;
      Label unique = null;
      for(Label lbl:ptaClassifier.graph.getCache().getAlphabet())
      {
        if (ptaClassifier.model.predictionsMatrix.containsKey(new Trace(Arrays.asList(new Label[]{l1,lbl}),true)))
        {
          if (unique == null)
            unique = lbl;
          else
          {
            nonUnique = true;break;
          }
        }
      }
      if (unique != null && !nonUnique)
        uniqueSequences.add(Arrays.asList(new Label[]{l1,unique}));
     
    }
   
    List<List<Label>> sequencesUnique2=new LinkedList<List<Label>>();
    for(List<Label> prefix:uniqueSequences)
      {
        boolean nonUnique = false;
        List<Label> unique = null;
        for(Label lbl:ptaClassifier.graph.getCache().getAlphabet())
        {
          List<Label> seq = new LinkedList<Label>(prefix);seq.add(lbl);
          if (ptaClassifier.model.predictionsMatrix.containsKey(new Trace(seq,true)))
          {
            if (unique == null)
              unique = seq;
            else
            {
View Full Code Here

        Map<Label, CmpVertex> edges = hardFacts.getTransitionMatrix().get(v);
        if (edges.isEmpty()) {
            result.add(prefix);
        } else {
            for (Map.Entry<Label, CmpVertex> e : edges.entrySet()) {
                Trace newPath = prefix.clone();
                newPath.add(e.getKey());
                result.addAll(getPaths(newPath, e.getValue(), hardFacts));
            }
        }

        return result;
View Full Code Here

  final Label lblA = AbstractLearnerGraph.generateNewLabel("a", config, converter),lblB = AbstractLearnerGraph.generateNewLabel("b", config, converter),lblC = AbstractLearnerGraph.generateNewLabel("c", config, converter),
      lblD = AbstractLearnerGraph.generateNewLabel("d", config, converter),lblU = AbstractLearnerGraph.generateNewLabel("u", config, converter);
 
  @Test
  public void testGetChunks1() {
    List<Trace> l = MarkovModel.splitTrace(new Trace(Arrays.asList(new Label[]{}),true),1);
    Assert.assertTrue(l.isEmpty());
  }
View Full Code Here

    Assert.assertTrue(l.isEmpty());
  }

  @Test
  public void testGetChunks2a() {
    List<Trace> l = MarkovModel.splitTrace(new Trace(Arrays.asList(new Label[]{lblA,lblB,lblC}),true),4);
    Assert.assertTrue(l.isEmpty());
  }
View Full Code Here

TOP

Related Classes of statechum.Trace

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.