ProtoTorch API Reference

Datasets

Common Datasets

ProtoTorch datasets.

Abstract Datasets

Abstract Datasets are used to build your own datasets.

class prototorch.datasets.abstract.NumpyDataset(data, targets)[source]

Create a PyTorch TensorDataset from NumPy arrays.

Functions

Dimensions:

  • \(B\) … Batch size

  • \(P\) … Number of prototypes

  • \(n_x\) … Data dimension for vectorial data

  • \(n_w\) … Data dimension for vectorial prototypes

Activations

ProtoTorch activation functions.

prototorch.functions.activations.identity(x, beta=0.0)[source]

Identity activation function.

Definition: \(f(x) = x\)

Keyword Arguments

beta (float) – Ignored.

prototorch.functions.activations.sigmoid_beta(x, beta=10.0)[source]

Sigmoid activation function with scaling.

Definition: \(f(x) = \frac{1}{1 + e^{-\beta x}}\)

Keyword Arguments

beta (float) – Scaling parameter \(\beta\)

prototorch.functions.activations.swish_beta(x, beta=10.0)[source]

Swish activation function with scaling.

Definition: \(f(x) = \frac{x}{1 + e^{-\beta x}}\)

Keyword Arguments

beta (float) – Scaling parameter \(\beta\)

Distances

ProtoTorch distance functions.

prototorch.functions.distances.euclidean_distance(x, y)[source]

Compute the Euclidean distance between \(x\) and \(y\).

Compute \(\sqrt{{\langle \bm x - \bm y \rangle}_2}\)

Returns

Distance Tensor of shape \(X \times Y\)

Return type

torch.tensor

prototorch.functions.distances.euclidean_distance_matrix(x, y, squared=False, epsilon=1e-10)[source]

Computes an euclidean distances matrix given two distinct vectors. last dimension must be the vector dimension! compute the distance via the identity of the dot product. This avoids the memory overhead due to the subtraction!

  • x.shape = (number_of_x_vectors, vector_dim)

  • y.shape = (number_of_y_vectors, vector_dim)

output: matrix of distances (number_of_x_vectors, number_of_y_vectors)

prototorch.functions.distances.euclidean_distance_v2(x, y)[source]
prototorch.functions.distances.lomega_distance(x, y, omegas)[source]

Localized Omega distance.

Compute \({\| \Omega_k \bm x - \Omega_k \bm y_k \|}_p\)

Parameters

omegas (torch.tensor) – Three dimensional matrix

prototorch.functions.distances.lpnorm_distance(x, y, p)[source]

Calculate the lp-norm between \(\bm x\) and \(\bm y\). Also known as Minkowski distance.

Compute \({\| \bm x - \bm y \|}_p\).

Calls torch.cdist

Parameters

p – p parameter of the lp norm

prototorch.functions.distances.omega_distance(x, y, omega)[source]

Omega distance.

Compute \({\| \Omega \bm x - \Omega \bm y \|}_p\)

Parameters

omega (torch.tensor) – Two dimensional matrix

prototorch.functions.distances.squared_euclidean_distance(x, y)[source]

Compute the squared Euclidean distance between \(\bm x\) and \(\bm y\).

Compute \({\langle \bm x - \bm y \rangle}_2\)

Alias: prototorch.functions.distances.sed

prototorch.functions.distances.tangent_distance(signals, protos, subspaces, squared=False, epsilon=1e-10)[source]

Tangent distances based on the tensorflow implementation of Sascha Saralajews

For more info about Tangen distances see

DOI:10.1109/IJCNN.2016.7727534.

The subspaces is always assumed as transposed and must be orthogonal! For local non sparse signals subspaces must be provided!

  • shape(signals): batch x proto_number x channels x dim1 x dim2 x … x dimN

  • shape(protos): proto_number x dim1 x dim2 x … x dimN

  • shape(subspaces): (optional [proto_number]) x prod(dim1 * dim2 * … * dimN) x prod(projected_atom_shape)

subspace should be orthogonalized Pytorch implementation of Sascha Saralajew’s tensorflow code. Translation by Christoph Raab

Modules

ProtoTorch modules.

Utilities