Ignore:
Timestamp:
07/23/15 13:43:38 (9 years ago)
Author:
sherbold
Message:
  • made generation of random sequences with an expected valid end and a predefined maximum length more robust. the generation now aborts after a user-defined number of attempts to create a valid sequence and returns an empty sequence instead.
Location:
trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles
Files:
2 edited

Legend:

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

    r1641 r2026  
    6161     */ 
    6262    double getProbability(List<Event> sequence); 
    63      
    64     /** 
    65      * <p> 
    66      * Returns the sum of the negative logarithm of the probabilities.  
    67      * </p> 
    68      * 
     63 
     64    /** 
     65     * <p> 
     66     * Returns the sum of the negative logarithm of the probabilities. 
     67     * </p> 
     68     *  
    6969     * @param sequence 
    7070     *            sequences of which the logsum is calculated 
     
    101101     * @param validEnd 
    102102     *            if true, only sequences that finish with {@link Event#ENDEVENT} are generated 
     103     * @param maxIter 
     104     *            maximum number of attempts for the generation of the sequence; in case of failure 
     105     *            and empty sequence is returned 
    103106     * @return randomly generated sequence 
    104107     *  
    105108     */ 
    106     public List<Event> randomSequence(int maxLength, boolean validEnd); 
     109    public List<Event> randomSequence(int maxLength, boolean validEnd, long maxIter); 
    107110 
    108111    /** 
  • trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles/TrieBasedModel.java

    r1996 r2026  
    147147    @Override 
    148148    public List<Event> randomSequence() { 
    149         return randomSequence(Integer.MAX_VALUE, true); 
     149        return randomSequence(Integer.MAX_VALUE, true, 100); 
    150150    } 
    151151 
     
    156156     */ 
    157157    @Override 
    158     public List<Event> randomSequence(int maxLength, boolean validEnd) { 
     158    public List<Event> randomSequence(int maxLength, boolean validEnd, long maxIter) { 
    159159        List<Event> sequence = new LinkedList<Event>(); 
     160        int attempts = 0; 
    160161        if (trie != null) { 
    161162            boolean endFound = false; 
    162             while (!endFound) { // outer loop for length checking 
    163                 sequence = new LinkedList<Event>(); 
     163            while (!endFound && attempts <= maxIter) { // outer loop for length checking 
    164164                IncompleteMemory<Event> context = new IncompleteMemory<Event>(trieOrder - 1); 
    165165                context.add(Event.STARTEVENT); 
     
    186186                    } 
    187187                } 
     188                if (!endFound) { 
     189                    sequence = new LinkedList<Event>(); 
     190                } 
     191                attempts++; 
    188192            } 
    189193        } 
     
    398402        List<Event> context = new LinkedList<Event>(); 
    399403        for (Event event : sequence) { 
    400             odds += Math.log(getProbability(context, event)+1); 
     404            odds += Math.log(getProbability(context, event) + 1); 
    401405            context.add(event); 
    402406        } 
Note: See TracChangeset for help on using the changeset viewer.