Skip to content

Commit

Permalink
Sort imports
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoabt committed Dec 12, 2024
1 parent 45aaaad commit 48b9cfd
Show file tree
Hide file tree
Showing 32 changed files with 93 additions and 184 deletions.
4 changes: 1 addition & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
)
author = "Diego Baptista Theuerkauf"

from probinet.version import (
__version__,
) # noqa: E402 # pylint: disable=wrong-import-position
from probinet.version import __version__ # noqa: E402 # pylint: disable=wrong-import-position

version = __version__

Expand Down
6 changes: 2 additions & 4 deletions probinet/evaluation/likelihood.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
import pandas as pd

from probinet.evaluation.expectation_computation import (
compute_expected_adjacency_tensor,
compute_expected_adjacency_tensor_multilayer,
compute_mean_lambda0,
)
compute_expected_adjacency_tensor, compute_expected_adjacency_tensor_multilayer,
compute_mean_lambda0)
from probinet.utils.tools import log_and_raise_error


Expand Down
4 changes: 1 addition & 3 deletions probinet/evaluation/link_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import numpy as np
from sklearn import metrics

from probinet.evaluation.expectation_computation import (
compute_expected_adjacency_tensor_multilayer,
)
from probinet.evaluation.expectation_computation import compute_expected_adjacency_tensor_multilayer


@singledispatch
Expand Down
13 changes: 5 additions & 8 deletions probinet/input/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,22 @@
Functions for handling the data.
"""

import logging
import csv
from importlib.resources import files
import logging
from os import PathLike
from pathlib import Path
from typing import Any, Optional, Union

import networkx as nx
import numpy as np
import pandas as pd
import csv


from .preprocessing import (
create_adjacency_tensor_from_graph_list,
create_sparse_adjacency_tensor_from_graph_list,
)
from .stats import print_graph_stats
from ..models.classes import GraphData
from ..utils.tools import log_and_raise_error
from .preprocessing import (
create_adjacency_tensor_from_graph_list, create_sparse_adjacency_tensor_from_graph_list)
from .stats import print_graph_stats


def build_adjacency_from_networkx(
Expand Down
5 changes: 1 addition & 4 deletions probinet/model_selection/acd_cross_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

import numpy as np

from probinet.evaluation.expectation_computation import (
calculate_expectation_acd,
calculate_Q_dense,
)
from probinet.evaluation.expectation_computation import calculate_expectation_acd, calculate_Q_dense

from ..evaluation.expectation_computation import compute_mean_lambda0
from ..evaluation.link_prediction import compute_link_prediction_AUC
Expand Down
9 changes: 2 additions & 7 deletions probinet/model_selection/cross_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@
import numpy as np

from probinet.evaluation.expectation_computation import (
calculate_conditional_expectation,
calculate_expectation,
)
calculate_conditional_expectation, calculate_expectation)
from probinet.evaluation.likelihood import calculate_opt_func
from probinet.evaluation.link_prediction import compute_link_prediction_AUC
from probinet.input.loader import build_adjacency_from_file
from probinet.model_selection.masking import (
extract_mask_kfold,
shuffle_indices_all_matrix,
)
from probinet.model_selection.masking import extract_mask_kfold, shuffle_indices_all_matrix
from probinet.models.classes import GraphData


Expand Down
4 changes: 1 addition & 3 deletions probinet/model_selection/dyncrep_cross_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

import numpy as np

from probinet.evaluation.expectation_computation import (
calculate_conditional_expectation_dyncrep,
)
from probinet.evaluation.expectation_computation import calculate_conditional_expectation_dyncrep
from probinet.evaluation.likelihood import likelihood_conditional
from probinet.evaluation.link_prediction import compute_link_prediction_AUC
from probinet.model_selection.cross_validation import CrossValidation
Expand Down
2 changes: 1 addition & 1 deletion probinet/model_selection/masking.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This module provides functions for shuffling indices and extracting masks for selecting the held-out set in the adjacency tensor and design matrix.
"""

from typing import List, Tuple, Sequence
from typing import List, Sequence, Tuple

import numpy as np

Expand Down
10 changes: 2 additions & 8 deletions probinet/model_selection/mtcov_cross_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,11 @@

import numpy as np

