Changeset 342 for trunk/EventBenchCore/src/de/ugoe
- Timestamp:
- 12/21/11 16:54:59 (13 years ago)
- Location:
- trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/DeterministicFiniteAutomaton.java
r102 r342 1 1 package de.ugoe.cs.eventbench.models; 2 2 3 import java.security.InvalidParameterException; 3 4 import java.util.Collection; 4 5 import java.util.LinkedList; … … 52 53 public double getProbability(List<? extends Event<?>> context, 53 54 Event<?> symbol) { 55 if( context==null ) { 56 throw new InvalidParameterException("context must not be null"); 57 } 58 if( symbol==null ) { 59 throw new InvalidParameterException("symbol must not be null"); 60 } 54 61 double result = 0.0d; 55 62 -
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/HighOrderMarkovModel.java
r102 r342 1 1 package de.ugoe.cs.eventbench.models; 2 2 3 import java.security.InvalidParameterException; 3 4 import java.util.Collection; 4 5 import java.util.LinkedList; … … 9 10 10 11 /** 11 * <p>Implements high-order Markov models.</p> 12 * <p> 13 * Implements high-order Markov models. 14 * </p> 12 15 * 13 16 * @author Steffen Herbold … … 15 18 */ 16 19 public class HighOrderMarkovModel extends TrieBasedModel { 17 20 18 21 /** 19 22 * <p> … … 24 27 25 28 /** 26 * <p>Constructor. Creates a new HighOrderMarkovModel with a defined Markov order.</p> 27 * @param maxOrder Markov order of the model 28 * @param r random number generator used by probabilistic methods of the class 29 * <p> 30 * Constructor. Creates a new HighOrderMarkovModel with a defined Markov 31 * order. 32 * </p> 33 * 34 * @param maxOrder 35 * Markov order of the model 36 * @param r 37 * random number generator used by probabilistic methods of the 38 * class 29 39 */ 30 40 public HighOrderMarkovModel(int maxOrder, Random r) { 31 41 super(maxOrder, r); 32 42 } 33 43 34 44 /** 35 45 * <p> 36 * Calculates the probability of the next Event being symbol based on the order of the Markov model. The order is defined in the constructor {@link #HighOrderMarkovModel(int, Random)}. 46 * Calculates the probability of the next Event being symbol based on the 47 * order of the Markov model. The order is defined in the constructor 48 * {@link #HighOrderMarkovModel(int, Random)}. 37 49 * </p> 38 * @see de.ugoe.cs.eventbench.models.IStochasticProcess#getProbability(java.util.List, de.ugoe.cs.eventbench.data.Event) 50 * 51 * @see de.ugoe.cs.eventbench.models.IStochasticProcess#getProbability(java.util.List, 52 * de.ugoe.cs.eventbench.data.Event) 39 53 */ 40 54 @Override 41 public double getProbability(List<? extends Event<?>> context, Event<?> symbol) { 55 public double getProbability(List<? extends Event<?>> context, 56 Event<?> symbol) { 57 if (context == null) { 58 throw new InvalidParameterException("context must not be null"); 59 } 60 if (symbol == null) { 61 throw new InvalidParameterException("symbol must not be null"); 62 } 42 63 double result = 0.0d; 43 64 44 65 List<Event<?>> contextCopy; 45 if( context.size()>=trieOrder ) { 46 contextCopy = new LinkedList<Event<?>>(context.subList(context.size()-trieOrder+1, context.size())); 66 if (context.size() >= trieOrder) { 67 contextCopy = new LinkedList<Event<?>>(context.subList( 68 context.size() - trieOrder + 1, context.size())); 47 69 } else { 48 70 contextCopy = new LinkedList<Event<?>>(context); 49 71 } 50 72 51 52 73 Collection<Event<?>> followers = trie.getFollowingSymbols(contextCopy); 53 74 int sumCountFollowers = 0; // N(s\sigma') 54 for ( Event<?> follower : followers) {75 for (Event<?> follower : followers) { 55 76 sumCountFollowers += trie.getCount(contextCopy, follower); 56 77 } 57 78 58 79 int countSymbol = trie.getCount(contextCopy, symbol); 59 if ( sumCountFollowers!=0) {80 if (sumCountFollowers != 0) { 60 81 result = ((double) countSymbol / sumCountFollowers); 61 82 } 62 83 63 84 return result; 64 85 } -
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/IStochasticProcess.java
r248 r342 2 2 3 3 import java.io.Serializable; 4 import java.security.InvalidParameterException; 4 5 import java.util.Collection; 5 6 import java.util.List; … … 30 31 * @return probabilty the {@code symbol} is the next event, given the last 31 32 * events {@code context} 33 * @throws InvalidParameterException 34 * thrown if context or symbol is null 32 35 */ 33 36 double getProbability(List<? extends Event<?>> context, Event<?> symbol); … … 42 45 * sequences of which the probability is calculated 43 46 * @return probability of the sequences; 1.0 if sequence is empty or null 47 * @throws InvalidParameterException 48 * thrown if sequence is null 44 49 */ 45 50 double getProbability(List<? extends Event<?>> sequence); … … 66 71 * @return generated sequences 67 72 * @see #generateSequences(int, boolean) 73 * @throws InvalidParameterException 74 * thrown if length is less than or equal to 0 68 75 */ 69 76 public Collection<List<? extends Event<?>>> generateSequences(int length); … … 84 91 * {@link Event#STARTEVENT} 85 92 * @return generated sequences 93 * @throws InvalidParameterException 94 * thrown if length is less than or equal to 0 86 95 */ 87 96 public Collection<List<? extends Event<?>>> generateSequences(int length, … … 99 108 * @param length 100 109 * @return generated sequences 110 * @throws InvalidParameterException 111 * thrown if length is less than or equal to 0 101 112 */ 102 113 public Collection<List<? extends Event<?>>> generateValidSequences( -
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/PredictionByPartialMatch.java
r258 r342 1 1 package de.ugoe.cs.eventbench.models; 2 2 3 import java.security.InvalidParameterException; 3 4 import java.util.Collection; 4 5 import java.util.LinkedList; … … 93 94 * @param probEscape 94 95 * escape probability used by the model 96 * @throws InvalidParameterException thrown if minOrder is less than 0 or greater than markovOrder or probEscape is not in the interval (0,1) 95 97 */ 96 98 public PredictionByPartialMatch(int markovOrder, int minOrder, Random r, 97 99 double probEscape) { 98 100 super(markovOrder, r); 101 if( minOrder< 0 ) { 102 throw new InvalidParameterException("minOrder must be greather than or equal to 0"); 103 } 104 if( minOrder>markovOrder) { 105 throw new InvalidParameterException("minOrder must be less than or equal to markovOrder"); 106 } 107 if( probEscape<=0.0 || probEscape>=1.0) { 108 throw new InvalidParameterException("probEscape must be in the interval (0,1)"); 109 } 99 110 this.probEscape = probEscape; 100 111 this.minOrder = minOrder; … … 133 144 * P_{MM^i} denotes the probability in an i-th order Markov model. 134 145 * </p> 146 * 147 * @see de.ugoe.cs.eventbench.models.IStochasticProcess#getProbability(java.util.List, 148 * de.ugoe.cs.eventbench.data.Event) 135 149 */ 136 150 @Override 137 151 public double getProbability(List<? extends Event<?>> context, 138 152 Event<?> symbol) { 153 if (context == null) { 154 throw new InvalidParameterException("context must not be null"); 155 } 156 if (symbol == null) { 157 throw new InvalidParameterException("symbol must not be null"); 158 } 139 159 double result = 0.0d; 140 160 double resultCurrentContex = 0.0d; … … 161 181 resultCurrentContex = (double) countSymbol / sumCountFollowers; 162 182 } 163 if (contextCopy.size() > =minOrder) {183 if (contextCopy.size() > minOrder) { 164 184 resultCurrentContex *= (1 - probEscape); 165 185 contextCopy.remove(0); -
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/TrieBasedModel.java
r325 r342 70 70 * random number generator used by probabilistic methods of the 71 71 * class 72 * @throws InvalidParameterException 73 * thrown if markovOrder is less than 0 or the random number 74 * generator r is null 72 75 */ 73 76 public TrieBasedModel(int markovOrder, Random r) { 74 77 super(); 78 if (markovOrder < 0) { 79 throw new InvalidParameterException( 80 "markov order must not be less than 0"); 81 } 82 if (r == null) { 83 throw new InvalidParameterException( 84 "random number generator r must not be null"); 85 } 75 86 this.trieOrder = markovOrder + 1; 76 87 this.r = r; … … 87 98 * @param sequences 88 99 * training data 100 * @throws InvalidParameterException 101 * thrown is sequences is null 89 102 */ 90 103 public void train(Collection<List<? extends Event<?>>> sequences) { … … 103 116 * @param sequences 104 117 * training data 118 * @throws InvalidParameterException 119 * thrown is sequences is null 105 120 */ 106 121 public void update(Collection<List<? extends Event<?>>> sequences) { 107 122 if (sequences == null) { 108 return;123 throw new InvalidParameterException("sequences must not be null"); 109 124 } 110 125 if (trie == null) { … … 129 144 public List<? extends Event<?>> randomSequence() { 130 145 List<Event<?>> sequence = new LinkedList<Event<?>>(); 131 if ( trie!=null) {146 if (trie != null) { 132 147 IncompleteMemory<Event<?>> context = new IncompleteMemory<Event<?>>( 133 148 trieOrder - 1); 134 149 context.add(Event.STARTEVENT); 135 150 136 151 Event<?> currentState = Event.STARTEVENT; 137 152 138 153 boolean endFound = false; 139 154 140 155 while (!endFound) { 141 156 double randVal = r.nextDouble(); … … 147 162 endFound = (symbol == Event.ENDEVENT); 148 163 if (!(symbol == Event.STARTEVENT || symbol == Event.ENDEVENT)) { 149 // only add the symbol the sequence if it is not START 164 // only add the symbol the sequence if it is not 165 // START 150 166 // or END 151 167 context.add(symbol); … … 344 360 @Override 345 361 public double getProbability(List<? extends Event<?>> sequence) { 362 if (sequence == null) { 363 throw new InvalidParameterException("sequence must not be null"); 364 } 346 365 double prob = 1.0; 347 if (sequence != null) { 348 List<Event<?>> context = new LinkedList<Event<?>>(); 349 for (Event<?> event : sequence) { 350 prob *= getProbability(context, event); 351 context.add(event); 352 } 366 List<Event<?>> context = new LinkedList<Event<?>>(); 367 for (Event<?> event : sequence) { 368 prob *= getProbability(context, event); 369 context.add(event); 353 370 } 354 371 return prob;
Note: See TracChangeset
for help on using the changeset viewer.