Changeset 109 for trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models
- Timestamp:
- 07/07/11 09:32:31 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/PredictionByPartialMatch.java
r102 r109 28 28 */ 29 29 private static final long serialVersionUID = 1L; 30 31 /** 32 * <p> 33 * Minimum order of the Markov model. 34 * </p> 35 */ 36 private int minOrder; 30 37 31 38 /** … … 67 74 */ 68 75 public PredictionByPartialMatch(int markovOrder, Random r, double probEscape) { 76 this(markovOrder, 0, r, probEscape); 77 } 78 79 /** 80 * <p> 81 * Creates a new PredictionByPartialMatch model with a given Markov order 82 * and escape probability. 83 * </p> 84 * 85 * @param markovOrder 86 * Markov order of the model 87 * @param minOrder 88 * minimum order of the model; if this order is reached, there is 89 * no escape 90 * @param r 91 * random number generator used by probabilistic methods of the 92 * class 93 * @param probEscape 94 * escape probability used by the model 95 */ 96 public PredictionByPartialMatch(int markovOrder, int minOrder, Random r, 97 double probEscape) { 69 98 super(markovOrder, r); 70 99 this.probEscape = probEscape; 100 this.minOrder = minOrder; 71 101 } 72 102 … … 97 127 * <p> 98 128 * Calculates the probability of the next event based on the formula:<br> 99 * P_{PPM}(X_n|X_{n-1},...,X_{n-k}) = \sum_{i=k}^1 escape^{i-1} 100 * P_{MM^i}(X_n|X_{n-1},...,X_{n-i})(1-escape)<br> 129 * P_{PPM}(X_n|X_{n-1},...,X_{n-k}) = \sum_{i=k}^min escape^{k-i} 130 * P_{MM^i}(X_n 131 * |X_{n-1},...,X_{n-i})(1-escape)+escape^(k-min)P(X_n|X_{n-i},... 132 * ,X_{n-min})<br> 101 133 * P_{MM^i} denotes the probability in an i-th order Markov model. 102 134 * </p> … … 124 156 125 157 int countSymbol = trie.getCount(contextCopy, symbol); // N(s\sigma) 126 if ( contextCopy.size()== 0) {127 resultCurrentContex = ((double) countSymbol) / sumCountFollowers;158 if (sumCountFollowers == 0) { 159 resultCurrentContex = 0.0; 128 160 } else { 129 if (sumCountFollowers == 0) { 130 resultCurrentContex = 0.0; 131 } else { 132 resultCurrentContex = ((double) countSymbol / sumCountFollowers) 133 * (1 - probEscape); 134 } 161 resultCurrentContex = (double) countSymbol / sumCountFollowers; 162 } 163 if (contextCopy.size() != minOrder) { 164 resultCurrentContex *= (1 - probEscape); 135 165 contextCopy.remove(0); 136 double probSuffix = getProbability(contextCopy, symbol); 137 if (followers.size() == 0) { 138 resultShorterContex = probSuffix; 139 } else { 140 resultShorterContex = probEscape * probSuffix; 166 if (contextCopy.size() >= minOrder) { 167 double probSuffix = getProbability(contextCopy, symbol); 168 169 if (followers.size() == 0) { 170 resultShorterContex = probSuffix; 171 } else { 172 resultShorterContex = probEscape * probSuffix; 173 } 141 174 } 142 175 }
Note: See TracChangeset
for help on using the changeset viewer.