Class WekaClassifierModelReader

  • All Implemented Interfaces:
    adams.core.Destroyable, adams.core.GlobalInfoSupporter, adams.core.io.FileFormatHandler, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.option.OptionHandler, adams.core.SizeOfHandler, Serializable

    public class WekaClassifierModelReader
    extends adams.data.io.input.AbstractObjectReader
    Reads Weka classifiers from serialized files.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int m_Iterations
      the number of warm up iterations to perform.
      protected boolean m_WarmUp
      whether to perform warm up.
      • 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 Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void defineOptions()
      Adds options to the internal list of options.
      protected Object doRead​(adams.core.io.PlaceholderFile file)
      Performs the actual reading of the object file.
      adams.data.io.output.AbstractObjectWriter getCorrespondingWriter()
      Returns, if available, the corresponding writer.
      String getFormatDescription()
      Returns a string describing the format (used in the file chooser).
      String[] getFormatExtensions()
      Returns the extension(s) of the format.
      int getIterations()
      Returns the number of warm up iterations to perform.
      boolean getWarmUp()
      Returns whether to warm up the model with a dummy instance after deserializing it.
      String globalInfo()
      Returns a string describing the object.
      String iterationsTipText()
      Returns the tip text for this property.
      protected boolean performWarmUp​(weka.core.Instances header, weka.classifiers.Classifier cls)
      Creates a dummy instance based on the header and attempts to classify it in order to warm up the classifier.
      void setIterations​(int value)
      Sets the number of warm up iterations to perform.
      void setWarmUp​(boolean value)
      Sets whether to warm up the model with a dummy instance after deserializing it.
      String warmUpTipText()
      Returns the tip text for this property.
      • Methods inherited from class adams.data.io.input.AbstractObjectReader

        check, getDefaultFormatExtension, getReaders, isAvailable, read
      • Methods inherited from class adams.core.option.AbstractOptionHandler

        cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, 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.logging.LoggingLevelHandler

        getLoggingLevel
    • Field Detail

      • m_WarmUp

        protected boolean m_WarmUp
        whether to perform warm up.
      • m_Iterations

        protected int m_Iterations
        the number of warm up iterations to perform.
    • Constructor Detail

      • WekaClassifierModelReader

        public WekaClassifierModelReader()
        Default constructor.
      • WekaClassifierModelReader

        public WekaClassifierModelReader​(boolean warmUp)
        Convenience constructor for setting the warmup flag.
        Parameters:
        warmUp - whether to perform warmup
      • WekaClassifierModelReader

        public WekaClassifierModelReader​(boolean warmUp,
                                         int iterations)
        Convenience constructor for configuring the warmup.
        Parameters:
        warmUp - whether to perform warmup
        iterations - the number of iterations to perform
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing the object.
        Specified by:
        globalInfo in interface adams.core.GlobalInfoSupporter
        Specified by:
        globalInfo in class adams.core.option.AbstractOptionHandler
        Returns:
        a description suitable for displaying in the gui
      • 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
      • setWarmUp

        public void setWarmUp​(boolean value)
        Sets whether to warm up the model with a dummy instance after deserializing it.
        Parameters:
        value - true if to warm up
      • getWarmUp

        public boolean getWarmUp()
        Returns whether to warm up the model with a dummy instance after deserializing it.
        Returns:
        true if to warm up
      • warmUpTipText

        public String warmUpTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setIterations

        public void setIterations​(int value)
        Sets the number of warm up iterations to perform.
        Parameters:
        value - the number of iterations
      • getIterations

        public int getIterations()
        Returns the number of warm up iterations to perform.
        Returns:
        the number of iterations
      • iterationsTipText

        public String iterationsTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • getFormatDescription

        public String getFormatDescription()
        Returns a string describing the format (used in the file chooser).
        Specified by:
        getFormatDescription in interface adams.core.io.FileFormatHandler
        Specified by:
        getFormatDescription in class adams.data.io.input.AbstractObjectReader
        Returns:
        a description suitable for displaying in the file chooser
      • getFormatExtensions

        public String[] getFormatExtensions()
        Returns the extension(s) of the format.
        Specified by:
        getFormatExtensions in interface adams.core.io.FileFormatHandler
        Specified by:
        getFormatExtensions in class adams.data.io.input.AbstractObjectReader
        Returns:
        the extension (without the dot!)
      • getCorrespondingWriter

        public adams.data.io.output.AbstractObjectWriter getCorrespondingWriter()
        Returns, if available, the corresponding writer.
        Specified by:
        getCorrespondingWriter in class adams.data.io.input.AbstractObjectReader
        Returns:
        the writer, null if none available
      • performWarmUp

        protected boolean performWarmUp​(weka.core.Instances header,
                                        weka.classifiers.Classifier cls)
        Creates a dummy instance based on the header and attempts to classify it in order to warm up the classifier.
        Parameters:
        header - the header to use
        cls - the classifier to warm up
        Returns:
        true if successfully warmed up
      • doRead

        protected Object doRead​(adams.core.io.PlaceholderFile file)
        Performs the actual reading of the object file.
        Specified by:
        doRead in class adams.data.io.input.AbstractObjectReader
        Parameters:
        file - the file to read
        Returns:
        the object, null if failed to read