ruckus.convolution module

class ruckus.convolution.ConvolutionalRKHS(window_shape=(2,), stride=(1,), rkhs=None, *, flatten_samples=True, flatten_features=False, copy_X=True)[source]

Bases: ruckus.base.RKHS

Kernels can be applied directly to data, or as a filter to a convolution [1]. This class allows one to convolve an RKHS filter over \(N\mathrm{D}\) data.

The dimension of the sample indices is set by the length of the window_shape and stride parameters, which must match. For instance, one can take a \(2\times 3\) dimension window over the first two dimensions of the data by setting window_shape = (2,3) and stride=(1,1). After pulling the sliding window data, it is fitted to or transformed by the rkhs specified by the parameters.

  1. Mairal, J., Koniusz, P., Harchaoui, Z., Schmid, C. “Convolutional Kernel Networks.” Advances in Neural Information Processing Systems 27 (NIPS 2014)

Parameters
  • window_shape (tuple) – Default = (2,). Specifies the shape of the sliding window to be passed over the first len(window_shape) axes of the data.

  • stride (tuple) – Default = (1,). Specifies how many steps the window takes in each direction during the convolution.

  • rkhs (RKHS or None) – Default = None. Specifies the RKHS to be applied to the convolved data. If None, a base RKHS instance is generated.

  • flatten_samples (bool) – Default = True. If True, the axes which the window was applied to are flattened after the convolution. Ideal for passing to other RKHS instances which only recognize one sample dimension.

  • flatten_features (bool) – Default = False. If True, the original features of X and the new window axes are flattened together.

  • copy_X (bool) – Default = True. If True, input X is copied and stored by the model in the X_fit_ attribute. If no further changes will be done to X, setting copy_X=False saves memory by storing a reference.

Parameters
  • shape_in_ (tuple) – The required shape of the input datapoints, aka the shape of the domain space \(X\).

  • shape_out_ (tuple) – The final shape of the transformed datapoints, aka the shape of the Hilbert space \(H\).

  • X_fit_ (numpy.ndarray of shape (n_samples,)+self.shape_in_) – The data which was used to fit the model.

fit(X, y=None)[source]

Fit the model from data in X.

Parameters

X (numpy.ndarray of shape (n_samples, n_features_1,...,n_features_d)) – Training vector, where n_samples is the number of samples and (n_features_1,...,n_features_d) is the shape of the input data. Must be consistent with preprocessing instructions in self.rkhs.take and self.rkhs.filter after convolution.

Returns

The instance itself

Return type

RKHS

fit_transform(X, y=None)[source]

Fit the model from data in X and transform X.

Parameters

X (numpy.ndarray of shape (n_samples, n_features_1,...,n_features_d)) – Training vector, where n_samples is the number of samples and (n_features_1,...,n_features_d) is the shape of the input data. Must be consistent with preprocessing instructions in self.rkhs.take and self.rkhs.filter after convolution.

Returns

The transformed data

Return type

numpy.ndarray of shape (n_samples,)+self.shape_out_

transform(X)[source]

Transform X.

Parameters

X (numpy.ndarray of shape (n_samples, n_features_1,...,n_features_d)) – Data vector, where n_samples is the number of samples and (n_features_1,...,n_features_d) is the shape of the input data. These must match self.shape_in_.

Returns

The transformed data

Return type

numpy.ndarray of shape (n_samples,)+self.shape_out_