Class PyroProxy

  • 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.flow.core.FlowContextHandler, Serializable, weka.classifiers.Classifier, weka.core.BatchPredictor, weka.core.CapabilitiesHandler, weka.core.OptionHandler, PyroProxyObject

    public class PyroProxy
    extends AbstractSimpleClassifier
    implements PyroProxyObject, adams.flow.core.FlowContextHandler, weka.core.BatchPredictor
    Proxy for a python model using Pyro4 for communication.
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • m_NameServer

        protected adams.core.base.BaseHostname m_NameServer
        the Pyro nameserver.
      • m_RemoteObjectName

        protected String m_RemoteObjectName
        the Pyro remote object.
      • m_MethodNameTrain

        protected String m_MethodNameTrain
        the Pyro remote method for training.
      • m_MethodNamePrediction

        protected String m_MethodNamePrediction
        the Pyro remote method for prediction.
      • m_ModelName

        protected String m_ModelName
        the model name.
      • m_PerformTraining

        protected boolean m_PerformTraining
        whether to perform training.
      • m_BatchSize

        protected int m_BatchSize
        the batch size.
      • m_FlowContext

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

        protected transient adams.flow.standalone.PyroNameServer m_NameServerActor
        the nameserver actor.
      • m_NameServerProxy

        protected transient net.razorvine.pyro.NameServerProxy m_NameServerProxy
        the nameserver.
      • m_RemoteObject

        protected transient net.razorvine.pyro.PyroProxy m_RemoteObject
        the remote object.
    • Constructor Detail

      • PyroProxy

        public PyroProxy()
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing classifier.
        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 explorer/experimenter 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
      • 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 actor
      • getFlowContext

        public adams.flow.core.Actor getFlowContext()
        Returns the flow context, if any.
        Specified by:
        getFlowContext in interface adams.flow.core.FlowContextHandler
        Returns:
        the actor, null if none available
      • setNameServer

        public void setNameServer​(adams.core.base.BaseHostname value)
        Sets the address of the Pyro nameserver.
        Specified by:
        setNameServer in interface PyroProxyObject
        Parameters:
        value - the address
      • getNameServer

        public adams.core.base.BaseHostname getNameServer()
        Returns the address of the Pyro nameserver.
        Specified by:
        getNameServer in interface PyroProxyObject
        Returns:
        the address
      • nameServerTipText

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

        public void setRemoteObjectName​(String value)
        Sets the name of the remote object to use.
        Specified by:
        setRemoteObjectName in interface PyroProxyObject
        Parameters:
        value - the name
      • remoteObjectNameTipText

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

        public void setPerformTraining​(boolean value)
        Sets whether to train the model as well.
        Parameters:
        value - true if also train
      • getPerformTraining

        public boolean getPerformTraining()
        Returns whether to train the model as well.
        Returns:
        true if also train
      • performTrainingTipText

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

        public void setMethodNameTrain​(String value)
        Sets the name of the method to call for training.
        Parameters:
        value - the name
      • getMethodNameTrain

        public String getMethodNameTrain()
        Returns the name of the method to call for training.
        Returns:
        the name
      • methodNameTrainTipText

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

        public void setMethodNamePrediction​(String value)
        Sets the name of the method to call for predictions.
        Parameters:
        value - the name
      • getMethodNamePrediction

        public String getMethodNamePrediction()
        Returns the name of the method to call for predictions.
        Returns:
        the name
      • methodNamePredictionTipText

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

        public void setModelName​(String value)
        Sets the name of the model to use.
        Parameters:
        value - the name
      • getModelName

        public String getModelName()
        Returns the name of the model to use.
        Returns:
        the name
      • modelNameTipText

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

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

        public void setBatchSize​(String value)
        Set the batch size to use. The implementer will prefer (but not necessarily expect) this many instances to be passed in to distributionsForInstances().
        Specified by:
        setBatchSize in interface weka.core.BatchPredictor
        Parameters:
        value - the batch size to use
      • getBatchSize

        public String getBatchSize()
        Get the batch size to use. The implementer will prefer (but not necessarily expect) this many instances to be passed in to distributionsForInstances(). Allows the preferred batch size to be encapsulated with the client.
        Specified by:
        getBatchSize in interface weka.core.BatchPredictor
        Returns:
        the batch size to use
      • batchSizeTipText

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

        public boolean implementsMoreEfficientBatchPrediction()
        Returns true if this BatchPredictor can generate batch predictions in an efficient manner.
        Specified by:
        implementsMoreEfficientBatchPrediction in interface weka.core.BatchPredictor
        Returns:
        true if batch predictions can be generated efficiently
      • getCapabilities

        public weka.core.Capabilities getCapabilities()
        Returns the Capabilities of this classifier.
        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
      • 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
      • distributionForInstance

        public double[] distributionForInstance​(weka.core.Instance instance)
                                         throws Exception
        Classifies the given test instance. The instance has to belong to a dataset when it's being classified.
        Specified by:
        distributionForInstance in interface weka.classifiers.Classifier
        Overrides:
        distributionForInstance 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
      • distributionsForInstances

        public double[][] distributionsForInstances​(weka.core.Instances insts)
                                             throws Exception
        Batch scoring method
        Specified by:
        distributionsForInstances in interface weka.core.BatchPredictor
        Parameters:
        insts - the instances to get predictions for
        Returns:
        an array of probability distributions, one for each instance
        Throws:
        Exception - if a problem occurs
      • toString

        public String toString()
        Returns a short description of the classifier.
        Overrides:
        toString in class adams.core.option.AbstractOptionHandler
        Returns:
        the description
      • main

        public static void main​(String[] args)
                         throws Exception
        Main method for running this class.
        Parameters:
        args - the options
        Throws:
        Exception