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

Last change on this file since 80 was 80, checked in by sherbold, 13 years ago
  • added getProbability() to de.ugoe.cs.eventbench.models.IStochasticProcess and implementing classes
  • added getEvents() to de.ugoe.cs.eventbench.models.IStochasticProcess and implementing classes
  • changed getProbability() of subclasses of de.ugoe.cs.eventbench.TrieBasedModel? such that the probability is not zero if the context length is higher than the order of the model, but rather the probability of the suffix of the length of the order, i.e., for a 2nd-order model context(X1,X2,X3,X4) becomes context(X3,X4)
File size: 2.0 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        public 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;
37                if( context.size()>=trieOrder ) {
38                        contextCopy = new LinkedList<Event<?>>(context.subList(context.size()-trieOrder+1, context.size()));
39                } else {
40                        contextCopy = new LinkedList<Event<?>>(context);
41                }
42
43       
44                List<Event<?>> followers = trie.getFollowingSymbols(contextCopy); // \Sigma'
45                int sumCountFollowers = 0; // N(s\sigma')
46                for( Event<?> follower : followers ) {
47                        sumCountFollowers += trie.getCount(contextCopy, follower);
48                }
49               
50                int countSymbol = trie.getCount(contextCopy, symbol); // N(s\sigma)
51                if( contextCopy.size()==0 ) {
52                        resultCurrentContex = ((double) countSymbol) / sumCountFollowers;
53                } else {
54                        if( sumCountFollowers==0 ) {
55                                resultCurrentContex = 0.0;
56                        }
57                        else {
58                                resultCurrentContex = ((double) countSymbol / sumCountFollowers)*(1-probEscape);
59                        }
60                        contextCopy.remove(0);
61                        double probSuffix = getProbability(contextCopy, symbol);
62                        if( followers.size()==0 ) {
63                                resultShorterContex = probSuffix;
64                        } else {
65                                resultShorterContex = probEscape*probSuffix;
66                        }
67                }
68                result = resultCurrentContex+resultShorterContex;
69               
70                return result;
71        }
72}
Note: See TracBrowser for help on using the repository browser.