Previous topic

backends

Next topic

backends.scipy_backend

This Page

backends.cython_backend

class glimpse.backends.cython_backend.CythonBackend

IBackend implementation using custom C++ code.

ContrastEnhance(data, kwidth, bias, scaling, out=None)

Apply local contrast stretch to an array.

Given a local input neighborhood \(X\), the output is

\[y = \frac{x_c - \mu}{\max(\sigma, \epsilon)}\]

where \(x_c\) is the center of the input neighborhood, \(\mu\) and \(\sigma\) are the mean and standard deviation of \(X\), and \(\epsilon\) is a bias term. This term is used to avoid the amplificiation of noise and to ensure a non-zero divisor.

Parameters:
  • data (2D ndarray of float) – Input data.
  • kwidth (int) – Kernel width.
  • bias (float) – Normalizing term \(\epsilon\) in denominator.
  • scaling (positive int) – Subsampling factor.
  • out (2D ndarray of float) – Array in which to store result. If None, a new array will be created.
Return type:

2D ndarray of float

DotProduct(data, kernels, scaling=None, out=None, **ignore)

Convolve an array with a set of kernels.

This function compares each kernel \(W\) and input neigborhood \(X\) using a dot product, where the output is given by

\[y = X^T W \, ,\]

where \(X^T\) denotes the matrix transpose.

Parameters:
  • data (3D ndarray of float) – Input data.
  • kernels (4D ndarray of float) – Array of 3D kernels.
  • scaling (positive int) – Subsampling factor.
  • out (3D ndarray of float) – Array in which to store result. If None, a new array will be created.
Return type:

3D ndarray of float

GlobalMax(data, out=None)

Find the per-band maxima.

Parameters:
  • data (3D ndarray of float) – Input data.
  • out (1D ndarray of float) – Array in which to store result. If None, a new array will be created.
Return type:

1D ndarray of float

InputMapShapeForOutput(kheight, kwidth, scaling, oheight, owidth)

Given an output map with the given dimensions, compute the shape of the corresponding input map.

This is the inverse of OutputMapShapeForInput().

Parameters:
  • kheight (positive int) – Kernel height.
  • kwidth (positive int) – Kernel width.
  • scaling (positive int) – Subsampling factor.
  • oheight (positive int) – Output map height.
  • owidth (positive int) – Output map width.
Returns:

Input map height and width, in that order.

Return type:

2-tuple of int

LocalMax(data, kwidth, scaling, out=None)

Convolve maps with local 2-D max filter.

The output for each local input neighborhood \(X\) is

\[y = max_i \ x_i \, .\]
Parameters:
  • data (3D ndarray of float) – Input data.
  • kwidth (positive int) – Width of pooling neighborhood.
  • scaling (positive int) – Subsampling factor.
  • out (3D ndarray of float) – Array in which to store result. If None, a new array will be created.
Return type:

3D ndarray of float

NormDotProduct(data, kernels, bias=None, scaling=None, out=None, **ignore)

Convolve an array with a set of kernels, normalizing the response by the vector length of the input neighborhood.

The output for each kernel \(W\) and input neighborhood \(X\) is given by

\[y = \frac{X^T W}{\left\Vert X \right\Vert \left\Vert W \right\Vert} \, ,\]

where \(\left\Vert \cdot \right\Vert\) denotes the Euclidean norm.

Parameters:
  • data (3D ndarray of float) – Input data.
  • kernels (4D ndarray of float) – Array of 3D kernels, where each kernel is expected to have unit vector length.
  • bias (float) – Additive term in denominator.
  • scaling (positive int) – Subsampling factor.
  • out (3D ndarray of float) – Array in which to store result. If None, a new array will be created.
Return type:

3D ndarray of float

NormRbf(data, kernels, bias=None, beta=None, scaling=None, out=None, **ignore)

Compare kernels to input data using the RBF activation function with normed inputs.

The output for each kernel \(W\) and input neighborhood \(X\) is given by

\[y = \exp \left\{ - 2\beta \left(1 - \text{NDP}(X, W) \right) \right\} \, ,\]

where \(\text{NDP}(\cdot)\) is the normalized dot product.

Parameters:
  • data (3D ndarray of float) – Input data.
  • kernels (4D ndarray of float) – Array of 3D kernels, where each kernel is expected to have unit length.
  • bias (float) – Additive term in denominator.
  • beta (float) – Tuning parameter for radial basis function.
  • scaling (positive int) – Subsampling factor.
  • out (3D ndarray of float) – Array in which to store result. If None, a new array will be created.
Return type:

3D ndarray of float

OutputMapShapeForInput(kheight, kwidth, scaling, iheight, iwidth)

Given an input map with the given dimensions, compute the shape of the corresponding output map.

Parameters:
  • kheight (positive int) – Kernel height.
  • kwidth (positive int) – Kernel width.
  • scaling (positive int) – Subsampling factor.
  • iheight (positive int) – Input map height.
  • iwidth (positive int) – Input map width.
Returns:

Output map height and width, in that order.

Return type:

2-tuple of int

PrepareArray(array)

Prepare array to be passed to backend methods.

Parameters:array (ndarray of float) – Array to be prepared, which will not be modified.
Return type:ndarray of float
Rbf(data, kernels, beta=None, scaling=None, out=None, **ignore)

Compare kernels to input data using the RBF activation function.

The output for each kernel \(W\) and input neighborhood \(X\) is given by

\[y = \exp \left\{ - \beta \left\Vert X - W \right\Vert ^2 \right\} \, ,\]

where \(\beta\) controls the sensitivity of the RBF.

Parameters:
  • data (3D ndarray of float) – Input data.
  • kernels (4D ndarray of float) – Array of 3D kernels.
  • beta (float) – Tuning parameter for radial basis function.
  • scaling (positive int) – Subsampling factor.
  • out (3D ndarray of float) – Array in which to store result. If None, a new array will be created.
Return type:

3D ndarray of float