source: trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/PredictionByPartialMatch.java @ 22

Last change on this file since 22 was 22, checked in by sherbold, 13 years ago
  • clean up
File size: 1.7 KB
Line 
1package de.ugoe.cs.eventbench.models;
2
3import java.util.LinkedList;
4import java.util.List;
5import java.util.Random;
6
7import de.ugoe.cs.eventbench.data.Event;
8
9public class PredictionByPartialMatch extends TrieBasedModel {
10       
11        double probEscape;
12       
13        public PredictionByPartialMatch(int markovOrder, Random r) {
14                this(markovOrder, r, 0.1);
15        }
16       
17        public PredictionByPartialMatch(int markovOrder, Random r, double probEscape) {
18                super(markovOrder, r);
19                this.probEscape = probEscape;
20        }
21       
22        public void setProbEscape(double probEscape) {
23                this.probEscape = probEscape;
24        }
25       
26        public double getProbEscape() {
27                return probEscape;
28        }
29       
30        @Override
31        protected double getProbability(List<Event<?>> context, Event<?> symbol) {
32                double result = 0.0d;
33                double resultCurrentContex = 0.0d;
34                double resultShorterContex = 0.0d;
35               
36                List<Event<?>> contextCopy = new LinkedList<Event<?>>(context); // defensive copy
37
38       
39                List<Event<?>> followers = trie.getFollowingSymbols(contextCopy); // \Sigma'
40                int sumCountFollowers = 0; // N(s\sigma')
41                for( Event<?> follower : followers ) {
42                        sumCountFollowers += trie.getCount(contextCopy, follower);
43                }
44               
45                int countSymbol = trie.getCount(contextCopy, symbol); // N(s\sigma)
46                if( contextCopy.size()==0 ) {
47                        resultCurrentContex = ((double) countSymbol) / sumCountFollowers;
48                } else {
49                        resultCurrentContex = ((double) countSymbol / sumCountFollowers)*(1-probEscape);
50                        contextCopy.remove(0);
51                        double probSuffix = getProbability(contextCopy, symbol);
52                        if( followers.size()==0 ) {
53                                resultShorterContex = probSuffix;
54                        } else {
55                                resultShorterContex = probEscape*probSuffix;
56                        }
57                }
58                result = resultCurrentContex+resultShorterContex;
59               
60                return result;
61        }
62}
Note: See TracBrowser for help on using the repository browser.