Skip to content

Commit

Permalink
Removed some numpy functions and replaced them with array methods to …
Browse files Browse the repository at this point in the history
…reduce the nummber of imports.
  • Loading branch information
jim-rafferty committed Oct 14, 2021
1 parent 096a354 commit 9369031
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions multimorbidity_hypergraphs/hypergraph_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# array tools
from numpy import zeros, zeros_like, ones_like, array, arange
# functions
from numpy import ceil, log, sqrt, multiply, abs, unique, sum, where, min, max
from numpy import ceil, log, sqrt, multiply, abs, unique, where

import numba # imported types would clash with some of the numpy imports.

Expand Down Expand Up @@ -619,13 +619,13 @@ def compute_hypergraph(
#edge_list = [list(elem) for elem in set.union(*valid_powersets)]

# my solution
m_data = m_data[sum(m_data, axis=1) >= 2] # m_data[m_data.sum(axis=1) >= 2]
m_data = m_data[m_data.sum(axis=1) >= 2]
edge_list = list(set().union(*[
list(
_reduced_powerset(
where(i)[0],
min_set=2,
max_set=min([sum(i)+1, n_diseases]).astype(int64)
max_set=array([i.sum()+1, n_diseases]).min().astype(int64)
)
) for i in m_data
]))
Expand All @@ -639,7 +639,7 @@ def compute_hypergraph(
# )
#)

max_edge = max([len(ii) for ii in edge_list])
max_edge = array([len(ii) for ii in edge_list]).max()
work_list = array(
[list(ii) + [-1] * (max_edge - len(ii)) for ii in edge_list],
dtype=int8
Expand Down Expand Up @@ -816,7 +816,7 @@ def eigenvector_centrality(
weight
)

eigenvector_boot.append(eig_vec / sum(eig_vec))
eigenvector_boot.append(eig_vec / eig_vec.sum())
eigenvalue_boot.append(eig_val)

eigenvector_boot = array(eigenvector_boot)
Expand Down

0 comments on commit 9369031

Please sign in to comment.