Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
edgeId = G.edgeId(edge[0], edge[1])
inputAttribute[edgeId] = G.weight(edge[0], edge[1])
scorer = MultiscaleScore(G, inputAttribute)
scorer.run()
scores = scorer.scores()
return scores
def _getSparsifiedGraph(self, G, parameter, attribute):
gf = GlobalThresholdFilter(G, attribute, parameter, True)
return gf.calculate()
def _getParameterizationAlgorithm(self):
return BinarySearchParameterization(False, 0.0, 1.0, 20)
class RandomEdgeSparsifier(Sparsifier):
""" Random Edge sampling. Edges to keep in the sparsified graph are selected uniformly at random. """
def scores(self, G):
""" Returns an edge attribute that holds for each edge the minimum parameter value
such that the edge is contained in the sparsified graph.
Keyword arguments:
G -- the input graph
"""
reScore = RandomEdgeScore(G)
reScore.run()
return reScore.scores()
def _getSparsifiedGraph(self, G, parameter, attribute):
Keyword arguments:
G -- the input graph
"""
reScore = RandomEdgeScore(G)
reScore.run()
return reScore.scores()
def _getSparsifiedGraph(self, G, parameter, attribute):
gf = GlobalThresholdFilter(G, attribute, parameter, False)
return gf.calculate()
def _getParameterizationAlgorithm(self):
return SimpleParameterization()
class RandomNodeEdgeSparsifier(Sparsifier):
""" [TODO not yet documented] """
def __init__(self, above = True):
self.above = above
def scores(self, G):
""" Returns an edge attribute that holds for each edge the minimum parameter value
such that the edge is contained in the sparsified graph.
Keyword arguments:
G -- the input graph
"""
rneScore = RandomNodeEdgeScore(G)
rneScore.run()
return rneScore.scores()
Keyword arguments:
G -- the input graph
"""
triangles = ChibaNishizekiTriangleEdgeScore(G).run().scores()
localSimScore = LocalSimilarityScore(G, triangles)
localSimScore.run()
return localSimScore.scores()
def _getSparsifiedGraph(self, G, parameter, attribute):
gf = GlobalThresholdFilter(G, attribute, parameter, True)
return gf.calculate()
def _getParameterizationAlgorithm(self):
return BinarySearchParameterization(False, 0.0, 1.0, 20)
class MultiscaleSparsifier(Sparsifier):
""" An implementation of the Multiscale backbone approach introduced by Serrano et al. """
def scores(self, G):
""" Returns an edge attribute that holds for each edge the minimum parameter value
such that the edge is contained in the sparsified graph.
Keyword arguments:
G -- the input graph
"""
inputAttribute = [0.0] * G.upperEdgeIdBound()
for edge in G.edges():
edgeId = G.edgeId(edge[0], edge[1])
inputAttribute[edgeId] = G.weight(edge[0], edge[1])
"""
chiba = ChibaNishizekiTriangleCounter(G)
triangles = chiba.getAttribute()
sj = SimmelianJaccardAttributizer(G, triangles)
a_sj = sj.getAttribute()
return a_sj
def _getSparsifiedGraph(self, G, parameter, attribute):
gf = GlobalThresholdFilter(G, attribute, parameter, True)
return gf.calculate()
def _getParameterizationAlgorithm(self):
return BinarySearchParameterization(False, 0.0, 1.0, 20)
class SimmelianMultiscaleBackbone(Sparsifier):
""" Multiscale Backbone that uses triangle counts as input edge weight. """
def getAttribute(self, G):
""" Returns an edge attribute that holds for each edge the maximum parameter value
such that the edge is contained in the sparsified graph.
Keyword arguments:
G -- the input graph
"""
chiba = ChibaNishizekiTriangleCounter(G)
triangles = chiba.getAttribute()
ms = MultiscaleAttributizer(G, triangles)
a_ms = ms.getAttribute()
return a_ms
Keyword arguments:
G -- the input graph
"""
ffScore = ForestFireScore(G, self.burnProbability, self.targetBurntRatio)
ffScore.run()
return ffScore.scores()
def _getSparsifiedGraph(self, G, parameter, attribute):
gf = GlobalThresholdFilter(G, attribute, parameter, True)
return gf.calculate()
def _getParameterizationAlgorithm(self):
return BinarySearchParameterization(False, 0.0, 1.0, 20)
class LocalDegreeSparsifier(Sparsifier):
""" An implementation of the Local Degree sparsification algorithm. """
def scores(self, G):
""" Returns an edge score that holds for each edge the minimum parameter value
such that the edge is contained in the sparsified graph.
Keyword arguments:
G -- the input graph
"""
localDegree = LocalDegreeScore(G)
localDegree.run()
localDegreeScore = localDegree.scores()
return localDegreeScore
Keyword arguments:
G -- the input graph
"""
quadrangles = ChibaNishizekiQuadrangleEdgeScore(G).run().scores()
meanQuadrangles = GeometricMeanScore(G, quadrangles).run().scores()
quadranglePrefixJaccard = PrefixJaccardScore(G, meanQuadrangles).run().scores()
return quadranglePrefixJaccard
def _getSparsifiedGraph(self, G, parameter, attribute):
gf = GlobalThresholdFilter(G, attribute, parameter, True)
return gf.calculate()
def _getParameterizationAlgorithm(self):
return BinarySearchParameterization(False, 0.0, 1.0, 20)
class SimmelianMultiscaleSparsifier(Sparsifier):
""" Multiscale Sparsifier that uses triangle counts as input edge weight. """
def scores(self, G):
""" Returns an edge attribute that holds for each edge the maximum parameter value
such that the edge is contained in the sparsified graph.
Keyword arguments:
G -- the input graph
"""
triangles = ChibaNishizekiTriangleEdgeScore(G).run().scores()
ms = MultiscaleScore(G, triangles)
ms.run()
a_ms = ms.scores()
return a_ms
Keyword arguments:
G -- the input graph
"""
attributizer = ForestFireAttributizer(G, self.burnProbability, self.targetBurntRatio)
return attributizer.getAttribute()
def _getSparsifiedGraph(self, G, parameter, attribute):
gf = GlobalThresholdFilter(G, attribute, parameter, True)
return gf.calculate()
def _getParameterizationAlgorithm(self):
return BinarySearchParameterization(False, 0.0, 1.0, 20)
class LocalDegreeBackbone(Sparsifier):
""" An implementation of the Local Degree backbone algorithm. """
def getAttribute(self, G):
""" Returns an edge attribute that holds for each edge the minimum parameter value
such that the edge is contained in the sparsified graph.
Keyword arguments:
G -- the input graph
"""
attributizer_ld = LocalDegreeAttributizer(G)
a_ld = attributizer_ld.getAttribute()
return a_ld
def _getSparsifiedGraph(self, G, parameter, attribute):
Keyword arguments:
G -- the input graph
"""
attributizer_ld = LocalDegreeAttributizer(G)
a_ld = attributizer_ld.getAttribute()
return a_ld
def _getSparsifiedGraph(self, G, parameter, attribute):
gf = GlobalThresholdFilter(G, attribute, parameter, True)
return gf.calculate()
def _getParameterizationAlgorithm(self):
return BinarySearchParameterization(False, 0.0, 1.0, 20)
class TriangleBackbone(Sparsifier):
""" Allows for global filtering with respect to triangle counts. """
def getAttribute(self, G):
""" Returns the triangle counts of the input graph. """
attributizer_t = TriangleCounter(G)
a_t = attributizer_t.getAttribute()
return a_t
def _getSparsifiedGraph(self, G, parameter, attribute):
gf = GlobalThresholdFilter(G, attribute, parameter, True)
return gf.calculate()
def _getParameterizationAlgorithm(self):
raise NotImplementedError("parameterization method not yet implemented.")
class ModularityPartitionAttributizer():
"""
chiba = ChibaNishizekiTriangleCounter(G)
triangles = chiba.getAttribute()
so = SimmelianOverlapAttributizer(G, triangles, self.maxRank)
a_so = so.getAttribute()
return a_so
def _getSparsifiedGraph(self, G, parameter, attribute):
gf = GlobalThresholdFilter(G, attribute, parameter, True)
return gf.calculate()
def _getParameterizationAlgorithm(self):
return CompleteSearchParameterization(0, self.maxRank)
class SimmelianBackboneNonParametric(Sparsifier):
""" An implementation of the Non-parametric variant of the Simmelian Backbones
introduced by Nick et al. """
def getAttribute(self, G):
""" Returns an edge attribute that holds for each edge the minimum jaccard filter value
such that the edge is contained in the sparsified graph.
Keyword arguments:
G -- the input graph
"""
chiba = ChibaNishizekiTriangleCounter(G)
triangles = chiba.getAttribute()
sj = SimmelianJaccardAttributizer(G, triangles)
a_sj = sj.getAttribute()
"""
chiba = ChibaNishizekiTriangleCounter(G)
triangles = chiba.getAttribute()
attributizer = LocalSimilarityAttributizer(G, triangles)
a_ls = attributizer.getAttribute()
return a_ls
def _getSparsifiedGraph(self, G, parameter, attribute):
gf = GlobalThresholdFilter(G, attribute, parameter, True)
return gf.calculate()
def _getParameterizationAlgorithm(self):
return BinarySearchParameterization(False, 0.0, 1.0, 20)
class MultiscaleBackbone(Sparsifier):
""" An implementation of the Multiscale backbone approach introduced by Serrano et al. """
def getAttribute(self, G):
""" Returns an edge attribute that holds for each edge the minimum parameter value
such that the edge is contained in the sparsified graph.
Keyword arguments:
G -- the input graph
"""
inputAttribute = [0.0] * G.upperEdgeIdBound()
for edge in G.edges():
edgeId = G.edgeId(edge[0], edge[1])
inputAttribute[edgeId] = G.weight(edge[0], edge[1])