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

Last change on this file since 198 was 171, checked in by sherbold, 13 years ago
  • code documentation and formatting
File size: 1.5 KB
Line 
1package de.ugoe.cs.eventbench.commands;
2import java.security.InvalidParameterException;
3import java.util.List;
4
5import de.ugoe.cs.eventbench.data.GlobalDataContainer;
6import de.ugoe.cs.eventbench.models.FirstOrderMarkovModel;
7import de.ugoe.cs.util.console.Command;
8import de.ugoe.cs.util.console.Console;
9
10/**
11 * <p>
12 * Command to calculate the entropy of first-order Markov models.
13 * </p>
14 *
15 * @author Steffen Herbold
16 * @version 1.0
17 */
18public class CMDcalcEntropy implements Command {
19
20        /* (non-Javadoc)
21         * @see de.ugoe.cs.util.console.Command#help()
22         */
23        @Override
24        public void help() {
25                Console.println("Usage: calcEntropy <modelname>");
26        }
27
28        /* (non-Javadoc)
29         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
30         */
31        @Override
32        public void run(List<Object> parameters) {
33                String modelname = "";
34                try {
35                        modelname = (String) parameters.get(0);
36                } catch (Exception e) {
37                        throw new InvalidParameterException();
38                }
39               
40                FirstOrderMarkovModel model = null;
41                Object dataObject = GlobalDataContainer.getInstance().getData(modelname);
42                if( dataObject==null ) {
43                        Console.println("Model " + modelname + "not found in storage.");
44                }
45                else if( !(dataObject instanceof FirstOrderMarkovModel) ) {
46                        Console.println("Object " + modelname + " is not a first-order Markov model!");
47                } else {
48                        model = (FirstOrderMarkovModel) dataObject;
49                        double entropy = model.calcEntropy();
50                        if( !Double.isNaN(entropy) ) {
51                                Console.println("entropy: " + entropy);
52                        }
53                }
54        }
55
56}
Note: See TracBrowser for help on using the repository browser.