- Timestamp:
- 09/09/11 06:23:36 (13 years ago)
- Location:
- trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDcalcCoverage.java
r130 r171 13 13 import de.ugoe.cs.util.console.Console; 14 14 15 /** 16 * <p> 17 * Command to calculate the coverage of a test suite. 18 * </p> 19 * 20 * @author Steffen Herbold 21 * @version 1.0 22 */ 15 23 public class CMDcalcCoverage implements Command { 16 24 25 /* 26 * (non-Javadoc) 27 * 28 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 29 */ 17 30 @SuppressWarnings("unchecked") 18 31 @Override 19 32 public void run(List<Object> parameters) { 20 String modelname; 33 String modelname; 21 34 String[] sequenceNames; 22 35 int minLength; … … 28 41 minLength = Integer.parseInt((String) parameters.get(2)); 29 42 maxLength = Integer.parseInt((String) parameters.get(3)); 30 if ( parameters.size()==5) {43 if (parameters.size() == 5) { 31 44 observedName = (String) parameters.get(1); 32 45 } 33 } 34 catch (Exception e) { 46 } catch (Exception e) { 35 47 throw new InvalidParameterException(); 36 48 } 37 38 IStochasticProcess process = null; 49 50 IStochasticProcess process = null; 39 51 Collection<List<? extends Event<?>>> observedSequences = null; 40 52 Collection<List<? extends Event<?>>> sequences = null; 41 Object dataObjectProcess = GlobalDataContainer.getInstance().getData(modelname); 42 Object dataObjectObserved = GlobalDataContainer.getInstance().getData(observedName); 43 if( dataObjectProcess==null ) { 53 Object dataObjectProcess = GlobalDataContainer.getInstance().getData( 54 modelname); 55 Object dataObjectObserved = GlobalDataContainer.getInstance().getData( 56 observedName); 57 if (dataObjectProcess == null) { 44 58 Console.printerrln("Model " + modelname + " not found in storage."); 45 59 return; 46 60 } 47 if( !(dataObjectProcess instanceof IStochasticProcess) ) { 48 Console.printerrln("Object " + modelname + " not of type IStochasticProcess!"); 61 if (!(dataObjectProcess instanceof IStochasticProcess)) { 62 Console.printerrln("Object " + modelname 63 + " not of type IStochasticProcess!"); 49 64 return; 50 65 } 51 if ( dataObjectObserved==null) {66 if (dataObjectObserved == null) { 52 67 Console.printerrln("Observed sequences not found in storage."); 53 68 return; 54 69 } 55 if ( !(dataObjectObserved instanceof Collection<?>)) {70 if (!(dataObjectObserved instanceof Collection<?>)) { 56 71 // weak instance check! 57 72 Console.printerrln("Object " + observedName + " not a Collection!"); … … 60 75 process = (IStochasticProcess) dataObjectProcess; 61 76 observedSequences = (Collection<List<? extends Event<?>>>) dataObjectObserved; 62 63 77 64 78 Console.print("seqName"); 65 for ( int length=minLength ; length<=maxLength; length++) {79 for (int length = minLength; length <= maxLength; length++) { 66 80 Console.print(";numObs_" + length); 67 81 Console.print(";numCov_" + length); … … 78 92 } 79 93 Console.println(""); 80 for( String sequenceName : sequenceNames ) { 81 Object dataObjectSequences = GlobalDataContainer.getInstance().getData(sequenceName); 82 if( dataObjectSequences==null ) { 83 Console.println("Sequences " + sequenceName + " not found in storage."); 84 } 85 else if( !(dataObjectSequences instanceof Collection<?>) ) { 86 // cannot really perform type check at runtime! this is an approximative substitute 87 Console.printerrln("Object " + sequenceName + "not of type Collection<?>!"); 94 for (String sequenceName : sequenceNames) { 95 Object dataObjectSequences = GlobalDataContainer.getInstance() 96 .getData(sequenceName); 97 if (dataObjectSequences == null) { 98 Console.println("Sequences " + sequenceName 99 + " not found in storage."); 100 } else if (!(dataObjectSequences instanceof Collection<?>)) { 101 // cannot really perform type check at runtime! this is an 102 // approximative substitute 103 Console.printerrln("Object " + sequenceName 104 + "not of type Collection<?>!"); 88 105 return; 89 106 } 90 107 sequences = (Collection<List<? extends Event<?>>>) dataObjectSequences; 91 108 Console.print(sequenceName); 92 for( int length=minLength ; length<=maxLength ; length++) { 93 CoverageCalculatorProcess covCalcProc = new CoverageCalculatorProcess(process, sequences, length); 94 CoverageCalculatorObserved covCalcObs = new CoverageCalculatorObserved(observedSequences, sequences, length); 109 for (int length = minLength; length <= maxLength; length++) { 110 CoverageCalculatorProcess covCalcProc = new CoverageCalculatorProcess( 111 process, sequences, length); 112 CoverageCalculatorObserved covCalcObs = new CoverageCalculatorObserved( 113 observedSequences, sequences, length); 95 114 Console.print(";" + covCalcObs.getNumObserved()); 96 115 Console.print(";" + covCalcObs.getNumCovered()); … … 101 120 Console.print(";" + covCalcProc.getCoveragePossibleWeight()); 102 121 Console.print(";" + covCalcObs.getCoverageObserved()); 103 Console.print(";" + covCalcObs.getCoverageObservedWeigth(process)); 122 Console.print(";" 123 + covCalcObs.getCoverageObservedWeigth(process)); 104 124 Console.print(";" + covCalcObs.getNewPercentage()); 105 125 Console.print(";" + covCalcObs.getCoveragePossibleNew(process)); 106 Console.print(";" + covCalcObs.getCoveragePossibleNewWeight(process)); 126 Console.print(";" 127 + covCalcObs.getCoveragePossibleNewWeight(process)); 107 128 } 108 129 Console.println(""); … … 110 131 } 111 132 133 /* 134 * (non-Javadoc) 135 * 136 * @see de.ugoe.cs.util.console.Command#help() 137 */ 112 138 @Override 113 139 public void help() { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDcalcEntropy.java
r82 r171 8 8 import de.ugoe.cs.util.console.Console; 9 9 10 10 /** 11 * <p> 12 * Command to calculate the entropy of first-order Markov models. 13 * </p> 14 * 15 * @author Steffen Herbold 16 * @version 1.0 17 */ 11 18 public class CMDcalcEntropy implements Command { 12 19 20 /* (non-Javadoc) 21 * @see de.ugoe.cs.util.console.Command#help() 22 */ 13 23 @Override 14 24 public void help() { … … 16 26 } 17 27 28 /* (non-Javadoc) 29 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 30 */ 18 31 @Override 19 32 public void run(List<Object> parameters) { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDgenerateFixedLengthSequences.java
r128 r171 17 17 import de.ugoe.cs.util.console.Console; 18 18 19 /** 20 * <p> 21 * Command to generate all sequences of a given length. 22 * </p> 23 * 24 * @author Steffen Herbold 25 * @version 1.0 26 */ 19 27 public class CMDgenerateFixedLengthSequences implements Command { 20 28 29 /* 30 * (non-Javadoc) 31 * 32 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 33 */ 21 34 @Override 22 35 public void run(List<Object> parameters) { … … 32 45 minLength = Integer.parseInt((String) parameters.get(2)); 33 46 maxLength = Integer.parseInt((String) parameters.get(3)); 34 if ( parameters.size()>=5) {47 if (parameters.size() >= 5) { 35 48 all = Boolean.parseBoolean((String) parameters.get(4)); 36 49 } 37 if ( parameters.size()==6) {38 numSequences = Integer.parseInt((String) parameters.get(5)); 50 if (parameters.size() == 6) { 51 numSequences = Integer.parseInt((String) parameters.get(5)); 39 52 } 40 } 41 catch (Exception e) { 53 } catch (Exception e) { 42 54 throw new InvalidParameterException(); 43 55 } 44 45 IStochasticProcess model = null; 46 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 47 if( dataObject==null ) { 56 57 IStochasticProcess model = null; 58 Object dataObject = GlobalDataContainer.getInstance() 59 .getData(modelname); 60 if (dataObject == null) { 48 61 Console.println("Model " + modelname + " not found in storage."); 49 } 50 else if( !(dataObject instanceof IStochasticProcess) ) { 62 } else if (!(dataObject instanceof IStochasticProcess)) { 51 63 Console.println("Object " + modelname + " not of type MarkovModel!"); 52 64 } else { 53 65 model = (IStochasticProcess) dataObject; 54 66 Collection<List<? extends Event<?>>> sequences = new LinkedHashSet<List<? extends Event<?>>>(); 55 for ( int length=minLength; length<=maxLength; length++) {56 sequences.addAll(model.generateValidSequences(length +2));67 for (int length = minLength; length <= maxLength; length++) { 68 sequences.addAll(model.generateValidSequences(length + 2)); 57 69 } 58 70 Console.traceln("" + sequences.size() + " possible"); 59 if( !all && numSequences<sequences.size() ) { 60 List<Double> probabilities = new ArrayList<Double>(sequences.size()); 71 if (!all && numSequences < sequences.size()) { 72 List<Double> probabilities = new ArrayList<Double>( 73 sequences.size()); 61 74 double probSum = 0.0; 62 for ( List<? extends Event<?>> sequence : sequences) {75 for (List<? extends Event<?>> sequence : sequences) { 63 76 double prob = model.getProbability(sequence); 64 77 probabilities.add(prob); … … 67 80 Set<Integer> drawnSequences = new HashSet<Integer>(numSequences); 68 81 Random r = new Random(); 69 while ( drawnSequences.size()<numSequences) {70 double randVal = r.nextDouble() *probSum;82 while (drawnSequences.size() < numSequences) { 83 double randVal = r.nextDouble() * probSum; 71 84 double sum = 0.0d; 72 85 int index = -1; 73 while ( sum<randVal) {86 while (sum < randVal) { 74 87 index++; 75 88 double currentProb = probabilities.get(index); 76 89 sum += currentProb; 77 90 } 78 if ( !drawnSequences.contains(index)) {91 if (!drawnSequences.contains(index)) { 79 92 drawnSequences.add(index); 80 93 probSum -= probabilities.get(index); … … 84 97 Collection<List<? extends Event<?>>> retainedSequences = new LinkedList<List<? extends Event<?>>>(); 85 98 int index = 0; 86 for (List<? extends Event<?>> sequence : sequences) {87 if ( drawnSequences.contains(index)) {99 for (List<? extends Event<?>> sequence : sequences) { 100 if (drawnSequences.contains(index)) { 88 101 retainedSequences.add(sequence); 89 102 } … … 92 105 sequences = retainedSequences; 93 106 } 94 if( GlobalDataContainer.getInstance().addData(sequencesName, sequences) ) { 95 Console.traceln("Old data \"" + sequencesName + "\" overwritten"); 107 if (GlobalDataContainer.getInstance().addData(sequencesName, 108 sequences)) { 109 Console.traceln("Old data \"" + sequencesName 110 + "\" overwritten"); 96 111 } 97 112 Console.println("" + sequences.size() + " sequences generated"); … … 99 114 } 100 115 116 /* 117 * (non-Javadoc) 118 * 119 * @see de.ugoe.cs.util.console.Command#help() 120 */ 101 121 @Override 102 122 public void help() { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDgenerateRandomReplay.java
r18 r171 12 12 import de.ugoe.cs.util.console.Console; 13 13 14 /** 15 * <p> 16 * Command to create a replay file with randomly generated sessions. 17 * </p> 18 * 19 * @author Steffen Herbold 20 * @version 1.0 21 */ 14 22 public class CMDgenerateRandomReplay implements Command { 15 23 24 /* 25 * (non-Javadoc) 26 * 27 * @see de.ugoe.cs.util.console.Command#help() 28 */ 16 29 @Override 17 30 public void help() { … … 19 32 } 20 33 34 /* 35 * (non-Javadoc) 36 * 37 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 38 */ 21 39 @SuppressWarnings("unchecked") 22 40 @Override … … 28 46 modelname = (String) parameters.get(0); 29 47 filename = (String) parameters.get(1); 30 if ( parameters.size()<3) {48 if (parameters.size() < 3) { 31 49 numSessions = Integer.parseInt((String) parameters.get(2)); 32 50 } 33 } 34 catch (Exception e) { 51 } catch (Exception e) { 35 52 throw new InvalidParameterException(); 36 53 } 37 38 IStochasticProcess model = null; 39 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 40 if( dataObject==null ) { 54 55 IStochasticProcess model = null; 56 Object dataObject = GlobalDataContainer.getInstance() 57 .getData(modelname); 58 if (dataObject == null) { 41 59 Console.println("Model " + modelname + " not found in storage."); 42 } 43 else if( !(dataObject instanceof IStochasticProcess) ) { 60 } else if (!(dataObject instanceof IStochasticProcess)) { 44 61 Console.println("Object " + modelname + " not of type MarkovModel!"); 45 62 } else { … … 47 64 List<List<ReplayableEvent<?>>> sequences = new LinkedList<List<ReplayableEvent<?>>>(); 48 65 try { 49 for( int i=0 ; i<numSessions ; i++ ) { 50 sequences.add((List<ReplayableEvent<?>>) model.randomSequence()); 66 for (int i = 0; i < numSessions; i++) { 67 sequences.add((List<ReplayableEvent<?>>) model 68 .randomSequence()); 51 69 } 52 70 } catch (ClassCastException e) { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDgenerateRandomSequences.java
r121 r171 12 12 import de.ugoe.cs.util.console.Console; 13 13 14 /** 15 * <p>Command to generate random sessions.</p> 16 * @author Steffen Herbold 17 * @version 1.0 18 */ 14 19 public class CMDgenerateRandomSequences implements Command { 15 20 21 /* (non-Javadoc) 22 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 23 */ 16 24 @Override 17 25 public void run(List<Object> parameters) { … … 68 76 } 69 77 78 /* (non-Javadoc) 79 * @see de.ugoe.cs.util.console.Command#help() 80 */ 70 81 @Override 71 82 public void help() { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDgenerateReplayfile.java
r98 r171 11 11 import de.ugoe.cs.util.console.Console; 12 12 13 /** 14 * <p>Command to create a replay file from stored sessions.</p> 15 * @author Steffen Herbold 16 * @version 1.0 17 */ 13 18 public class CMDgenerateReplayfile implements Command { 14 19 20 /* (non-Javadoc) 21 * @see de.ugoe.cs.util.console.Command#help() 22 */ 15 23 @Override 16 24 public void help() { … … 18 26 } 19 27 28 /* (non-Javadoc) 29 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 30 */ 20 31 @SuppressWarnings("unchecked") 21 32 @Override -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDlistSymbols.java
r130 r171 10 10 import de.ugoe.cs.util.console.Console; 11 11 12 /** 13 * <p> 14 * Command to list all events (symbols) known to a usage profile (stochastic 15 * process). 16 * </p> 17 * 18 * @author Steffen Herbold 19 * @version 1.0 20 */ 12 21 public class CMDlistSymbols implements Command { 13 22 23 /* 24 * (non-Javadoc) 25 * 26 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 27 */ 14 28 @Override 15 29 public void run(List<Object> parameters) { … … 18 32 try { 19 33 modelname = (String) parameters.get(0); 20 if ( parameters.size()==2) {34 if (parameters.size() == 2) { 21 35 sort = Boolean.parseBoolean((String) parameters.get(1)); 22 36 } … … 24 38 throw new InvalidParameterException(); 25 39 } 26 27 IStochasticProcess model = null; 28 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 29 if( dataObject==null ) { 40 41 IStochasticProcess model = null; 42 Object dataObject = GlobalDataContainer.getInstance() 43 .getData(modelname); 44 if (dataObject == null) { 30 45 Console.println("Model " + modelname + "not found in storage."); 31 } 32 else if( !(dataObject instanceof IStochasticProcess) ) {33 Console.println("Object " + modelname+ " is not a stochastic process!");46 } else if (!(dataObject instanceof IStochasticProcess)) { 47 Console.println("Object " + modelname 48 + " is not a stochastic process!"); 34 49 } else { 35 50 model = (IStochasticProcess) dataObject; 36 51 String[] stateStrings = model.getSymbolStrings(); 37 if ( sort) {52 if (sort) { 38 53 Arrays.sort(stateStrings); 39 54 } 40 for ( String stateString : stateStrings) {55 for (String stateString : stateStrings) { 41 56 Console.println(stateString); 42 57 } … … 44 59 } 45 60 61 /* 62 * (non-Javadoc) 63 * 64 * @see de.ugoe.cs.util.console.Command#help() 65 */ 46 66 @Override 47 67 public void help() { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDload.java
r89 r171 7 7 import java.util.List; 8 8 9 import de.ugoe.cs.eventbench.data.GlobalDataContainer; 9 10 import de.ugoe.cs.util.console.Command; 10 11 import de.ugoe.cs.util.console.Console; 11 12 13 /** 14 * <p> 15 * Command that loads a previously serialized {@link GlobalDataContainer}. 16 * </p> 17 * 18 * @author Steffen Herbold 19 * @version 1.0 20 */ 12 21 public class CMDload implements Command { 13 22 23 /* 24 * (non-Javadoc) 25 * 26 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 27 */ 14 28 @Override 15 29 public void run(List<Object> parameters) { … … 35 49 } 36 50 51 /* 52 * (non-Javadoc) 53 * 54 * @see de.ugoe.cs.util.console.Command#help() 55 */ 37 56 @Override 38 57 public void help() { 39 58 Console.println("Usage: loadObject <filename>"); 40 59 } 41 60 42 61 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDloadObject.java
r89 r171 11 11 import de.ugoe.cs.util.console.Console; 12 12 13 /** 14 * <p> 15 * Command to load a previously serialized object and store it in the 16 * {@link GlobalDataContainer}. 17 * </p> 18 * 19 * @author Steffen Herbold 20 * @version 1.0 21 */ 13 22 public class CMDloadObject implements Command { 14 23 24 /* 25 * (non-Javadoc) 26 * 27 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 28 */ 15 29 @Override 16 30 public void run(List<Object> parameters) { … … 37 51 ex.printStackTrace(); 38 52 } 39 if ( GlobalDataContainer.getInstance().addData(objectName, data )) {53 if (GlobalDataContainer.getInstance().addData(objectName, data)) { 40 54 Console.traceln("Old data \"" + objectName + "\" overwritten"); 41 55 } 42 56 } 43 57 58 /* 59 * (non-Javadoc) 60 * 61 * @see de.ugoe.cs.util.console.Command#help() 62 */ 44 63 @Override 45 64 public void help() { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDmodelSize.java
r131 r171 1 /**2 *3 */4 1 package de.ugoe.cs.eventbench.commands; 5 2 … … 13 10 14 11 /** 15 * @author sherbold 16 * 12 * <p> 13 * Command that prints the size of a stochastic process to the console. 14 * </p> 15 * 16 * @author Steffen Herbold 17 * @version 1.0 17 18 */ 18 19 public class CMDmodelSize implements Command { 19 20 20 /* (non-Javadoc) 21 /* 22 * (non-Javadoc) 23 * 21 24 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 22 25 */ … … 29 32 throw new InvalidParameterException(); 30 33 } 31 32 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 33 if( dataObject==null ) { 34 35 Object dataObject = GlobalDataContainer.getInstance() 36 .getData(modelname); 37 if (dataObject == null) { 34 38 Console.printerrln("No model with name " + modelname + "found"); 35 39 return; 36 40 } 37 if( !(dataObject instanceof IStochasticProcess) ) { 38 Console.printerrln("Object " + modelname + " not of type IStochasticProcess!"); 41 if (!(dataObject instanceof IStochasticProcess)) { 42 Console.printerrln("Object " + modelname 43 + " not of type IStochasticProcess!"); 39 44 return; 40 45 } 41 46 42 47 IStochasticProcess process = (IStochasticProcess) dataObject; 43 Console.println("#symbols: " + process.getNumSymbols() + " ; #FOMstates " + process.getNumFOMStates()); 48 Console.println("#symbols: " + process.getNumSymbols() 49 + " ; #FOMstates " + process.getNumFOMStates()); 44 50 } 45 51 46 /* (non-Javadoc) 52 /* 53 * (non-Javadoc) 54 * 47 55 * @see de.ugoe.cs.util.console.Command#help() 48 56 */ -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDprintDot.java
r26 r171 9 9 import de.ugoe.cs.util.console.Console; 10 10 11 /** 12 * <p> 13 * Command that prints a dot representation of a model (if supported) to the 14 * console. 15 * </p> 16 * 17 * @author Steffen Herbold 18 * @version 1.0 19 */ 11 20 public class CMDprintDot implements Command { 12 21 22 /* 23 * (non-Javadoc) 24 * 25 * @see de.ugoe.cs.util.console.Command#help() 26 */ 13 27 @Override 14 28 public void help() { … … 16 30 } 17 31 32 /* 33 * (non-Javadoc) 34 * 35 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 36 */ 18 37 @Override 19 38 public void run(List<Object> parameters) { … … 24 43 throw new InvalidParameterException(); 25 44 } 26 27 IDotCompatible model = null; 28 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 29 if( dataObject==null ) { 45 46 IDotCompatible model = null; 47 Object dataObject = GlobalDataContainer.getInstance() 48 .getData(modelname); 49 if (dataObject == null) { 30 50 Console.println("Model " + modelname + "not found in storage."); 31 } 32 else if( !(dataObject instanceof IDotCompatible) ) {33 Console.println("Object " + modelname+ " does not implement IDotCompatible!");51 } else if (!(dataObject instanceof IDotCompatible)) { 52 Console.println("Object " + modelname 53 + " does not implement IDotCompatible!"); 34 54 } else { 35 55 model = (IDotCompatible) dataObject; -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDprintRandomSession.java
r18 r171 10 10 import de.ugoe.cs.util.console.Console; 11 11 12 /** 13 * <p> 14 * Command that prints a randomly generated sessions of events to the console. 15 * </p> 16 * 17 * @author Steffen Herbold 18 * @version 1.0 19 */ 12 20 public class CMDprintRandomSession implements Command { 13 21 22 /* 23 * (non-Javadoc) 24 * 25 * @see de.ugoe.cs.util.console.Command#help() 26 */ 14 27 @Override 15 28 public void help() { … … 17 30 } 18 31 32 /* 33 * (non-Javadoc) 34 * 35 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 36 */ 19 37 @Override 20 38 public void run(List<Object> parameters) { … … 22 40 try { 23 41 modelname = (String) parameters.get(0); 24 } 25 catch (Exception e) { 42 } catch (Exception e) { 26 43 throw new InvalidParameterException(); 27 44 } 28 29 IStochasticProcess model = null; 30 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 31 if( dataObject==null ) { 45 46 IStochasticProcess model = null; 47 Object dataObject = GlobalDataContainer.getInstance() 48 .getData(modelname); 49 if (dataObject == null) { 32 50 Console.println("Model " + modelname + " not found in storage."); 33 } 34 else if( !(dataObject instanceof IStochasticProcess) ) { 51 } else if (!(dataObject instanceof IStochasticProcess)) { 35 52 Console.println("Object " + modelname + " not of type MarkovModel!"); 36 53 } else { 37 54 model = (IStochasticProcess) dataObject; 38 for ( Event<?> event : model.randomSequence()) {55 for (Event<?> event : model.randomSequence()) { 39 56 Console.println(event.toString()); 40 57 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDprintTrieDot.java
r31 r171 5 5 6 6 import de.ugoe.cs.eventbench.data.GlobalDataContainer; 7 import de.ugoe.cs.eventbench.models.Trie; 7 8 import de.ugoe.cs.eventbench.models.TrieBasedModel; 8 9 import de.ugoe.cs.util.console.Command; 9 10 import de.ugoe.cs.util.console.Console; 10 11 12 /** 13 * <p> 14 * Command that prints the {@link Trie} of a {@link TrieBasedModel} as dot to 15 * the console. 16 * </p> 17 * 18 * @author Steffen Herbold 19 * @version 20 */ 11 21 public class CMDprintTrieDot implements Command { 12 22 23 /* 24 * (non-Javadoc) 25 * 26 * @see de.ugoe.cs.util.console.Command#help() 27 */ 13 28 @Override 14 29 public void help() { … … 16 31 } 17 32 33 /* 34 * (non-Javadoc) 35 * 36 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 37 */ 18 38 @Override 19 39 public void run(List<Object> parameters) { … … 24 44 throw new InvalidParameterException(); 25 45 } 26 27 TrieBasedModel model = null; 28 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 29 if( dataObject==null ) { 46 47 TrieBasedModel model = null; 48 Object dataObject = GlobalDataContainer.getInstance() 49 .getData(modelname); 50 if (dataObject == null) { 30 51 Console.println("Model " + modelname + "not found in storage."); 31 } 32 else if( !(dataObject instanceof TrieBasedModel) ) { 52 } else if (!(dataObject instanceof TrieBasedModel)) { 33 53 Console.println("Object " + modelname + " is not a TrieBasedModel!"); 34 54 } else { … … 37 57 } 38 58 } 39 59 40 60 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDsave.java
r88 r171 11 11 import de.ugoe.cs.util.console.Console; 12 12 13 /** 14 * <p> 15 * Command to save the {@link GlobalDataContainer} through serialization. 16 * </p> 17 * 18 * @author Steffen Herbold 19 * @version 1.0 20 */ 13 21 public class CMDsave implements Command { 14 22 23 /* 24 * (non-Javadoc) 25 * 26 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 27 */ 15 28 @Override 16 29 public void run(List<Object> parameters) { … … 18 31 try { 19 32 filename = (String) parameters.get(0); 20 } 21 catch (Exception e) { 33 } catch (Exception e) { 22 34 throw new InvalidParameterException(); 23 35 } 24 25 36 26 37 FileOutputStream fos = null; 27 38 ObjectOutputStream out = null; … … 36 47 } 37 48 49 /* 50 * (non-Javadoc) 51 * 52 * @see de.ugoe.cs.util.console.Command#help() 53 */ 38 54 @Override 39 55 public void help() { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDsaveObject.java
r90 r171 11 11 import de.ugoe.cs.util.console.Console; 12 12 13 /** 14 * <p> 15 * Command that saves an object contained in the {@link GlobalDataContainer} 16 * through serialization. 17 * </p> 18 * 19 * @author Steffen Herbold 20 * @version 21 */ 13 22 public class CMDsaveObject implements Command { 14 23 24 /* 25 * (non-Javadoc) 26 * 27 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 28 */ 15 29 @Override 16 30 public void run(List<Object> parameters) { … … 20 34 filename = (String) parameters.get(0); 21 35 objectName = (String) parameters.get(1); 22 } 23 catch (Exception e) { 36 } catch (Exception e) { 24 37 throw new InvalidParameterException(); 25 38 } 26 27 Object dataObject = GlobalDataContainer.getInstance().getData(objectName); 28 if( dataObject==null ) { 39 40 Object dataObject = GlobalDataContainer.getInstance().getData( 41 objectName); 42 if (dataObject == null) { 29 43 Console.println("Object " + objectName + " not found in storage."); 30 44 } 31 45 32 46 FileOutputStream fos = null; 33 47 ObjectOutputStream out = null; … … 42 56 } 43 57 58 /* 59 * (non-Javadoc) 60 * 61 * @see de.ugoe.cs.util.console.Command#help() 62 */ 44 63 @Override 45 64 public void help() { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDsequenceStatistics.java
r113 r171 11 11 import de.ugoe.cs.util.console.Console; 12 12 13 /** 14 * <p> 15 * Command to print basic statistical information about stored sequences, e.g., 16 * how many there are of which lenght. 17 * </p> 18 * 19 * @author Steffen Herbold 20 * @version 1.0 21 */ 13 22 public class CMDsequenceStatistics implements Command { 14 23 24 /* 25 * (non-Javadoc) 26 * 27 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 28 */ 15 29 @SuppressWarnings("unchecked") 16 30 @Override 17 31 public void run(List<Object> parameters) { 18 32 String sequencesName = "sequences"; 19 if ( parameters.size()==1) {33 if (parameters.size() == 1) { 20 34 sequencesName = (String) parameters.get(0); 21 35 } 22 23 36 24 37 List<List<Event<?>>> sequences = null; 25 Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName); 26 38 Object dataObject = GlobalDataContainer.getInstance().getData( 39 sequencesName); 40 27 41 try { 28 42 sequences = (List<List<Event<?>>>) dataObject; 29 43 Console.traceln("Number of Sequences: " + sequences.size()); 30 SortedMap<Integer, Integer> lengthMap = new TreeMap<Integer, Integer>();31 for ( List<Event<?>> sequence : sequences) {44 SortedMap<Integer, Integer> lengthMap = new TreeMap<Integer, Integer>(); 45 for (List<Event<?>> sequence : sequences) { 32 46 Integer currentSize = sequence.size(); 33 if ( lengthMap.containsKey(currentSize)) {34 lengthMap.put(currentSize, lengthMap.get(currentSize) +1);47 if (lengthMap.containsKey(currentSize)) { 48 lengthMap.put(currentSize, lengthMap.get(currentSize) + 1); 35 49 } else { 36 50 lengthMap.put(currentSize, 1); 37 51 } 38 52 } 39 for( Entry<Integer, Integer> entry : lengthMap.entrySet() ) { 40 Console.traceln("Of length " + entry.getKey() + ": " + entry.getValue()); 53 for (Entry<Integer, Integer> entry : lengthMap.entrySet()) { 54 Console.traceln("Of length " + entry.getKey() + ": " 55 + entry.getValue()); 41 56 } 42 43 } 44 catch(ClassCastException e) { 57 58 } catch (ClassCastException e) { 45 59 Console.println("Sequences not found"); 46 60 } 47 61 } 48 62 63 /* 64 * (non-Javadoc) 65 * 66 * @see de.ugoe.cs.util.console.Command#help() 67 */ 49 68 @Override 50 69 public void help() { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDshowMarkovModel.java
r18 r171 23 23 import edu.uci.ics.jung.visualization.renderers.Renderer.VertexLabel.Position; 24 24 25 /** 26 * <p> 27 * Command that visualizes first-order Markov models. 28 * </p> 29 * 30 * @author Steffen Herbold 31 * @version 1.0 32 */ 25 33 public class CMDshowMarkovModel implements Command { 26 34 35 /* 36 * (non-Javadoc) 37 * 38 * @see de.ugoe.cs.util.console.Command#help() 39 */ 27 40 @Override 28 41 public void help() { … … 30 43 } 31 44 45 /* 46 * (non-Javadoc) 47 * 48 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 49 */ 32 50 @Override 33 51 public void run(List<Object> parameters) { … … 36 54 try { 37 55 modelname = (String) parameters.get(0); 38 if( parameters.size()==2 ) { 39 showNodeNames = Boolean.parseBoolean((String) parameters.get(1)); 56 if (parameters.size() == 2) { 57 showNodeNames = Boolean 58 .parseBoolean((String) parameters.get(1)); 40 59 } 41 60 } catch (Exception e) { 42 61 throw new InvalidParameterException(); 43 62 } 44 45 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 46 if( dataObject==null ) { 63 64 Object dataObject = GlobalDataContainer.getInstance() 65 .getData(modelname); 66 if (dataObject == null) { 47 67 Console.printerrln("No model with name " + modelname + "found"); 48 68 } else { 49 69 FirstOrderMarkovModel mm = (FirstOrderMarkovModel) dataObject; 50 70 51 71 Graph<String, MarkovEdge> graph = mm.getGraph(); 52 Layout<String, MarkovEdge> layout = new ISOMLayout<String, MarkovEdge>(graph); 53 layout.setSize(new Dimension(1000,800)); // sets the initial size of the space 54 // The BasicVisualizationServer<V,E> is parameterized by the edge types 55 BasicVisualizationServer<String,MarkovEdge> vv = 56 new BasicVisualizationServer<String,MarkovEdge>(layout); 57 vv.setPreferredSize(new Dimension(1100,850)); //Sets the viewing area size 72 Layout<String, MarkovEdge> layout = new ISOMLayout<String, MarkovEdge>( 73 graph); 74 layout.setSize(new Dimension(1000, 800)); // sets the initial size 75 // of the space 76 // The BasicVisualizationServer<V,E> is parameterized by the edge 77 // types 78 BasicVisualizationServer<String, MarkovEdge> vv = new BasicVisualizationServer<String, MarkovEdge>( 79 layout); 80 vv.setPreferredSize(new Dimension(1100, 850)); // Sets the viewing 81 // area size 58 82 59 if ( showNodeNames) {83 if (showNodeNames) { 60 84 final Rectangle rect = new Rectangle(240, 20); 61 62 Transformer<String, Shape> vertexShapeTransformer = 63 new Transformer<String, Shape>() { 64 public Shape transform(String s) { 65 return rect; 66 } 85 86 Transformer<String, Shape> vertexShapeTransformer = new Transformer<String, Shape>() { 87 public Shape transform(String s) { 88 return rect; 89 } 67 90 }; 68 vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR); 69 vv.getRenderContext().setVertexShapeTransformer(vertexShapeTransformer); 70 vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>()); 91 vv.getRenderer().getVertexLabelRenderer() 92 .setPosition(Position.CNTR); 93 vv.getRenderContext().setVertexShapeTransformer( 94 vertexShapeTransformer); 95 vv.getRenderContext().setVertexLabelTransformer( 96 new ToStringLabeller<String>()); 71 97 } 72 73 vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<MarkovEdge>()); 74 98 99 vv.getRenderContext().setEdgeLabelTransformer( 100 new ToStringLabeller<MarkovEdge>()); 101 75 102 JFrame frame = new JFrame("Markov Model"); 76 103 frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDshowTrie.java
r24 r171 12 12 13 13 import de.ugoe.cs.eventbench.data.GlobalDataContainer; 14 import de.ugoe.cs.eventbench.models.Trie; 14 15 import de.ugoe.cs.eventbench.models.Trie.Edge; 15 16 import de.ugoe.cs.eventbench.models.Trie.TrieVertex; … … 24 25 import edu.uci.ics.jung.visualization.renderers.Renderer.VertexLabel.Position; 25 26 27 /** 28 * <p> 29 * Command that visualizes the {@link Trie} of a {@link TrieBasedModel}. 30 * </p> 31 * 32 * @author Steffen Herbold 33 * @version 1.0 34 */ 26 35 public class CMDshowTrie implements Command { 27 36 37 /* 38 * (non-Javadoc) 39 * 40 * @see de.ugoe.cs.util.console.Command#help() 41 */ 28 42 @Override 29 43 public void help() { 30 44 Console.println("Usage: showTrie <modelName>"); 31 45 } 32 46 47 /* 48 * (non-Javadoc) 49 * 50 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 51 */ 33 52 @Override 34 53 public void run(List<Object> parameters) { … … 39 58 throw new InvalidParameterException(); 40 59 } 41 42 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 43 if( dataObject==null ) { 60 61 Object dataObject = GlobalDataContainer.getInstance() 62 .getData(modelname); 63 if (dataObject == null) { 44 64 Console.printerrln("No model with name " + modelname + "found"); 45 65 } else { 46 66 TrieBasedModel model = (TrieBasedModel) dataObject; 47 67 Tree<TrieVertex, Edge> graph = model.getTrieGraph(); 48 Layout<TrieVertex, Edge> layout = new TreeLayout<TrieVertex, Edge>(graph, 60); 49 // The BasicVisualizationServer<V,E> is parameterized by the edge types 50 BasicVisualizationServer<TrieVertex,Edge> vv = 51 new BasicVisualizationServer<TrieVertex,Edge>(layout); 52 vv.setPreferredSize(new Dimension(1100,850)); //Sets the viewing area size 53 54 68 Layout<TrieVertex, Edge> layout = new TreeLayout<TrieVertex, Edge>( 69 graph, 60); 70 // The BasicVisualizationServer<V,E> is parameterized by the edge 71 // types 72 BasicVisualizationServer<TrieVertex, Edge> vv = new BasicVisualizationServer<TrieVertex, Edge>( 73 layout); 74 vv.setPreferredSize(new Dimension(1100, 850)); // Sets the viewing 75 // area size 76 55 77 final Rectangle rect = new Rectangle(40, 20); 56 57 Transformer<TrieVertex, Shape> vertexShapeTransformer = 58 new Transformer<TrieVertex, Shape>() { 59 public Shape transform(TrieVertex s) { 60 return rect; 61 } 78 79 Transformer<TrieVertex, Shape> vertexShapeTransformer = new Transformer<TrieVertex, Shape>() { 80 public Shape transform(TrieVertex s) { 81 return rect; 82 } 62 83 }; 63 vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR); 64 vv.getRenderContext().setVertexShapeTransformer(vertexShapeTransformer); 65 vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<TrieVertex>()); 66 84 vv.getRenderer().getVertexLabelRenderer() 85 .setPosition(Position.CNTR); 86 vv.getRenderContext().setVertexShapeTransformer( 87 vertexShapeTransformer); 88 vv.getRenderContext().setVertexLabelTransformer( 89 new ToStringLabeller<TrieVertex>()); 90 67 91 JFrame frame = new JFrame("Trie"); 68 92 frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); … … 73 97 } 74 98 75 76 77 99 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDtrainDFA.java
r96 r171 11 11 import de.ugoe.cs.util.console.Console; 12 12 13 /** 14 * <p> 15 * Command to train a Deterministic Finite Automaton (DFA). 16 * </p> 17 * 18 * @author Steffen Herbold 19 * @version 1.0 20 */ 13 21 public class CMDtrainDFA implements Command { 14 22 23 /* 24 * (non-Javadoc) 25 * 26 * @see de.ugoe.cs.util.console.Command#help() 27 */ 15 28 @Override 16 29 public void help() { … … 18 31 } 19 32 33 /* 34 * (non-Javadoc) 35 * 36 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 37 */ 20 38 @SuppressWarnings("unchecked") 21 39 @Override … … 27 45 throw new InvalidParameterException(); 28 46 } 29 47 30 48 List<List<Event<?>>> sequences = null; 31 Object dataObject = GlobalDataContainer.getInstance().getData("sequences"); 32 49 Object dataObject = GlobalDataContainer.getInstance().getData( 50 "sequences"); 51 33 52 try { 34 53 sequences = (List<List<Event<?>>>) dataObject; 35 if( sequences.size()>0 ) { 36 if( sequences.get(0).get(0) instanceof Event ) { 37 DeterministicFiniteAutomaton model = new DeterministicFiniteAutomaton(new Random()); 54 if (sequences.size() > 0) { 55 if (sequences.get(0).get(0) instanceof Event) { 56 DeterministicFiniteAutomaton model = new DeterministicFiniteAutomaton( 57 new Random()); 38 58 model.train(sequences); 39 if( GlobalDataContainer.getInstance().addData(modelname, model) ) { 40 Console.traceln("Old data \"" + modelname + "\" overwritten"); 59 if (GlobalDataContainer.getInstance().addData(modelname, 60 model)) { 61 Console.traceln("Old data \"" + modelname 62 + "\" overwritten"); 41 63 } 42 64 } else { … … 45 67 } 46 68 } 47 } 48 catch(ClassCastException e) { 69 } catch (ClassCastException e) { 49 70 Console.println("Sequences need to be loaded first using parseXML"); 50 71 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDtrainMarkovModel.java
r116 r171 1 1 package de.ugoe.cs.eventbench.commands; 2 3 2 4 3 import java.security.InvalidParameterException; … … 13 12 import de.ugoe.cs.util.console.Console; 14 13 14 /** 15 * <p> 16 * Command to train first-order and high-order Markov models. 17 * </p> 18 * 19 * @author Steffen Herbold 20 * @version 1.0 21 */ 15 22 public class CMDtrainMarkovModel implements Command { 16 23 24 /* 25 * (non-Javadoc) 26 * 27 * @see de.ugoe.cs.util.console.Command#help() 28 */ 17 29 @Override 18 30 public void help() { … … 20 32 } 21 33 34 /* 35 * (non-Javadoc) 36 * 37 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 38 */ 22 39 @SuppressWarnings("unchecked") 23 40 @Override … … 27 44 try { 28 45 modelname = (String) parameters.get(0); 29 if ( parameters.size()==2) {46 if (parameters.size() == 2) { 30 47 order = Integer.parseInt((String) parameters.get(1)); 31 48 } … … 33 50 throw new InvalidParameterException(); 34 51 } 35 52 36 53 List<List<Event<?>>> sequences = null; 37 Object dataObject = GlobalDataContainer.getInstance().getData("sequences"); 38 54 Object dataObject = GlobalDataContainer.getInstance().getData( 55 "sequences"); 56 39 57 try { 40 58 sequences = (List<List<Event<?>>>) dataObject; 41 if ( sequences.size()>0) {42 if ( sequences.get(0).get(0) instanceof Event) {59 if (sequences.size() > 0) { 60 if (sequences.get(0).get(0) instanceof Event) { 43 61 HighOrderMarkovModel model; 44 if ( order==1) {62 if (order == 1) { 45 63 model = new FirstOrderMarkovModel(new Random()); 46 64 } else { … … 48 66 } 49 67 model.train(sequences); 50 if( GlobalDataContainer.getInstance().addData(modelname, model) ) { 51 Console.traceln("Old data \"" + modelname + "\" overwritten"); 68 if (GlobalDataContainer.getInstance().addData(modelname, 69 model)) { 70 Console.traceln("Old data \"" + modelname 71 + "\" overwritten"); 52 72 } 53 73 } else { … … 56 76 } 57 77 } 58 } 59 catch(ClassCastException e) { 78 } catch (ClassCastException e) { 60 79 Console.println("Sequences need to be loaded first using parseXML"); 61 80 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDtrainPPM.java
r116 r171 11 11 import de.ugoe.cs.util.console.Console; 12 12 13 /** 14 * <p> 15 * Command that trains Prediction by Partial Match (PPM) models. 16 * </p> 17 * 18 * @author Steffen Herbold 19 * @version 1.0 20 */ 13 21 public class CMDtrainPPM implements Command { 14 22 23 /* 24 * (non-Javadoc) 25 * 26 * @see de.ugoe.cs.util.console.Command#help() 27 */ 15 28 @Override 16 29 public void help() { … … 18 31 } 19 32 33 /* 34 * (non-Javadoc) 35 * 36 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 37 */ 20 38 @SuppressWarnings("unchecked") 21 39 @Override … … 29 47 probEscape = Double.parseDouble((String) parameters.get(1)); 30 48 maxOrder = Integer.parseInt((String) parameters.get(2)); 31 if ( parameters.size()==4) {49 if (parameters.size() == 4) { 32 50 minOrder = Integer.parseInt((String) parameters.get(3)); 33 51 } … … 35 53 throw new InvalidParameterException(); 36 54 } 37 55 38 56 List<List<Event<?>>> sequences = null; 39 Object dataObject = GlobalDataContainer.getInstance().getData("sequences"); 40 57 Object dataObject = GlobalDataContainer.getInstance().getData( 58 "sequences"); 59 41 60 try { 42 61 sequences = (List<List<Event<?>>>) dataObject; 43 if( sequences.size()>0 ) { 44 if( sequences.get(0).get(0) instanceof Event ) { 45 PredictionByPartialMatch model = new PredictionByPartialMatch(maxOrder, minOrder, new Random(), probEscape); 62 if (sequences.size() > 0) { 63 if (sequences.get(0).get(0) instanceof Event) { 64 PredictionByPartialMatch model = new PredictionByPartialMatch( 65 maxOrder, minOrder, new Random(), probEscape); 46 66 model.train(sequences); 47 if( GlobalDataContainer.getInstance().addData(modelname, model) ) { 48 Console.traceln("Old data \"" + modelname + "\" overwritten"); 49 } 67 if (GlobalDataContainer.getInstance().addData(modelname, 68 model)) { 69 Console.traceln("Old data \"" + modelname 70 + "\" overwritten"); 71 } 50 72 } else { 51 73 Console.traceln("Illegal use of \"sequences\" parameter in the GlobalDataContainer."); … … 53 75 } 54 76 } 55 } 56 catch(ClassCastException e) { 77 } catch (ClassCastException e) { 57 78 Console.println("Sequences need to be loaded first using parseXML"); 58 79 }
Note: See TracChangeset
for help on using the changeset viewer.