jsat.datatransform.kernel
Class Nystrom
- java.lang.Object
-
- jsat.datatransform.DataTransformBase
-
- jsat.datatransform.kernel.Nystrom
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, DataTransform, Parameterized
public class Nystrom extends DataTransformBase
An implementation of the Nystrom approximation for any Kernel Trick. The full rank kernel is approximated by a basis set of a subset of the data points that make up the original data set. Instead of explicitly forming the approximately decomposed matrix, this transform projects the original numeric features of a data set into a new feature space where the dot product in the linear space approximates the dot product in the given kernel space.
See:
- Williams, C.,&Seeger, M. (2001). Using the Nyström Method to Speed Up Kernel Machines. Advances in Neural Information Processing Systems 13 (pp. 682–688). MIT Press. Retrieved from here
- Yang, T., Li, Y.-F., Mahdavi, M., Jin, R.,&Zhou, Z.-H. (2012). Nystrom Method vs Random Fourier Features A Theoretical and Empirical Comparison. Advances in Neural Information Processing Systems (pp. 485–493). Retrieved from here
- Kumar, S., Mohri, M.,&Talwalkar, A. (2012). Sampling methods for the Nyström method. The Journal of Machine Learning Research, 5, 981–1006. Retrieved from here
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classNystrom.SamplingMethodDifferent sample methods may be used to select a better and more representative set of vectors to form the basis vectors at increased cost, wherenis the number of data points in the full data set andbis the number of basis vectors to obtain.
-
Constructor Summary
Constructors Constructor and Description Nystrom()Creates a new Nystrom approximation object using theRBF Kernelwith 500 basis vectorsNystrom(KernelTrick k, DataSet dataset, int basisSize, Nystrom.SamplingMethod method)Creates a new Nystrom approximation objectNystrom(KernelTrick k, DataSet dataset, int basisSize, Nystrom.SamplingMethod method, double ridge, boolean sampleWithReplacment)Creates a new Nystrom approximation objectNystrom(KernelTrick k, int basisSize)Creates a new Nystrom approximation objectNystrom(KernelTrick k, int basisSize, Nystrom.SamplingMethod method, double ridge, boolean sampleWithReplacment)Creates a new Nystrom approximation object
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description Nystromclone()voidfit(DataSet dataset)Fits this transform to the given dataset.Nystrom.SamplingMethodgetBasisSamplingMethod()Returns the method of selecting the basis vectorsintgetBasisSize()Returns the number of basis vectors to useintgetDimension()Returns the number of dimensions to project down tooKernelTrickgetKernel()doublegetRidge()Returns the regularization value added to each eigen valuestatic java.util.List<Vec>sampleBasisVectors(KernelTrick k, DataSet dataset, java.util.List<Vec> X, Nystrom.SamplingMethod method, int basisSize, boolean sampleWithReplacment, java.util.Random rand)Performs sampling of a data set for a subset of the vectors that make a good set of basis vectors for forming an approximation of a full kernel space.voidsetBasisSamplingMethod(Nystrom.SamplingMethod method)Sets the method of selecting the basis vectorsvoidsetBasisSize(int basisSize)Sets the basis size for the Kernel PCA to be learned from.voidsetDimension(int dimension)Sets the dimension of the new feature space, which is the number of principal components to select from the kernelized feature space.voidsetKernel(KernelTrick k)voidsetRidge(double ridge)Sets the regularization parameter to add to the eigen values of the gram matrix.DataPointtransform(DataPoint dp)Returns a new data point that is a transformation of the original data point.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.parameters.Parameterized
getParameter, getParameters
-
-
-
-
Constructor Detail
-
Nystrom
public Nystrom(KernelTrick k, DataSet dataset, int basisSize, Nystrom.SamplingMethod method)
Creates a new Nystrom approximation object- Parameters:
k- the kernel trick to form an approximation ofdataset- the data set to form the approximate feature space frombasisSize- the number of basis vectors to use, this is the output dimension size.method- what sampling method should be used to select the basis vectors from the full data set.
-
Nystrom
public Nystrom()
Creates a new Nystrom approximation object using theRBF Kernelwith 500 basis vectors
-
Nystrom
public Nystrom(KernelTrick k, int basisSize)
Creates a new Nystrom approximation object- Parameters:
k- the kernel trick to form an approximation ofbasisSize- the number of basis vectors to use, this is the output dimension size.
-
Nystrom
public Nystrom(KernelTrick k, int basisSize, Nystrom.SamplingMethod method, double ridge, boolean sampleWithReplacment)
Creates a new Nystrom approximation object- Parameters:
k- the kernel trick to form an approximation ofbasisSize- the number of basis vectors to use, this is the output dimension size.method- what sampling method should be used to select the basis vectors from the full data set.ridge- a non negative additive term to regularize the eigen values of the decomposition.sampleWithReplacment-trueif the basis vectors should be sampled with replacement,falseif they should not.
-
Nystrom
public Nystrom(KernelTrick k, DataSet dataset, int basisSize, Nystrom.SamplingMethod method, double ridge, boolean sampleWithReplacment)
Creates a new Nystrom approximation object- Parameters:
k- the kernel trick to form an approximation ofdataset- the data set to form the approximate feature space frombasisSize- the number of basis vectors to use, this is the output dimension size.method- what sampling method should be used to select the basis vectors from the full data set.ridge- a non negative additive term to regularize the eigen values of the decomposition.sampleWithReplacment-trueif the basis vectors should be sampled with replacement,falseif they should not.
-
-
Method Detail
-
fit
public void fit(DataSet dataset)
Description copied from interface:DataTransformFits this transform to the given dataset. Some transforms can only be learned from classification or regression datasets. If an incompatible dataset type is given, aFailedToFitExceptionexception may be thrown.- Parameters:
dataset- the dataset to fir this transform to
-
sampleBasisVectors
public static java.util.List<Vec> sampleBasisVectors(KernelTrick k, DataSet dataset, java.util.List<Vec> X, Nystrom.SamplingMethod method, int basisSize, boolean sampleWithReplacment, java.util.Random rand)
Performs sampling of a data set for a subset of the vectors that make a good set of basis vectors for forming an approximation of a full kernel space. While these methods are motivated from Nystrom's algorithm, they are also useful for others.- Parameters:
k- the kernel trick to form the basis fordataset- the data set to sample fromX- the list of vectors from the data setmethod- the sampling method to usebasisSize- the number of basis vectors to selectsampleWithReplacment- whether or not the sample with replacementrand- the source of randomness for the sampling- Returns:
- a list of basis vectors sampled from the data set.
- See Also:
Nystrom.SamplingMethod
-
transform
public DataPoint transform(DataPoint dp)
Description copied from interface:DataTransformReturns a new data point that is a transformation of the original data point. This new data point is a different object, but may contain the same references as the original data point. It is not guaranteed that you can mutate the transformed point without having a side effect on the original point.- Parameters:
dp- the data point to apply a transformation to- Returns:
- a transformed data point
-
clone
public Nystrom clone()
- Specified by:
clonein interfaceDataTransform- Specified by:
clonein classDataTransformBase
-
setRidge
public void setRidge(double ridge)
Sets the regularization parameter to add to the eigen values of the gram matrix. This can be particularly useful when using a large (500+) number of components.- Parameters:
ridge- the non-negative value in [0, ∞) to add to each eigen value
-
getRidge
public double getRidge()
Returns the regularization value added to each eigen value- Returns:
- the regularization value added to each eigen value
-
setDimension
public void setDimension(int dimension)
Sets the dimension of the new feature space, which is the number of principal components to select from the kernelized feature space.- Parameters:
dimension- the number of dimensions to project down too
-
getDimension
public int getDimension()
Returns the number of dimensions to project down too- Returns:
- the number of dimensions to project down too
-
setBasisSamplingMethod
public void setBasisSamplingMethod(Nystrom.SamplingMethod method)
Sets the method of selecting the basis vectors- Parameters:
method- the method of selecting the basis vectors
-
getBasisSamplingMethod
public Nystrom.SamplingMethod getBasisSamplingMethod()
Returns the method of selecting the basis vectors- Returns:
- the method of selecting the basis vectors
-
setBasisSize
public void setBasisSize(int basisSize)
Sets the basis size for the Kernel PCA to be learned from. Increasing the basis increase the accuracy of the transform, but increased the training time at a cubic rate.- Parameters:
basisSize- the number of basis vectors to build Kernel PCA from
-
getBasisSize
public int getBasisSize()
Returns the number of basis vectors to use- Returns:
- the number of basis vectors to use
-
setKernel
public void setKernel(KernelTrick k)
- Parameters:
k- the kernel trick to use
-
getKernel
public KernelTrick getKernel()
- Returns:
- the kernel trick to use
-
-
DataMelt 3.0 © DataMelt by jWork.ORG