Commit 5b67db19 by Tiago Peixoto

### Fix computation of normalized Laplacian matrix

parent fc732cfa
 ... @@ -228,15 +228,24 @@ def laplacian(g, deg="total", normalized=True, sparse=True, weight=None): ... @@ -228,15 +228,24 @@ def laplacian(g, deg="total", normalized=True, sparse=True, weight=None): d = _get_deg(v, deg, weight) d = _get_deg(v, deg, weight) for e in v.out_edges(): for e in v.out_edges(): if not normalized: if not normalized: m[index[v], index[e.target()]] += (-1 if weight is None if weight is None: else -weight[e]) val = -1 else: val = -weight[e] # increment in case of parallel edges m[index[v], index[e.target()]] += val else: else: val = (d * _get_deg(e.target(), deg, weight)) ** (-0.5) d2 = _get_deg(e.target(), deg, weight) m[index[v], index[e.target()]] = val if weight is None: w = 1 else: w = weight[e] # increment in case of parallel edges m[index[v], index[e.target()]] += - w / sqrt(d * d2) if not normalized: if not normalized: m[index[v], index[v]] = d m[index[v], index[v]] = d elif d > 0: elif d > 0: m[index[v], index[v]] = 1 m[index[v], index[v]] = 1 if d != 0 else 0 if sparse: if sparse: m = m.tocsr() m = m.tocsr() return m return m ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!