Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:KrishnaswamyLab/graphtools into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgigante committed Jul 27, 2018
2 parents 5b4c3e2 + 3328610 commit 17212c1
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 241 deletions.
9 changes: 0 additions & 9 deletions doc/source/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,3 @@ Utilities
:undoc-members:
:inherited-members:
:show-inheritance:

Logging
-------

.. automodule:: graphtools.logging
:members:
:undoc-members:
:inherited-members:
:show-inheritance:
8 changes: 4 additions & 4 deletions graphtools/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import warnings
import tasklogger

from . import logging
from . import base
from . import graphs

Expand Down Expand Up @@ -137,7 +137,7 @@ def Graph(data,
------
ValueError : if selected parameters are incompatible.
"""
logging.set_logging(verbose)
tasklogger.set_level(verbose)
if sample_idx is not None and len(np.unique(sample_idx)) == 1:
warnings.warn("Only one unique sample. "
"Not using MNNGraph")
Expand Down Expand Up @@ -197,7 +197,7 @@ def Graph(data,
else:
msg = msg + " and PyGSP inheritance"

logging.log_debug(msg)
tasklogger.log_debug(msg)

class_names = [p.__name__.replace("Graph", "") for p in parent_classes]
try:
Expand All @@ -215,7 +215,7 @@ def Graph(data,
pass

# build graph and return
logging.log_debug("Initializing {} with arguments {}".format(
tasklogger.log_debug("Initializing {} with arguments {}".format(
parent_classes,
", ".join(["{}='{}'".format(key, value)
for key, value in params.items()
Expand Down
30 changes: 15 additions & 15 deletions graphtools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from scipy import sparse
import warnings
import numbers
import tasklogger

try:
import pandas as pd
except ImportError:
Expand All @@ -24,10 +26,6 @@
from .utils import (elementwise_minimum,
elementwise_maximum,
set_diagonal)
from .logging import (set_logging,
log_start,
log_complete,
log_debug)


class Base(object):
Expand Down Expand Up @@ -152,7 +150,7 @@ def _reduce_data(self):
Reduced data matrix
"""
if self.n_pca is not None and self.n_pca < self.data.shape[1]:
log_start("PCA")
tasklogger.log_start("PCA")
if sparse.issparse(self.data):
if isinstance(self.data, sparse.coo_matrix) or \
isinstance(self.data, sparse.lil_matrix) or \
Expand All @@ -166,7 +164,7 @@ def _reduce_data(self):
random_state=self.random_state)
self.data_pca.fit(self.data)
data_nu = self.data_pca.transform(self.data)
log_complete("PCA")
tasklogger.log_complete("PCA")
return data_nu
else:
data_nu = self.data
Expand Down Expand Up @@ -342,10 +340,10 @@ def __init__(self, kernel_symm='+',
self._check_symmetrization(kernel_symm, gamma)

if initialize:
log_debug("Initializing kernel...")
tasklogger.log_debug("Initializing kernel...")
self.K
else:
log_debug("Not initializing kernel.")
tasklogger.log_debug("Not initializing kernel.")
super().__init__(**kwargs)

def _check_symmetrization(self, kernel_symm, gamma):
Expand All @@ -363,7 +361,8 @@ def _check_symmetrization(self, kernel_symm, gamma):
warnings.warn("kernel_symm='gamma' but gamma not given. "
"Defaulting to gamma=0.5.")
self.gamma = gamma = 0.5
elif not isinstance(gamma, numbers.Number) or gamma < 0 or gamma > 1:
elif not isinstance(gamma, numbers.Number) or \
gamma < 0 or gamma > 1:
raise ValueError("gamma {} not recognized. Expected "
"a float between 0 and 1".format(gamma))

Expand Down Expand Up @@ -392,18 +391,18 @@ def _build_kernel(self):
def symmetrize_kernel(self, K):
# symmetrize
if self.kernel_symm == "+":
log_debug("Using addition symmetrization.")
tasklogger.log_debug("Using addition symmetrization.")
K = (K + K.T) / 2
elif self.kernel_symm == "*":
log_debug("Using multiplication symmetrization.")
tasklogger.log_debug("Using multiplication symmetrization.")
K = K.multiply(K.T)
elif self.kernel_symm == 'gamma':
log_debug(
tasklogger.log_debug(
"Using gamma symmetrization (gamma = {}).".format(self.gamma))
K = self.gamma * elementwise_minimum(K, K.T) + \
(1 - self.gamma) * elementwise_maximum(K, K.T)
elif self.kernel_symm is None:
log_debug("Using no symmetrization.")
tasklogger.log_debug("Using no symmetrization.")
pass
else:
# this should never happen
Expand Down Expand Up @@ -438,7 +437,8 @@ def set_params(self, **params):
"""
if 'gamma' in params and params['gamma'] != self.gamma:
raise ValueError("Cannot update gamma. Please create a new graph")
if 'kernel_symm' in params and params['kernel_symm'] != self.kernel_symm:
if 'kernel_symm' in params and \
params['kernel_symm'] != self.kernel_symm:
raise ValueError(
"Cannot update kernel_symm. Please create a new graph")
return self
Expand Down Expand Up @@ -622,7 +622,7 @@ def __init__(self, data,
# kwargs are ignored
self.n_jobs = n_jobs
self.verbose = verbose
set_logging(verbose)
tasklogger.set_level(verbose)
super().__init__(data, **kwargs)

def get_params(self):
Expand Down

0 comments on commit 17212c1

Please sign in to comment.