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)
|
-
Property svn:mime-type set to
text/plain
|
File size:
1.1 KB
|
Line | |
---|
1 | package de.ugoe.cs.eventbench.models;
|
---|
2 |
|
---|
3 | import java.util.LinkedList;
|
---|
4 | import java.util.List;
|
---|
5 | import java.util.Random;
|
---|
6 |
|
---|
7 | import de.ugoe.cs.eventbench.data.Event;
|
---|
8 |
|
---|
9 | public class HighOrderMarkovModel extends TrieBasedModel {
|
---|
10 |
|
---|
11 | public HighOrderMarkovModel(int maxOrder, Random r) {
|
---|
12 | super(maxOrder, r);
|
---|
13 | }
|
---|
14 |
|
---|
15 | @Override
|
---|
16 | public double getProbability(List<Event<?>> context, Event<?> symbol) {
|
---|
17 | double result = 0.0d;
|
---|
18 |
|
---|
19 | List<Event<?>> contextCopy;
|
---|
20 | if( context.size()>=trieOrder ) {
|
---|
21 | contextCopy = new LinkedList<Event<?>>(context.subList(context.size()-trieOrder+1, context.size()));
|
---|
22 | } else {
|
---|
23 | contextCopy = new LinkedList<Event<?>>(context);
|
---|
24 | }
|
---|
25 |
|
---|
26 |
|
---|
27 | List<Event<?>> followers = trie.getFollowingSymbols(contextCopy);
|
---|
28 | int sumCountFollowers = 0; // N(s\sigma')
|
---|
29 | for( Event<?> follower : followers ) {
|
---|
30 | sumCountFollowers += trie.getCount(contextCopy, follower);
|
---|
31 | }
|
---|
32 |
|
---|
33 | int countSymbol = trie.getCount(contextCopy, symbol);
|
---|
34 | if( sumCountFollowers!=0 ) {
|
---|
35 | result = ((double) countSymbol / sumCountFollowers);
|
---|
36 | }
|
---|
37 |
|
---|
38 | return result;
|
---|
39 | }
|
---|
40 |
|
---|
41 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.