Class AbstractEvaluator

  • All Implemented Interfaces:
    adams.core.CleanUpHandler, adams.core.Destroyable, adams.core.GlobalInfoSupporter, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.option.OptionHandler, adams.core.ShallowCopySupporter<Evaluator>, adams.core.SizeOfHandler, Evaluator, Serializable, Comparable
    Direct Known Subclasses:
    AbstractSerializableEvaluator, FakeEvaluator, NullEvaluator

    public abstract class AbstractEvaluator
    extends adams.core.option.AbstractOptionHandler
    implements Evaluator
    Abstract base class for evaluator handling weka.core.Instance objects. Derived classes only have to override the check(Instance) method. The reset() method can be used to reset an algorithms internal state, e.g., after setting options.
    Version:
    $Revision: 2242 $
    Author:
    dale (dale at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String DEFAULT_METRIC
      the default metric.
      protected float m_MissingEvaluation
      the value to return in case no evaluation can be performed.
      • Fields inherited from class adams.core.option.AbstractOptionHandler

        m_OptionManager
      • Fields inherited from class adams.core.logging.LoggingObject

        m_Logger, m_LoggingIsEnabled, m_LoggingLevel
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      boolean build​(weka.core.Instances data)
      Performs the check.
      int compareTo​(Object o)
      Compares this object with the specified object for order.
      void defineOptions()
      Adds options to the internal list of options.
      boolean equals​(Object o)
      Returns whether the two objects are the same.
      HashMap<String,​Float> evaluate​(weka.core.Instance data)
      Performs the check.
      static AbstractEvaluator forCommandLine​(String cmdline)
      Instantiates the filter from the given commandline (i.e., classname and optional options).
      static AbstractEvaluator forName​(String classname, String[] options)
      Instantiates the filter with the given options.
      protected abstract float getDefaultMissingEvaluation()
      Returns the default value in case of missing evaluations.
      static String[] getEvaluators()
      Returns a list with classnames of filters.
      float getMissingEvaluation()
      Returns the replacement string for missing evaluations.
      String missingEvaluationTipText()
      Returns the tip text for this property.
      protected abstract boolean performBuild​(weka.core.Instances data)
      Builds the evaluator.
      protected Float performEvaluate​(weka.core.Instance data)
      Performs the actual evaluation.
      protected HashMap<String,​Float> performMultiEvaluate​(weka.core.Instance data)
      Performs the actual evaluation, allowing return of multiple evaluation metrics.
      protected void preCheck​(weka.core.Instance data)
      Performs the some pre-checks whether the data is actually suitable.
      protected void preCheck​(weka.core.Instances data)
      Performs the some pre-checks whether the data is actually suitable.
      void setMissingEvaluation​(float value)
      Sets the replacement string for missing evaluations.
      AbstractEvaluator shallowCopy()
      Returns a shallow copy of itself, i.e., based on the commandline options.
      AbstractEvaluator shallowCopy​(boolean expand)
      Returns a shallow copy of itself, i.e., based on the commandline options.
      • Methods inherited from class adams.core.option.AbstractOptionHandler

        cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, globalInfo, initialize, loggingLevelTipText, newOptionManager, reset, setLoggingLevel, toCommandLine, toString
      • Methods inherited from class adams.core.logging.LoggingObject

        configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
      • Methods inherited from interface adams.core.CleanUpHandler

        cleanUp
      • Methods inherited from interface adams.core.Destroyable

        destroy
      • Methods inherited from interface adams.core.logging.LoggingLevelHandler

        getLoggingLevel
      • Methods inherited from interface adams.core.option.OptionHandler

        cleanUpOptions, getOptionManager, toCommandLine
    • Field Detail

      • m_MissingEvaluation

        protected float m_MissingEvaluation
        the value to return in case no evaluation can be performed.
    • Constructor Detail

      • AbstractEvaluator

        public AbstractEvaluator()
    • Method Detail

      • defineOptions

        public void defineOptions()
        Adds options to the internal list of options.
        Specified by:
        defineOptions in interface adams.core.option.OptionHandler
        Overrides:
        defineOptions in class adams.core.option.AbstractOptionHandler
      • getDefaultMissingEvaluation

        protected abstract float getDefaultMissingEvaluation()
        Returns the default value in case of missing evaluations.
        Returns:
        the default value
      • setMissingEvaluation

        public void setMissingEvaluation​(float value)
        Sets the replacement string for missing evaluations.
        Specified by:
        setMissingEvaluation in interface Evaluator
        Parameters:
        value - the replacement
      • getMissingEvaluation

        public float getMissingEvaluation()
        Returns the replacement string for missing evaluations.
        Specified by:
        getMissingEvaluation in interface Evaluator
        Returns:
        the replacement
      • missingEvaluationTipText

        public String missingEvaluationTipText()
        Returns the tip text for this property.
        Specified by:
        missingEvaluationTipText in interface Evaluator
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • preCheck

        protected void preCheck​(weka.core.Instance data)
        Performs the some pre-checks whether the data is actually suitable. Data needs to be non-null and a class attribute defined.
        Parameters:
        data - the instance to check
      • preCheck

        protected void preCheck​(weka.core.Instances data)
        Performs the some pre-checks whether the data is actually suitable.
        Parameters:
        data - the instance to check
      • performEvaluate

        protected Float performEvaluate​(weka.core.Instance data)
        Performs the actual evaluation.

        Default implementation returns m_MissingEvaluation.
        Parameters:
        data - the instance to check
        Returns:
        evaluation metric, m_MissingEvaluation in case the class value is missing
      • performMultiEvaluate

        protected HashMap<String,​Float> performMultiEvaluate​(weka.core.Instance data)
        Performs the actual evaluation, allowing return of multiple evaluation metrics.

        Default implementation returns null.
        Parameters:
        data - the instance to check
        Returns:
        evaluation metrics, m_MissingEvaluation in case the class value is missing
      • performBuild

        protected abstract boolean performBuild​(weka.core.Instances data)
        Builds the evaluator.
        Parameters:
        data - the instance to check
        Returns:
        true if build successful
      • build

        public boolean build​(weka.core.Instances data)
        Performs the check.
        Specified by:
        build in interface Evaluator
        Parameters:
        data - the instances to check
        Returns:
        evaluation metric
      • compareTo

        public int compareTo​(Object o)
        Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

        Only compares the commandlines of the two objects.
        Specified by:
        compareTo in interface Comparable
        Parameters:
        o - the object to be compared.
        Returns:
        a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
        Throws:
        ClassCastException - if the specified object's type prevents it from being compared to this object.
      • equals

        public boolean equals​(Object o)
        Returns whether the two objects are the same.

        Only compares the commandlines of the two objects.
        Overrides:
        equals in class Object
        Parameters:
        o - the object to be compared
        Returns:
        true if the object is the same as this one
      • shallowCopy

        public AbstractEvaluator shallowCopy()
        Returns a shallow copy of itself, i.e., based on the commandline options.
        Specified by:
        shallowCopy in interface adams.core.ShallowCopySupporter<Evaluator>
        Returns:
        the shallow copy
      • shallowCopy

        public AbstractEvaluator shallowCopy​(boolean expand)
        Returns a shallow copy of itself, i.e., based on the commandline options.
        Specified by:
        shallowCopy in interface adams.core.ShallowCopySupporter<Evaluator>
        Parameters:
        expand - whether to expand variables to their current values
        Returns:
        the shallow copy
      • getEvaluators

        public static String[] getEvaluators()
        Returns a list with classnames of filters.
        Returns:
        the filter classnames
      • forName

        public static AbstractEvaluator forName​(String classname,
                                                String[] options)
        Instantiates the filter with the given options.
        Parameters:
        classname - the classname of the filter to instantiate
        options - the options for the filter
        Returns:
        the instantiated filter or null if an error occurred
      • forCommandLine

        public static AbstractEvaluator forCommandLine​(String cmdline)
        Instantiates the filter from the given commandline (i.e., classname and optional options).
        Parameters:
        cmdline - the classname (and optional options) of the filter to instantiate
        Returns:
        the instantiated filter or null if an error occurred