Last change
on this file since 86 was
86,
checked in by sherbold, 14 years ago
|
- made stochastic models and events serializable
|
-
Property svn:mime-type set to
text/plain
|
File size:
1.2 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 | /**
|
---|
12 | * Id for object serialization.
|
---|
13 | */
|
---|
14 | private static final long serialVersionUID = 1L;
|
---|
15 |
|
---|
16 | public HighOrderMarkovModel(int maxOrder, Random r) {
|
---|
17 | super(maxOrder, r);
|
---|
18 | }
|
---|
19 |
|
---|
20 | @Override
|
---|
21 | public double getProbability(List<Event<?>> context, Event<?> symbol) {
|
---|
22 | double result = 0.0d;
|
---|
23 |
|
---|
24 | List<Event<?>> contextCopy;
|
---|
25 | if( context.size()>=trieOrder ) {
|
---|
26 | contextCopy = new LinkedList<Event<?>>(context.subList(context.size()-trieOrder+1, context.size()));
|
---|
27 | } else {
|
---|
28 | contextCopy = new LinkedList<Event<?>>(context);
|
---|
29 | }
|
---|
30 |
|
---|
31 |
|
---|
32 | List<Event<?>> followers = trie.getFollowingSymbols(contextCopy);
|
---|
33 | int sumCountFollowers = 0; // N(s\sigma')
|
---|
34 | for( Event<?> follower : followers ) {
|
---|
35 | sumCountFollowers += trie.getCount(contextCopy, follower);
|
---|
36 | }
|
---|
37 |
|
---|
38 | int countSymbol = trie.getCount(contextCopy, symbol);
|
---|
39 | if( sumCountFollowers!=0 ) {
|
---|
40 | result = ((double) countSymbol / sumCountFollowers);
|
---|
41 | }
|
---|
42 |
|
---|
43 | return result;
|
---|
44 | }
|
---|
45 |
|
---|
46 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.