Ignore:
Timestamp:
04/13/11 14:13:45 (13 years ago)
Author:
sherbold
Message:
  • moved training logic for single sequences from PPM to Trie
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/EventBenchCore/src/de/ugoe/cs/eventbench/ppm/PredictionByPartialMatch.java

    r7 r9  
    11package de.ugoe.cs.eventbench.ppm; 
    22 
    3 import java.util.LinkedHashSet; 
    43import java.util.LinkedList; 
    54import java.util.List; 
    65import java.util.Random; 
    7 import java.util.Set; 
    86 
    97import de.ugoe.cs.eventbench.data.Event; 
     
    1210public class PredictionByPartialMatch { 
    1311         
    14         private int maxOrder = 3; 
     12        private int maxOrder; 
    1513         
    1614        private Trie<Event<?>> trie; 
    1715         
    18         private Set<Event<?>> knownSymbols; 
    19          
    2016        private double probEscape; 
    2117         
    2218        private final Random r; 
    2319         
    24         public PredictionByPartialMatch(Random r) { 
    25                 this(r, 0.1); 
    26         } 
    27          
    28         public PredictionByPartialMatch(Random r, double probEscape) { 
     20        public PredictionByPartialMatch(int maxOrder, Random r) { 
     21                this(maxOrder, r, 0.1); 
     22        } 
     23         
     24        public PredictionByPartialMatch(int maxOrder, Random r, double probEscape) { 
     25                this.maxOrder = maxOrder; 
    2926                this.r = r; // TODO defensive copy instead? 
    3027                this.probEscape = probEscape; 
     
    4239        public void train(List<List<Event<?>>> sequences) { 
    4340                trie = new Trie<Event<?>>(); 
    44                 knownSymbols = new LinkedHashSet<Event<?>>(); 
    45                 knownSymbols.add(Event.STARTEVENT); 
    46                 knownSymbols.add(Event.ENDEVENT); 
    4741                 
    4842                for(List<Event<?>> sequence : sequences) { 
     
    5145                        currentSequence.add(Event.ENDEVENT); 
    5246                         
    53                         addToTrie(currentSequence); 
    54                 } 
    55         } 
    56          
    57         private void addToTrie(List<Event<?>> sequence) { 
     47                        trie.train(currentSequence, maxOrder); 
     48                } 
     49        } 
     50         
     51        /*private void addToTrie(List<Event<?>> sequence) { 
    5852                if( knownSymbols==null ) { 
    5953                        knownSymbols = new LinkedHashSet<Event<?>>(); 
     
    7367                        trie.add(sequence.subList(sequenceLength-j, sequenceLength)); 
    7468                } 
    75         } 
     69        }*/ 
    7670         
    7771        public List<? extends Event<?>> randomSequence() { 
     
    8983                        double probSum = 0.0; 
    9084                        List<Event<?>> currentContext = context.getLast(maxOrder); 
    91                         for( Event<?> symbol : knownSymbols ) { 
     85                        for( Event<?> symbol : trie.getKnownSymbols() ) { 
    9286                                probSum += getProbability(currentContext, symbol); 
    9387                                if( probSum>=randVal ) { 
Note: See TracChangeset for help on using the changeset viewer.