sksfa.utils.ReceptiveRebuilder

sksfa.utils.ReceptiveRebuilder(reconstruction_shape, copy=True)[source]

Reconstruction part of field slicing

This transformer takes input of shape (n_field_samples, n_features) and, given a reconstruction shape reshapes it to (n_samples, width, height, n_features) by simply reshaping. This is necessary to reconstruct the between-field structure in a sample to re-apply the slicer.

Parameters
reconstruction_shapetuple

A tuple defining the local structure to reconstruct without the sample dimension, e.g., (8, 8) will result the output to be of shape (n_samples, 8, 8, n_features).

copybool, default=True

If False, data passed to fit are overwritten and running fit(X).transform(X) will not yield the expected results, use fit_transform(X) instead.

Examples

>>> from sksfa.utils import ReceptiveRebuilder
>>> import numpy as np
>>>
>>> # This could come out of a slicer + transformation.
>>> sliced_input = np.repeat(np.arange(9)[..., None], 4, axis=1)
>>> print(f"Input shape: {sliced_input.shape}")
Input shape: (9, 4)
>>> for idx, sample in enumerate(sliced_input): print(f"Sample {idx}: {sample}")
Sample 0: [0 0 0 0]
Sample 1: [1 1 1 1]
Sample 2: [2 2 2 2]
Sample 3: [3 3 3 3]
Sample 4: [4 4 4 4]
Sample 5: [5 5 5 5]
Sample 6: [6 6 6 6]
Sample 7: [7 7 7 7]
Sample 8: [8 8 8 8]
>>> rebuilder = ReceptiveRebuilder(reconstruction_shape=(3, 3))
>>> rebuilder = rebuilder.fit(sliced_input)
>>>
>>> output = rebuilder.transform(sliced_input)
>>> print(f"Output shape: {output.shape}")
Output shape: (1, 3, 3, 4)
>>> print("Output sample:")
Output sample:
>>> for channel_idx in range(4): print(f"Channel {channel_idx}:\n{output[..., channel_idx].squeeze()}")
Channel 0:
[[0. 1. 2.]
 [3. 4. 5.]
 [6. 7. 8.]]
Channel 1:
[[0. 1. 2.]
 [3. 4. 5.]
 [6. 7. 8.]]
Channel 2:
[[0. 1. 2.]
 [3. 4. 5.]
 [6. 7. 8.]]
Channel 3:
[[0. 1. 2.]
 [3. 4. 5.]
 [6. 7. 8.]]