from probinet.evaluation.expectation_computation import (
compute_covariate_prediction_accuracy,
)
from probinet.evaluation.expectation_computation import compute_covariate_prediction_accuracy
from probinet.evaluation.likelihood import loglikelihood
from probinet.evaluation.link_prediction import compute_multilayer_link_prediction_AUC
from probinet.model_selection.cross_validation import CrossValidation
from probinet.model_selection.masking import (
extract_masks,
shuffle_indicesG,
shuffle_indicesX,
)
from probinet.model_selection.masking import extract_masks, shuffle_indicesG, shuffle_indicesX
from probinet.models.classes import GraphData
from probinet.models.mtcov import MTCOV

Expand Down
30 changes: 9 additions & 21 deletions probinet/models/acd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,26 @@
"""

import logging
import time
from os import PathLike
from pathlib import Path
from typing import Any, List, Tuple, Optional
import time
from typing import Any, List, Optional, Tuple

import numpy as np
import pandas as pd
from scipy.stats import poisson
from sparse import COO

from probinet.evaluation.expectation_computation import (
compute_mean_lambda0,
compute_mean_lambda0_nonzero,
)
from .base import ModelBase, ModelUpdateMixin
from .classes import GraphData
from .constants import EPS_, OUTPUT_FOLDER, BG_DEFAULT, K_DEFAULT, AG_DEFAULT
compute_mean_lambda0, compute_mean_lambda0_nonzero)

from ..input.preprocessing import preprocess_adjacency_tensor
from ..types import (
GraphDataType,
MaskType,
EndFileType,
FilesType,
ArraySequence,
SubsNzType,
)
from ..utils.matrix_operations import (
sp_uttkrp,
sp_uttkrp_assortative,
transpose_tensor,
)
from ..types import ArraySequence, EndFileType, FilesType, GraphDataType, MaskType, SubsNzType
from ..utils.matrix_operations import sp_uttkrp, sp_uttkrp_assortative, transpose_tensor
from ..utils.tools import get_item_array_from_subs, log_and_raise_error
from .base import ModelBase, ModelUpdateMixin
from .classes import GraphData
from .constants import AG_DEFAULT, BG_DEFAULT, EPS_, K_DEFAULT, OUTPUT_FOLDER


class AnomalyDetection(ModelBase, ModelUpdateMixin):
Expand Down
8 changes: 4 additions & 4 deletions probinet/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
Base classes for the models classes.
"""

import dataclasses
import logging
import os
import time
from abc import ABC, abstractmethod
from argparse import Namespace
import dataclasses
from functools import singledispatchmethod
import logging
import os
from pathlib import Path
import time
from typing import Any, Dict, Optional, Tuple

import numpy as np
Expand Down
18 changes: 6 additions & 12 deletions probinet/models/crep.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,22 @@
"""

import logging
import time
from pathlib import Path
import time
from typing import Any, List, Optional, Tuple, Union

import numpy as np
from numpy import dtype, ndarray
import numpy as np
from sparse import COO

from .base import ModelBase, ModelUpdateMixin
from .classes import GraphData
from .constants import OUTPUT_FOLDER
from ..evaluation.expectation_computation import compute_mean_lambda0
from ..input.preprocessing import preprocess_adjacency_tensor
from ..types import (
GraphDataType,
MaskType,
EndFileType,
FilesType,
ArraySequence,
)
from ..types import ArraySequence, EndFileType, FilesType, GraphDataType, MaskType
from ..utils.matrix_operations import sp_uttkrp, sp_uttkrp_assortative
from ..utils.tools import get_item_array_from_subs, log_and_raise_error
from .base import ModelBase, ModelUpdateMixin
from .classes import GraphData
from .constants import OUTPUT_FOLDER


class CRep(ModelBase, ModelUpdateMixin):
Expand Down
23 changes: 7 additions & 16 deletions probinet/models/dyncrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,25 @@
Class definition of DynCRep, the algorithm to perform inference in temporal networks :cite:`safdari2022reciprocity`.
"""

import logging
import time
from argparse import Namespace
import logging
from pathlib import Path
import time
from typing import Any, Dict, Optional, Tuple

import numpy as np
from scipy.optimize import brentq, root
from sparse import COO

from .base import ModelBase, ModelUpdateMixin
from .classes import GraphData
from .constants import EPS_, OUTPUT_FOLDER
from ..evaluation.expectation_computation import (
compute_lagrange_multiplier,
compute_mean_lambda0,
u_with_lagrange_multiplier,
)
compute_lagrange_multiplier, compute_mean_lambda0, u_with_lagrange_multiplier)
from ..input.preprocessing import preprocess_adjacency_tensor
from ..types import (
GraphDataType,
MaskType,
EndFileType,
FilesType,
ArraySequence,
)
from ..types import ArraySequence, EndFileType, FilesType, GraphDataType, MaskType
from ..utils.matrix_operations import sp_uttkrp, sp_uttkrp_assortative
from ..utils.tools import get_item_array_from_subs, log_and_raise_error
from .base import ModelBase, ModelUpdateMixin
from .classes import GraphData
from .constants import EPS_, OUTPUT_FOLDER


