mvpa2.kernels.base.CachedKernel

Inheritance diagram of CachedKernel

class mvpa2.kernels.base.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).

Methods

add_conversion(typename, methodfull, methodraw) Adds methods to the Kernel class for new conversions
as_np() Converts this kernel to a Numpy-based representation
as_raw_np() Directly return this kernel as a numpy array.
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

Initialize CachedKernel

Parameters:

kernel : Kernel

Base kernel to cache. Any kernel which can be converted to a NumpyKernel is allowed

enable_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

Methods

add_conversion(typename, methodfull, methodraw) Adds methods to the Kernel class for new conversions
as_np() Converts this kernel to a Numpy-based representation
as_raw_np() Directly return this kernel as a numpy array.
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
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 re-caching of the kernel. It is advised to be used whenever explicitly pre-caching the kernel and it is known that data was changed.