Changeset 184 for trunk/EventBenchConsole
- Timestamp:
- 09/14/11 20:17:10 (13 years ago)
- Location:
- trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDtrainDFA.java
r171 r184 1 1 package de.ugoe.cs.eventbench.commands; 2 2 3 import java.security.InvalidParameterException;4 3 import java.util.List; 5 4 import java.util.Random; 6 5 7 import de.ugoe.cs.eventbench.data.Event;8 import de.ugoe.cs.eventbench.data.GlobalDataContainer;9 6 import de.ugoe.cs.eventbench.models.DeterministicFiniteAutomaton; 10 import de.ugoe.cs. util.console.Command;7 import de.ugoe.cs.eventbench.models.TrieBasedModel; 11 8 import de.ugoe.cs.util.console.Console; 12 9 … … 17 14 * 18 15 * @author Steffen Herbold 19 * @version 1.016 * @version 2.0 20 17 */ 21 public class CMDtrainDFA implementsCommand {18 public class CMDtrainDFA extends AbstractTrainCommand { 22 19 23 20 /* … … 28 25 @Override 29 26 public void help() { 30 Console.println("Usage: trainDFA <modelName>"); 27 Console.println("Usage: trainDFA <modelName> <sequencesName>"); 28 } 29 30 /** 31 * <p> 32 * No additional parameters. 33 * </p> 34 * 35 * @see de.ugoe.cs.eventbench.commands.AbstractTrainCommand#handleAdditionalParameters(java.util.List) 36 */ 37 @Override 38 void handleAdditionalParameters(List<Object> parameters) throws Exception { 39 // no additional parameters. 31 40 } 32 41 … … 34 43 * (non-Javadoc) 35 44 * 36 * @see de.ugoe.cs. util.console.Command#run(java.util.List)45 * @see de.ugoe.cs.eventbench.commands.AbstractTrainCommand#createModel() 37 46 */ 38 @SuppressWarnings("unchecked")39 47 @Override 40 public void run(List<Object> parameters) { 41 String modelname; 42 try { 43 modelname = (String) parameters.get(0); 44 } catch (Exception e) { 45 throw new InvalidParameterException(); 46 } 47 48 List<List<Event<?>>> sequences = null; 49 Object dataObject = GlobalDataContainer.getInstance().getData( 50 "sequences"); 51 52 try { 53 sequences = (List<List<Event<?>>>) dataObject; 54 if (sequences.size() > 0) { 55 if (sequences.get(0).get(0) instanceof Event) { 56 DeterministicFiniteAutomaton model = new DeterministicFiniteAutomaton( 57 new Random()); 58 model.train(sequences); 59 if (GlobalDataContainer.getInstance().addData(modelname, 60 model)) { 61 Console.traceln("Old data \"" + modelname 62 + "\" overwritten"); 63 } 64 } else { 65 Console.traceln("Illegal use of \"sequences\" parameter in the GlobalDataContainer."); 66 Console.traceln("The parameter should always be of type List<List<? extends Event<?>>!"); 67 } 68 } 69 } catch (ClassCastException e) { 70 Console.println("Sequences need to be loaded first using parseXML"); 71 } 48 TrieBasedModel createModel() { 49 return new DeterministicFiniteAutomaton(new Random()); 72 50 } 73 51 -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDtrainMarkovModel.java
r171 r184 1 1 package de.ugoe.cs.eventbench.commands; 2 2 3 import java.security.InvalidParameterException;4 3 import java.util.List; 5 4 import java.util.Random; 6 5 7 import de.ugoe.cs.eventbench.data.Event;8 import de.ugoe.cs.eventbench.data.GlobalDataContainer;9 6 import de.ugoe.cs.eventbench.models.FirstOrderMarkovModel; 10 7 import de.ugoe.cs.eventbench.models.HighOrderMarkovModel; 11 import de.ugoe.cs. util.console.Command;8 import de.ugoe.cs.eventbench.models.TrieBasedModel; 12 9 import de.ugoe.cs.util.console.Console; 13 10 … … 18 15 * 19 16 * @author Steffen Herbold 20 * @version 1.017 * @version 2.0 21 18 */ 22 public class CMDtrainMarkovModel implements Command { 19 public class CMDtrainMarkovModel extends AbstractTrainCommand { 20 21 /** 22 * <p> 23 * Order of the Markov model. 24 * </p> 25 */ 26 int order; 23 27 24 28 /* … … 29 33 @Override 30 34 public void help() { 31 Console.println("Usage: trainMarkovModel <modelName> {<order>}"); 35 Console.println("Usage: trainMarkovModel <modelName> <sequencesName> {<order>}"); 36 } 37 38 /** 39 * <p> 40 * Handles the parameter order. 41 * </p> 42 * 43 * @see de.ugoe.cs.eventbench.commands.AbstractTrainCommand#handleOptionalParameters(java.util.List) 44 */ 45 @Override 46 void handleAdditionalParameters(List<Object> parameters) throws Exception { 47 if (parameters.size() >= 3) { 48 order = Integer.parseInt((String) parameters.get(2)); 49 } 32 50 } 33 51 … … 35 53 * (non-Javadoc) 36 54 * 37 * @see de.ugoe.cs. util.console.Command#run(java.util.List)55 * @see de.ugoe.cs.eventbench.commands.AbstractTrainCommand#createModel() 38 56 */ 39 @SuppressWarnings("unchecked")40 57 @Override 41 public void run(List<Object> parameters) { 42 String modelname; 43 int order = 1; 44 try { 45 modelname = (String) parameters.get(0); 46 if (parameters.size() == 2) { 47 order = Integer.parseInt((String) parameters.get(1)); 48 } 49 } catch (Exception e) { 50 throw new InvalidParameterException(); 51 } 52 53 List<List<Event<?>>> sequences = null; 54 Object dataObject = GlobalDataContainer.getInstance().getData( 55 "sequences"); 56 57 try { 58 sequences = (List<List<Event<?>>>) dataObject; 59 if (sequences.size() > 0) { 60 if (sequences.get(0).get(0) instanceof Event) { 61 HighOrderMarkovModel model; 62 if (order == 1) { 63 model = new FirstOrderMarkovModel(new Random()); 64 } else { 65 model = new HighOrderMarkovModel(order, new Random()); 66 } 67 model.train(sequences); 68 if (GlobalDataContainer.getInstance().addData(modelname, 69 model)) { 70 Console.traceln("Old data \"" + modelname 71 + "\" overwritten"); 72 } 73 } else { 74 Console.traceln("Illegal use of \"sequences\" parameter in the GlobalDataContainer."); 75 Console.traceln("The parameter should always be of type List<List<Event>>!"); 76 } 77 } 78 } catch (ClassCastException e) { 79 Console.println("Sequences need to be loaded first using parseXML"); 58 TrieBasedModel createModel() { 59 if (order == 1) { 60 return new FirstOrderMarkovModel(new Random()); 61 } else { 62 return new HighOrderMarkovModel(order, new Random()); 80 63 } 81 64 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDtrainPPM.java
r171 r184 1 1 package de.ugoe.cs.eventbench.commands; 2 2 3 import java.security.InvalidParameterException;4 3 import java.util.List; 5 4 import java.util.Random; 6 5 7 import de.ugoe.cs.eventbench.data.Event;8 import de.ugoe.cs.eventbench.data.GlobalDataContainer;9 6 import de.ugoe.cs.eventbench.models.PredictionByPartialMatch; 10 import de.ugoe.cs. util.console.Command;7 import de.ugoe.cs.eventbench.models.TrieBasedModel; 11 8 import de.ugoe.cs.util.console.Console; 12 9 … … 17 14 * 18 15 * @author Steffen Herbold 19 * @version 1.016 * @version 2.0 20 17 */ 21 public class CMDtrainPPM implements Command { 18 public class CMDtrainPPM extends AbstractTrainCommand { 19 20 /** 21 * <p> 22 * Escape probability of the PPM model. 23 * </p> 24 */ 25 double probEscape; 26 27 /** 28 * <p> 29 * Maximal Markov order of the PPM model. 30 * </p> 31 */ 32 int maxOrder; 33 34 /** 35 * <p> 36 * Minimal Markov order of the PPM model. Default: 0 37 * </p> 38 */ 39 int minOrder = 0; 22 40 23 41 /* … … 28 46 @Override 29 47 public void help() { 30 Console.println("Usage: trainPPM <modelName> <probEscape> <maxOrder> {<minOrder>}"); 48 Console.println("Usage: trainPPM <modelName> <sequencesName> <probEscape> <maxOrder> {<minOrder>}"); 49 } 50 51 /** 52 * <p> 53 * Handles the parameters probEscape, maxOrder, and minOrder. 54 * </p> 55 * 56 * @see de.ugoe.cs.eventbench.commands.AbstractTrainCommand#handleOptionalParameters(java.util.List) 57 */ 58 @Override 59 void handleAdditionalParameters(List<Object> parameters) throws Exception { 60 probEscape = Double.parseDouble((String) parameters.get(2)); 61 maxOrder = Integer.parseInt((String) parameters.get(3)); 62 if (parameters.size() == 5) { 63 minOrder = Integer.parseInt((String) parameters.get(4)); 64 } 31 65 } 32 66 … … 34 68 * (non-Javadoc) 35 69 * 36 * @see de.ugoe.cs. util.console.Command#run(java.util.List)70 * @see de.ugoe.cs.eventbench.commands.AbstractTrainCommand#createModel() 37 71 */ 38 @SuppressWarnings("unchecked")39 72 @Override 40 public void run(List<Object> parameters) { 41 String modelname; 42 double probEscape; 43 int maxOrder; 44 int minOrder = 0; 45 try { 46 modelname = (String) parameters.get(0); 47 probEscape = Double.parseDouble((String) parameters.get(1)); 48 maxOrder = Integer.parseInt((String) parameters.get(2)); 49 if (parameters.size() == 4) { 50 minOrder = Integer.parseInt((String) parameters.get(3)); 51 } 52 } catch (Exception e) { 53 throw new InvalidParameterException(); 54 } 55 56 List<List<Event<?>>> sequences = null; 57 Object dataObject = GlobalDataContainer.getInstance().getData( 58 "sequences"); 59 60 try { 61 sequences = (List<List<Event<?>>>) dataObject; 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); 66 model.train(sequences); 67 if (GlobalDataContainer.getInstance().addData(modelname, 68 model)) { 69 Console.traceln("Old data \"" + modelname 70 + "\" overwritten"); 71 } 72 } else { 73 Console.traceln("Illegal use of \"sequences\" parameter in the GlobalDataContainer."); 74 Console.traceln("The parameter should always be of type List<List<Event>>!"); 75 } 76 } 77 } catch (ClassCastException e) { 78 Console.println("Sequences need to be loaded first using parseXML"); 79 } 73 TrieBasedModel createModel() { 74 return new PredictionByPartialMatch(maxOrder, minOrder, new Random(), 75 probEscape); 80 76 } 81 77
Note: See TracChangeset
for help on using the changeset viewer.