- Timestamp:
- 04/13/11 14:13:45 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/ppm/PredictionByPartialMatch.java
r7 r9 1 1 package de.ugoe.cs.eventbench.ppm; 2 2 3 import java.util.LinkedHashSet;4 3 import java.util.LinkedList; 5 4 import java.util.List; 6 5 import java.util.Random; 7 import java.util.Set;8 6 9 7 import de.ugoe.cs.eventbench.data.Event; … … 12 10 public class PredictionByPartialMatch { 13 11 14 private int maxOrder = 3;12 private int maxOrder; 15 13 16 14 private Trie<Event<?>> trie; 17 15 18 private Set<Event<?>> knownSymbols;19 20 16 private double probEscape; 21 17 22 18 private final Random r; 23 19 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; 29 26 this.r = r; // TODO defensive copy instead? 30 27 this.probEscape = probEscape; … … 42 39 public void train(List<List<Event<?>>> sequences) { 43 40 trie = new Trie<Event<?>>(); 44 knownSymbols = new LinkedHashSet<Event<?>>();45 knownSymbols.add(Event.STARTEVENT);46 knownSymbols.add(Event.ENDEVENT);47 41 48 42 for(List<Event<?>> sequence : sequences) { … … 51 45 currentSequence.add(Event.ENDEVENT); 52 46 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) { 58 52 if( knownSymbols==null ) { 59 53 knownSymbols = new LinkedHashSet<Event<?>>(); … … 73 67 trie.add(sequence.subList(sequenceLength-j, sequenceLength)); 74 68 } 75 } 69 }*/ 76 70 77 71 public List<? extends Event<?>> randomSequence() { … … 89 83 double probSum = 0.0; 90 84 List<Event<?>> currentContext = context.getLast(maxOrder); 91 for( Event<?> symbol : knownSymbols) {85 for( Event<?> symbol : trie.getKnownSymbols() ) { 92 86 probSum += getProbability(currentContext, symbol); 93 87 if( probSum>=randVal ) {
Note: See TracChangeset
for help on using the changeset viewer.