class AlphaLayer(nn.Module): """ Alpha persistence layer Parameters: maxdim : maximum homology dimension (default=0) alg : algorithm 'hom' = homology (default) 'cohom' = cohomology """ def __init__(self, maxdim=0, alg='hom'): super(AlphaLayer, self).__init__() self.maxdim = maxdim self.fnobj = FlagDiagram() self.alg = alg def forward(self, x): xnp = x.cpu().detach().numpy() complex = None if xnp.shape[1] == 1: xnp = xnp.flatten() complex = delaunay_complex_1d(xnp) else: complex = delaunay_complex(xnp, maxdim=self.maxdim + 1) complex.initialize() dgms = self.fnobj.apply(complex, x, self.maxdim, self.alg) return dgms, True
class RipsLayer(nn.Module): """ Rips persistence layer Parameters: n : number of points maxdim : maximum homology dimension (default=1) """ def __init__(self, n, maxdim=1): super(RipsLayer, self).__init__() self.maxdim = maxdim self.complex = clique_complex(n, maxdim + 1) self.complex.initialize() self.fnobj = FlagDiagram() def forward(self, x): dgms = self.fnobj.apply(self.complex, x, self.maxdim) return dgms, True
class AlphaLayer(nn.Module): """ Alpha persistence layer Parameters: maxdim : maximum homology dimension (default=0) """ def __init__(self, maxdim=0): super(AlphaLayer, self).__init__() self.maxdim = maxdim self.fnobj = FlagDiagram() def forward(self, x): xnp = x.data.numpy() complex = None if xnp.shape[1] == 1: xnp = xnp.flatten() complex = delaunay_complex_1d(xnp) else: complex = delaunay_complex(xnp, maxdim=self.maxdim+1) complex.initialize() dgms = self.fnobj.apply(complex, x, self.maxdim) return dgms, True
def __init__(self, maxdim=0): super(AlphaLayer, self).__init__() self.maxdim = maxdim self.fnobj = FlagDiagram()
def __init__(self, n, maxdim=1): super(RipsLayer, self).__init__() self.maxdim = maxdim self.complex = clique_complex(n, maxdim + 1) self.complex.initialize() self.fnobj = FlagDiagram()