Changeset 209 for trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDgenerateFixedLengthSequences.java
- Timestamp:
- 09/28/11 03:03:13 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDgenerateFixedLengthSequences.java
r171 r209 60 60 if (dataObject == null) { 61 61 Console.println("Model " + modelname + " not found in storage."); 62 return; 62 63 } else if (!(dataObject instanceof IStochasticProcess)) { 63 64 Console.println("Object " + modelname + " not of type MarkovModel!"); 64 } else { 65 model = (IStochasticProcess) dataObject; 66 Collection<List<? extends Event<?>>> sequences = new LinkedHashSet<List<? extends Event<?>>>(); 67 for (int length = minLength; length <= maxLength; length++) { 68 sequences.addAll(model.generateValidSequences(length + 2)); 65 return; 66 } 67 model = (IStochasticProcess) dataObject; 68 Collection<List<? extends Event<?>>> sequences = new LinkedHashSet<List<? extends Event<?>>>(); 69 for (int length = minLength; length <= maxLength; length++) { 70 sequences.addAll(model.generateValidSequences(length + 2)); 71 } 72 Console.traceln("" + sequences.size() + " possible"); 73 if (!all && numSequences < sequences.size()) { 74 List<Double> probabilities = new ArrayList<Double>(sequences.size()); 75 double probSum = 0.0; 76 for (List<? extends Event<?>> sequence : sequences) { 77 double prob = model.getProbability(sequence); 78 probabilities.add(prob); 79 probSum += prob; 69 80 } 70 Console.traceln("" + sequences.size() + " possible"); 71 if (!all && numSequences < sequences.size()) { 72 List<Double> probabilities = new ArrayList<Double>( 73 sequences.size()); 74 double probSum = 0.0; 75 for (List<? extends Event<?>> sequence : sequences) { 76 double prob = model.getProbability(sequence); 77 probabilities.add(prob); 78 probSum += prob; 81 Set<Integer> drawnSequences = new HashSet<Integer>(numSequences); 82 Random r = new Random(); 83 while (drawnSequences.size() < numSequences) { 84 double randVal = r.nextDouble() * probSum; 85 double sum = 0.0d; 86 int index = -1; 87 while (sum < randVal) { 88 index++; 89 double currentProb = probabilities.get(index); 90 sum += currentProb; 79 91 } 80 Set<Integer> drawnSequences = new HashSet<Integer>(numSequences); 81 Random r = new Random(); 82 while (drawnSequences.size() < numSequences) { 83 double randVal = r.nextDouble() * probSum; 84 double sum = 0.0d; 85 int index = -1; 86 while (sum < randVal) { 87 index++; 88 double currentProb = probabilities.get(index); 89 sum += currentProb; 90 } 91 if (!drawnSequences.contains(index)) { 92 drawnSequences.add(index); 93 probSum -= probabilities.get(index); 94 probabilities.set(index, 0.0d); 95 } 92 if (!drawnSequences.contains(index)) { 93 drawnSequences.add(index); 94 probSum -= probabilities.get(index); 95 probabilities.set(index, 0.0d); 96 96 } 97 Collection<List<? extends Event<?>>> retainedSequences = new LinkedList<List<? extends Event<?>>>(); 98 int index = 0; 99 for (List<? extends Event<?>> sequence : sequences) { 100 if (drawnSequences.contains(index)) { 101 retainedSequences.add(sequence); 102 } 103 index++; 97 } 98 Collection<List<? extends Event<?>>> retainedSequences = new LinkedList<List<? extends Event<?>>>(); 99 int index = 0; 100 for (List<? extends Event<?>> sequence : sequences) { 101 if (drawnSequences.contains(index)) { 102 retainedSequences.add(sequence); 104 103 } 105 sequences = retainedSequences;104 index++; 106 105 } 107 if (GlobalDataContainer.getInstance().addData(sequencesName, 108 sequences)) { 109 Console.traceln("Old data \"" + sequencesName 110 + "\" overwritten"); 111 } 112 Console.println("" + sequences.size() + " sequences generated"); 106 sequences = retainedSequences; 113 107 } 108 if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) { 109 Console.traceln("Old data \"" + sequencesName + "\" overwritten"); 110 } 111 Console.println("" + sequences.size() + " sequences generated"); 114 112 } 115 113
Note: See TracChangeset
for help on using the changeset viewer.