Create patches by sampling components uniformly.
Draw samples of layer activity and build a simple patch model.
Parameters: |
|
---|---|
Return type: | list of (N+1)-dimensional array, where N is the number of dimensions in a patch. |
Returns: | Set of patches for each patch size. |
For each size in patch_widths, a set of num_samples is drawn from the images and modelled via the learner.
Create patches from a histogram over sample values.
Parameters: |
|
---|---|
Return type: | 2D array with num_patches rows and N columns, where N is the number of columns in samples. |
Returns: | created patches |
Estimate parameters of a normal distribution and sample from it.
Parameters: |
|
---|---|
Return type: | 2D array with num_patches rows and N columns, where N is the number of columns in samples. |
Returns: | created patches |
Estimate patches as centroids of samples using k-Means.
Parameters: |
|
---|---|
Return type: | 2D array with num_patches rows and N columns, where N is the number of columns in samples. |
Returns: | created patches |
Estimate patches as centroids of samples using nearest-value k-Means.
This performs k-Means cluster of the samples, and then replaces each centroid with its nearest cluster element.
Parameters: |
|
---|---|
Return type: | 2D array with num_patches rows and N columns, where N is the number of columns in samples. |
Returns: | created patches |
Estimate patches as centroids of samples using k-Medoids.
This requires the Pycluster library to be installed.
Parameters: |
|
---|---|
Return type: | 2D array with num_patches rows and N columns, where N is the number of columns in samples. |
Returns: | created patches |
Estimate patches using Independent Components Analysis.
Parameters: |
|
---|---|
Return type: | 2D array with num_patches rows and N columns, where N is the number of columns in samples. |
Returns: | created patches |
Estimate patches using Principal Components Analysis.
Parameters: |
|
---|---|
Return type: | 2D array with num_patches rows and N columns, where N is the number of columns in samples. |
Returns: | created patches |
Estimate patches using Non-negative Matrix Factorization.
Parameters: |
|
---|---|
Return type: | 2D array with num_patches rows and N columns, where N is the number of columns in samples. |
Returns: | created patches |
Estimate patches using Sparse Principal Components Analysis.
See sklearn.decomposition.MiniBatchSparsePCA for more information.
Parameters: |
|
---|---|
Return type: | 2D array with num_patches rows and N columns, where N is the number of columns in samples. |
Returns: | created patches |
Sample patches of multiple sizes from a set of images.
Parameters: |
|
---|---|
Returns: | Kernels, and their corresponding locations. Kernels are returned as a list of (N+1)-dimensional arrays, where N is the number of dimensions in a single kernel. The list axis and first axis of the array correspond to the kernel size and kernel offset, respectively. Locations are returned as a 2D list of 4-tuples, where list axes correspond to kernel size and kernel offset, respectively. Each location is given as a 4-tuple, with elements corresponding to the input state index, scale, y-offset, and x-offset of the corresponding kernel. |
Note that the maximum kernel size must not be larger than the smallest response map at the given layer. To imprint a 7x7 kernel from C1, for example, the C1 response map for the lowest frequency band must be at least 7x7 in spatial extent.
Examples:
For each kernel size, sample 10 image patches from four (random) images. Kernels will be 7 and 11 pixel wide.
>>> model = BaseModel()
>>> images = np.random.random((4,100,100)).astype(ACTIVATION_DTYPE)
>>> states = map(model.MakeState, images)
>>> kernels,locations = SamplePatches(model, BaseLayer.IMAGE,
kernel_sizes=(7,11), num_kernels=10, input_state=states)
The result will contain a sub-list for each of the two kernel sizes.
>>> assert len(kernels) == len(images)
>>> assert all(len(ks) == 10 for ks in kernels)
>>> assert len(locations) == len(images)
>>> assert all(len(ls) == 10 for ls in locations)