mvpa2.kernels.CachedKernel¶

class
mvpa2.kernels.
CachedKernel
(kernel=None, *args, **kwargs)¶ Kernel which caches all data to avoid duplicate computation
This kernel is very useful for any analysis which will retrain or repredict the same data multiple times, as this kernel will avoid recalculating the kernel function. Examples of such analyses include cross validation, bootstrapping, and model selection (assuming the kernel function itself does not change, e.g. when selecting for C in an SVM).
The kernel will automatically cache any new data sent through compute, and will be able to use this cache whenever a subset of this data is sent through compute again. If new (uncached) data is sent through compute, then the cache is recreated from scratch. Therefore, you should compute the kernel on the entire superset of your data before using this kernel normally (computing a new cache invalidates any previous cached data).
The cache is asymmetric for lhs and rhs, so compute(d1, d2) does not create a cache usable for compute(d2, d1).
Attributes
descr
Description of the object if any Methods
add_conversion
(typename, methodfull, methodraw)Adds methods to the Kernel class for new conversions as_ls
(kernel)as_np
()Converts this kernel to a Numpybased representation as_raw_ls
(kernel)as_raw_np
()Directly return this kernel as a numpy array. as_raw_sg
(kernel)Converts directly to a Shogun kernel as_sg
(kernel)Converts this kernel to a Shogunbased representation cleanup
()Wipe out internal representation compute
(ds1[, ds2, force])Automatically computes and caches the kernel or extracts the computed
(\*args, \*\*kwargs)Compute kernel and return self reset
()Initialize
CachedKernel
Parameters: kernel : Kernel
Base kernel to cache. Any kernel which can be converted to a
NumpyKernel
is allowedenable_ca : None or list of str
Names of the conditional attributes which should be enabled in addition to the default ones
disable_ca : None or list of str
Names of the conditional attributes which should be disabled
Attributes
descr
Description of the object if any Methods
add_conversion
(typename, methodfull, methodraw)Adds methods to the Kernel class for new conversions as_ls
(kernel)as_np
()Converts this kernel to a Numpybased representation as_raw_ls
(kernel)as_raw_np
()Directly return this kernel as a numpy array. as_raw_sg
(kernel)Converts directly to a Shogun kernel as_sg
(kernel)Converts this kernel to a Shogunbased representation cleanup
()Wipe out internal representation compute
(ds1[, ds2, force])Automatically computes and caches the kernel or extracts the computed
(\*args, \*\*kwargs)Compute kernel and return self reset
()
compute
(ds1, ds2=None, force=False)¶ Automatically computes and caches the kernel or extracts the relevant part of a precached kernel into self._k
Parameters: force : bool
If True it forces recaching of the kernel. It is advised to be used whenever explicitly precaching the kernel and it is known that data was changed.
