Skip to content

Commit f925a94

Browse files
committed
Pass flake8
1 parent 431907a commit f925a94

4 files changed

Lines changed: 48 additions & 34 deletions

File tree

src/diffupy/diffuse.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# -*- coding: utf-8 -*-
22

3-
"""This module provides a generalized function as an interface to interact with the different diffusion methods
4-
offered in this diffuPy package."""
3+
"""This module provides a generalized function as an interface to interact with the different diffusion methods offered
4+
in this diffuPy package.
5+
"""
56

67
import copy
78
import logging
@@ -27,7 +28,7 @@ def diffuse(
2728
graph: nx.Graph = None,
2829
**kwargs
2930
) -> Matrix:
30-
"""Manages the treatment of the different score diffusion methods applied of/from an path set of labels/scores
31+
"""Manage the treatment of the different score diffusion methods applied of/from an path set of labels/scores
3132
of/on a certain network (as a graph format or a graph kernel matrix stemming from a graph).
3233
3334
Diffusion methods procedures provided in this package differ on:

src/diffupy/diffuse_raw.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def calculate_scores(
2626
const_mean: np.array,
2727
const_var: np.array
2828
) -> float:
29-
"""Helper function for diffuse_raw, which operate the z-scores calculation given a whole column of the score matrix.
29+
"""Help function for diffuse_raw, which operate the z-scores calculation given a whole column of the score matrix.
3030
3131
:param col_ind: background object for the diffusion
3232
:param scores: list of score matrices. For a single path with a single background, supply a list with a vector column
@@ -55,8 +55,8 @@ def diffuse_raw(
5555
scores: Matrix,
5656
z: bool = False,
5757
K: Matrix = None,
58-
**karg) -> Matrix:
59-
""" Computes the score diffusion procedure, given an initial state as a set of scores and a network where diffuse it.
58+
) -> Matrix:
59+
"""Compute the score diffusion procedure, given an initial state as a set of scores and a network where diffuse it.
6060
6161
:param graph: background network
6262
:param scores: list of score matrices. For a single path with a single background, supply a list with a vector column

src/diffupy/kernels.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ def diffusion_kernel(graph: nx.Graph, sigma2: float = 1, normalized: bool = True
6666

6767

6868
def inverse_cosine_kernel(graph: nx.Graph) -> Matrix:
69-
"""Compute the inverse cosine kernel, which is based on a cosine transform
70-
on the spectrum of the normalized Laplacian matrix.
69+
"""Compute the inverse cosine kernel, which is based on a cosine transform on the spectrum of the normalized LM.
7170
7271
Quoting [Smola, 2003]: the inverse cosine kernel treats lower complexity
7372
functions almost equally, with a significant reduction in the upper end of the spectrum.
@@ -80,15 +79,14 @@ def inverse_cosine_kernel(graph: nx.Graph) -> Matrix:
8079
# Decompose matrix (Singular Value Decomposition)
8180
laplacian = LaplacianMatrix(graph, normalized=True)
8281
# Decompose matrix (Singular Value Decomposition)
83-
U, S, _ = np.linalg.svd(laplacian.mat * (pi / 4))
84-
laplacian.mat = np.matmul(np.matmul(U, np.diag(np.cos(S))), np.transpose(U))
82+
u, s, _ = np.linalg.svd(laplacian.mat * (pi / 4))
83+
laplacian.mat = np.matmul(np.matmul(u, np.diag(np.cos(s))), np.transpose(u))
8584

8685
return laplacian
8786

8887

8988
def p_step_kernel(graph: nx.Graph, a: int = 2, p: int = 5) -> Matrix:
90-
"""Compute the inverse cosine kernel, which is based on a cosine transform on the spectrum of the normalized
91-
Laplacian matrix.
89+
"""Compute the inverse cosine kernel, which is based on a cosine transform on the spectrum of the normalized LM.
9290
9391
This kernel is more focused on local properties of the nodes, because random walks
9492
are limited in terms of length. Therefore, if p is small, only a fraction of the values K(x1,x2)

src/diffupy/process_input.py

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@
55
from .matrix import Matrix
66

77

8-
def generate_categoric_input_vector_from_labels(rows_labeled, col_label, background_mat, missing_value=-1,
9-
rows_unlabeled=None):
8+
def generate_categoric_input_vector_from_labels(
9+
rows_labeled,
10+
col_label,
11+
background_mat,
12+
missing_value=-1,
13+
rows_unlabeled=None,
14+
):
15+
"""Generate input vector from labels."""
1016
if isinstance(col_label, str):
1117
col_label = [col_label]
1218

@@ -22,30 +28,39 @@ def generate_categoric_input_vector_from_labels(rows_labeled, col_label, backgro
2228
return input_mat.match_missing_rows(background_mat.rows_labels, missing_value).match_rows(background_mat)
2329

2430

25-
def generate_categoric_input_from_labels(rows_labels, cols_labels, background_mat, missing_value=-1,
26-
rows_unlabeled=None, ):
31+
def generate_categoric_input_from_labels(
32+
rows_labels,
33+
cols_labels,
34+
background_mat,
35+
missing_value=-1,
36+
rows_unlabeled=None,
37+
):
38+
"""Generate input vector from labels."""
2739
if isinstance(cols_labels, list) and len(cols_labels) > 1:
28-
input_mat = generate_categoric_input_vector_from_labels(rows_labels[0],
29-
cols_labels[0],
30-
background_mat,
31-
missing_value,
32-
rows_unlabeled[0]
33-
)
40+
input_mat = generate_categoric_input_vector_from_labels(
41+
rows_labels[0],
42+
cols_labels[0],
43+
background_mat,
44+
missing_value,
45+
rows_unlabeled[0]
46+
)
3447

3548
for idx, row_label in enumerate(rows_labels[1:]):
36-
input_vector = generate_categoric_input_vector_from_labels(row_label,
37-
cols_labels[idx + 1],
38-
background_mat,
39-
missing_value,
40-
rows_unlabeled[idx + 1],
41-
)
49+
input_vector = generate_categoric_input_vector_from_labels(
50+
row_label,
51+
cols_labels[idx + 1],
52+
background_mat,
53+
missing_value,
54+
rows_unlabeled[idx + 1],
55+
)
4256
input_mat.col_bind(matrix=input_vector)
4357

4458
return input_mat
4559
else:
46-
return generate_categoric_input_vector_from_labels(rows_labels,
47-
cols_labels,
48-
background_mat,
49-
missing_value,
50-
rows_unlabeled
51-
)
60+
return generate_categoric_input_vector_from_labels(
61+
rows_labels,
62+
cols_labels,
63+
background_mat,
64+
missing_value,
65+
rows_unlabeled
66+
)

0 commit comments

Comments
 (0)