class DynCRep(ModelBase, ModelUpdateMixin):
Expand Down
12 changes: 6 additions & 6 deletions probinet/models/jointcrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
"""

import logging
import time
from pathlib import Path
from typing import Any, Tuple, Union, Optional
import time
from typing import Any, Optional, Tuple, Union

import numpy as np

from .base import ModelBase, ModelUpdateMixin
from .classes import GraphData
from .constants import OUTPUT_FOLDER, K_DEFAULT
from ..evaluation.expectation_computation import compute_mean_lambda0
from ..input.preprocessing import preprocess_adjacency_tensor
from ..types import GraphDataType, EndFileType, FilesType
from ..types import EndFileType, FilesType, GraphDataType
from ..utils.matrix_operations import sp_uttkrp, sp_uttkrp_assortative, transpose_tensor
from ..utils.tools import check_symmetric, get_item_array_from_subs, log_and_raise_error
from .base import ModelBase, ModelUpdateMixin
from .classes import GraphData
from .constants import K_DEFAULT, OUTPUT_FOLDER


class JointCRep(ModelBase, ModelUpdateMixin):
Expand Down
12 changes: 6 additions & 6 deletions probinet/models/mtcov.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
:cite:`contisciani2020community`.
"""

from argparse import Namespace
import logging
from pathlib import Path
import sys
import time
from argparse import Namespace
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple

import numpy as np
import scipy.sparse
from sparse import COO

from .base import ModelBase, ModelUpdateMixin
from .classes import GraphData
from .constants import OUTPUT_FOLDER
from ..evaluation.expectation_computation import compute_mean_lambda0
from ..input.loader import build_adjacency_and_design_from_file
from ..input.preprocessing import preprocess_adjacency_tensor, preprocess_data_matrix
from ..types import GraphDataType, EndFileType, FilesType, ArraySequence
from ..types import ArraySequence, EndFileType, FilesType, GraphDataType
from ..utils.matrix_operations import sp_uttkrp, sp_uttkrp_assortative
from .base import ModelBase, ModelUpdateMixin
from .classes import GraphData
from .constants import OUTPUT_FOLDER

MAX_BATCH_SIZE = 5000
RANDOM_SEED = 10
Expand Down
2 changes: 1 addition & 1 deletion probinet/synthetic/anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from scipy.optimize import brentq

from ..models.constants import OUTPUT_FOLDER
from ..synthetic.base import GraphProcessingMixin, affinity_matrix
from ..synthetic.base import affinity_matrix, GraphProcessingMixin
from ..synthetic.dynamic import eq_c, membership_vectors
from ..utils.tools import flt
from ..visualization.plot import plot_M
Expand Down
6 changes: 3 additions & 3 deletions probinet/synthetic/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
"""

from abc import ABCMeta
from enum import Enum
import logging
import math
from os import PathLike
from enum import Enum
from pathlib import Path
from typing import Tuple, Optional, Union
from typing import Optional, Tuple, Union

import pandas as pd
from matplotlib import pyplot as plt
import networkx as nx
import numpy as np
import pandas as pd

from probinet.visualization.plot import plot_A

Expand Down
2 changes: 1 addition & 1 deletion probinet/synthetic/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
from scipy.sparse import coo_matrix

from probinet.visualization.plot import plot_M
from .base import GraphProcessingMixin, affinity_matrix

from ..models.constants import EPS_, OUTPUT_FOLDER
from ..utils.matrix_operations import normalize_nonzero_membership
from .base import affinity_matrix, GraphProcessingMixin


class SyntheticDynCRep(GraphProcessingMixin):
Expand Down
4 changes: 2 additions & 2 deletions probinet/synthetic/multilayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
with one categorical attribute. Self-loops are removed and only the largest connected component is considered.
"""

import logging
from abc import ABCMeta
import logging
import os
import warnings
from pathlib import Path
from typing import Optional
import warnings

import matplotlib.pyplot as plt
import networkx as nx
Expand Down
Loading

0 comments on commit 48b9cfd

Please sign in to comment.