Package weka.classifiers.meta
Class SocketFacade
- java.lang.Object
-
- weka.classifiers.AbstractClassifier
-
- weka.classifiers.meta.SocketFacade
-
- All Implemented Interfaces:
Serializable,Cloneable,weka.classifiers.Classifier,weka.core.BatchPredictor,weka.core.CapabilitiesHandler,weka.core.CapabilitiesIgnorer,weka.core.CommandlineRunnable,weka.core.OptionHandler,weka.core.RevisionHandler
public class SocketFacade extends weka.classifiers.AbstractClassifierUses sockets to communicate with a process for training and making predictions.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected BaseHostnamem_Localthe return address for the remote process to use.protected AbstractDataPreparationm_Preparationthe data preparation to use.protected BaseHostnamem_Remotethe address of the remote process.protected ServerSocketm_Serverthe server socket for receiving the replies.protected booleanm_SkipTrainwhether to skip training.protected intm_Timeoutthe timeout for the socket.
-
Constructor Summary
Constructors Constructor Description SocketFacade()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbuildClassifier(weka.core.Instances data)Generates a classifier.doubleclassifyInstance(weka.core.Instance instance)Generates a classification for the instance.protected voidcloseServer()Closes the server socket if necessary.double[]distributionForInstance(weka.core.Instance instance)Generates a class distribution for the instance.weka.core.CapabilitiesgetCapabilities()Returns the Capabilities of this classifier.protected BaseHostnamegetDefaultLocal()Returns the default address of the return address.protected AbstractDataPreparationgetDefaultPreparation()Returns the default data preparation scheme to use.protected BaseHostnamegetDefaultRemote()Returns the default address of the remote process.protected intgetDefaultTimeout()The default timeout in milli-second.BaseHostnamegetLocal()Returns the return address for the remote process to use.String[]getOptions()Gets the current settings of the classifier.AbstractDataPreparationgetPreparation()Returns the data preparation scheme to use.BaseHostnamegetRemote()Returns the address of the remote process.protected ServerSocketgetServer()Returns the server socket, instantiates it if necessary.booleangetSkipTrain()Returns whether to skip training, eg when using a pre-built model.intgetTimeout()Returns the timeout in milli-second to wait for new connections.StringglobalInfo()Returns a string describing this classifier.protected voidinitServer()Initializes the server socket if necessary.EnumerationlistOptions()Returns an enumeration describing the available options.StringlocalTipText()Returns the tip text for this property.StringpreparationTipText()Returns the tip text for this property.protected byte[]receive()Receives the response data.StringremoteTipText()Returns the tip text for this property.protected byte[]send(byte[] data)Sends the data to the remote host.voidsetLocal(BaseHostname value)Sets the return address for the remote process to use.voidsetOptions(String[] options)Parses a given list of options.voidsetPreparation(AbstractDataPreparation value)Sets the data preparation scheme to use.voidsetRemote(BaseHostname value)Sets address of the remote process.voidsetSkipTrain(boolean value)Sets whether to skip training, eg when using a pre-built model.voidsetTimeout(int value)Sets the timeout in milli-second to wait for new connections.StringskipTrainTipText()Returns the tip text for this property.StringtimeoutTipText()Returns the tip text for this property.StringtoString()Just returns the commandline options.-
Methods inherited from class weka.classifiers.AbstractClassifier
batchSizeTipText, debugTipText, distributionsForInstances, doNotCheckCapabilitiesTipText, forName, getBatchSize, getDebug, getDoNotCheckCapabilities, getNumDecimalPlaces, getRevision, implementsMoreEfficientBatchPrediction, makeCopies, makeCopy, numDecimalPlacesTipText, postExecution, preExecution, run, runClassifier, setBatchSize, setDebug, setDoNotCheckCapabilities, setNumDecimalPlaces
-
-
-
-
Field Detail
-
m_Remote
protected BaseHostname m_Remote
the address of the remote process.
-
m_Local
protected BaseHostname m_Local
the return address for the remote process to use.
-
m_Timeout
protected int m_Timeout
the timeout for the socket.
-
m_Preparation
protected AbstractDataPreparation m_Preparation
the data preparation to use.
-
m_SkipTrain
protected boolean m_SkipTrain
whether to skip training.
-
m_Server
protected transient ServerSocket m_Server
the server socket for receiving the replies.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing this classifier.- Returns:
- a description of the classifier suitable for displaying in the explorer/experimenter gui
-
listOptions
public Enumeration listOptions()
Returns an enumeration describing the available options.- Specified by:
listOptionsin interfaceweka.core.OptionHandler- Overrides:
listOptionsin classweka.classifiers.AbstractClassifier- Returns:
- an enumeration of all the available options.
-
setOptions
public void setOptions(String[] options) throws Exception
Parses a given list of options.- Specified by:
setOptionsin interfaceweka.core.OptionHandler- Overrides:
setOptionsin classweka.classifiers.AbstractClassifier- Parameters:
options- the list of options as an array of strings- Throws:
Exception- if an option is not supported
-
getOptions
public String[] getOptions()
Gets the current settings of the classifier.- Specified by:
getOptionsin interfaceweka.core.OptionHandler- Overrides:
getOptionsin classweka.classifiers.AbstractClassifier- Returns:
- an array of strings suitable for passing to setOptions
-
getDefaultRemote
protected BaseHostname getDefaultRemote()
Returns the default address of the remote process.- Returns:
- the default
-
setRemote
public void setRemote(BaseHostname value)
Sets address of the remote process.- Parameters:
value- the address
-
getRemote
public BaseHostname getRemote()
Returns the address of the remote process.- Returns:
- the address
-
remoteTipText
public String remoteTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getDefaultLocal
protected BaseHostname getDefaultLocal()
Returns the default address of the return address.- Returns:
- the default
-
setLocal
public void setLocal(BaseHostname value)
Sets the return address for the remote process to use.- Parameters:
value- the address
-
getLocal
public BaseHostname getLocal()
Returns the return address for the remote process to use.- Returns:
- the address
-
localTipText
public String localTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getDefaultTimeout
protected int getDefaultTimeout()
The default timeout in milli-second.- Returns:
- the default
-
setTimeout
public void setTimeout(int value)
Sets the timeout in milli-second to wait for new connections.- Parameters:
value- the timeout in msec
-
getTimeout
public int getTimeout()
Returns the timeout in milli-second to wait for new connections.- Returns:
- the timeout in msec
-
timeoutTipText
public String timeoutTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the gui
-
getDefaultPreparation
protected AbstractDataPreparation getDefaultPreparation()
Returns the default data preparation scheme to use.- Returns:
- the default
-
setPreparation
public void setPreparation(AbstractDataPreparation value)
Sets the data preparation scheme to use.- Parameters:
value- the scheme
-
getPreparation
public AbstractDataPreparation getPreparation()
Returns the data preparation scheme to use.- Returns:
- the scheme
-
preparationTipText
public String preparationTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setSkipTrain
public void setSkipTrain(boolean value)
Sets whether to skip training, eg when using a pre-built model.- Parameters:
value- true if to skip training
-
getSkipTrain
public boolean getSkipTrain()
Returns whether to skip training, eg when using a pre-built model.- Returns:
- true if to skip training
-
skipTrainTipText
public String skipTrainTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
initServer
protected void initServer() throws ExceptionInitializes the server socket if necessary.- Throws:
Exception- if initialization fails
-
closeServer
protected void closeServer()
Closes the server socket if necessary.
-
getServer
protected ServerSocket getServer() throws Exception
Returns the server socket, instantiates it if necessary.- Returns:
- the socket
- Throws:
Exception- if binding of socket fails
-
receive
protected byte[] receive() throws ExceptionReceives the response data.- Returns:
- the received data
- Throws:
Exception- if fails to receive data
-
send
protected byte[] send(byte[] data) throws ExceptionSends the data to the remote host.- Parameters:
data- the data to send- Returns:
- the response data
- Throws:
Exception- if sending fails
-
getCapabilities
public weka.core.Capabilities getCapabilities()
Returns the Capabilities of this classifier.- Specified by:
getCapabilitiesin interfaceweka.core.CapabilitiesHandler- Specified by:
getCapabilitiesin interfaceweka.classifiers.Classifier- Overrides:
getCapabilitiesin classweka.classifiers.AbstractClassifier- Returns:
- the capabilities of this object
-
buildClassifier
public void buildClassifier(weka.core.Instances data) throws ExceptionGenerates a classifier.- Parameters:
data- set of instances serving as training data- Throws:
Exception- if the classifier has not been generated successfully
-
classifyInstance
public double classifyInstance(weka.core.Instance instance) throws ExceptionGenerates a classification for the instance.- Specified by:
classifyInstancein interfaceweka.classifiers.Classifier- Overrides:
classifyInstancein classweka.classifiers.AbstractClassifier- Parameters:
instance- the instance to classify- Returns:
- the classification
- Throws:
Exception- if classification failed
-
distributionForInstance
public double[] distributionForInstance(weka.core.Instance instance) throws ExceptionGenerates a class distribution for the instance.- Specified by:
distributionForInstancein interfaceweka.classifiers.Classifier- Overrides:
distributionForInstancein classweka.classifiers.AbstractClassifier- Parameters:
instance- the instance to get the class distribution for- Returns:
- the class distribution
- Throws:
Exception- if class distribution fails
-
-