weka.attributeSelection

## Class GreedyStepwise

- java.lang.Object
- - weka.attributeSelection.ASSearch
  - - weka.attributeSelection.GreedyStepwise

- All Implemented Interfaces:
    java.io.Serializable, RankedOutputSearch, StartSetHandler, OptionHandler, RevisionHandler

      public class GreedyStepwise
      extends ASSearch
      implements RankedOutputSearch, StartSetHandler, OptionHandler

  GreedyStepwise :
  Performs a greedy forward or backward search through the space of attribute subsets. May start with no/all attributes or from an arbitrary point in the space. Stops when the addition/deletion of any remaining attributes results in a decrease in evaluation. Can also produce a ranked list of attributes by traversing the space from one side to the other and recording the order that attributes are selected.

  Valid options are:

       -C
        Use conservative forward search

       -B
        Use a backward search instead of a
        forward one.

       -P <start set>
        Specify a starting set of attributes.
        Eg. 1,3,5-7.

       -R
        Produce a ranked list of attributes.

       -T <threshold>
        Specify a theshold by which attributes
        may be discarded from the ranking.
        Use in conjuction with -R

       -N <num to select>
        Specify number of attributes to select

       -num-slots <int>
        The number of execution slots, for example, the number of cores in the CPU. (default 1)

       -D
        Print debugging output

  Version:
    $Revision: 11227 $
  Author:
    Mark Hall
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `GreedyStepwise()` Constructor

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.String` | `conservativeForwardSelectionTipText()` Returns the tip text for this property
    `java.lang.String` | `debuggingOutputTipText()` Returns the tip text for this property
    `java.lang.String` | `generateRankingTipText()` Returns the tip text for this property
    `int` | `getCalculatedNumToSelect()` Gets the calculated number of attributes to retain.
    `boolean` | `getConservativeForwardSelection()` Gets whether conservative selection has been enabled
    `boolean` | `getDebuggingOutput()` Get whether to output debugging info to the console
    `boolean` | `getGenerateRanking()` Gets whether ranking has been requested.
    `int` | `getNumExecutionSlots()` Gets the number of threads.
    `int` | `getNumToSelect()` Gets the number of attributes to be retained.
    `java.lang.String[]` | `getOptions()` Gets the current settings of ReliefFAttributeEval.
    `java.lang.String` | `getRevision()` Returns the revision string.
    `boolean` | `getSearchBackwards()` Get whether to search backwards
    `java.lang.String` | `getStartSet()` Returns a list of attributes (and or attribute ranges) as a String
    `double` | `getThreshold()` Returns the threshold so that the AttributeSelection module can discard attributes from the ranking.
    `java.lang.String` | `globalInfo()` Returns a string describing this search method
    `java.util.Enumeration<Option>` | `listOptions()` Returns an enumeration describing the available options.
    `java.lang.String` | `numExecutionSlotsTipText()`
    `java.lang.String` | `numToSelectTipText()` Returns the tip text for this property
    `double[][]` | `rankedAttributes()` Produces a ranked list of attributes.
    `int[]` | `search(ASEvaluation ASEval, Instances data)` Searches the attribute subset space by forward selection.
    `java.lang.String` | `searchBackwardsTipText()` Returns the tip text for this property
    `void` | `setConservativeForwardSelection(boolean c)` Set whether attributes should continue to be added during a forward search as long as merit does not decrease
    `void` | `setDebuggingOutput(boolean d)` Set whether to output debugging info to the console
    `void` | `setGenerateRanking(boolean doRank)` Records whether the user has requested a ranked list of attributes.
    `void` | `setNumExecutionSlots(int nT)` Sets the number of threads
    `void` | `setNumToSelect(int n)` Specify the number of attributes to select from the ranked list (if generating a ranking).
    `void` | `setOptions(java.lang.String[] options)` Parses a given list of options.
    `void` | `setSearchBackwards(boolean back)` Set whether to search backwards instead of forwards
    `void` | `setStartSet(java.lang.String startSet)` Sets a starting set of attributes for the search.
    `void` | `setThreshold(double threshold)` Set the threshold by which the AttributeSelection module can discard attributes.
    `java.lang.String` | `startSetTipText()` Returns the tip text for this property
    `java.lang.String` | `thresholdTipText()` Returns the tip text for this property
    `java.lang.String` | `toString()` returns a description of the search.

    - ### Methods inherited from class weka.attributeSelection.ASSearch

      `forName, makeCopies`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### GreedyStepwise

          public GreedyStepwise()

      Constructor

  - ### Method Detail

    - #### globalInfo

          public java.lang.String globalInfo()

      Returns a string describing this search method
      Returns:
        a description of the search suitable for displaying in the explorer/experimenter gui

    - #### searchBackwardsTipText

          public java.lang.String searchBackwardsTipText()

      Returns the tip text for this property
      Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui

    - #### setSearchBackwards

          public void setSearchBackwards(boolean back)

      Set whether to search backwards instead of forwards
      Parameters:
        `back` - true to search backwards

    - #### getSearchBackwards

          public boolean getSearchBackwards()

      Get whether to search backwards
      Returns:
        true if the search will proceed backwards

    - #### thresholdTipText

          public java.lang.String thresholdTipText()

      Returns the tip text for this property
      Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui

    - #### setThreshold

          public void setThreshold(double threshold)

      Set the threshold by which the AttributeSelection module can discard attributes.
      Specified by:
        `setThreshold` in interface `RankedOutputSearch`
      Parameters:
        `threshold` - the threshold.

    - #### getThreshold

          public double getThreshold()

      Returns the threshold so that the AttributeSelection module can discard attributes from the ranking.
      Specified by:
        `getThreshold` in interface `RankedOutputSearch`
      Returns:
        a threshold by which to discard attributes

    - #### numToSelectTipText

          public java.lang.String numToSelectTipText()

      Returns the tip text for this property
      Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui

    - #### setNumToSelect

          public void setNumToSelect(int n)

      Specify the number of attributes to select from the ranked list (if generating a ranking). -1 indicates that all attributes are to be retained.
      Specified by:
        `setNumToSelect` in interface `RankedOutputSearch`
      Parameters:
        `n` - the number of attributes to retain

    - #### getNumToSelect

          public int getNumToSelect()

      Gets the number of attributes to be retained.
      Specified by:
        `getNumToSelect` in interface `RankedOutputSearch`
      Returns:
        the number of attributes to retain

    - #### getCalculatedNumToSelect

          public int getCalculatedNumToSelect()

      Gets the calculated number of attributes to retain. This is the actual number of attributes to retain. This is the same as getNumToSelect if the user specifies a number which is not less than zero. Otherwise it should be the number of attributes in the (potentially transformed) data.
      Specified by:
        `getCalculatedNumToSelect` in interface `RankedOutputSearch`

    - #### generateRankingTipText

          public java.lang.String generateRankingTipText()

      Returns the tip text for this property
      Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui

    - #### setGenerateRanking

          public void setGenerateRanking(boolean doRank)

      Records whether the user has requested a ranked list of attributes.
      Specified by:
        `setGenerateRanking` in interface `RankedOutputSearch`
      Parameters:
        `doRank` - true if ranking is requested

    - #### getGenerateRanking

          public boolean getGenerateRanking()

      Gets whether ranking has been requested. This is used by the AttributeSelection module to determine if rankedAttributes() should be called.
      Specified by:
        `getGenerateRanking` in interface `RankedOutputSearch`
      Returns:
        true if ranking has been requested.

    - #### startSetTipText

          public java.lang.String startSetTipText()

      Returns the tip text for this property
      Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui

    - #### setStartSet

          public void setStartSet(java.lang.String startSet)
                           throws java.lang.Exception

      Sets a starting set of attributes for the search. It is the search method's responsibility to report this start set (if any) in its toString() method.
      Specified by:
        `setStartSet` in interface `StartSetHandler`
      Parameters:
        `startSet` - a string containing a list of attributes (and or ranges), eg. 1,2,6,10-15.
      Throws:
        `java.lang.Exception` - if start set can't be set.

    - #### getStartSet

          public java.lang.String getStartSet()

      Returns a list of attributes (and or attribute ranges) as a String
      Specified by:
        `getStartSet` in interface `StartSetHandler`
      Returns:
        a list of attributes (and or attribute ranges)

    - #### conservativeForwardSelectionTipText

          public java.lang.String conservativeForwardSelectionTipText()

      Returns the tip text for this property
      Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui

    - #### setConservativeForwardSelection

          public void setConservativeForwardSelection(boolean c)

      Set whether attributes should continue to be added during a forward search as long as merit does not decrease
      Parameters:
        `c` - true if atts should continue to be atted

    - #### getConservativeForwardSelection

          public boolean getConservativeForwardSelection()

      Gets whether conservative selection has been enabled
      Returns:
        true if conservative forward selection is enabled

    - #### debuggingOutputTipText

          public java.lang.String debuggingOutputTipText()

      Returns the tip text for this property
      Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui

    - #### setDebuggingOutput

          public void setDebuggingOutput(boolean d)

      Set whether to output debugging info to the console
      Parameters:
        `d` - true if dubugging info is to be output

    - #### getDebuggingOutput

          public boolean getDebuggingOutput()

      Get whether to output debugging info to the console
      Returns:
        true if dubugging info is to be output

    - #### numExecutionSlotsTipText

          public java.lang.String numExecutionSlotsTipText()

      Returns:
        a string to describe the option

    - #### getNumExecutionSlots

          public int getNumExecutionSlots()

      Gets the number of threads.

    - #### setNumExecutionSlots

          public void setNumExecutionSlots(int nT)

      Sets the number of threads

    - #### listOptions

          public java.util.Enumeration<Option> listOptions()

      Returns an enumeration describing the available options.
      Specified by:
        `listOptions` in interface `OptionHandler`
      Returns:
        an enumeration of all the available options.

    - #### setOptions

          public void setOptions(java.lang.String[] options)
                          throws java.lang.Exception

      Parses a given list of options.

      Valid options are:

           -C
            Use conservative forward search

           -B
            Use a backward search instead of a
            forward one.

           -P <start set>
            Specify a starting set of attributes.
            Eg. 1,3,5-7.

           -R
            Produce a ranked list of attributes.

           -T <threshold>
            Specify a theshold by which attributes
            may be discarded from the ranking.
            Use in conjuction with -R

           -N <num to select>
            Specify number of attributes to select

           -num-slots <int>
            The number of execution slots, for example, the number of cores in the CPU. (default 1)

           -D
            Print debugging output

      Specified by:
        `setOptions` in interface `OptionHandler`
      Parameters:
        `options` - the list of options as an array of strings
      Throws:
        `java.lang.Exception` - if an option is not supported

    - #### getOptions

          public java.lang.String[] getOptions()

      Gets the current settings of ReliefFAttributeEval.
      Specified by:
        `getOptions` in interface `OptionHandler`
      Returns:
        an array of strings suitable for passing to setOptions()

    - #### toString

          public java.lang.String toString()

      returns a description of the search.
      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        a description of the search as a String.

    - #### search

          public int[] search(ASEvaluation ASEval,
                     Instances data)
                       throws java.lang.Exception

      Searches the attribute subset space by forward selection.
      Specified by:
        `search` in class `ASSearch`
      Parameters:
        `ASEval` - the attribute evaluator to guide the search
        `data` - the training instances.
      Returns:
        an array (not necessarily ordered) of selected attribute indexes
      Throws:
        `java.lang.Exception` - if the search can't be completed

    - #### rankedAttributes

          public double[][] rankedAttributes()
                                      throws java.lang.Exception

      Produces a ranked list of attributes. Search must have been performed prior to calling this function. Search is called by this function to complete the traversal of the the search space. A list of attributes and merits are returned. The attributes a ranked by the order they are added to the subset during a forward selection search. Individual merit values reflect the merit associated with adding the corresponding attribute to the subset; because of this, merit values may initially increase but then decrease as the best subset is "passed by" on the way to the far side of the search space.
      Specified by:
        `rankedAttributes` in interface `RankedOutputSearch`
      Returns:
        an array of attribute indexes and associated merit values
      Throws:
        `java.lang.Exception` - if something goes wrong.

    - #### getRevision

          public java.lang.String getRevision()

      Returns the revision string.
      Specified by:
        `getRevision` in interface `RevisionHandler`
      Overrides:
        `getRevision` in class `ASSearch`
      Returns:
        the revision