Class Kernel
- java.lang.Object
-
- weka.classifiers.functions.supportVector.Kernel
-
- All Implemented Interfaces:
java.io.Serializable,CapabilitiesHandler,OptionHandler,RevisionHandler
- Direct Known Subclasses:
CachedKernel,PrecomputedKernelMatrixKernel,StringKernel
public abstract class Kernel extends java.lang.Object implements java.io.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: 9897 $
- Author:
- Eibe Frank (eibe@cs.waikato.ac.nz), FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Kernel()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidbuildKernel(Instances data)builds the kernel with the given datajava.lang.StringchecksTurnedOffTipText()Returns the tip text for this propertyabstract voidclean()Frees the memory used by the kernel.java.lang.StringdebugTipText()Returns the tip text for this propertyabstract doubleeval(int id1, int id2, Instance inst1)Computes the result of the kernel function for two instances.static KernelforName(java.lang.String kernelName, java.lang.String[] options)Creates a new instance of a kernel given it's class name and (optional) arguments to pass to it's setOptions method.CapabilitiesgetCapabilities()Returns the Capabilities of this kernel.booleangetChecksTurnedOff()Returns whether the checks are turned off or not.booleangetDebug()Gets whether debugging output is turned on or not.java.lang.String[]getOptions()Gets the current settings of the Kernel.java.lang.StringgetRevision()Returns the revision string.abstract java.lang.StringglobalInfo()Returns a string describing the kerneljava.util.EnumerationlistOptions()Returns 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 KernelmakeCopy(Kernel kernel)Creates a shallow copy of the kernel (if it implements Copyable) otherwise a deep copy using serialization.abstract intnumCacheHits()Returns the number of dot product cache hits.abstract intnumEvals()Returns the number of kernel evaluation performed.voidsetChecksTurnedOff(boolean value)Disables or enables the checks (which could be time-consuming).voidsetDebug(boolean value)Enables or disables the output of debug information (if the derived kernel supports that)voidsetOptions(java.lang.String[] options)Parses a given list of options.
-
-
-
Method Detail
-
globalInfo
public abstract java.lang.String globalInfo()
Returns a string describing the kernel- Returns:
- a description suitable for displaying in the explorer/experimenter gui
-
eval
public abstract double eval(int id1, int id2, Instance inst1) throws java.lang.ExceptionComputes 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:
java.lang.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
public java.util.Enumeration listOptions()
Returns an enumeration describing the available options.- Specified by:
listOptionsin interfaceOptionHandler- Returns:
- an enumeration of all the available options.
-
setOptions
public void setOptions(java.lang.String[] options) throws java.lang.ExceptionParses a given list of options.- Specified by:
setOptionsin interfaceOptionHandler- Parameters:
options- the list of options as an array of strings- Throws:
java.lang.Exception- if an option is not supported
-
getOptions
public java.lang.String[] getOptions()
Gets the current settings of the Kernel.- Specified by:
getOptionsin 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
public java.lang.String debugTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setChecksTurnedOff
public void setChecksTurnedOff(boolean value)
Disables or enables the checks (which could be time-consuming). Use with caution!- Parameters:
value- if true turns off all checks
-
getChecksTurnedOff
public boolean getChecksTurnedOff()
Returns whether the checks are turned off or not.- Returns:
- true if the checks are turned off
-
checksTurnedOffTipText
public java.lang.String checksTurnedOffTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getCapabilities
public Capabilities getCapabilities()
Returns the Capabilities of this kernel. Derived kernels have to override this method to enable capabilities.- Specified by:
getCapabilitiesin interfaceCapabilitiesHandler- Returns:
- the capabilities of this object
- See Also:
Capabilities
-
getRevision
public java.lang.String getRevision()
Returns the revision string.- Specified by:
getRevisionin interfaceRevisionHandler- Returns:
- the revision
-
buildKernel
public void buildKernel(Instances data) throws java.lang.Exception
builds the kernel with the given data- Parameters:
data- the data to base the kernel on- Throws:
java.lang.Exception- if something goes wrong
-
makeCopy
public static Kernel makeCopy(Kernel kernel) throws java.lang.Exception
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:
java.lang.Exception- if an error occurs
-
makeCopies
public static Kernel[] makeCopies(Kernel model, int num) throws java.lang.Exception
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:
java.lang.Exception- if an error occurs
-
forName
public static Kernel forName(java.lang.String kernelName, java.lang.String[] options) throws java.lang.Exception
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:
java.lang.Exception- if the classifier name is invalid, or the options supplied are not acceptable to the classifier
-
-