Creating Options to Pass Into GUI

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Creating Options to Pass Into GUI

Jordan Troutman
Hello,

I want to pass in a string to use as part of an evaluator I am creating, but I am having trouble with the implementation.  I have thus far implemented the getter, setter, and even added the option to the enumeration of the list of options.  But when I try to enter information into the GUI (or directly edit the configuration) my added option is not even being recognized.  It just disappears as if it was never inputted.  Any suggestions?

Thank you
Jordan

--
Jordan T. Troutman (LD49936) 
Computer Science and Mathematics 2021
Meyerhoff Scholar, M29
NSA Scholar
University of Maryland, Baltimore County (UMBC)
Pronouns: He, Him, His

_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to: To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit
https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Creating Options to Pass Into GUI

Eibe Frank-2
Administrator
Traditionally, in WEKA, to implement command-line option handling completely, you had to implement listOptions(), getOptions(), and setOptions(), i.e., all three methods from the OptionHandler interface.

However, in recent versions of WEKA, for most schemes, e.g. Classifier objects, it has been possible to use Java annotations to define command-line options to go along with the corresponding getters and setters for the GUI-based specification of option settings.

Unfortunately, this had not been implemented for attribute evaluation and search methods. We have rectified this in SVN, and the next nightly snapshots of WEKA (all relevant branches) will have the changes.

Appended at the bottom of this message is an example of an attribute evaluator that employs the @OptionMetadata annotation to define four command-line options to go along with the four get/set pairs for the GUI.

Here is an example of how to use this class:

public static void main(String[] args) {
 
 Instances data = (new weka.core.converters.ConverterUtils.DataSource("C:/Users/eibe/datasets/UCI/breast-cancer.arff")).getDataSet();
  data.setClassIndex(data.numAttributes() - 1);
  AttributeEvaluator ae = new PermutationTestAttributeEval();
  ae.setOptions(Utils.splitOptions("-evaluator .GainRatioAttributeEval -seed 2 -numTries 2000 -significanceLevel 0.01"));
  ae.buildEvaluator(data);
  for (int i = 0; i < data.numAttributes(); i++) {
    if (i != data.classIndex()) {
      System.out.print(data.attribute(i).name() + "\t");
      System.out.println(ae.evaluateAttribute(i));
    }
  }
}

Cheers,
Eibe

package weka.attributeSelection;

import weka.core.*;

public class PermutationTestAttributeEval extends ASEvaluation implements AttributeEvaluator {
 
    protected double[] scores;
   
    protected int numTries = 1000;
    protected double significanceLevel = 0.05;
    protected int seed = 1;
    protected AttributeEvaluator evaluator = new InfoGainAttributeEval();

    @OptionMetadata(displayName = "Attribute evaluator",
                    description = "Attribute evaluator to use in conjunction with permutation test.",
                    commandLineParamName = "evaluator",
                    commandLineParamSynopsis = "-evaluator <name of evaluator class>", displayOrder = 1)
    public AttributeEvaluator getAttributeEvaluator() { return evaluator; }
    public void setAttributeEvaluator(AttributeEvaluator e) { evaluator = e; }
   
    @OptionMetadata(displayName = "Number random permutations to be evaluated",
                    description = "The number of random permutations to use for estimating the p-value.",
                    commandLineParamName = "numTries",
                    commandLineParamSynopsis = "-numTries <int>", displayOrder = 2)
    public int getNumTries() { return numTries; }
    public void setNumTries(int n) { numTries = n; }
   
    @OptionMetadata(displayName = "Significance level",
                    description = "The significance level to use for the permutation test.",
                    commandLineParamName = "significanceLevel",
                    commandLineParamSynopsis = "-significanceLevel <double>", displayOrder = 3)
    public double getSignificanceLevel() { return significanceLevel; }
    public void setSignificanceLevel(double s) { significanceLevel = s; }
   
    @OptionMetadata(displayName = "Seed",
                    description = "The seed to use for the random number generator.",
                    commandLineParamName = "seed",
                    commandLineParamSynopsis = "-seed <int>", displayOrder = 4)
    public int getSeed() { return seed; }
    public void setSeed(int s) { seed = s; }

    public void buildEvaluator(Instances data) {
   
        scores = new double[data.numAttributes()];
        AttributeEvaluator eval = getAttributeEvaluator();
        eval.buildEvaluator(data);
        for (int i = 0; i < scores.length; i++) {
          if (i != data.classIndex()) {
            scores[i] = eval.evaluateAttribute(i);
          }
        }
       int[] countRandomBeatsObserved = new int[data.numAttributes()];
       Random random = new Random(getSeed())
       for (int j = 0; j < numTries; j++) {
          Instances randomData = new Instances(data);
          randomData.randomize(random);
          for (int i = 0; i < randomData.numInstances(); i++) {
            randomData.instance(i).setClassValue(data.instance(i).classValue());
          }
          eval = getAttributeEvaluator();
          eval.buildEvaluator(randomData);
          for (int i = 0; i < scores.length; i++) {
            if (i != data.classIndex()) {
              if (eval.evaluateAttribute(i) >= scores[i]) {
                countRandomBeatsObserved[i]++;
              }
            }
          }
        }  
        for (int i = 0; i < scores.length; i++) {
          if (i != data.classIndex()) {
            if ((double)countRandomBeatsObserved[i] / (double)numTries > getSignificanceLevel()) {
              scores[i] = -Double.MAX_VALUE;
            }
          }
        }
    }
   
    public double evaluateAttribute(int i) {
      return scores[i];
    }
}


On Mon, Dec 9, 2019 at 7:11 PM Jordan Troutman <[hidden email]> wrote:
Hello,

I want to pass in a string to use as part of an evaluator I am creating, but I am having trouble with the implementation.  I have thus far implemented the getter, setter, and even added the option to the enumeration of the list of options.  But when I try to enter information into the GUI (or directly edit the configuration) my added option is not even being recognized.  It just disappears as if it was never inputted.  Any suggestions?

Thank you
Jordan

--
Jordan T. Troutman (LD49936) 
Computer Science and Mathematics 2021
Meyerhoff Scholar, M29
NSA Scholar
University of Maryland, Baltimore County (UMBC)
Pronouns: He, Him, His
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to: To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit
https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to: To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit
https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html