Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.2.x #57

Merged
merged 12 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions .github/workflows/github-actions-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,22 @@ jobs:
# python setup.py bdist_wheel
python setup.py install
# pytest -v --cov-config=.coveragerc --cov-report term --cov=gklearn gklearn/tests/ged/
pytest -v --cov-config=.coveragerc --cov-report term --cov=gklearn gklearn/tests/ --ignore=gklearn/tests/test_median_preimage_generator.py --ignore=gklearn/tests/test_graphkernels.py
pytest -v --cov-config=.coveragerc --cov-report term --cov=gklearn gklearn/tests/ --ignore=gklearn/tests/test_median_preimage_generator.py --ignore=gklearn/tests/test_graphkernels.py --ignore=gklearn/tests/ged/test_gedlib.py

- name: Run code coverage
run: |
codecov

- name: Publish distribution 📦 to Test PyPI
if: matrix.python-version == '3.8' && matrix.os == 'ubuntu-latest'
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/

- name: Publish distribution 📦 to PyPI
if: matrix.python-version == '3.8' && matrix.os == 'ubuntu-latest'
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
# - name: Publish distribution 📦 to Test PyPI
# if: matrix.python-version == '3.8' && matrix.os == 'ubuntu-latest'
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# password: ${{ secrets.TEST_PYPI_API_TOKEN }}
# repository-url: https://test.pypi.org/legacy/

# - name: Publish distribution 📦 to PyPI
# if: matrix.python-version == '3.8' && matrix.os == 'ubuntu-latest'
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# user: __token__
# password: ${{ secrets.PYPI_API_TOKEN }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# graphkit-learn

![GitHub Actions](https://github.com/jajupmochi/graphkit-learn/actions/workflows/github-actions.yml/badge.svg)
![GitHub Actions](https://github.com/jajupmochi/graphkit-learn/actions/workflows/github-actions-ubuntu.yml/badge.svg)
[![Build status](https://ci.appveyor.com/api/projects/status/bdxsolk0t1uji9rd?svg=true)](https://ci.appveyor.com/project/jajupmochi/graphkit-learn)
[![codecov](https://codecov.io/gh/jajupmochi/graphkit-learn/branch/master/graph/badge.svg)](https://codecov.io/gh/jajupmochi/graphkit-learn)
[![Documentation Status](https://readthedocs.org/projects/graphkit-learn/badge/?version=master)](https://graphkit-learn.readthedocs.io/en/master/?badge=master)
Expand Down
Empty file added gklearn/ged/model/__init__.py
Empty file.
49 changes: 39 additions & 10 deletions gklearn/ged/model/ged_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ def clear_attributes(self): # @todo: update
delattr(self, '_Y')
if hasattr(self, '_run_time'):
delattr(self, '_run_time')
if hasattr(self, '_test_run_time'):
delattr(self, '_test_run_time')


def validate_parameters(self):
Expand Down Expand Up @@ -330,24 +332,26 @@ def compute_distance_matrix(self, Y=None, **kwargs):

else:
# Compute kernel matrix between Y and self._graphs (X).
Y_copy = ([g.copy() for g in Y] if self.copy_graphs else Y)
graphs_copy = ([g.copy() for g in
self._graphs] if self.copy_graphs else self._graphs)

start_time = time.time()

if self.parallel == 'imap_unordered':
dis_matrix = self._compute_distance_matrix_imap_unordered(Y)

elif self.parallel is None:
Y_copy = ([g.copy() for g in Y] if self.copy_graphs else Y)
graphs_copy = ([g.copy() for g in
self._graphs] if self.copy_graphs else self._graphs)
dis_matrix = self._compute_distance_matrix_series(
Y_copy, graphs_copy, **kwargs
)

self._run_time = time.time() - start_time
self._test_run_time = time.time() - start_time

if self.verbose:
print(
'Distance matrix of size (%d, %d) built in %s seconds.'
% (len(Y), len(self._graphs), self._run_time)
% (len(Y), len(self._graphs), self._test_run_time)
)

return dis_matrix
Expand Down Expand Up @@ -620,10 +624,11 @@ def compute_edit_costs(self, Y=None, Y_targets=None, **kwargs):
# return dis_mat, dis_max, dis_min, dis_mean

def _compute_X_distance_matrix(self, **kwargs):
start_time = time.time()

graphs = ([g.copy() for g in
self._graphs] if self.copy_graphs else self._graphs)

start_time = time.time()

if self.parallel == 'imap_unordered':
dis_matrix = self._compute_X_dm_imap_unordered(graphs, **kwargs)
elif self.parallel is None:
Expand All @@ -632,6 +637,7 @@ def _compute_X_distance_matrix(self, **kwargs):
raise Exception('Parallel mode is not set correctly.')

self._run_time = time.time() - start_time

if self.verbose:
print(
'Distance matrix of size %d built in %s seconds.'
Expand All @@ -646,7 +652,7 @@ def _compute_X_dm_series(self, graphs, **kwargs):
dis_matrix = np.zeros((n, n))

iterator = combinations(range(n), 2)
len_itr = int(n * (n + 1) / 2)
len_itr = int(n * (n - 1) / 2)
if self.verbose:
print('Graphs in total: %d.' % len(graphs))
print('The total # of pairs is %d.' % len_itr)
Expand Down Expand Up @@ -780,6 +786,26 @@ def is_graph(self, graph):
if isinstance(graph, nx.MultiDiGraph):
return True
return False


def __repr__(self):
return (
f"{self.__class__.__name__}("
f"optim_method={self.optim_method}, "
f"ed_method={self.ed_method}, "
f"edit_cost_fun={self.edit_cost_fun}, "
f"node_labels={self.node_labels}, "
f"edge_labels={self.edge_labels}, "
f"optim_options={self.optim_options}, "
f"init_edit_cost_constants={self.init_edit_cost_constants}, "
f"copy_graphs={self.copy_graphs}, "
f"parallel={self.parallel}, "
f"n_jobs={self.n_jobs}, "
f"verbose={self.verbose}, "
f"normalize={self.normalize}, "
f"run_time={self.run_time}"
f")"
)


@property
Expand Down Expand Up @@ -807,15 +833,18 @@ def graphs(self):
def run_time(self):
return self._run_time

@property
def test_run_time(self):
return self._test_run_time

@property
def dis_matrix(self):
return self._dis_matrix
return self._dm_train


@dis_matrix.setter
def dis_matrix(self, value):
self._dis_matrix = value
self._dm_train = value


@property
Expand Down
Loading