source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDcalcEntropy.java @ 233

Last change on this file since 233 was 209, checked in by sherbold, 13 years ago
  • greatly improved type checking and consistency of type checking for objects checked out of the GlobalDataContainer?
File size: 1.5 KB
Line 
1package de.ugoe.cs.eventbench.commands;
2
3import java.security.InvalidParameterException;
4import java.util.List;
5
6import de.ugoe.cs.eventbench.data.GlobalDataContainer;
7import de.ugoe.cs.eventbench.models.FirstOrderMarkovModel;
8import de.ugoe.cs.util.console.Command;
9import 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 */
19public 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}
Note: See TracBrowser for help on using the repository browser.