[518] | 1 | package de.ugoe.cs.quest.usageprofiles;
|
---|
| 2 |
|
---|
| 3 | import java.security.InvalidParameterException;
|
---|
| 4 | import java.util.Collection;
|
---|
| 5 | import java.util.LinkedList;
|
---|
| 6 | import java.util.List;
|
---|
| 7 | import java.util.Random;
|
---|
| 8 |
|
---|
| 9 | import de.ugoe.cs.quest.eventcore.Event;
|
---|
| 10 |
|
---|
| 11 | /**
|
---|
| 12 | * <p>
|
---|
| 13 | * Implements a Deterministic Finite Automata (DFA) capable of random session
|
---|
| 14 | * generation. It is a special case of a first-order Markov model, where the
|
---|
| 15 | * transition probability is equally high for all following states.
|
---|
| 16 | * </p>
|
---|
| 17 | *
|
---|
| 18 | * @author Steffen Herbold
|
---|
| 19 | * @version 1.0
|
---|
| 20 | */
|
---|
| 21 | public class DeterministicFiniteAutomaton extends FirstOrderMarkovModel {
|
---|
| 22 |
|
---|
| 23 | /**
|
---|
| 24 | * <p>
|
---|
| 25 | * Id for object serialization.
|
---|
| 26 | * </p>
|
---|
| 27 | */
|
---|
| 28 | private static final long serialVersionUID = 1L;
|
---|
| 29 |
|
---|
| 30 | /**
|
---|
| 31 | * <p>
|
---|
| 32 | * Constructor. Creates a new DeterministicFiniteAutomaton.
|
---|
| 33 | * </p>
|
---|
| 34 | *
|
---|
| 35 | * @param r
|
---|
| 36 | * random number generator used by probabilistic methods of the
|
---|
| 37 | * class
|
---|
| 38 | */
|
---|
| 39 | public DeterministicFiniteAutomaton(Random r) {
|
---|
| 40 | super(r);
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | /**
|
---|
| 44 | * <p>
|
---|
| 45 | * Calculates the proability of the next state. Each of the following states
|
---|
| 46 | * in the automaton is equally probable.
|
---|
| 47 | * </p>
|
---|
| 48 | *
|
---|
| 49 | * @see de.ugoe.cs.quest.usageprofiles.IStochasticProcess#getProbability(java.util.List,
|
---|
| 50 | * de.ugoe.cs.quest.eventcore.Event)
|
---|
| 51 | */
|
---|
| 52 | @Override
|
---|
[547] | 53 | public double getProbability(List<Event> context,
|
---|
| 54 | Event symbol) {
|
---|
[518] | 55 | if( context==null ) {
|
---|
| 56 | throw new InvalidParameterException("context must not be null");
|
---|
| 57 | }
|
---|
| 58 | if( symbol==null ) {
|
---|
| 59 | throw new InvalidParameterException("symbol must not be null");
|
---|
| 60 | }
|
---|
| 61 | double result = 0.0d;
|
---|
| 62 |
|
---|
[547] | 63 | List<Event> contextCopy;
|
---|
[518] | 64 | if (context.size() >= trieOrder) {
|
---|
[547] | 65 | contextCopy = new LinkedList<Event>(context.subList(
|
---|
[518] | 66 | context.size() - trieOrder + 1, context.size()));
|
---|
| 67 | } else {
|
---|
[547] | 68 | contextCopy = new LinkedList<Event>(context);
|
---|
[518] | 69 | }
|
---|
| 70 |
|
---|
[547] | 71 | Collection<Event> followers = trie.getFollowingSymbols(contextCopy);
|
---|
[518] | 72 |
|
---|
| 73 | if (followers.size() != 0 && followers.contains(symbol)) {
|
---|
| 74 | result = 1.0d / followers.size();
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | return result;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | }
|
---|