Skip to content

Commit

Permalink
Add overlap option to GetInitialPatterns
Browse files Browse the repository at this point in the history
  • Loading branch information
holderlb committed Jan 21, 2021
1 parent 7959c64 commit 07b7419
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions src/Subdue.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,37 +66,37 @@ def DiscoverPatterns(parameters, graph):
Pattern.PatternListInsert(parentPattern, discoveredPatternList, parameters.numBest, False) # valueBased = False
return discoveredPatternList

def GetInitialPatterns(graph, temporal = False):
"""Returns list of single-edge, evaluated patterns in given graph with more than one instance."""
def GetInitialPatterns(graph, temporal = False, overlap = True):
"""Returns list of single-edge, evaluated patterns in given graph with more than one instance.
If overlap=False, then instances of a single-edge pattern cannot share vertices."""
initialPatternList = []
candidateEdges = list(graph.edges.values())
while candidateEdges:
edge1 = candidateEdges.pop(0)
matchingEdges = [edge1]
nonmatchingEdges = []
graph1 = Graph.CreateGraphFromEdge(edge1)
# Create a graph and an instance for each edge
edgeGraphInstancePairs = []
for edge in graph.edges.values():
graph1 = Graph.CreateGraphFromEdge(edge)
if temporal:
graph1.TemporalOrder()
for edge2 in candidateEdges:
graph2 = Graph.CreateGraphFromEdge(edge2)
if temporal:
graph2.TemporalOrder()
if Graph.GraphMatch(graph1,graph2):
matchingEdges.append(edge2)
instance1 = Pattern.CreateInstanceFromEdge(edge)
edgeGraphInstancePairs.append((graph1,instance1))
while edgeGraphInstancePairs:
edgePair1 = edgeGraphInstancePairs.pop(0)
graph1 = edgePair1[0]
instance1 = edgePair1[1]
pattern = Pattern.Pattern()
pattern.definition = graph1
pattern.instances.append(instance1)
nonmatchingEdgePairs = []
for edgePair2 in edgeGraphInstancePairs:
graph2 = edgePair2[0]
instance2 = edgePair2[1]
if Graph.GraphMatch(graph1,graph2) and (overlap or (not Pattern.InstancesOverlap(pattern.instances,instance2))):
pattern.instances.append(instance2)
else:
nonmatchingEdges.append(edge2)
if len(matchingEdges) > 1:
# Create initial pattern
pattern = Pattern.Pattern()
pattern.definition = Graph.CreateGraphFromEdge(matchingEdges[0])
if temporal:
pattern.definition.TemporalOrder()
pattern.instances = []
for edge in matchingEdges:
pattern.instances.append(Pattern.CreateInstanceFromEdge(edge))
nonmatchingEdgePairs.append(edgePair2)
if len(pattern.instances) > 1:
pattern.evaluate(graph)
initialPatternList.append(pattern)
candidateEdges = nonmatchingEdges
edgeGraphInstancePairs = nonmatchingEdgePairs
return initialPatternList

def Subdue(parameters, graph):
Expand Down

0 comments on commit 07b7419

Please sign in to comment.