1 """@namespace IMP.spatiotemporal.score_graph
2 Functions to traverse and score the spatiotemporal graphs.
10 converts a list of graphNode objects (nodes), which have been initiated
11 with scores and edges into a dictionary representation of a graph (graph).
12 Each node in the graph is a key, which returns edges in the next state.
14 @param nodes: list of graphNode objects
15 @return graph: dictionary where each node is a key and the values are
16 the edges in the graph for that node
21 graph[node] = node.get_edges()
28 Finds all paths between nodes, which already have edges drawn between them.
30 @param graph: dictionary representation of the graph, acquired
31 in get_graph_as_dict()
32 @param start: graphNode, candidate for starting the graph
33 @param end: graphNode, candidate to end the graph
34 @param path: list of graphNodes on the path, which is defined recursively.
35 @return paths: list of all paths that exist between the starting node
42 if start
not in graph.keys():
45 for node
in graph[start]:
48 for newpath
in newpaths:
58 Function to score a graph based on nodes, which has scores and edges,
59 as well as keys, which is a list of the states visited. Note that all
60 edges must be drawn and scores must be added to nodes before calling
63 @param nodes: list of graphNode objects, which has been initialized with
65 @param keys: list of all ordered states (strings) visited along the graph.
66 Paths will be determined in sequential order passed to this
68 @return all_paths: list of all paths through the graph. Each path is a
69 list of graphNode objects that correspond to the states visited
71 @return path_prob: list of probabilities for each path, ordered in the
72 same order as all_paths
73 @return path_scores: list of tuples, where the first object is the path
74 (list of graphNode objects for each state along the trajectory),
75 and the second object is the score of the path, which can be used
76 to calculate the probability.
89 starting_nodes = [n
for n
in nodes
if n.get_time() == time_start]
92 ending_nodes = [n
for n
in nodes
if n.get_time() == time_end]
97 for sn
in starting_nodes:
98 for en
in ending_nodes:
102 path_scores = [(path, np.array([n.get_weight()
for n
in path]).sum())
103 for path
in all_paths]
104 s = np.array([p[1]
for p
in path_scores])
106 path_prob = np.exp(-s) / np.exp(-s).sum()
108 return all_paths, path_prob, path_scores
def get_graph_as_dict
converts a list of graphNode objects (nodes), which have been initiated with scores and edges into a ...
def score_graph
Function to score a graph based on nodes, which has scores and edges, as well as keys, which is a list of the states visited.
def find_all_paths
Finds all paths between nodes, which already have edges drawn between them.