Changeset 93 for trunk/EventBenchCore/src/de/ugoe
- Timestamp:
- 07/04/11 10:35:39 (13 years ago)
- Location:
- trunk/EventBenchCore/src/de/ugoe/cs/eventbench
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/coverage/CoverageCalculator.java
r85 r93 1 1 package de.ugoe.cs.eventbench.coverage; 2 2 3 import java.security.InvalidParameterException;4 import java.util.ArrayList;5 3 import java.util.LinkedHashMap; 6 4 import java.util.LinkedHashSet; … … 16 14 17 15 private final IStochasticProcess process; 18 private final List<List< Event<?>>> sequences;16 private final List<List<? extends Event<?>>> sequences; 19 17 private final int length; 20 18 21 private Set<List< Event<?>>> containedSubSeqs = null;22 private Set<List< Event<?>>> allPossibleSubSeqs = null;23 private Map<List< Event<?>>, Double> subSeqWeights = null;19 private Set<List<? extends Event<?>>> containedSubSeqs = null; 20 private Set<List<? extends Event<?>>> allPossibleSubSeqs = null; 21 private Map<List<? extends Event<?>>, Double> subSeqWeights = null; 24 22 25 23 26 public CoverageCalculator(IStochasticProcess process, List<List< Event<?>>> sequences, int length) {24 public CoverageCalculator(IStochasticProcess process, List<List<? extends Event<?>>> sequences, int length) { 27 25 this.process = process; 28 26 this.sequences = sequences; … … 43 41 } 44 42 if( allPossibleSubSeqs==null ) { 45 allPossibleSubSeqs = generateSubSequences(process,length);43 allPossibleSubSeqs = process.generateSequences(length); 46 44 } 47 45 return((double) containedSubSeqs.size())/allPossibleSubSeqs.size(); … … 53 51 } 54 52 if( allPossibleSubSeqs==null ) { 55 allPossibleSubSeqs = generateSubSequences(process,length);53 allPossibleSubSeqs = process.generateSequences(length); 56 54 } 57 55 if( subSeqWeights==null ) { … … 59 57 } 60 58 double weight = 0.0; 61 for( List< Event<?>> subSeq : containedSubSeqs ) {59 for( List<? extends Event<?>> subSeq : containedSubSeqs ) { 62 60 weight += subSeqWeights.get(subSeq); 63 61 } … … 65 63 } 66 64 67 private Map<List< Event<?>>, Double> generateWeights(IStochasticProcess process, Set<List<Event<?>>> sequences) {68 Map<List< Event<?>>, Double> subSeqWeights = new LinkedHashMap<List<Event<?>>, Double>();65 private Map<List<? extends Event<?>>, Double> generateWeights(IStochasticProcess process, Set<List<? extends Event<?>>> sequences) { 66 Map<List<? extends Event<?>>, Double> subSeqWeights = new LinkedHashMap<List<? extends Event<?>>, Double>(); 69 67 double sum = 0.0; 70 for( List< Event<?>> sequence : sequences ) {68 for( List<? extends Event<?>> sequence : sequences ) { 71 69 double prob = 1.0; 72 70 List<Event<?>> context = new LinkedList<Event<?>>(); … … 79 77 } 80 78 if( sum<1.0 ) { 81 for( Map.Entry<List< Event<?>>, Double> entry : subSeqWeights.entrySet() ) {79 for( Map.Entry<List<? extends Event<?>>, Double> entry : subSeqWeights.entrySet() ) { 82 80 entry.setValue(entry.getValue()/sum); 83 81 } … … 90 88 } 91 89 92 // O(symbols^length)93 private Set<List<Event<?>>> generateSubSequences(IStochasticProcess process, int length) {94 Set<List<Event<?>>> subSequenceSet = new LinkedHashSet<List<Event<?>>>();;95 if( length<1 ) {96 throw new InvalidParameterException("Length of generated subsequences must be at least 1.");97 }98 if( length==1 ) {99 for( Event<?> event : process.getEvents() ) {100 List<Event<?>> subSeq = new LinkedList<Event<?>>();101 subSeq.add(event);102 subSequenceSet.add(subSeq);103 }104 return subSequenceSet;105 }106 Set<Event<?>> events = process.getEvents();107 Set<List<Event<?>>> subSeqsShorter = generateSubSequences(process, length-1);108 for( Event<?> event : events ) {109 for( List<Event<?>> subSequence : subSeqsShorter ) {110 Event<?> lastEvent = event;111 if( process.getProbability(subSequence, lastEvent)>0.0 ) {112 List<Event<?>> subSeq = new ArrayList<Event<?>>(subSequence);113 subSeq.add(lastEvent);114 subSequenceSet.add(subSeq);115 }116 }117 }118 return subSequenceSet;119 }120 121 90 // O(numSeq*lenSeq) 122 private Set<List< Event<?>>> containedSubSequences(List<List<Event<?>>> sequences, int length) {123 Set<List< Event<?>>> containedSubSeqs = new LinkedHashSet<List<Event<?>>>();91 private Set<List<? extends Event<?>>> containedSubSequences(List<List<? extends Event<?>>> sequences, int length) { 92 Set<List<? extends Event<?>>> containedSubSeqs = new LinkedHashSet<List<? extends Event<?>>>(); 124 93 List<Event<?>> subSeq = new LinkedList<Event<?>>(); 125 94 boolean minLengthReached = false; 126 for( List< Event<?>> sequence : sequences ) {95 for( List<? extends Event<?>> sequence : sequences ) { 127 96 for( Event<?> event : sequence ) { 128 97 subSeq.add(event); -
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/DeterministicFiniteAutomaton.java
r92 r93 19 19 20 20 @Override 21 public double getProbability(List< Event<?>> context, Event<?> symbol) {21 public double getProbability(List<? extends Event<?>> context, Event<?> symbol) { 22 22 double result = 0.0d; 23 23 -
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/HighOrderMarkovModel.java
r86 r93 19 19 20 20 @Override 21 public double getProbability(List< Event<?>> context, Event<?> symbol) {21 public double getProbability(List<? extends Event<?>> context, Event<?> symbol) { 22 22 double result = 0.0d; 23 23 -
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/IStochasticProcess.java
r86 r93 9 9 public interface IStochasticProcess extends Serializable { 10 10 11 double getProbability(List< Event<?>> context, Event<?> symbol);11 double getProbability(List<? extends Event<?>> context, Event<?> symbol); 12 12 13 13 public List<? extends Event<?>> randomSequence(); 14 15 public Set<List<? extends Event<?>>> generateSequences(int length); 14 16 15 17 public int getNumStates(); … … 17 19 public String[] getStateStrings(); 18 20 19 public Set< Event<?>> getEvents();21 public Set<? extends Event<?>> getEvents(); 20 22 21 23 } -
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/PredictionByPartialMatch.java
r86 r93 34 34 35 35 @Override 36 public double getProbability(List< Event<?>> context, Event<?> symbol) {36 public double getProbability(List<? extends Event<?>> context, Event<?> symbol) { 37 37 double result = 0.0d; 38 38 double resultCurrentContex = 0.0d; -
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/TrieBasedModel.java
r86 r93 1 1 package de.ugoe.cs.eventbench.models; 2 2 3 import java.security.InvalidParameterException; 4 import java.util.ArrayList; 5 import java.util.LinkedHashSet; 3 6 import java.util.LinkedList; 4 7 import java.util.List; … … 104 107 } 105 108 106 public Set< Event<?>> getEvents() {109 public Set<? extends Event<?>> getEvents() { 107 110 return trie.getKnownSymbols(); 111 } 112 113 public Set<List<? extends Event<?>>> generateSequences(int length) { 114 Set<List<? extends Event<?>>> sequenceSet = new LinkedHashSet<List<? extends Event<?>>>();; 115 if( length<1 ) { 116 throw new InvalidParameterException("Length of generated subsequences must be at least 1."); 117 } 118 if( length==1 ) { 119 for( Event<?> event : getEvents() ) { 120 List<Event<?>> subSeq = new LinkedList<Event<?>>(); 121 subSeq.add(event); 122 sequenceSet.add(subSeq); 123 } 124 return sequenceSet; 125 } 126 Set<? extends Event<?>> events = getEvents(); 127 Set<List<? extends Event<?>>> seqsShorter = generateSequences(length-1); 128 for( Event<?> event : events ) { 129 for( List<? extends Event<?>> seqShorter : seqsShorter ) { 130 Event<?> lastEvent = event; 131 if( getProbability(seqShorter, lastEvent)>0.0 ) { 132 List<Event<?>> subSeq = new ArrayList<Event<?>>(seqShorter); 133 subSeq.add(lastEvent); 134 sequenceSet.add(subSeq); 135 } 136 } 137 } 138 return sequenceSet; 108 139 } 109 140
Note: See TracChangeset
for help on using the changeset viewer.