1 | package de.ugoe.cs.eventbench.commands;
|
---|
2 |
|
---|
3 | import java.security.InvalidParameterException;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
7 | import de.ugoe.cs.eventbench.models.FirstOrderMarkovModel;
|
---|
8 | import de.ugoe.cs.util.console.Command;
|
---|
9 | import de.ugoe.cs.util.console.Console;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * <p>
|
---|
13 | * Command to calculate the entropy of first-order Markov models.
|
---|
14 | * </p>
|
---|
15 | *
|
---|
16 | * @author Steffen Herbold
|
---|
17 | * @version 1.0
|
---|
18 | */
|
---|
19 | public class CMDcalcEntropy implements Command {
|
---|
20 |
|
---|
21 | /*
|
---|
22 | * (non-Javadoc)
|
---|
23 | *
|
---|
24 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
25 | */
|
---|
26 | @Override
|
---|
27 | public void help() {
|
---|
28 | Console.println("Usage: calcEntropy <modelname>");
|
---|
29 | }
|
---|
30 |
|
---|
31 | /*
|
---|
32 | * (non-Javadoc)
|
---|
33 | *
|
---|
34 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
35 | */
|
---|
36 | @Override
|
---|
37 | public void run(List<Object> parameters) {
|
---|
38 | String modelname = "";
|
---|
39 | try {
|
---|
40 | modelname = (String) parameters.get(0);
|
---|
41 | } catch (Exception e) {
|
---|
42 | throw new InvalidParameterException();
|
---|
43 | }
|
---|
44 |
|
---|
45 | FirstOrderMarkovModel model = null;
|
---|
46 | Object dataObject = GlobalDataContainer.getInstance()
|
---|
47 | .getData(modelname);
|
---|
48 | if (dataObject == null) {
|
---|
49 | Console.println("Model " + modelname + "not found in storage.");
|
---|
50 | return;
|
---|
51 | }
|
---|
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);
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | }
|
---|