Package weka.classifiers.functions
Class PyroProxy
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- weka.core.AbstractSimpleOptionHandler
-
- weka.classifiers.simple.AbstractSimpleClassifier
-
- weka.classifiers.functions.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 Summary
Fields Modifier and Type Field Description protected int
m_BatchSize
the batch size.protected AbstractCommunicationProcessor
m_Communication
the instance converter to use.protected adams.flow.core.Actor
m_FlowContext
the flow context.protected String
m_MethodNamePrediction
the Pyro remote method for prediction.protected String
m_MethodNameTrain
the Pyro remote method for training.protected String
m_ModelName
the model name.protected adams.core.base.BaseHostname
m_NameServer
the Pyro nameserver.protected adams.flow.standalone.PyroNameServer
m_NameServerActor
the nameserver actor.protected net.razorvine.pyro.NameServerProxy
m_NameServerProxy
the nameserver.protected boolean
m_PerformTraining
whether to perform training.protected net.razorvine.pyro.PyroProxy
m_RemoteObject
the remote object.protected String
m_RemoteObjectName
the Pyro remote object.
-
Constructor Summary
Constructors Constructor Description PyroProxy()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
batchSizeTipText()
Returns the tip text for this property.void
buildClassifier(weka.core.Instances data)
Generates a classifier.String
communicationTipText()
Returns the tip text for this property.void
defineOptions()
Adds options to the internal list of options.double[]
distributionForInstance(weka.core.Instance instance)
Classifies the given test instance.double[][]
distributionsForInstances(weka.core.Instances insts)
Batch scoring methodString
getBatchSize()
Get the batch size to use.weka.core.Capabilities
getCapabilities()
Returns the Capabilities of this classifier.AbstractCommunicationProcessor
getCommunication()
Returns the model proxy to use for communication.adams.flow.core.Actor
getFlowContext()
Returns the flow context, if any.String
getMethodNamePrediction()
Returns the name of the method to call for predictions.String
getMethodNameTrain()
Returns the name of the method to call for training.String
getModelName()
Returns the name of the model to use.adams.core.base.BaseHostname
getNameServer()
Returns the address of the Pyro nameserver.boolean
getPerformTraining()
Returns whether to train the model as well.String
getRemoteObjectName()
Returns the name of the remote object to use.String
globalInfo()
Returns a string describing classifier.boolean
implementsMoreEfficientBatchPrediction()
Returns true if this BatchPredictor can generate batch predictions in an efficient manner.static void
main(String[] args)
Main method for running this class.String
methodNamePredictionTipText()
Returns the tip text for this property.String
methodNameTrainTipText()
Returns the tip text for this property.String
modelNameTipText()
Returns the tip text for this property.String
nameServerTipText()
Returns the tip text for this property.String
performTrainingTipText()
Returns the tip text for this property.String
remoteObjectNameTipText()
Returns the tip text for this property.void
setBatchSize(String value)
Set the batch size to use.void
setCommunication(AbstractCommunicationProcessor value)
Sets the model proxy to use for communication.void
setFlowContext(adams.flow.core.Actor value)
Sets the flow context.void
setMethodNamePrediction(String value)
Sets the name of the method to call for predictions.void
setMethodNameTrain(String value)
Sets the name of the method to call for training.void
setModelName(String value)
Sets the name of the model to use.void
setNameServer(adams.core.base.BaseHostname value)
Sets the address of the Pyro nameserver.void
setPerformTraining(boolean value)
Sets whether to train the model as well.void
setRemoteObjectName(String value)
Sets the name of the remote object to use.String
toString()
Returns a short description of the classifier.-
Methods inherited from class weka.classifiers.simple.AbstractSimpleClassifier
classifyInstance, 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
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
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_Communication
protected AbstractCommunicationProcessor m_Communication
the instance converter to use.
-
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.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing classifier.- Specified by:
globalInfo
in interfaceadams.core.GlobalInfoSupporter
- Specified by:
globalInfo
in classadams.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 interfaceadams.core.option.OptionHandler
- Overrides:
defineOptions
in classadams.core.option.AbstractOptionHandler
-
setFlowContext
public void setFlowContext(adams.flow.core.Actor value)
Sets the flow context.- Specified by:
setFlowContext
in interfaceadams.flow.core.FlowContextHandler
- Parameters:
value
- the actor
-
getFlowContext
public adams.flow.core.Actor getFlowContext()
Returns the flow context, if any.- Specified by:
getFlowContext
in interfaceadams.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 interfacePyroProxyObject
- Parameters:
value
- the address
-
getNameServer
public adams.core.base.BaseHostname getNameServer()
Returns the address of the Pyro nameserver.- Specified by:
getNameServer
in interfacePyroProxyObject
- Returns:
- the address
-
nameServerTipText
public String nameServerTipText()
Returns the tip text for this property.- Specified by:
nameServerTipText
in interfacePyroProxyObject
- 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 interfacePyroProxyObject
- Parameters:
value
- the name
-
getRemoteObjectName
public String getRemoteObjectName()
Returns the name of the remote object to use.- Specified by:
getRemoteObjectName
in interfacePyroProxyObject
- Returns:
- the name
-
remoteObjectNameTipText
public String remoteObjectNameTipText()
Returns the tip text for this property.- Specified by:
remoteObjectNameTipText
in interfacePyroProxyObject
- 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.
-
setCommunication
public void setCommunication(AbstractCommunicationProcessor value)
Sets the model proxy to use for communication.- Specified by:
setCommunication
in interfacePyroProxyObject
- Parameters:
value
- the proxy
-
getCommunication
public AbstractCommunicationProcessor getCommunication()
Returns the model proxy to use for communication.- Specified by:
getCommunication
in interfacePyroProxyObject
- Returns:
- the proxy
-
communicationTipText
public String communicationTipText()
Returns the tip text for this property.- Specified by:
communicationTipText
in interfacePyroProxyObject
- 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 interfaceweka.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 interfaceweka.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 interfaceweka.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 interfaceweka.core.CapabilitiesHandler
- Specified by:
getCapabilities
in interfaceweka.classifiers.Classifier
- Overrides:
getCapabilities
in classAbstractSimpleClassifier
- 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 interfaceweka.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 interfaceweka.classifiers.Classifier
- Overrides:
distributionForInstance
in classAbstractSimpleClassifier
- 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 interfaceweka.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 classadams.core.option.AbstractOptionHandler
- Returns:
- the description
-
-