Ignore:
Timestamp:
08/17/12 09:05:19 (12 years ago)
Author:
sherbold
Message:
  • adapted to quest coding style
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/quest-core-usageprofiles/src/main/java/de/ugoe/cs/quest/usageprofiles/DeterministicFiniteAutomaton.java

    r547 r559  
     1 
    12package de.ugoe.cs.quest.usageprofiles; 
    23 
     
    1112/** 
    1213 * <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. 
     14 * Implements a Deterministic Finite Automata (DFA) capable of random session generation. It is a 
     15 * special case of a first-order Markov model, where the transition probability is equally high for 
     16 * all following states. 
    1617 * </p> 
    1718 *  
     
    2122public class DeterministicFiniteAutomaton extends FirstOrderMarkovModel { 
    2223 
    23         /** 
    24         * <p> 
    25         * Id for object serialization. 
    26         * </p> 
    27         */ 
    28         private static final long serialVersionUID = 1L; 
     24    /** 
     25    * <p> 
     26    * Id for object serialization. 
     27    * </p> 
     28    */ 
     29    private static final long serialVersionUID = 1L; 
    2930 
    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         } 
     31    /** 
     32     * <p> 
     33     * Constructor. Creates a new DeterministicFiniteAutomaton. 
     34     * </p> 
     35     *  
     36     * @param r 
     37     *            random number generator used by probabilistic methods of the class 
     38     */ 
     39    public DeterministicFiniteAutomaton(Random r) { 
     40        super(r); 
     41    } 
    4242 
    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 
    53         public double getProbability(List<Event> context, 
    54                         Event symbol) { 
    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; 
     43    /** 
     44     * <p> 
     45     * Calculates the proability of the next state. Each of the following states in the automaton is 
     46     * 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 
     53    public double getProbability(List<Event> context, Event symbol) { 
     54        if (context == null) { 
     55            throw new InvalidParameterException("context must not be null"); 
     56        } 
     57        if (symbol == null) { 
     58            throw new InvalidParameterException("symbol must not be null"); 
     59        } 
     60        double result = 0.0d; 
    6261 
    63                 List<Event> contextCopy; 
    64                 if (context.size() >= trieOrder) { 
    65                         contextCopy = new LinkedList<Event>(context.subList( 
    66                                         context.size() - trieOrder + 1, context.size())); 
    67                 } else { 
    68                         contextCopy = new LinkedList<Event>(context); 
    69                 } 
     62        List<Event> contextCopy; 
     63        if (context.size() >= trieOrder) { 
     64            contextCopy = 
     65                new LinkedList<Event>(context.subList(context.size() - trieOrder + 1, 
     66                                                      context.size())); 
     67        } 
     68        else { 
     69            contextCopy = new LinkedList<Event>(context); 
     70        } 
    7071 
    71                 Collection<Event> followers = trie.getFollowingSymbols(contextCopy); 
     72        Collection<Event> followers = trie.getFollowingSymbols(contextCopy); 
    7273 
    73                 if (followers.size() != 0 && followers.contains(symbol)) { 
    74                         result = 1.0d / followers.size(); 
    75                 } 
     74        if (followers.size() != 0 && followers.contains(symbol)) { 
     75            result = 1.0d / followers.size(); 
     76        } 
    7677 
    77                 return result; 
    78         } 
     78        return result; 
     79    } 
    7980 
    8081} 
Note: See TracChangeset for help on using the changeset viewer.