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

Last change on this file since 70 was 22, checked in by sherbold, 13 years ago
  • clean up
File size: 1.7 KB
RevLine 
[13]1package de.ugoe.cs.eventbench.models;
[1]2
[5]3import java.util.LinkedList;
[1]4import java.util.List;
5import java.util.Random;
6
7import de.ugoe.cs.eventbench.data.Event;
8
[12]9public class PredictionByPartialMatch extends TrieBasedModel {
[1]10       
[12]11        double probEscape;
[1]12       
[16]13        public PredictionByPartialMatch(int markovOrder, Random r) {
14                this(markovOrder, r, 0.1);
[7]15        }
16       
[16]17        public PredictionByPartialMatch(int markovOrder, Random r, double probEscape) {
18                super(markovOrder, r);
[7]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       
[12]30        @Override
31        protected double getProbability(List<Event<?>> context, Event<?> symbol) {
[6]32                double result = 0.0d;
33                double resultCurrentContex = 0.0d;
34                double resultShorterContex = 0.0d;
35               
[7]36                List<Event<?>> contextCopy = new LinkedList<Event<?>>(context); // defensive copy
[6]37
38       
[7]39                List<Event<?>> followers = trie.getFollowingSymbols(contextCopy); // \Sigma'
[6]40                int sumCountFollowers = 0; // N(s\sigma')
[7]41                for( Event<?> follower : followers ) {
[6]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        }
[1]62}
Note: See TracBrowser for help on using the repository browser.