eXNN.InnerNeuralTopology.api
1import matplotlib 2import torch 3from typing import Dict, List 4from eXNN.InnerNeuralTopology.homologies import InnerNetspaceHomologies, _ComputeBarcode 5 6 7def ComputeBarcode(data: torch.Tensor, 8 hom_type: str, 9 coefs_type: str) -> matplotlib.figure.Figure: 10 """This function plots persistent homologies for a cloud of points as barcodes. 11 12 Args: 13 data (torch.Tensor): input data of shape NxC1x...xCk, 14 where N is the number of data points, 15 C1,...,Ck are dimensions of each data point 16 hom_type (str): homotopy type 17 coefs_type (str): coefficients type 18 19 Returns: 20 matplotlib.figure.Figure: barcode plot 21 """ 22 return _ComputeBarcode(data, hom_type, coefs_type) 23 24 25def NetworkHomologies(model: torch.nn.Module, 26 data: torch.Tensor, 27 layers: List[str], 28 hom_type: str, 29 coefs_type: str) -> Dict[str, matplotlib.figure.Figure]: 30 """ 31 The function plots persistent homologies for latent representations 32 on different levels of the neural network as barcodes. 33 34 Args: 35 model (torch.nn.Module): neural network 36 data (torch.Tensor): input data of shape NxC1x...xCk, 37 where N is the number of data points, 38 C1,...,Ck are dimensions of each data point 39 layers (List[str]): list of layers for visualization. Defaults to None. 40 If None, visualization for all layers is performed 41 hom_type (str): homotopy type 42 coefs_type (str): coefficients type 43 44 Returns: 45 Dict[str, matplotlib.figure.Figure]: dictionary with a barcode plot for each layer 46 """ 47 res = {} 48 for layer in layers: 49 res[layer] = InnerNetspaceHomologies(model, data, layer, hom_type, coefs_type) 50 return res
8def ComputeBarcode(data: torch.Tensor, 9 hom_type: str, 10 coefs_type: str) -> matplotlib.figure.Figure: 11 """This function plots persistent homologies for a cloud of points as barcodes. 12 13 Args: 14 data (torch.Tensor): input data of shape NxC1x...xCk, 15 where N is the number of data points, 16 C1,...,Ck are dimensions of each data point 17 hom_type (str): homotopy type 18 coefs_type (str): coefficients type 19 20 Returns: 21 matplotlib.figure.Figure: barcode plot 22 """ 23 return _ComputeBarcode(data, hom_type, coefs_type)
This function plots persistent homologies for a cloud of points as barcodes.
Args: data (torch.Tensor): input data of shape NxC1x...xCk, where N is the number of data points, C1,...,Ck are dimensions of each data point hom_type (str): homotopy type coefs_type (str): coefficients type
Returns: matplotlib.figure.Figure: barcode plot
26def NetworkHomologies(model: torch.nn.Module, 27 data: torch.Tensor, 28 layers: List[str], 29 hom_type: str, 30 coefs_type: str) -> Dict[str, matplotlib.figure.Figure]: 31 """ 32 The function plots persistent homologies for latent representations 33 on different levels of the neural network as barcodes. 34 35 Args: 36 model (torch.nn.Module): neural network 37 data (torch.Tensor): input data of shape NxC1x...xCk, 38 where N is the number of data points, 39 C1,...,Ck are dimensions of each data point 40 layers (List[str]): list of layers for visualization. Defaults to None. 41 If None, visualization for all layers is performed 42 hom_type (str): homotopy type 43 coefs_type (str): coefficients type 44 45 Returns: 46 Dict[str, matplotlib.figure.Figure]: dictionary with a barcode plot for each layer 47 """ 48 res = {} 49 for layer in layers: 50 res[layer] = InnerNetspaceHomologies(model, data, layer, hom_type, coefs_type) 51 return res
The function plots persistent homologies for latent representations on different levels of the neural network as barcodes.
Args: model (torch.nn.Module): neural network data (torch.Tensor): input data of shape NxC1x...xCk, where N is the number of data points, C1,...,Ck are dimensions of each data point layers (List[str]): list of layers for visualization. Defaults to None. If None, visualization for all layers is performed hom_type (str): homotopy type coefs_type (str): coefficients type
Returns: Dict[str, matplotlib.figure.Figure]: dictionary with a barcode plot for each layer