Changeset 258 for trunk/EventBenchCore
- Timestamp:
- 10/15/11 01:41:55 (13 years ago)
- Location:
- trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/FirstOrderMarkovModel.java
r102 r258 3 3 import java.util.ArrayList; 4 4 import java.util.Collection; 5 import java.util.LinkedList; 5 6 import java.util.List; 6 7 import java.util.Random; … … 99 100 int numStates = knownSymbols.size(); 100 101 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()) { 104 115 Console.printerrln("Error calculating entropy. Initial state of markov chain not found."); 105 116 return Double.NaN; 106 117 } 107 if (end StateIndex == -1) {118 if (endIndexList.isEmpty()) { 108 119 Console.printerrln("Error calculating entropy. End state of markov chain not found."); 109 120 return Double.NaN; 110 121 } 111 transmissionMatrix.set(endStateIndex, startStateIndex, 1); 122 for( Integer i : endIndexList ) { 123 for(Integer j : startIndexList ) { 124 transmissionMatrix.set(i, j, 1); 125 } 126 } 112 127 113 128 // Calculate stationary distribution by raising the power of the … … 160 175 List<Event<?>> knownSymbols = new ArrayList<Event<?>>( 161 176 trie.getKnownSymbols()); 162 163 177 for (Event<?> symbol : knownSymbols) { 164 178 final String thisSaneId = symbol.getShortId().replace("\"", "\\\"") … … 183 197 /** 184 198 * <p> 185 * Returns a {@link Graph} represen ation of the model with the states as199 * Returns a {@link Graph} representation of the model with the states as 186 200 * nodes and directed edges weighted with transition probabilities. 187 201 * </p> -
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/PredictionByPartialMatch.java
r115 r258 34 34 * </p> 35 35 */ 36 pr ivateint minOrder;36 protected int minOrder; 37 37 38 38 /** … … 41 41 * </p> 42 42 */ 43 double probEscape;43 protected double probEscape; 44 44 45 45 /** -
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/Trie.java
r251 r258 85 85 */ 86 86 public void train(List<T> sequence, int maxOrder) { 87 if ( maxOrder<1) {87 if (maxOrder < 1) { 88 88 return; 89 89 } … … 400 400 return rootNode.getNumLeafs(); 401 401 } 402 403 /** 404 * <p> 405 * Updates the list of known symbols by replacing it with all symbols that 406 * are found in the child nodes of the root node. This should be the same as 407 * all symbols that are contained in the trie. 408 * </p> 409 */ 410 public void updateKnownSymbols() { 411 knownSymbols = new HashSet<T>(); 412 for (TrieNode<T> node : rootNode.getChildren()) { 413 knownSymbols.add(node.getSymbol()); 414 } 415 } 402 416 } -
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/TrieNode.java
r251 r258 178 178 /** 179 179 * <p> 180 * Returns all children of this node. 181 * </p> 182 * 183 * @return children of this node 184 */ 185 protected Collection<TrieNode<T>> getChildren() { 186 return children; 187 } 188 189 /** 190 * <p> 180 191 * Searches the sub-trie of this trie node for a given sequence and returns 181 192 * the node associated with the sequence or null if no such node is found. … … 298 309 return children.isEmpty(); 299 310 } 300 311 301 312 /** 302 313 * <p> … … 307 318 */ 308 319 protected boolean isRoot() { 309 return symbol ==null;320 return symbol == null; 310 321 } 311 322 … … 329 340 } 330 341 } 331 332 /** 333 * <p>Returns the number of descendants of this node that are leafs. This does not only include direct children of this node, but all leafs in the sub-trie with this node as root. 334 * </p> 335 * @return 342 343 /** 344 * <p> 345 * Returns the number of descendants of this node that are leafs. This does 346 * not only include direct children of this node, but all leafs in the 347 * sub-trie with this node as root. 348 * </p> 349 * 350 * @return number of leafs in this sub-trie 336 351 */ 337 352 protected int getNumLeafs() { 338 353 int numLeafs = 0; 339 for (TrieNode<T> child : children) {340 if ( child.isLeaf()) {354 for (TrieNode<T> child : children) { 355 if (child.isLeaf()) { 341 356 numLeafs++; 342 357 } else { … … 346 361 return numLeafs; 347 362 } 363 364 /** 365 * <p> 366 * Sets the {@link #count} of this node. 367 * </p> 368 * <p> 369 * This function should only be used sparingly and very carefully! The count 370 * is usually maintained automatically by the training procedures. 371 * </p> 372 * 373 * @param count 374 * new count 375 */ 376 protected void setCount(int count) { 377 this.count = count; 378 } 348 379 }
Note: See TracChangeset
for help on using the changeset viewer.