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, ScriptedClassifier, weka.core.CapabilitiesHandler, weka.core.OptionHandler

    public class JepRegressor
    extends AbstractSimpleClassifier
    implements adams.core.StoppableWithFeedback, 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
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected adams.core.scripting.JepScript m_ClassifyScript
      the classify script.
      protected adams.core.scripting.JepScript m_ClassifyScriptActual
      the classify script instance to use.
      protected String m_ClassifyVarPrefix
      the variable prefix to use at prediction time.
      protected adams.flow.standalone.JepEngine m_Engine
      the engine in use.
      protected adams.flow.core.Actor m_FlowContext
      the flow context.
      protected Object m_Model
      the model object.
      protected boolean m_Stopped
      whether the classifier was stopped.
      protected adams.core.scripting.JepScript m_TrainScript
      the train script.
      static String VAR_PREFIX  
      • Fields inherited from class adams.core.option.AbstractOptionHandler

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

        m_Logger, m_LoggingIsEnabled, m_LoggingLevel
    • Constructor Summary

      Constructors 
      Constructor Description
      JepRegressor()  
    • Field Detail

      • m_TrainScript

        protected adams.core.scripting.JepScript m_TrainScript
        the train script.
      • m_ClassifyScript

        protected adams.core.scripting.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 adams.flow.standalone.JepEngine m_Engine
        the engine in use.
      • m_Model

        protected transient Object m_Model
        the model object.
      • m_ClassifyScriptActual

        protected transient adams.core.scripting.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​(adams.core.scripting.JepScript value)
        Sets the train script to use.
        Parameters:
        value - the script
      • getTrainScript

        public adams.core.scripting.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​(adams.core.scripting.JepScript value)
        Sets the script to use for classifying Instance objects.
        Parameters:
        value - the script
      • getClassifyScript

        public adams.core.scripting.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 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 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 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