[434] | 1 | package de.ugoe.cs.quest.ui.commands;
|
---|
[209] | 2 |
|
---|
[1] | 3 | import java.security.InvalidParameterException;
|
---|
| 4 | import java.util.List;
|
---|
| 5 |
|
---|
[432] | 6 | import de.ugoe.cs.quest.CommandHelpers;
|
---|
[434] | 7 | import de.ugoe.cs.quest.ui.GlobalDataContainer;
|
---|
[433] | 8 | import de.ugoe.cs.quest.usageprofiles.FirstOrderMarkovModel;
|
---|
[1] | 9 | import de.ugoe.cs.util.console.Command;
|
---|
| 10 | import de.ugoe.cs.util.console.Console;
|
---|
| 11 |
|
---|
[171] | 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 | */
|
---|
[1] | 20 | public class CMDcalcEntropy implements Command {
|
---|
| 21 |
|
---|
[209] | 22 | /*
|
---|
| 23 | * (non-Javadoc)
|
---|
| 24 | *
|
---|
[171] | 25 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 26 | */
|
---|
[1] | 27 | @Override
|
---|
[664] | 28 | public String help() {
|
---|
| 29 | return "calcEntropy <modelname>";
|
---|
[1] | 30 | }
|
---|
| 31 |
|
---|
[209] | 32 | /*
|
---|
| 33 | * (non-Javadoc)
|
---|
| 34 | *
|
---|
[171] | 35 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 36 | */
|
---|
[1] | 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 | }
|
---|
[209] | 45 |
|
---|
| 46 | FirstOrderMarkovModel model = null;
|
---|
| 47 | Object dataObject = GlobalDataContainer.getInstance()
|
---|
| 48 | .getData(modelname);
|
---|
| 49 | if (dataObject == null) {
|
---|
[240] | 50 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
[209] | 51 | return;
|
---|
[1] | 52 | }
|
---|
[209] | 53 | if (!(dataObject instanceof FirstOrderMarkovModel)) {
|
---|
[240] | 54 | CommandHelpers.objectNotType(modelname, "FirstOrderMarkovModel");
|
---|
[209] | 55 | return;
|
---|
[1] | 56 | }
|
---|
[209] | 57 | model = (FirstOrderMarkovModel) dataObject;
|
---|
| 58 | double entropy = model.calcEntropy();
|
---|
| 59 | if (!Double.isNaN(entropy)) {
|
---|
| 60 | Console.println("entropy: " + entropy);
|
---|
| 61 | }
|
---|
[1] | 62 | }
|
---|
| 63 |
|
---|
| 64 | }
|
---|