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.ppm.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> <order>");
|
---|
18 | }
|
---|
19 |
|
---|
20 | @SuppressWarnings("unchecked")
|
---|
21 | @Override
|
---|
22 | public void run(List<Object> parameters) {
|
---|
23 | String modelname;
|
---|
24 | int order;
|
---|
25 | try {
|
---|
26 | modelname = (String) parameters.get(0);
|
---|
27 | order = Integer.parseInt((String) parameters.get(1));
|
---|
28 | } catch (Exception e) {
|
---|
29 | throw new InvalidParameterException();
|
---|
30 | }
|
---|
31 |
|
---|
32 | List<List<Event<?>>> sequences = null;
|
---|
33 | Object dataObject = GlobalDataContainer.getInstance().getData("sequences");
|
---|
34 |
|
---|
35 | try {
|
---|
36 | sequences = (List<List<Event<?>>>) dataObject;
|
---|
37 | if( sequences.size()>0 ) {
|
---|
38 | if( sequences.get(0).get(0) instanceof Event ) {
|
---|
39 | PredictionByPartialMatch model = new PredictionByPartialMatch(order, new Random());
|
---|
40 | model.train(sequences);
|
---|
41 | if( GlobalDataContainer.getInstance().addData(modelname, model) ) {
|
---|
42 | Console.traceln("Old model overwritten");
|
---|
43 | }
|
---|
44 | // TODO TMP!!
|
---|
45 | Console.traceln(model.randomSequence().toString());
|
---|
46 |
|
---|
47 | } else {
|
---|
48 | Console.traceln("Illegal use of \"sequences\" parameter in the GlobalDataContainer.");
|
---|
49 | Console.traceln("The parameter should always be of type List<List<Event>>!");
|
---|
50 | }
|
---|
51 | }
|
---|
52 | }
|
---|
53 | catch(ClassCastException e) {
|
---|
54 | Console.println("Sequences need to be loaded first using parseXML");
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | }
|
---|