Changeset 209 for trunk/EventBenchConsole/src
- Timestamp:
- 09/28/11 03:03:13 (13 years ago)
- Location:
- trunk/EventBenchConsole/src/de/ugoe/cs/eventbench
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/AbstractTrainCommand.java
r203 r209 5 5 import java.util.List; 6 6 7 import de.ugoe.cs.eventbench.SequenceInstanceOf; 7 8 import de.ugoe.cs.eventbench.data.Event; 8 9 import de.ugoe.cs.eventbench.data.GlobalDataContainer; … … 69 70 } 70 71 71 Collection<List<Event<?>>> sequences = null;72 72 Object dataObject = GlobalDataContainer.getInstance().getData( 73 73 sequencesName); … … 77 77 return; 78 78 } 79 try { 80 sequences = (Collection<List<Event<?>>>) dataObject; 81 } catch (ClassCastException e) { 79 if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) { 82 80 Console.println("Object " + sequencesName 83 81 + "not of type Collection<List<Event<?>>>."); 84 82 return; 85 83 } 86 /* TODO implement better type check 87 if (sequences.size() == 0 || !(sequences.get(0).get(0) instanceof Event) ) { 88 Console.println("Object " + sequencesName 89 + "not of type Collection<List<Event<?>>>."); 90 return; 91 } 92 */ 84 Collection<List<Event<?>>> sequences = (Collection<List<Event<?>>>) dataObject; 93 85 94 86 TrieBasedModel model = createModel(); 95 87 model.train(sequences); 96 if (GlobalDataContainer.getInstance().addData(modelname, 97 model)) { 98 Console.traceln("Old data \"" + modelname 99 + "\" overwritten"); 88 if (GlobalDataContainer.getInstance().addData(modelname, model)) { 89 Console.traceln("Old data \"" + modelname + "\" overwritten"); 100 90 } 101 91 102 92 } 103 93 -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDcalcCoverage.java
r171 r209 5 5 import java.util.List; 6 6 7 import de.ugoe.cs.eventbench.SequenceInstanceOf; 7 8 import de.ugoe.cs.eventbench.coverage.CoverageCalculatorObserved; 8 9 import de.ugoe.cs.eventbench.coverage.CoverageCalculatorProcess; … … 68 69 return; 69 70 } 70 if (! (dataObjectObserved instanceof Collection<?>)) {71 // weak instance check!72 Console.printerrln("Object " + observedName + " not a Collection!");71 if (!SequenceInstanceOf.isCollectionOfSequences(dataObjectObserved)) { 72 Console.printerrln("Object " + observedName 73 + " of type Collection<List<Event<?>>>!"); 73 74 return; 74 75 } … … 98 99 Console.println("Sequences " + sequenceName 99 100 + " not found in storage."); 100 } else if (!(dataObjectSequences instanceof Collection<?>)) {101 // cannot really perform type check at runtime! this is an102 // approximative substitute101 return; 102 } else if (!SequenceInstanceOf 103 .isCollectionOfSequences(dataObjectSequences)) { 103 104 Console.printerrln("Object " + sequenceName 104 + "not of type Collection< ?>!");105 + "not of type Collection<List<Event<?>!"); 105 106 return; 106 107 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDcalcEntropy.java
r171 r209 1 1 package de.ugoe.cs.eventbench.commands; 2 2 3 import java.security.InvalidParameterException; 3 4 import java.util.List; … … 18 19 public class CMDcalcEntropy implements Command { 19 20 20 /* (non-Javadoc) 21 /* 22 * (non-Javadoc) 23 * 21 24 * @see de.ugoe.cs.util.console.Command#help() 22 25 */ … … 26 29 } 27 30 28 /* (non-Javadoc) 31 /* 32 * (non-Javadoc) 33 * 29 34 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 30 35 */ … … 37 42 throw new InvalidParameterException(); 38 43 } 39 40 FirstOrderMarkovModel model = null; 41 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 42 if( dataObject==null ) { 44 45 FirstOrderMarkovModel model = null; 46 Object dataObject = GlobalDataContainer.getInstance() 47 .getData(modelname); 48 if (dataObject == null) { 43 49 Console.println("Model " + modelname + "not found in storage."); 50 return; 44 51 } 45 else if( !(dataObject instanceof FirstOrderMarkovModel) ) { 46 Console.println("Object " + modelname + " is not a first-order Markov model!"); 47 } else { 48 model = (FirstOrderMarkovModel) dataObject; 49 double entropy = model.calcEntropy(); 50 if( !Double.isNaN(entropy) ) { 51 Console.println("entropy: " + entropy); 52 } 52 if (!(dataObject instanceof FirstOrderMarkovModel)) { 53 Console.println("Object " + modelname 54 + " is not a first-order Markov model!"); 55 return; 56 } 57 model = (FirstOrderMarkovModel) dataObject; 58 double entropy = model.calcEntropy(); 59 if (!Double.isNaN(entropy)) { 60 Console.println("entropy: " + entropy); 53 61 } 54 62 } -
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 -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDgenerateRandomReplay.java
r203 r209 59 59 if (dataObject == null) { 60 60 Console.println("Model " + modelname + " not found in storage."); 61 } else if (!(dataObject instanceof IStochasticProcess)) { 61 return; 62 } 63 if (!(dataObject instanceof IStochasticProcess)) { 62 64 Console.println("Object " + modelname + " not of type MarkovModel!"); 63 } else { 64 model = (IStochasticProcess) dataObject; 65 Collection<List<ReplayableEvent<?>>> sequences = new LinkedList<List<ReplayableEvent<?>>>(); 66 try { 67 for (int i = 0; i < numSessions; i++) { 68 sequences.add((List<ReplayableEvent<?>>) model 69 .randomSequence()); 70 } 71 } catch (ClassCastException e) { 72 Console.println("Modeled events don't support replay."); 65 return; 66 } 67 model = (IStochasticProcess) dataObject; 68 Collection<List<ReplayableEvent<?>>> sequences = new LinkedList<List<ReplayableEvent<?>>>(); 69 try { 70 for (int i = 0; i < numSessions; i++) { 71 sequences 72 .add((List<ReplayableEvent<?>>) model.randomSequence()); 73 73 } 74 ReplayGenerator generator = new ReplayGenerator();75 generator.createLogfileMultipleSessions(sequences, filename);74 } catch (ClassCastException e) { 75 Console.println("Modeled events don't support replay."); 76 76 } 77 ReplayGenerator generator = new ReplayGenerator(); 78 generator.createLogfileMultipleSessions(sequences, filename); 77 79 } 78 80 -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDgenerateRandomSequences.java
r171 r209 13 13 14 14 /** 15 * <p>Command to generate random sessions.</p> 15 * <p> 16 * Command to generate random sessions. 17 * </p> 18 * 16 19 * @author Steffen Herbold 17 20 * @version 1.0 … … 19 22 public class CMDgenerateRandomSequences implements Command { 20 23 21 /* (non-Javadoc) 24 /* 25 * (non-Javadoc) 26 * 22 27 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 23 28 */ … … 34 39 sequencesName = (String) parameters.get(1); 35 40 numSessions = Integer.parseInt((String) parameters.get(2)); 36 maxIter = numSessions *10;37 if ( parameters.size()>=4) {41 maxIter = numSessions * 10; 42 if (parameters.size() >= 4) { 38 43 maxIter = Long.parseLong((String) parameters.get(3)); 39 44 } 40 if ( parameters.size()>=5) {45 if (parameters.size() >= 5) { 41 46 minLength = Integer.parseInt((String) parameters.get(4)); 42 47 } 43 if ( parameters.size()>=6) {48 if (parameters.size() >= 6) { 44 49 maxLength = Integer.parseInt((String) parameters.get(5)); 45 50 } 46 } 47 catch (Exception e) { 51 } catch (Exception e) { 48 52 throw new InvalidParameterException(); 49 53 } 50 51 IStochasticProcess model = null; 52 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 53 if( dataObject==null ) { 54 55 IStochasticProcess model = null; 56 Object dataObject = GlobalDataContainer.getInstance() 57 .getData(modelname); 58 if (dataObject == null) { 54 59 Console.println("Model " + modelname + " not found in storage."); 60 return; 55 61 } 56 else if( !(dataObject instanceof IStochasticProcess)) {62 if (!(dataObject instanceof IStochasticProcess)) { 57 63 Console.println("Object " + modelname + " not of type MarkovModel!"); 58 } else { 59 model = (IStochasticProcess) dataObject; 60 Set<List<? extends Event<?>>> sequences = new HashSet<List<? extends Event<?>>>(numSessions); 61 long numIterations = 0; 62 while( sequences.size()<numSessions && numIterations<maxIter ) { 63 List<? extends Event<?>> generatedSequence = model.randomSequence(); 64 if( generatedSequence.size()>=minLength && generatedSequence.size()<=maxLength ) { 65 sequences.add(generatedSequence); 66 } 67 numIterations++; 64 return; 65 } 66 model = (IStochasticProcess) dataObject; 67 Set<List<? extends Event<?>>> sequences = new HashSet<List<? extends Event<?>>>( 68 numSessions); 69 long numIterations = 0; 70 while (sequences.size() < numSessions && numIterations < maxIter) { 71 List<? extends Event<?>> generatedSequence = model.randomSequence(); 72 if (generatedSequence.size() >= minLength 73 && generatedSequence.size() <= maxLength) { 74 sequences.add(generatedSequence); 68 75 } 69 if( sequences.size() < numSessions ) { 70 Console.println("Only " + sequences.size() + " unique sessions generated after " + maxIter + " iterations"); 71 } 72 if( GlobalDataContainer.getInstance().addData(sequencesName, sequences) ) { 73 Console.traceln("Old data \"" + sequencesName + "\" overwritten"); 74 } 76 numIterations++; 77 } 78 if (sequences.size() < numSessions) { 79 Console.println("Only " + sequences.size() 80 + " unique sessions generated after " + maxIter 81 + " iterations"); 82 } 83 if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) { 84 Console.traceln("Old data \"" + sequencesName + "\" overwritten"); 75 85 } 76 86 } 77 87 78 /* (non-Javadoc) 88 /* 89 * (non-Javadoc) 90 * 79 91 * @see de.ugoe.cs.util.console.Command#help() 80 92 */ -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDgenerateReplayfile.java
r203 r209 6 6 7 7 import de.ugoe.cs.eventbench.ReplayGenerator; 8 import de.ugoe.cs.eventbench. data.Event;8 import de.ugoe.cs.eventbench.SequenceInstanceOf; 9 9 import de.ugoe.cs.eventbench.data.GlobalDataContainer; 10 10 import de.ugoe.cs.eventbench.data.ReplayableEvent; … … 13 13 14 14 /** 15 * <p>Command to create a replay file from stored sessions.</p> 15 * <p> 16 * Command to create a replay file from stored sessions. 17 * </p> 18 * 16 19 * @author Steffen Herbold 17 20 * @version 1.0 … … 19 22 public class CMDgenerateReplayfile implements Command { 20 23 21 /* (non-Javadoc) 24 /* 25 * (non-Javadoc) 26 * 22 27 * @see de.ugoe.cs.util.console.Command#help() 23 28 */ 24 29 @Override 25 30 public void help() { 26 Console.println("Usage: generateReplayfile <filename> {<sequences>}"); 31 Console.println("Usage: generateReplayfile <filename> {<sequences>}"); 27 32 } 28 33 29 /* (non-Javadoc) 34 /* 35 * (non-Javadoc) 36 * 30 37 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 31 38 */ … … 33 40 @Override 34 41 public void run(List<Object> parameters) { 35 if ( parameters.size() < 1) {42 if (parameters.size() < 1) { 36 43 throw new InvalidParameterException(); 37 44 } 38 45 String filename = (String) parameters.get(0); 39 46 String sequencesName = "sequences"; 40 if ( parameters.size()==2) {47 if (parameters.size() == 2) { 41 48 sequencesName = (String) parameters.get(1); 42 49 } 43 50 44 51 Collection<List<ReplayableEvent<?>>> sequences = null; 45 Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName); 46 47 try { 48 sequences = (Collection<List<ReplayableEvent<?>>>) dataObject; 49 ReplayGenerator generator = new ReplayGenerator(); 50 if( sequences!=null && sequences.size()>0 && sequences.iterator().next().get(0) instanceof Event ) { 51 generator.createLogfileMultipleSessions(sequences, filename); 52 } else { 53 Console.printerrln("Loaded data not are not sequences!"); 54 if( sequencesName.equals("sequences") ) { 55 Console.traceln("Illegal use of \"sequences\" parameter in the GlobalDataContainer."); 56 Console.traceln("The parameter should always be of type Collection<List<Event>>!"); 57 } 58 } 52 Object dataObject = GlobalDataContainer.getInstance().getData( 53 sequencesName); 54 if (dataObject == null) { 55 Console.println("Object " + sequencesName 56 + " not found in storage."); 57 return; 59 58 } 60 catch(ClassCastException e) { 61 Console.printerrln("Sequences not found"); 59 if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) { 60 Console.println("Object " + sequencesName 61 + "not of type Collection<List<Event<?>>>."); 62 return; 62 63 } 63 64 65 sequences = (Collection<List<ReplayableEvent<?>>>) dataObject; 66 ReplayGenerator generator = new ReplayGenerator(); 67 generator.createLogfileMultipleSessions(sequences, filename); 64 68 } 65 69 -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDlistSymbols.java
r179 r209 44 44 if (dataObject == null) { 45 45 Console.println("Model " + modelname + "not found in storage."); 46 } else if (!(dataObject instanceof IStochasticProcess)) { 46 return; 47 } 48 if (!(dataObject instanceof IStochasticProcess)) { 47 49 Console.println("Object " + modelname 48 50 + " is not a stochastic process!"); 49 } else {50 model = (IStochasticProcess) dataObject;51 String[] stateStrings = model.getSymbolStrings();52 if (sort) {53 Arrays.sort(stateStrings);54 }55 for (String stateString : stateStrings) {56 Console.println(stateString);57 }51 return; 52 } 53 model = (IStochasticProcess) dataObject; 54 String[] stateStrings = model.getSymbolStrings(); 55 if (sort) { 56 Arrays.sort(stateStrings); 57 } 58 for (String stateString : stateStrings) { 59 Console.println(stateString); 58 60 } 59 61 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDload.java
r171 r209 43 43 in.close(); 44 44 } catch (IOException ex) { 45 ex.printStackTrace();45 Console.printStacktrace(ex); 46 46 } catch (ClassNotFoundException ex) { 47 ex.printStackTrace();47 Console.printStacktrace(ex); 48 48 } 49 49 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDloadObject.java
r171 r209 47 47 in.close(); 48 48 } catch (IOException ex) { 49 ex.printStackTrace();49 Console.printStacktrace(ex); 50 50 } catch (ClassNotFoundException ex) { 51 ex.printStackTrace();51 Console.printStacktrace(ex); 52 52 } 53 53 if (GlobalDataContainer.getInstance().addData(objectName, data)) { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDprintDot.java
r171 r209 49 49 if (dataObject == null) { 50 50 Console.println("Model " + modelname + "not found in storage."); 51 } else if (!(dataObject instanceof IDotCompatible)) { 51 return; 52 } 53 if (!(dataObject instanceof IDotCompatible)) { 52 54 Console.println("Object " + modelname 53 55 + " does not implement IDotCompatible!"); 54 } else { 55 model = (IDotCompatible) dataObject; 56 Console.println(model.getDotRepresentation()); 56 return; 57 57 } 58 59 model = (IDotCompatible) dataObject; 60 Console.println(model.getDotRepresentation()); 58 61 } 59 62 -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDprintRandomSession.java
r171 r209 49 49 if (dataObject == null) { 50 50 Console.println("Model " + modelname + " not found in storage."); 51 } else if (!(dataObject instanceof IStochasticProcess)) { 51 return; 52 } 53 if (!(dataObject instanceof IStochasticProcess)) { 52 54 Console.println("Object " + modelname + " not of type MarkovModel!"); 53 } else { 54 model = (IStochasticProcess) dataObject; 55 for (Event<?> event : model.randomSequence()) { 56 Console.println(event.toString()); 57 } 55 return; 56 } 57 58 model = (IStochasticProcess) dataObject; 59 for (Event<?> event : model.randomSequence()) { 60 Console.println(event.toString()); 58 61 } 59 62 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDprintTrieDot.java
r171 r209 50 50 if (dataObject == null) { 51 51 Console.println("Model " + modelname + "not found in storage."); 52 } else if (!(dataObject instanceof TrieBasedModel)) { 52 return; 53 } 54 if (!(dataObject instanceof TrieBasedModel)) { 53 55 Console.println("Object " + modelname + " is not a TrieBasedModel!"); 54 } else { 55 model = (TrieBasedModel) dataObject; 56 Console.println(model.getTrieDotRepresentation()); 56 return; 57 57 } 58 59 model = (TrieBasedModel) dataObject; 60 Console.println(model.getTrieDotRepresentation()); 58 61 } 59 62 -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDsave.java
r171 r209 43 43 out.close(); 44 44 } catch (IOException ex) { 45 ex.printStackTrace();45 Console.printStacktrace(ex); 46 46 } 47 47 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDsaveObject.java
r171 r209 52 52 out.close(); 53 53 } catch (IOException ex) { 54 ex.printStackTrace();54 Console.printStacktrace(ex); 55 55 } 56 56 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDsequenceStatistics.java
r203 r209 7 7 import java.util.TreeMap; 8 8 9 import de.ugoe.cs.eventbench.SequenceInstanceOf; 9 10 import de.ugoe.cs.eventbench.data.Event; 10 11 import de.ugoe.cs.eventbench.data.GlobalDataContainer; … … 39 40 Object dataObject = GlobalDataContainer.getInstance().getData( 40 41 sequencesName); 42 if (dataObject == null) { 43 Console.println("Object " + sequencesName 44 + " not found in storage."); 45 return; 46 } 47 if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) { 48 Console.println("Object " + sequencesName 49 + "not of type Collection<List<Event<?>>>."); 50 return; 51 } 41 52 42 try { 43 sequences = (Collection<List<Event<?>>>) dataObject; 44 Console.traceln("Number of Sequences: " + sequences.size()); 45 SortedMap<Integer, Integer> lengthMap = new TreeMap<Integer, Integer>(); 46 for (List<Event<?>> sequence : sequences) { 47 Integer currentSize = sequence.size(); 48 if (lengthMap.containsKey(currentSize)) { 49 lengthMap.put(currentSize, lengthMap.get(currentSize) + 1); 50 } else { 51 lengthMap.put(currentSize, 1); 52 } 53 sequences = (Collection<List<Event<?>>>) dataObject; 54 Console.traceln("Number of Sequences: " + sequences.size()); 55 SortedMap<Integer, Integer> lengthMap = new TreeMap<Integer, Integer>(); 56 for (List<Event<?>> sequence : sequences) { 57 Integer currentSize = sequence.size(); 58 if (lengthMap.containsKey(currentSize)) { 59 lengthMap.put(currentSize, lengthMap.get(currentSize) + 1); 60 } else { 61 lengthMap.put(currentSize, 1); 53 62 } 54 for (Entry<Integer, Integer> entry : lengthMap.entrySet()) { 55 Console.traceln("Of length " + entry.getKey() + ": " 56 + entry.getValue()); 57 } 58 59 } catch (ClassCastException e) { 60 Console.println("Sequences not found"); 63 } 64 for (Entry<Integer, Integer> entry : lengthMap.entrySet()) { 65 Console.traceln("Of length " + entry.getKey() + ": " 66 + entry.getValue()); 61 67 } 62 68 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDshowMarkovModel.java
r171 r209 65 65 .getData(modelname); 66 66 if (dataObject == null) { 67 Console.printerrln("No model with name " + modelname + "found"); 68 } else { 69 FirstOrderMarkovModel mm = (FirstOrderMarkovModel) dataObject; 67 Console.println("Object " + modelname + " not found in storage."); 68 return; 69 } 70 if (!(dataObject instanceof FirstOrderMarkovModel)) { 71 Console.println("Object " + modelname 72 + "not of type FirstOrderMarkovModel."); 73 return; 74 } 75 FirstOrderMarkovModel mm = (FirstOrderMarkovModel) dataObject; 70 76 71 72 73 74 75 76 77 78 79 80 81 77 Graph<String, MarkovEdge> graph = mm.getGraph(); 78 Layout<String, MarkovEdge> layout = new ISOMLayout<String, MarkovEdge>( 79 graph); 80 layout.setSize(new Dimension(1000, 800)); // sets the initial size 81 // of the space 82 // The BasicVisualizationServer<V,E> is parameterized by the edge 83 // types 84 BasicVisualizationServer<String, MarkovEdge> vv = new BasicVisualizationServer<String, MarkovEdge>( 85 layout); 86 vv.setPreferredSize(new Dimension(1100, 850)); // Sets the viewing 87 // area size 82 88 83 84 89 if (showNodeNames) { 90 final Rectangle rect = new Rectangle(240, 20); 85 91 86 87 88 89 90 91 92 93 94 95 96 97 92 Transformer<String, Shape> vertexShapeTransformer = new Transformer<String, Shape>() { 93 public Shape transform(String s) { 94 return rect; 95 } 96 }; 97 vv.getRenderer().getVertexLabelRenderer() 98 .setPosition(Position.CNTR); 99 vv.getRenderContext().setVertexShapeTransformer( 100 vertexShapeTransformer); 101 vv.getRenderContext().setVertexLabelTransformer( 102 new ToStringLabeller<String>()); 103 } 98 104 99 100 105 vv.getRenderContext().setEdgeLabelTransformer( 106 new ToStringLabeller<MarkovEdge>()); 101 107 102 JFrame frame = new JFrame("Markov Model"); 103 frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 104 frame.getContentPane().add(vv); 105 frame.pack(); 106 frame.setVisible(true); 107 } 108 JFrame frame = new JFrame("Markov Model"); 109 frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 110 frame.getContentPane().add(vv); 111 frame.pack(); 112 frame.setVisible(true); 108 113 } 109 114 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDshowTrie.java
r171 r209 62 62 .getData(modelname); 63 63 if (dataObject == null) { 64 Console.printerrln("No model with name " + modelname + "found"); 65 } else { 66 TrieBasedModel model = (TrieBasedModel) dataObject; 67 Tree<TrieVertex, Edge> graph = model.getTrieGraph(); 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 64 Console.printerrln("Object " + modelname + " not found in storage."); 65 return; 66 } 67 if (!(dataObject instanceof TrieBasedModel)) { 68 Console.printerr("Object " + modelname 69 + " not of type TrieBasedModel."); 70 } 71 TrieBasedModel model = (TrieBasedModel) dataObject; 72 Tree<TrieVertex, Edge> graph = model.getTrieGraph(); 73 Layout<TrieVertex, Edge> layout = new TreeLayout<TrieVertex, Edge>( 74 graph, 60); 75 // The BasicVisualizationServer<V,E> is parameterized by the edge 76 // types 77 BasicVisualizationServer<TrieVertex, Edge> vv = new BasicVisualizationServer<TrieVertex, Edge>( 78 layout); 79 vv.setPreferredSize(new Dimension(1100, 850)); // Sets the viewing 80 // area size 76 81 77 82 final Rectangle rect = new Rectangle(40, 20); 78 83 79 Transformer<TrieVertex, Shape> vertexShapeTransformer = new Transformer<TrieVertex, Shape>() { 80 public Shape transform(TrieVertex s) { 81 return rect; 82 } 83 }; 84 vv.getRenderer().getVertexLabelRenderer() 85 .setPosition(Position.CNTR); 86 vv.getRenderContext().setVertexShapeTransformer( 87 vertexShapeTransformer); 88 vv.getRenderContext().setVertexLabelTransformer( 89 new ToStringLabeller<TrieVertex>()); 84 Transformer<TrieVertex, Shape> vertexShapeTransformer = new Transformer<TrieVertex, Shape>() { 85 public Shape transform(TrieVertex s) { 86 return rect; 87 } 88 }; 89 vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR); 90 vv.getRenderContext().setVertexShapeTransformer(vertexShapeTransformer); 91 vv.getRenderContext().setVertexLabelTransformer( 92 new ToStringLabeller<TrieVertex>()); 90 93 91 JFrame frame = new JFrame("Trie"); 92 frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 93 frame.getContentPane().add(vv); 94 frame.pack(); 95 frame.setVisible(true); 96 } 94 JFrame frame = new JFrame("Trie"); 95 frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 96 frame.getContentPane().add(vv); 97 frame.pack(); 98 frame.setVisible(true); 97 99 } 98 100 -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDupdateModel.java
r203 r209 5 5 import java.util.List; 6 6 7 import de.ugoe.cs.eventbench.SequenceInstanceOf; 7 8 import de.ugoe.cs.eventbench.data.Event; 8 9 import de.ugoe.cs.eventbench.data.GlobalDataContainer; … … 39 40 } 40 41 41 Collection<List<Event<?>>> sequences = null;42 42 Object dataObject = GlobalDataContainer.getInstance().getData( 43 43 sequencesName); … … 47 47 return; 48 48 } 49 try { 50 sequences = (Collection<List<Event<?>>>) dataObject; 51 } catch (ClassCastException e) { 52 Console.println("Object " + sequencesName 53 + "not of type Collection<List<Event<?>>>."); 54 } 55 if (sequences.size() == 0 56 || !(sequences.iterator().next().get(0) instanceof Event)) { 49 if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) { 57 50 Console.println("Object " + sequencesName 58 51 + "not of type Collection<List<Event<?>>>."); 59 52 return; 60 53 } 54 Collection<List<Event<?>>> sequences = (Collection<List<Event<?>>>) dataObject; 61 55 62 56 dataObject = GlobalDataContainer.getInstance().getData(modelname); 63 57 if (dataObject == null) { 64 Console.println(" Model" + modelname + " not found in storage.");58 Console.println("Object " + modelname + " not found in storage."); 65 59 return; 66 60 } 67 61 if (!(dataObject instanceof TrieBasedModel)) { 68 62 Console.println("Object " + modelname 69 + " not of type TrieBasedModel !");63 + " not of type TrieBasedModel"); 70 64 return; 71 65 } 66 72 67 TrieBasedModel model = (TrieBasedModel) dataObject; 73 68 model.update(sequences); -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/data/GlobalDataContainer.java
r191 r209 8 8 import java.util.HashMap; 9 9 import java.util.LinkedList; 10 import java.util.List;11 10 import java.util.Map; 12 11 import java.util.Map.Entry; 13 12 13 import de.ugoe.cs.eventbench.SequenceInstanceOf; 14 14 import de.ugoe.cs.eventbench.models.IStochasticProcess; 15 15 … … 188 188 Collection<String> allSequencesNames = new LinkedList<String>(); 189 189 for (Entry<String, Object> entry : dataObjects.entrySet()) { 190 if (entry.getValue() instanceof Collection<?>) { 191 Object listObj = ((Collection<?>) entry.getValue()).iterator() 192 .next(); 193 if (listObj instanceof List<?>) { 194 if (((List<?>) listObj).iterator().next() instanceof Event<?>) { 195 allSequencesNames.add(entry.getKey()); 196 } 197 } 190 if( SequenceInstanceOf.isCollectionOfSequences(entry.getValue())) { 191 allSequencesNames.add(entry.getKey()); 198 192 } 199 193 }
Note: See TracChangeset
for help on using the changeset viewer.