Class JepRegressor

  • All Implemented Interfaces:
    adams.core.Destroyable, adams.core.GlobalInfoSupporter, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.option.OptionHandler, adams.core.SizeOfHandler, adams.core.Stoppable, adams.core.StoppableWithFeedback, adams.flow.core.FlowContextHandler, Serializable, weka.classifiers.Classifier, weka.classifiers.ScriptedClassifier, weka.core.CapabilitiesHandler, weka.core.OptionHandler

    public class JepRegressor
    extends weka.classifiers.simple.AbstractSimpleClassifier
    implements adams.core.StoppableWithFeedback, weka.classifiers.ScriptedClassifier
    Regressor that uses Jep to train and execute a Python-based regressor.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      JepRegressor()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void buildClassifier​(weka.core.Instances data)
      Generates a classifier.
      double classifyInstance​(weka.core.Instance instance)
      Classifies the given test instance.
      String classifyScriptTipText()
      Returns the tip text for this property.
      void defineOptions()
      Adds options to the internal list of options.
      weka.core.Capabilities getCapabilities()
      Returns the Capabilities of this classifier.
      JepScript getClassifyScript()
      Gets the script to use for classifying Instance objects.
      adams.flow.core.Actor getFlowContext()
      Returns the flow context.
      JepScript getTrainScript()
      Gets the train script to use.
      String globalInfo()
      Returns a string describing the object.
      void initPrediction​(adams.flow.core.Actor context)
      Prepares the classifier for predictions.
      boolean isStopped()
      Whether the execution has been stopped.
      static void main​(String[] args)
      Runs the classifier from the command-line with the specified options.
      void setClassifyScript​(JepScript value)
      Sets the script to use for classifying Instance objects.
      void setFlowContext​(adams.flow.core.Actor value)
      Sets the flow context.
      void setTrainScript​(JepScript value)
      Sets the train script to use.
      protected void setupJepEngine()
      Configures the Jep engine if necessary.
      void stopExecution()
      Stops the execution.
      String trainScriptTipText()
      Returns the tip text for this property.
      • Methods inherited from class weka.classifiers.simple.AbstractSimpleClassifier

        distributionForInstance, runClassifier
      • Methods inherited from class weka.core.AbstractSimpleOptionHandler

        getOptions, listOptions, setOptions
      • 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 weka.classifiers.Classifier

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

        getLoggingLevel
    • Field Detail

      • m_TrainScript

        protected JepScript m_TrainScript
        the train script.
      • m_ClassifyScript

        protected JepScript m_ClassifyScript
        the classify script.
      • m_Stopped

        protected boolean m_Stopped
        whether the classifier was stopped.
      • m_FlowContext

        protected transient adams.flow.core.Actor m_FlowContext
        the flow context.
      • m_Engine

        protected transient JepEngine m_Engine
        the engine in use.
      • m_Model

        protected transient Object m_Model
        the model object.
      • m_ClassifyScriptActual

        protected transient JepScript m_ClassifyScriptActual
        the classify script instance to use.
      • m_ClassifyVarPrefix

        protected transient String m_ClassifyVarPrefix
        the variable prefix to use at prediction time.
    • Constructor Detail

      • JepRegressor

        public JepRegressor()
    • 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
      • setTrainScript

        public void setTrainScript​(JepScript value)
        Sets the train script to use.
        Parameters:
        value - the script
      • getTrainScript

        public JepScript getTrainScript()
        Gets the train script to use.
        Returns:
        the script
      • trainScriptTipText

        public String trainScriptTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • setClassifyScript

        public void setClassifyScript​(JepScript value)
        Sets the script to use for classifying Instance objects.
        Parameters:
        value - the script
      • getClassifyScript

        public JepScript getClassifyScript()
        Gets the script to use for classifying Instance objects.
        Returns:
        the script
      • classifyScriptTipText

        public String classifyScriptTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • setFlowContext

        public void setFlowContext​(adams.flow.core.Actor value)
        Sets the flow context.
        Specified by:
        setFlowContext in interface adams.flow.core.FlowContextHandler
        Parameters:
        value - the context
      • getFlowContext

        public adams.flow.core.Actor getFlowContext()
        Returns the flow context.
        Specified by:
        getFlowContext in interface adams.flow.core.FlowContextHandler
        Returns:
        the context, null if not available
      • getCapabilities

        public weka.core.Capabilities getCapabilities()
        Returns the Capabilities of this classifier. Maximally permissive capabilities are allowed by default. Derived classifiers should override this method and first disable all capabilities and then enable just those capabilities that make sense for the scheme.
        Specified by:
        getCapabilities in interface weka.core.CapabilitiesHandler
        Specified by:
        getCapabilities in interface weka.classifiers.Classifier
        Overrides:
        getCapabilities in class weka.classifiers.simple.AbstractSimpleClassifier
        Returns:
        the capabilities of this object
        See Also:
        Capabilities
      • setupJepEngine

        protected void setupJepEngine()
        Configures the Jep engine if necessary.
      • buildClassifier

        public void buildClassifier​(weka.core.Instances data)
                             throws Exception
        Generates a classifier. Must initialize all fields of the classifier that are not being set via options (ie. multiple calls of buildClassifier must always lead to the same result). Must not change the dataset in any way.
        Specified by:
        buildClassifier in interface weka.classifiers.Classifier
        Parameters:
        data - set of instances serving as training data
        Throws:
        Exception - if the classifier has not been generated successfully
      • initPrediction

        public void initPrediction​(adams.flow.core.Actor context)
        Prepares the classifier for predictions.
        Specified by:
        initPrediction in interface weka.classifiers.ScriptedClassifier
        Parameters:
        context - the context to use
      • classifyInstance

        public double classifyInstance​(weka.core.Instance instance)
                                throws Exception
        Classifies the given test instance. The instance has to belong to a dataset when it's being classified. Note that a classifier MUST implement either this or distributionForInstance().
        Specified by:
        classifyInstance in interface weka.classifiers.Classifier
        Overrides:
        classifyInstance in class weka.classifiers.simple.AbstractSimpleClassifier
        Parameters:
        instance - the instance to be classified
        Returns:
        the predicted most likely class for the instance or Utils.missingValue() if no prediction is made
        Throws:
        Exception - if an error occurred during the prediction
      • stopExecution

        public void stopExecution()
        Stops the execution.
        Specified by:
        stopExecution in interface adams.core.Stoppable
      • isStopped

        public boolean isStopped()
        Whether the execution has been stopped.
        Specified by:
        isStopped in interface adams.core.StoppableWithFeedback
        Returns:
        true if stopped
      • main

        public static void main​(String[] args)
                         throws Exception
        Runs the classifier from the command-line with the specified options.
        Parameters:
        args - the options for the classifier
        Throws:
        Exception - if execution fails