Element_PI.PersImage

Note

The implementation of this class is adapted from the scikit-tda/PerSim package, whose code can be found at this link.

class Element_PI.PersImage(pixels=20, 20, spread=None, specs=None, kernel_type='gaussian', weighting_type='linear', verbose=True)

Initialize a persistence image generator.

Parameters
  • pixels (pair of ints like (int, int)) –

    • Tuple representing number of pixels in return image along x and y axis.

  • spread (float) –

    • Standard deviation of gaussian kernel

  • specs (dict) –

    • Parameters for shape of image with respect to diagram domain.

    • Units are specified in Angstroms.

    • This is used if you would like images to have a particular range. Shaped like:

      {
          "maxBD": float,
          "minBD": float
      }
      

  • kernel_type (string or ..) –

    • TODO: Implement this feature.

    • Determine which type of kernel used in the convolution, or pass in custom kernel. Currently only implements Gaussian.

  • weighting_type (string or ..) –

    • TODO: Implement this feature.

    • Determine which type of weighting function used, or pass in custom weighting function.

    • Currently only implements linear weighting.

Methods

__init__([pixels, spread, specs, …])

Initialize self.

transform(diagrams)

Convert diagram or list of diagrams to a persistence image.

weighting([landscape])

Define a weighting function.

kernel([spread])

This will return whatever kind of kernel we want to use.

to_landscape(diagram)

Convert a diagram to a landscape (birth, death) -> (birth, death-birth)

show(imgs[, ax])

Visualize the persistence image.

__init__(pixels=20, 20, spread=None, specs=None, kernel_type='gaussian', weighting_type='linear', verbose=True)

Initialize self. See help(type(self)) for accurate signature.

transform(diagrams)

Convert diagram or list of diagrams to a persistence image.

Parameters

diagrams (list of or singleton diagram, list of pairs. [(birth, death)]) –

  • Persistence diagrams to be converted to persistence images.

  • It is assumed they are in (birth, death) format.

  • Can input a list of diagrams or a single diagram.

Returns

imgs

  • Persistence images converted from corresponding diagrams

Return type

list or singular

weighting(landscape=None)
Define a weighting function.

Note

For stability results to hold, the function must be 0 at y=0.

Parameters

landscape (Numpy array) –

  • Converted diagram feature (see diagram argument in tranform function)

  • Note: diagram converted to landscape in to_landscape function

Returns

weighting_fn

  • The weighting function based on specifications in __init__

Return type

function

kernel(spread=1)
This will return whatever kind of kernel we want to use.

Must have signature (ndarray size NxM, ndarray size 1xM) -> ndarray size Nx1.

Parameters

spread (float, optional) –

  • Default: 1

  • Variance/covariance for the kernel

Returns

kernel_fn

  • Kernel function based on specification in __init__

Return type

function

static to_landscape(diagram)

Convert a diagram to a landscape (birth, death) -> (birth, death-birth)

Parameters

diagram (list of pairs, [(birth, death)]) –

  • Persistence diagram to be converted to persistence image.

  • It is assumed to be in (birth, death) format.

Returns

diagram

  • Converted persistence diagram with coordinates [(birth, death-birth)]

Return type

list of pairs, [(birth, death)]

show(imgs, ax=None)

Visualize the persistence image.

Parameters
  • imgs (Numpy array) –

    • Persistence images to show

    • Can be list of images or single image

  • ax (Axes instance from matplotlib.pyplot, optional) –

    • Option to provide a plotting object for plotting PI

Returns

  • None (None)

  • No explicit return. Plots the PI on the given Axes (or a new one if not given).