Ignore:
Timestamp:
10/15/11 01:41:55 (13 years ago)
Author:
sherbold
Message:
  • added methods getChildren() and setCount() to de.ugoe.cs.eventbench.models.TrieNode?
  • added method updateKnownSymbols() to de.ugoe.cs.eventbench.models.Trie
  • changed the visibility of some members of de.ugoe.cs.eventbench.models.PredictionByPartionMatch?
  • added class de.ugoe.cs.eventbench.models.ModelFlattener? to generate FirstOrderMarkovModel? from higher-order models through state splitting
  • tweaked entropy calculation of de.ugoe.cs.eventbench.models.FirstOrderMarkovModel? to work with flattened models (locating of START and END was a problem)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/FirstOrderMarkovModel.java

    r102 r258  
    33import java.util.ArrayList; 
    44import java.util.Collection; 
     5import java.util.LinkedList; 
    56import java.util.List; 
    67import java.util.Random; 
     
    99100                int numStates = knownSymbols.size(); 
    100101 
    101                 int startStateIndex = knownSymbols.indexOf(Event.STARTEVENT); 
    102                 int endStateIndex = knownSymbols.indexOf(Event.ENDEVENT); 
    103                 if (startStateIndex == -1) { 
     102                List<Integer> startIndexList = new LinkedList<Integer>(); 
     103                List<Integer> endIndexList = new LinkedList<Integer>(); 
     104                for( int i=0 ; i<knownSymbols.size() ; i++ ) { 
     105                        String id = knownSymbols.get(i).getStandardId(); 
     106                        if( id.equals(Event.STARTEVENT.getStandardId()) || id.contains(Event.STARTEVENT.getStandardId()+"-=-") ) { 
     107                                startIndexList.add(i); 
     108                        } 
     109                        if( id.equals(Event.ENDEVENT.getStandardId()) || id.contains("-=-"+Event.ENDEVENT.getStandardId()) ) { 
     110                                endIndexList.add(i); 
     111                        } 
     112                } 
     113                 
     114                if (startIndexList.isEmpty()) {  
    104115                        Console.printerrln("Error calculating entropy. Initial state of markov chain not found."); 
    105116                        return Double.NaN; 
    106117                } 
    107                 if (endStateIndex == -1) { 
     118                if (endIndexList.isEmpty()) { 
    108119                        Console.printerrln("Error calculating entropy. End state of markov chain not found."); 
    109120                        return Double.NaN; 
    110121                } 
    111                 transmissionMatrix.set(endStateIndex, startStateIndex, 1); 
     122                for( Integer i : endIndexList ) { 
     123                        for(Integer j : startIndexList ) { 
     124                                transmissionMatrix.set(i, j, 1); 
     125                        } 
     126                } 
    112127 
    113128                // Calculate stationary distribution by raising the power of the 
     
    160175                List<Event<?>> knownSymbols = new ArrayList<Event<?>>( 
    161176                                trie.getKnownSymbols()); 
    162  
    163177                for (Event<?> symbol : knownSymbols) { 
    164178                        final String thisSaneId = symbol.getShortId().replace("\"", "\\\"") 
     
    183197        /** 
    184198         * <p> 
    185          * Returns a {@link Graph} represenation of the model with the states as 
     199         * Returns a {@link Graph} representation of the model with the states as 
    186200         * nodes and directed edges weighted with transition probabilities. 
    187201         * </p> 
Note: See TracChangeset for help on using the changeset viewer.