jsat.distributions.kernels
Class BaseL2Kernel
- java.lang.Object
-
- jsat.distributions.kernels.BaseL2Kernel
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, KernelTrick, Parameterized
- Direct Known Subclasses:
- PukKernel, RationalQuadraticKernel, RBFKernel
public abstract class BaseL2Kernel extends java.lang.Object implements KernelTrick
Many Kernels can be described in terms the L2 norm with some operations performed on it. For example, theRBFKernelandRationalQuadraticKernelcan both be expressed in terms of the L2 norm of the two inputs. To simplify the addition of other kernels based on the same norm, this base class exists.
All Kernels extending this base kernel support acceleration. This is done making use of the fact that || x - y ||2 = x x' +y y' - 2 x y'
Thus the cached value for each vector is its self dot product.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description BaseL2Kernel()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description voidaddToCache(Vec newVec, java.util.List<java.lang.Double> cache)Appends the new cache values for the given vector to the list of cache values.abstract KernelTrickclone()abstract doubleeval(int a, int b, java.util.List<? extends Vec> trainingSet, java.util.List<java.lang.Double> cache)Produces the correct kernel evaluation given the training set and the cache generated byKernelTrick.getAccelerationCache(List).abstract doubleeval(int a, Vec b, java.util.List<java.lang.Double> qi, java.util.List<? extends Vec> vecs, java.util.List<java.lang.Double> cache)Computes the kernel product between one vector in the original list of vectors with that of another vector not from the original list, but had information generated byKernelTrick.getQueryInfo(jsat.linear.Vec).abstract doubleeval(Vec a, Vec b)Evaluate this kernel function for the two given vectors.doubleevalSum(java.util.List<? extends Vec> finalSet, java.util.List<java.lang.Double> cache, double[] alpha, Vec y, int start, int end)Performs an efficient summation of kernel products of the form
∑ αi k(xi, y)
where x are the final set of vectors, and α the associated scalar multipliersdoubleevalSum(java.util.List<? extends Vec> finalSet, java.util.List<java.lang.Double> cache, double[] alpha, Vec y, java.util.List<java.lang.Double> qi, int start, int end)Performs an efficient summation of kernel products of the form
∑ αi k(xi, y)
where x are the final set of vectors, and α the associated scalar multipliersjava.util.List<java.lang.Double>getAccelerationCache(java.util.List<? extends Vec> trainingSet)Creates a new list cache values from a given list of training set vectors.java.util.List<java.lang.Double>getQueryInfo(Vec q)Pre computes query information that would have be generated if the query was a member of the original list of vectors when callingKernelTrick.getAccelerationCache(java.util.List).booleansupportsAcceleration()Indicates if this kernel supports building an acceleration cache using theKernelTrick.getAccelerationCache(List)and associated cache accelerated methods.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.distributions.kernels.KernelTrick
normalized, toString
-
Methods inherited from interface jsat.parameters.Parameterized
getParameter, getParameters
-
-
-
-
Method Detail
-
eval
public abstract double eval(Vec a, Vec b)
Description copied from interface:KernelTrickEvaluate this kernel function for the two given vectors.- Specified by:
evalin interfaceKernelTrick- Parameters:
a- the first vectorb- the first vector- Returns:
- the evaluation
-
clone
public abstract KernelTrick clone()
- Specified by:
clonein interfaceKernelTrick- Overrides:
clonein classjava.lang.Object
-
supportsAcceleration
public boolean supportsAcceleration()
Description copied from interface:KernelTrickIndicates if this kernel supports building an acceleration cache using theKernelTrick.getAccelerationCache(List)and associated cache accelerated methods. By default this method will returnfalse. Iftrue, then a cache can be obtained from this matrix and used in conjunction withKernelTrick.eval(int, Vec, List, List, List)andKernelTrick.eval(int, int, List, List)to perform kernel products.- Specified by:
supportsAccelerationin interfaceKernelTrick- Returns:
trueif cache acceleration is supported for this kernel,falseotherwise.
-
getAccelerationCache
public java.util.List<java.lang.Double> getAccelerationCache(java.util.List<? extends Vec> trainingSet)
Description copied from interface:KernelTrickCreates a new list cache values from a given list of training set vectors. If this kernel does not support acceleration,nullwill be returned.- Specified by:
getAccelerationCachein interfaceKernelTrick- Parameters:
trainingSet- the list of training set vectors- Returns:
- a list of cache values that may be used by this kernel
-
getQueryInfo
public java.util.List<java.lang.Double> getQueryInfo(Vec q)
Description copied from interface:KernelTrickPre computes query information that would have be generated if the query was a member of the original list of vectors when callingKernelTrick.getAccelerationCache(java.util.List). This can then be used if a large number of kernel computations are going to be done against points in the original set for a point that is outside the original space.
If this kernel does not support acceleration,nullwill be returned.- Specified by:
getQueryInfoin interfaceKernelTrick- Parameters:
q- the query point to generate cache information for- Returns:
- the cache information for the query point
-
addToCache
public void addToCache(Vec newVec, java.util.List<java.lang.Double> cache)
Description copied from interface:KernelTrickAppends the new cache values for the given vector to the list of cache values. This method is present for online style kernel learning algorithms, where the set of vectors is not known in advance. When a vector is added to the set of kernel vectors, its cache values can be added using this method.
The results of calling this sequentially on a lit of vectors starting with an empty double list is equivalent to getting the results from callingKernelTrick.getAccelerationCache(java.util.List)
If this kernel does not support acceleration, this method call will function as a nop.- Specified by:
addToCachein interfaceKernelTrick- Parameters:
newVec- the new vector to add to the cache valuescache- the original list of cache values to add to
-
eval
public abstract double eval(int a, Vec b, java.util.List<java.lang.Double> qi, java.util.List<? extends Vec> vecs, java.util.List<java.lang.Double> cache)Description copied from interface:KernelTrickComputes the kernel product between one vector in the original list of vectors with that of another vector not from the original list, but had information generated byKernelTrick.getQueryInfo(jsat.linear.Vec).
If the cache input isnull, thenKernelTrick.eval(jsat.linear.Vec, jsat.linear.Vec)will be called directly.- Specified by:
evalin interfaceKernelTrick- Parameters:
a- the index of the vector in the cacheb- the other vectorqi- the query information about bvecs- the list of vectors used to build the cachecache- the cache associated with the given list of vectors- Returns:
- the kernel product of the two vectors
-
eval
public abstract double eval(int a, int b, java.util.List<? extends Vec> trainingSet, java.util.List<java.lang.Double> cache)Description copied from interface:KernelTrickProduces the correct kernel evaluation given the training set and the cache generated byKernelTrick.getAccelerationCache(List). The training vectors should be in the same order.- Specified by:
evalin interfaceKernelTrick- Parameters:
a- the index of the first training vectorb- the index of the second training vectortrainingSet- the list of training set vectorscache- the double list of cache values generated by this kernel for the given training set- Returns:
- the same kernel evaluation result as
KernelTrick.eval(jsat.linear.Vec, jsat.linear.Vec)
-
evalSum
public double evalSum(java.util.List<? extends Vec> finalSet, java.util.List<java.lang.Double> cache, double[] alpha, Vec y, int start, int end)
Description copied from interface:KernelTrickPerforms an efficient summation of kernel products of the form
∑ αi k(xi, y)
where x are the final set of vectors, and α the associated scalar multipliers- Specified by:
evalSumin interfaceKernelTrick- Parameters:
finalSet- the final set of vectorscache- the cache associated with the final set of vectorsalpha- the coefficients associated with each vectory- the vector to perform the summed kernel products againststart- the starting index (inclusive) to sum fromend- the ending index (exclusive) to sum from- Returns:
- the sum of the multiplied kernel products
-
evalSum
public double evalSum(java.util.List<? extends Vec> finalSet, java.util.List<java.lang.Double> cache, double[] alpha, Vec y, java.util.List<java.lang.Double> qi, int start, int end)
Description copied from interface:KernelTrickPerforms an efficient summation of kernel products of the form
∑ αi k(xi, y)
where x are the final set of vectors, and α the associated scalar multipliers- Specified by:
evalSumin interfaceKernelTrick- Parameters:
finalSet- the final set of vectorscache- the cache associated with the final set of vectorsalpha- the coefficients associated with each vectory- the vector to perform the summed kernel products againstqi- the query information about ystart- the starting index (inclusive) to sum fromend- the ending index (exclusive) to sum from- Returns:
- the sum of the multiplied kernel products
-
-
DataMelt 3.0 © DataMelt by jWork.ORG