- Timestamp:
- 12/16/11 10:50:04 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/coverage/SequenceTools.java
r129 r328 1 1 package de.ugoe.cs.eventbench.coverage; 2 2 3 import java.security.InvalidParameterException; 3 4 import java.util.Collection; 4 5 import java.util.LinkedHashMap; … … 40 41 Collection<List<? extends Event<?>>> sequences) { 41 42 Map<List<? extends Event<?>>, Double> subSeqWeights = new LinkedHashMap<List<? extends Event<?>>, Double>(); 42 double sum = 0.0; 43 for (List<? extends Event<?>> sequence : sequences) { 44 double prob = process.getProbability(sequence); 45 subSeqWeights.put(sequence, prob); 46 sum += prob; 47 } 48 if (sum < 1.0) { 49 for (Map.Entry<List<? extends Event<?>>, Double> entry : subSeqWeights 50 .entrySet()) { 51 entry.setValue(entry.getValue() / sum); 43 if (sequences != null && !sequences.isEmpty()) { 44 if (process != null) { 45 double sum = 0.0; 46 for (List<? extends Event<?>> sequence : sequences) { 47 double prob = process.getProbability(sequence); 48 subSeqWeights.put(sequence, prob); 49 sum += prob; 50 } 51 if (sum < 1.0) { 52 for (Map.Entry<List<? extends Event<?>>, Double> entry : subSeqWeights 53 .entrySet()) { 54 entry.setValue(entry.getValue() / sum); 55 } 56 } 57 } else { 58 for( List<? extends Event<?>> sequence : sequences ) { 59 subSeqWeights.put(sequence, 0.0d); 60 } 52 61 } 53 62 } … … 67 76 * lenght of the sequences 68 77 * @return numStates^length 78 * @throws InvalidParameterException 79 * thrown if length less or equal to 0 69 80 */ 70 81 public static long numSequences(IStochasticProcess process, int length) { 71 return (long) Math.pow(process.getNumSymbols(), length); 82 if (length <= 0) { 83 throw new InvalidParameterException( 84 "length must be a positive integer"); 85 } 86 long result = 0; 87 if (process != null) { 88 result = (long) Math.pow(process.getNumSymbols(), length); 89 } 90 return result; 72 91 } 73 92 … … 83 102 * length of the subsequences 84 103 * @return {@link Set} of all subsequences 104 * @throws InvalidParameterException 105 * thrown if length less or equal to 0 85 106 */ 86 107 public static Set<List<? extends Event<?>>> containedSubSequences( 87 108 Collection<List<? extends Event<?>>> sequences, int length) { 109 if (length <= 0) { 110 throw new InvalidParameterException( 111 "length must be a positive integer"); 112 } 88 113 Set<List<? extends Event<?>>> containedSubSeqs = new LinkedHashSet<List<? extends Event<?>>>(); 89 for (List<? extends Event<?>> sequence : sequences) { 90 List<Event<?>> subSeq = new LinkedList<Event<?>>(); 91 boolean minLengthReached = false; 92 for (Event<?> event : sequence) { 93 subSeq.add(event); 94 if (!minLengthReached) { 95 if (subSeq.size() == length) { 96 minLengthReached = true; 114 if (sequences != null) { 115 for (List<? extends Event<?>> sequence : sequences) { 116 List<Event<?>> subSeq = new LinkedList<Event<?>>(); 117 boolean minLengthReached = false; 118 for (Event<?> event : sequence) { 119 subSeq.add(event); 120 if (!minLengthReached) { 121 if (subSeq.size() == length) { 122 minLengthReached = true; 123 } 124 } else { 125 subSeq.remove(0); 97 126 } 98 } else { 99 subSeq.remove(0); 100 } 101 if (minLengthReached) { 102 if (!containedSubSeqs.contains(subSeq)) { 103 containedSubSeqs.add(new LinkedList<Event<?>>(subSeq)); 127 if (minLengthReached) { 128 if (!containedSubSeqs.contains(subSeq)) { 129 containedSubSeqs.add(new LinkedList<Event<?>>( 130 subSeq)); 131 } 104 132 } 105 133 }
Note: See TracChangeset
for help on using the changeset viewer.