Skip to content

Commit

Permalink
Merge pull request #5 from dkaslovsky/eliminate_runtime_warning_for_l…
Browse files Browse the repository at this point in the history
…og_calculation

Eliminate runtime warning for log calculation
  • Loading branch information
dkaslovsky committed Jun 27, 2021
2 parents 8f9541a + d81c606 commit 5336a9c
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -5,6 +5,7 @@ matrix:
- python: 3.6
- python: 3.7
- python: 3.8
- python: 3.9

install:
- pip install -r requirements.txt
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
## 1.0.2 / 2021-06-26

* [Fixed] eliminated runtime warning when computing log of array containing zeros
* [Changed] added Python 3.9 support and updated necessary dependencies

## 1.0.1 / 2020-08-25

* [Changed] updated dependencies to latest versions
3 changes: 1 addition & 2 deletions graphrole/graph/interface/__init__.py
Expand Up @@ -2,7 +2,6 @@

from graphrole.graph.interface.base import BaseGraphInterface
from graphrole.graph.interface.networkx import NetworkxInterface
from graphrole.types import Edge, Node

# IgraphInterface should not be imported if igraph is not installed
try:
Expand All @@ -14,7 +13,7 @@
'networkx': NetworkxInterface,
# lazy eval in case IgraphInterface was not imported
# pylint: disable=unnecessary-lambda
'igraph': lambda x: IgraphInterface(x),
'igraph': lambda x: IgraphInterface(x),
}


Expand Down
2 changes: 1 addition & 1 deletion graphrole/graph/interface/base.py
Expand Up @@ -55,4 +55,4 @@ def _get_egonet_features(self) -> pd.DataFrame:
"""
Return egonet features for each node in the graph
"""
pass
pass
4 changes: 1 addition & 3 deletions graphrole/graph/interface/igraph.py
Expand Up @@ -155,7 +155,5 @@ def _is_boundary(self, edge: Edge, interior: Set[Node], exterior: Set[Node]) ->
return v1 in interior and v2 in exterior

return (
(v1 in interior and v2 in exterior)
or
(v1 in exterior and v2 in interior)
(v1 in interior and v2 in exterior) or (v1 in exterior and v2 in interior)
)
3 changes: 1 addition & 2 deletions graphrole/graph/interface/networkx.py
Expand Up @@ -77,7 +77,6 @@ def _get_edge_sum(self, edges: Iterable[Edge]) -> float:
:param edges: edges to sum
"""
return sum(
self.G.get_edge_data(*edge, default={})\
.get('weight', 1)
self.G.get_edge_data(*edge, default={}).get('weight', 1)
for edge in edges
)
6 changes: 5 additions & 1 deletion graphrole/roles/description_length.py
Expand Up @@ -53,5 +53,9 @@ def get_error_cost(
# KL divergence as given in section 2.3 of RolX paper
vec1 = V.ravel()
vec2 = V_approx.ravel()
kl_div = np.sum(np.where(vec1 != 0, vec1 * np.log(vec1 / vec2) - vec1 + vec2, 0))

# use mask in np.log to avoid runtime warning for zeros and in np.where to ensure correct value
mask = vec1 != 0
log_vals = np.log(vec1 / vec2, where=mask, out=np.zeros(vec1.shape))
kl_div = np.sum(np.where(mask, vec1 * log_vals - vec1 + vec2, 0))
return kl_div
2 changes: 1 addition & 1 deletion graphrole/roles/extract.py
Expand Up @@ -91,7 +91,7 @@ def extract_role_factors(
index=role_labels,
columns=features.columns
)

def explain(self):
raise NotImplementedError('Role explanation (\"sense making\") is not yet implemented.')

Expand Down
11 changes: 6 additions & 5 deletions requirements.txt
@@ -1,5 +1,6 @@
networkx==2.5
numpy==1.19.1
pandas==1.1.1
scikit-learn==0.23.2
scipy==1.5.2
networkx==2.5.1
numpy==1.19.5
pandas==1.1.5
scikit-learn==0.24.2
scipy==1.5.4

3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -10,7 +10,7 @@

setup(
name='graphrole',
version='1.0.1',
version='1.0.2',
author='Daniel Kaslovsky',
author_email='dkaslovsky@gmail.com',
license='MIT',
Expand All @@ -32,5 +32,6 @@
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
]
)

0 comments on commit 5336a9c

Please sign in to comment.