コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
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
コード例 #4
0
 def __init__(self, maxdim=0):
     super(AlphaLayer, self).__init__()
     self.maxdim = maxdim
     self.fnobj = FlagDiagram()
コード例 #5
0
 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()