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

Last change on this file since 92 was 82, checked in by sherbold, 14 years ago
  • output corrected
File size: 1.2 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
11public class CMDcalcEntropy implements Command {
12
13        @Override
14        public void help() {
15                Console.println("Usage: calcEntropy <modelname>");
16        }
17
18        @Override
19        public void run(List<Object> parameters) {
20                String modelname = "";
21                try {
22                        modelname = (String) parameters.get(0);
23                } catch (Exception e) {
24                        throw new InvalidParameterException();
25                }
26               
27                FirstOrderMarkovModel model = null;
28                Object dataObject = GlobalDataContainer.getInstance().getData(modelname);
29                if( dataObject==null ) {
30                        Console.println("Model " + modelname + "not found in storage.");
31                }
32                else if( !(dataObject instanceof FirstOrderMarkovModel) ) {
33                        Console.println("Object " + modelname + " is not a first-order Markov model!");
34                } else {
35                        model = (FirstOrderMarkovModel) dataObject;
36                        double entropy = model.calcEntropy();
37                        if( !Double.isNaN(entropy) ) {
38                                Console.println("entropy: " + entropy);
39                        }
40                }
41        }
42
43}
Note: See TracBrowser for help on using the repository browser.