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