CachedKernel (original) (raw)
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:4549Revision: 4549 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 and Description CachedKernel() default constructor - does nothing. Method Summary
All Methods Instance Methods Concrete Methods
Modifier and Type Method and Description void buildKernel(Instances data) builds the kernel with the given data. java.lang.String cacheSizeTipText() Returns the tip text for this property void clean() Frees the cache used by the kernel. double eval(int id1, int id2,Instance inst1) Implements the abstract function of Kernel using the cache. int getCacheSize() Gets the size of the cache java.lang.String[] getOptions() Gets the current settings of the Kernel. java.util.Enumeration listOptions() Returns an enumeration describing the available options. int numCacheHits() Returns the number of cache hits on dot products. int numEvals() Returns the number of time Eval has been called. void setCacheSize(int value) Sets the size of the cache to use (a prime number) void setOptions(java.lang.String[] options) Parses a given list of options. * ### Methods inherited from class weka.classifiers.functions.supportVector.[Kernel](../../../../weka/classifiers/functions/supportVector/Kernel.html "class in weka.classifiers.functions.supportVector") `[checksTurnedOffTipText](../../../../weka/classifiers/functions/supportVector/Kernel.html#checksTurnedOffTipText--), [debugTipText](../../../../weka/classifiers/functions/supportVector/Kernel.html#debugTipText--), [forName](../../../../weka/classifiers/functions/supportVector/Kernel.html#forName-java.lang.String-java.lang.String:A-), [getCapabilities](../../../../weka/classifiers/functions/supportVector/Kernel.html#getCapabilities--), [getChecksTurnedOff](../../../../weka/classifiers/functions/supportVector/Kernel.html#getChecksTurnedOff--), [getDebug](../../../../weka/classifiers/functions/supportVector/Kernel.html#getDebug--), [getRevision](../../../../weka/classifiers/functions/supportVector/Kernel.html#getRevision--), [globalInfo](../../../../weka/classifiers/functions/supportVector/Kernel.html#globalInfo--), [makeCopies](../../../../weka/classifiers/functions/supportVector/Kernel.html#makeCopies-weka.classifiers.functions.supportVector.Kernel-int-), [makeCopy](../../../../weka/classifiers/functions/supportVector/Kernel.html#makeCopy-weka.classifiers.functions.supportVector.Kernel-), [setChecksTurnedOff](../../../../weka/classifiers/functions/supportVector/Kernel.html#setChecksTurnedOff-boolean-), [setDebug](../../../../weka/classifiers/functions/supportVector/Kernel.html#setDebug-boolean-)` * ### Methods inherited from class java.lang.Object `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
Constructor Detail
* #### CachedKernel public CachedKernel() default constructor - does nothing.
Method Detail
* #### listOptions public java.util.Enumeration listOptions() Returns an enumeration describing the available options. Specified by: `[listOptions](../../../../weka/core/OptionHandler.html#listOptions--)` in interface `[OptionHandler](../../../../weka/core/OptionHandler.html "interface in weka.core")` Overrides: `[listOptions](../../../../weka/classifiers/functions/supportVector/Kernel.html#listOptions--)` in class `[Kernel](../../../../weka/classifiers/functions/supportVector/Kernel.html "class in weka.classifiers.functions.supportVector")` Returns: an enumeration of all the available options. * #### setOptions public void setOptions(java.lang.String[] options) throws java.lang.Exception Parses a given list of options. Specified by: `[setOptions](../../../../weka/core/OptionHandler.html#setOptions-java.lang.String:A-)` in interface `[OptionHandler](../../../../weka/core/OptionHandler.html "interface in weka.core")` Overrides: `[setOptions](../../../../weka/classifiers/functions/supportVector/Kernel.html#setOptions-java.lang.String:A-)` in class `[Kernel](../../../../weka/classifiers/functions/supportVector/Kernel.html "class in weka.classifiers.functions.supportVector")` 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: `[getOptions](../../../../weka/core/OptionHandler.html#getOptions--)` in interface `[OptionHandler](../../../../weka/core/OptionHandler.html "interface in weka.core")` Overrides: `[getOptions](../../../../weka/classifiers/functions/supportVector/Kernel.html#getOptions--)` in class `[Kernel](../../../../weka/classifiers/functions/supportVector/Kernel.html "class in weka.classifiers.functions.supportVector")` Returns: an array of strings suitable for passing to setOptions * #### eval public double eval(int id1, int id2, [Instance](../../../../weka/core/Instance.html "class in weka.core") inst1) throws java.lang.Exception Implements the abstract function of Kernel using the cache. This method uses the evaluate() method to do the actual dot product. Specified by: `[eval](../../../../weka/classifiers/functions/supportVector/Kernel.html#eval-int-int-weka.core.Instance-)` in class `[Kernel](../../../../weka/classifiers/functions/supportVector/Kernel.html "class in weka.classifiers.functions.supportVector")` Parameters: `id1` \- the index of the first instance in the dataset `id2` \- the index of the second instance in the dataset `inst1` \- 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. Specified by: `[numEvals](../../../../weka/classifiers/functions/supportVector/Kernel.html#numEvals--)` in class `[Kernel](../../../../weka/classifiers/functions/supportVector/Kernel.html "class in weka.classifiers.functions.supportVector")` Returns: the number of kernel evaluation. * #### numCacheHits public int numCacheHits() Returns the number of cache hits on dot products. Specified by: `[numCacheHits](../../../../weka/classifiers/functions/supportVector/Kernel.html#numCacheHits--)` in class `[Kernel](../../../../weka/classifiers/functions/supportVector/Kernel.html "class in weka.classifiers.functions.supportVector")` Returns: the number of cache hits. * #### clean public void clean() Frees the cache used by the kernel. Specified by: `[clean](../../../../weka/classifiers/functions/supportVector/Kernel.html#clean--)` in class `[Kernel](../../../../weka/classifiers/functions/supportVector/Kernel.html "class in weka.classifiers.functions.supportVector")` * #### 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](../../../../weka/core/Instances.html "class in weka.core") 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: `[buildKernel](../../../../weka/classifiers/functions/supportVector/Kernel.html#buildKernel-weka.core.Instances-)` in class `[Kernel](../../../../weka/classifiers/functions/supportVector/Kernel.html "class in weka.classifiers.functions.supportVector")` Parameters: `data` \- the data to base the kernel on Throws: `java.lang.Exception` \- if something goes wrong