Skip to content

Commit

Permalink
add dw property
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgigante committed Jan 9, 2020
1 parent db1e625 commit c73bcad
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion graphtools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,24 @@ def P(self):
self._diff_op = normalize(self.kernel, "l1", axis=1)
return self._diff_op

@property
def dw(self):
"""Weighted degree vector (cached)
Return or calculate the degree vector
Returns
-------
dw : array-like, shape=[n_samples]
Row sums of graph kernel
"""
try:
return self._dw
except AttributeError:
self._dw = utils.to_array(self.kernel.sum(axis=1))
return self._dw

@property
def diff_aff(self):
"""Symmetric diffusion affinity matrix
Expand All @@ -675,7 +693,7 @@ def diff_aff(self):
symmetric diffusion affinity matrix defined as a
doubly-stochastic form of the kernel matrix
"""
row_degrees = utils.to_array(self.kernel.sum(axis=1))
row_degrees = self.dw
if sparse.issparse(self.kernel):
# diagonal matrix
degrees = sparse.csr_matrix(
Expand Down Expand Up @@ -940,6 +958,20 @@ def K():
"""
raise NotImplementedError

@property
def dw(self):
"""Weighted degree vector (cached)
Return or calculate the degree vector
Returns
-------
dw : array-like, shape=[n_samples]
Row sums of graph kernel
"""
return pygsp.graphs.Graph.dw(self)

def _build_weight_from_kernel(self, kernel):
"""Private method to build an adjacency matrix from
a kernel matrix
Expand Down

0 comments on commit c73bcad

Please sign in to comment.