Class CachedKernel
- java.lang.Object
-
- weka.classifiers.functions.supportVector.Kernel
-
- weka.classifiers.functions.supportVector.CachedKernel
-
- All Implemented Interfaces:
java.io.Serializable,CapabilitiesHandler,OptionHandler,RevisionHandler
- Direct Known Subclasses:
PolyKernel,Puk,RBFKernel
public abstract class CachedKernel extends Kernel
Base class for RBFKernel and PolyKernel that implements a simple LRU. (least-recently-used) cache if the cache size is set to a value > 0. Otherwise it uses a full cache.- Version:
- $Revision: 4549 $
- Author:
- Eibe Frank (eibe@cs.waikato.ac.nz), Shane Legg (shane@intelligenesis.net) (sparse vector code), Stuart Inglis (stuart@reeltwo.com) (sparse vector code), J. Lindgren (jtlindgr{at}cs.helsinki.fi) (RBF kernel), Steven Hugg (hugg@fasterlight.com) (refactored, LRU cache), Bernhard Pfahringer (bernhard@cs.waikato.ac.nz) (full cache)
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CachedKernel()default constructor - does nothing.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbuildKernel(Instances data)builds the kernel with the given data.java.lang.StringcacheSizeTipText()Returns the tip text for this propertyvoidclean()Frees the cache used by the kernel.doubleeval(int id1, int id2, Instance inst1)Implements the abstract function of Kernel using the cache.intgetCacheSize()Gets the size of the cachejava.lang.String[]getOptions()Gets the current settings of the Kernel.java.util.EnumerationlistOptions()Returns an enumeration describing the available options.intnumCacheHits()Returns the number of cache hits on dot products.intnumEvals()Returns the number of time Eval has been called.voidsetCacheSize(int value)Sets the size of the cache to use (a prime number)voidsetOptions(java.lang.String[] options)Parses a given list of options.-
Methods inherited from class weka.classifiers.functions.supportVector.Kernel
checksTurnedOffTipText, debugTipText, forName, getCapabilities, getChecksTurnedOff, getDebug, getRevision, globalInfo, makeCopies, makeCopy, setChecksTurnedOff, setDebug
-
-
-
-
Method Detail
-
listOptions
public java.util.Enumeration listOptions()
Returns an enumeration describing the available options.- Specified by:
listOptionsin interfaceOptionHandler- Overrides:
listOptionsin classKernel- 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- Overrides:
setOptionsin classKernel- 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- Overrides:
getOptionsin classKernel- Returns:
- an array of strings suitable for passing to setOptions
-
eval
public double eval(int id1, int id2, Instance inst1) throws java.lang.ExceptionImplements the abstract function of Kernel using the cache. This method uses the evaluate() method to do the actual dot product.- Specified by:
evalin classKernel- 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
-
numEvals
public int numEvals()
Returns the number of time Eval has been called.
-
numCacheHits
public int numCacheHits()
Returns the number of cache hits on dot products.- Specified by:
numCacheHitsin classKernel- Returns:
- the number of cache hits.
-
setCacheSize
public void setCacheSize(int value)
Sets the size of the cache to use (a prime number)- Parameters:
value- the size of the cache
-
getCacheSize
public int getCacheSize()
Gets the size of the cache- Returns:
- the cache size
-
cacheSizeTipText
public java.lang.String cacheSizeTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
buildKernel
public void buildKernel(Instances data) throws java.lang.Exception
builds the kernel with the given data. Initializes the kernel cache. The actual size of the cache in bytes is (64 * cacheSize).- Overrides:
buildKernelin classKernel- Parameters:
data- the data to base the kernel on- Throws:
java.lang.Exception- if something goes wrong
-
-