Class Kernel
java.lang.Object
weka.classifiers.functions.supportVector.Kernel
- All Implemented Interfaces:
Serializable
,CapabilitiesHandler
,OptionHandler
,RevisionHandler
- Direct Known Subclasses:
CachedKernel
,PrecomputedKernelMatrixKernel
,StringKernel
public abstract class Kernel
extends Object
implements Serializable, OptionHandler, CapabilitiesHandler, RevisionHandler
Abstract kernel. Kernels implementing this class must respect Mercer's
condition in order to ensure a correct behaviour of SMOreg.
- Version:
- $Revision: 14516 $
- Author:
- Eibe Frank (eibe@cs.waikato.ac.nz), FracPete (fracpete at waikato dot ac dot nz)
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
buildKernel
(Instances data) builds the kernel with the given dataabstract void
clean()
Frees the memory used by the kernel.Returns the tip text for this propertyabstract double
Computes the result of the kernel function for two instances.static Kernel
Creates a new instance of a kernel given it's class name and (optional) arguments to pass to it's setOptions method.Returns the Capabilities of this kernel.boolean
boolean
getDebug()
Gets whether debugging output is turned on or not.boolean
String[]
Gets the current settings of the Kernel.Returns the revision string.abstract String
Returns a string describing the kernelReturns an enumeration describing the available options.static Kernel[]
makeCopies
(Kernel model, int num) Creates a given number of deep or shallow (if the kernel implements Copyable) copies of the given kernel using serialization.static Kernel
Creates a shallow copy of the kernel (if it implements Copyable) otherwise a deep copy using serialization.abstract int
Returns the number of dot product cache hits.abstract int
numEvals()
Returns the number of kernel evaluation performed.void
setChecksTurnedOff
(boolean value) These methods remain for backwards compatibility.void
setDebug
(boolean value) Enables or disables the output of debug information (if the derived kernel supports that)void
setDoNotCheckCapabilities
(boolean doNotCheckCapabilities) These methods remain for backwards compatibility.void
setOptions
(String[] options) Parses a given list of options.
-
Constructor Details
-
Kernel
public Kernel()
-
-
Method Details
-
setDoNotCheckCapabilities
These methods remain for backwards compatibility. The first one does nothing, the second one always returns true. Checking capabilities is the responsibility of the class using the kernel. -
getDoNotCheckCapabilities
public boolean getDoNotCheckCapabilities() -
globalInfo
Returns a string describing the kernel- Returns:
- a description suitable for displaying in the explorer/experimenter gui
-
eval
Computes the result of the kernel function for two instances. If id1 == -1, eval use inst1 instead of an instance in the dataset.- Parameters:
id1
- the index of the first instance in the datasetid2
- the index of the second instance in the datasetinst1
- the instance corresponding to id1 (used if id1 == -1)- Returns:
- the result of the kernel function
- Throws:
Exception
- if something goes wrong
-
clean
public abstract void clean()Frees the memory used by the kernel. (Useful with kernels which use cache.) This function is called when the training is done. i.e. after that, eval will be called with id1 == -1. -
numEvals
public abstract int numEvals()Returns the number of kernel evaluation performed.- Returns:
- the number of kernel evaluation performed.
-
numCacheHits
public abstract int numCacheHits()Returns the number of dot product cache hits.- Returns:
- the number of dot product cache hits, or -1 if not supported by this kernel.
-
listOptions
Returns an enumeration describing the available options.- Specified by:
listOptions
in interfaceOptionHandler
- Returns:
- an enumeration of all the available options.
-
setOptions
Parses a given list of options.- Specified by:
setOptions
in interfaceOptionHandler
- Parameters:
options
- the list of options as an array of strings- Throws:
Exception
- if an option is not supported
-
getOptions
Gets the current settings of the Kernel.- Specified by:
getOptions
in interfaceOptionHandler
- Returns:
- an array of strings suitable for passing to setOptions
-
setDebug
public void setDebug(boolean value) Enables or disables the output of debug information (if the derived kernel supports that)- Parameters:
value
- whether to output debugging information
-
getDebug
public boolean getDebug()Gets whether debugging output is turned on or not.- Returns:
- true if debugging output is produced.
-
debugTipText
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setChecksTurnedOff
These methods remain for backwards compatibility. The first one does nothing, the second one always returns true. Checking capabilities is the responsibility of the class using the kernel. -
getChecksTurnedOff
public boolean getChecksTurnedOff() -
getCapabilities
Returns the Capabilities of this kernel. Derived kernels have to override this method to enable capabilities.- Specified by:
getCapabilities
in interfaceCapabilitiesHandler
- Returns:
- the capabilities of this object
- See Also:
-
getRevision
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Returns:
- the revision
-
buildKernel
builds the kernel with the given data- Parameters:
data
- the data to base the kernel on- Throws:
Exception
- if something goes wrong
-
makeCopy
Creates a shallow copy of the kernel (if it implements Copyable) otherwise a deep copy using serialization.- Parameters:
kernel
- the kernel to copy- Returns:
- a shallow or deep copy of the kernel
- Throws:
Exception
- if an error occurs
-
makeCopies
Creates a given number of deep or shallow (if the kernel implements Copyable) copies of the given kernel using serialization.- Parameters:
model
- the kernel to copynum
- the number of kernel copies to create.- Returns:
- an array of kernels.
- Throws:
Exception
- if an error occurs
-
forName
Creates a new instance of a kernel given it's class name and (optional) arguments to pass to it's setOptions method.- Parameters:
kernelName
- the fully qualified class name of the classifieroptions
- an array of options suitable for passing to setOptions. May be null.- Returns:
- the newly created classifier, ready for use.
- Throws:
Exception
- if the classifier name is invalid, or the options supplied are not acceptable to the classifier
-