Added example for region boundary merging

This commit is contained in:
Vighnesh Birodkar
2016-04-27 01:03:09 -04:00
parent 2a87c07800
commit b3f6b545cb
4 changed files with 82 additions and 36 deletions
+10 -9
View File
@@ -23,29 +23,30 @@ import numpy as np
def max_edge(g, src, dst, n):
"""Callback to handle merging nodes by choosing maximum weight.
Returns either the weight between (`src`, `n`) or (`dst`, `n`)
in `g` or the maximum of the two when both exist.
Returns a dictionary with `"weight"` set as either the weight between
(`src`, `n`) or (`dst`, `n`) in `graph` or the maximum of the two when
both exist.
Parameters
----------
g : RAG
graph : RAG
The graph under consideration.
src, dst : int
The vertices in `g` to be merged.
The verices in `graph` to be merged.
n : int
A neighbor of `src` or `dst` or both.
Returns
-------
weight : float
The weight between (`src`, `n`) or (`dst`, `n`) in `g` or the
maximum of the two when both exist.
data : dict
A dict with the `"weight"` attribute set the weight between
(`src`, `n`) or (`dst`, `n`) in `graph` or the maximum of the two when
both exist.
"""
w1 = g[n].get(src, {'weight': -np.inf})['weight']
w2 = g[n].get(dst, {'weight': -np.inf})['weight']
return max(w1, w2)
return {'weight': max(w1, w2)}
def display(g, title):