1 | package de.ugoe.cs.eventbench.commands;
|
---|
2 |
|
---|
3 | import java.security.InvalidParameterException;
|
---|
4 | import java.util.List;
|
---|
5 | import java.util.Random;
|
---|
6 |
|
---|
7 | import de.ugoe.cs.eventbench.data.Event;
|
---|
8 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
9 | import de.ugoe.cs.eventbench.models.PredictionByPartialMatch;
|
---|
10 | import de.ugoe.cs.util.console.Command;
|
---|
11 | import de.ugoe.cs.util.console.Console;
|
---|
12 |
|
---|
13 | public class CMDtrainPPM implements Command {
|
---|
14 |
|
---|
15 | @Override
|
---|
16 | public void help() {
|
---|
17 | Console.println("Usage: trainPPM <modelName> <probEscape> <maxOrder> {<minOrder>}");
|
---|
18 | }
|
---|
19 |
|
---|
20 | @SuppressWarnings("unchecked")
|
---|
21 | @Override
|
---|
22 | public void run(List<Object> parameters) {
|
---|
23 | String modelname;
|
---|
24 | double probEscape;
|
---|
25 | int maxOrder;
|
---|
26 | int minOrder = 0;
|
---|
27 | try {
|
---|
28 | modelname = (String) parameters.get(0);
|
---|
29 | probEscape = Double.parseDouble((String) parameters.get(1));
|
---|
30 | maxOrder = Integer.parseInt((String) parameters.get(2));
|
---|
31 | if( parameters.size()==4 ) {
|
---|
32 | minOrder = Integer.parseInt((String) parameters.get(3));
|
---|
33 | }
|
---|
34 | } catch (Exception e) {
|
---|
35 | throw new InvalidParameterException();
|
---|
36 | }
|
---|
37 |
|
---|
38 | List<List<Event<?>>> sequences = null;
|
---|
39 | Object dataObject = GlobalDataContainer.getInstance().getData("sequences");
|
---|
40 |
|
---|
41 | try {
|
---|
42 | 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);
|
---|
46 | model.train(sequences);
|
---|
47 | if( GlobalDataContainer.getInstance().addData(modelname, model) ) {
|
---|
48 | Console.traceln("Old data \"" + modelname + "\" overwritten");
|
---|
49 | }
|
---|
50 | } else {
|
---|
51 | Console.traceln("Illegal use of \"sequences\" parameter in the GlobalDataContainer.");
|
---|
52 | Console.traceln("The parameter should always be of type List<List<Event>>!");
|
---|
53 | }
|
---|
54 | }
|
---|
55 | }
|
---|
56 | catch(ClassCastException e) {
|
---|
57 | Console.println("Sequences need to be loaded first using parseXML");
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | }
|
---|