Skip to content

Commit

Permalink
Pull request #147: Hypergraph edit
Browse files Browse the repository at this point in the history
Merge in HYP/hypernetx from hypergraph_edit to develop

* commit '1e1dbf7cb6797255b32116fa23954dd9e7d2cca3':
  removed old hypergraph code
  removed .github from .gitignore
  updated hypergraph from incidence matrix constructor
  removing notebooks not intended for sharing
  • Loading branch information
brendapraggastis authored and bonicim committed Apr 1, 2024
2 parents d0a7e3d + 1e1dbf7 commit 638870a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3,042 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,3 @@ coverage.xml
cov.syspath.txt
*.whl
*dogsAndcats*
.github/
34 changes: 13 additions & 21 deletions hypernetx/classes/hypergraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def properties(self):
"""
return self._E.properties

def incidence_matrix(self, index=False, use_weights=False):
def incidence_matrix(self, index=False, weights=False):
"""
_summary_
Expand All @@ -281,8 +281,8 @@ def incidence_matrix(self, index=False, use_weights=False):
_description_
"""
e, n = self._state_dict["data"].T
if use_weights == True:
data = [self._E[d].weight for d in self._E]
if weights == True:
data = self._E.dataframe['weight']
else:
data = np.ones(len(e)).astype(int)
mat = csr_matrix((data, (n, e)))
Expand All @@ -295,8 +295,8 @@ def incidence_matrix(self, index=False, use_weights=False):
self._state_dict["labels"]["edges"],
)

def incidence_dataframe(self, use_weights=False):
mat, rindex, cindex = self.incidence_matrix(index=True, use_weights=use_weights)
def incidence_dataframe(self, weights=False):
mat, rindex, cindex = self.incidence_matrix(index=True, weights=weights)
return pd.DataFrame(mat.toarray(), columns=cindex, index=rindex)

@property
Expand Down Expand Up @@ -1841,26 +1841,18 @@ def from_bipartite(cls, B, node_id=1, name=None, **kwargs):
def from_incidence_matrix(
cls,
M,
node_names=None,
edge_names=None,
node_label="nodes",
edge_label="edges",
name=None,
key=None,
**kwargs,
):
"""
Same as from_numpy_array.
Accepts numpy.matrix or scipy.sparse matrix
"""
return Hypergraph.from_numpy_array(
M,
node_names=node_names,
edge_names=edge_names,
node_label=node_label,
edge_label=edge_label,
name=name,
key=key,
)
mat = coo_matrix(M)
edges = mat.col
nodes = mat.row
weights = mat.data
df = pd.DataFrame({'edges':edges,'nodes':nodes,'weights':weights})
return Hypergraph(df,cell_weight_col='weights',name=name,**kwargs)

@classmethod
def from_numpy_array(
Expand All @@ -1873,7 +1865,7 @@ def from_numpy_array(
**kwargs,
):
"""
Create a hypergraph from a real valued matrix represented as a 2 dimensionsl numpy array.
Create a hypergraph from a real valued matrix represented as a 2 dimensional numpy array.
The matrix is converted to a matrix of 0's and 1's so that any truthy cells are converted to 1's and
all others to 0's.
Expand Down
Loading

0 comments on commit 638870a

Please sign in to comment.