morphoclass.layers.perslay module¶
Implementation of the PersLay layer.
-
class
morphoclass.layers.perslay.GaussianPointTransformer(out_features)¶ Bases:
morphoclass.layers.perslay.PointTransformerApplies Gaussian point transformation for persistence diagram embedding.
This transformation can be applied to persistence diagrams, and is implemented as described in [1]. Note that points are assumed to lie in a normalized diagram, i.e. coordinates should lie in the interval (0, 1).
Shapes:
input: [N, 2]. N is the total number of points in the batch (belonging to different persistence diagrams as specified by point_index), and 2 refers to the 2 coordinates of each point of each persistence diagram i.e. (birth_date, death_date).
point_index: [N]. N is the total number of points in the batch.
output: [N, Q]. N is the total number of points in the batch, and Q is the desired number of learnable sample points used in the transformation.
- Parameters
out_features (int) – Size of each output sample, corresponding to the desired number of sample points.
-
sample_points¶ Sample points of the transformation, with shape [2, Q].
- Type
tensor
-
sample_inverse_sigmas¶ Inverse standard deviations of the transformation, with shape [2, Q] since each of the 2 dimensions may have different sigma.
- Type
tensor
Examples
>>> inp = torch.tensor([[0.2, 0.3], [0.1, 0.4], [0.6, 0.3], [0.2, 0.1], [0.5, 0.2], [0.1, 0.3], [0.6, 0.2]]) >>> point_index = torch.tensor([0, 0, 0, 1, 1, 2, 2]) >>> m = GaussianPointTransformer(out_features=32) >>> output = m(inp) >>> print(inp.size()) torch.Size([7, 2]) >>> print(output.size()) torch.Size([7, 32])
References
[1] Carriere, Mathieu, et al. “PersLay: A Neural Network Layer for Persistence Diagrams and New Graph Topological Signatures.” stat 1050 (2019): 17.
-
extra_repr()¶ Get a string representation of layer parameters.
-
forward(input, point_index)¶ Perform the forward pass.
- Parameters
input (torch.Tensor) – A batch of input data.
point_index (torch.Tensor) – A segmentation map for the samples in the batch.
- Returns
The output tensor.
- Return type
torch.Tensor
-
reset_parameters()¶ Randomly initialize the trainable parameters.
-
training: bool¶
-
class
morphoclass.layers.perslay.PersLay(out_features, transformation='gaussian', operation='sum', weights='uniform')¶ Bases:
torch.nn.modules.module.ModuleApplies PersLay embedding layer.
This transformation can be applied to persistence diagrams, and is implemented as described in [1]. Note that points are assumed to lie in a normalized diagram, i.e. coordinates should lie in the interval (0, 1).
Shapes:
input : [N, 2]. N is the total number of points in the batch (belonging to different persistence diagrams as specified by point_index), and 2 refers to the 2 coordinates of each point of each persistence diagram i.e. (birth_date, death_date).
point_index : [N]. N is the total number of points in the batch.
output : [D, Q]. D is the number of different persistence diagrams in the batch, and Q is the desired number of learnable sample points used in the transformation.
- Parameters
out_features (int) – Output size of the produced embedding.
transformation (str or nn.Module) – A point transformation, mapping each point of a persistence diagram to a vector. One of ‘gaussian’, ‘pointwise’, or a nn.Module.
operation (str) – A permutation invariant operation. One of ‘sum’, ‘mean’, ‘max’.
weights (str) – Approach to be used for the weights. One of ‘attention’ (learnable pointwise weights), ‘uniform’ (all weights set to 1), ‘grid’ (learnable weights on a 10x10 grid).
References
[1] Carriere, Mathieu, et al. “PersLay: A Neural Network Layer for Persistence Diagrams and New Graph Topological Signatures.” stat 1050 (2019): 17.
-
forward(input, point_index)¶ Perform the forward pass.
- Parameters
input (torch.Tensor) – A batch of input data.
point_index (torch.Tensor) – A segmentation map for the samples in the batch.
- Returns
The output tensor.
- Return type
torch.Tensor
-
point_transformer: PointTransformer¶
-
reduction: Callable¶
-
reset_parameters()¶ Randomly initialize trainable parameters.
-
training: bool¶
-
class
morphoclass.layers.perslay.PointTransformer¶ Bases:
torch.nn.modules.module.Module,abc.ABCA point transformation for persistence diagram embedding.
-
abstract
extra_repr() → str¶ Get a string representation of layer parameters.
-
abstract
forward(input: torch.Tensor, point_index: torch.Tensor) → torch.Tensor¶ Perform the forward pass.
- Parameters
input (torch.Tensor) – A batch of input data.
point_index (torch.Tensor) – A segmentation map for the samples in the batch.
- Returns
The output tensor.
- Return type
torch.Tensor
-
training: bool¶
-
abstract
-
class
morphoclass.layers.perslay.PointwisePointTransformer(out_features, hidden_features=32)¶ Bases:
morphoclass.layers.perslay.PointTransformerApplies point-wise point transformation for persistence diagram embedding.
- Parameters
out_features (int) – Size of each output sample, corresponding to the desired number of sample points.
hidden_features (int) – The size of the hidden layer.
-
extra_repr()¶ Get a string representation of layer parameters.
-
forward(input, point_index)¶ Perform the forward pass.
- Parameters
input (torch.Tensor) – A batch of input data.
point_index (torch.Tensor) – A segmentation map for the samples in the batch.
- Returns
The output tensor.
- Return type
torch.Tensor
-
training: bool¶