Skip to content

Commit

Permalink
updating set to list in PATCH
Browse files Browse the repository at this point in the history
  • Loading branch information
lisette-espin committed Nov 29, 2023
1 parent a1efff0 commit a1f8cb8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion netin/generators/dpa.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_in_degree(self, n: int) -> int:
def get_target_probabilities(self, source: int, available_nodes: Union[None, list[int], np.array],
special_targets: Union[None, object, iter] = None) -> np.array:
"""
Returns the probabilities for each target node in `target_list` to be selected as target node
Returns the probabilities for each target node in `available_nodes` to be selected as target node
given source node `source`.
Parameters
Expand Down
18 changes: 5 additions & 13 deletions netin/generators/graph.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import time
import warnings
from collections import Counter
from typing import Union, Tuple, Iterable, Any
from typing import Union, Iterable, Any

import networkx as nx
import numpy as np
Expand Down Expand Up @@ -581,7 +581,7 @@ def get_potential_nodes_to_connect(self, source: int,

def get_target_probabilities(self, source: int,
available_nodes: list[int],
special_targets: Union[None, object, iter] = None) -> Tuple[np.array, list[int]]:
special_targets: Union[None, object, iter] = None) -> tuple[np.array, list[int]]:
"""
Returns the probability for each target node to be connected to the source node.
Expand Down Expand Up @@ -737,7 +737,7 @@ def calculate_edge_type_counts(self) -> Counter:
"""
return net.get_edge_type_counts(self)

def fit_powerlaw(self, metric: str) -> Tuple[powerlaw.Fit, powerlaw.Fit]:
def fit_powerlaw(self, metric: str) -> tuple[powerlaw.Fit, powerlaw.Fit]:
"""
Fits a power law to the distribution given by 'metric' (the in- or out-degree of nodes in the graph).
Expand All @@ -757,17 +757,9 @@ def fit_powerlaw(self, metric: str) -> Tuple[powerlaw.Fit, powerlaw.Fit]:

fit_M, fit_m = fit_powerlaw_groups(self, metric)

# vM = self.get_majority_value()
# dist_fnc = self.in_degree if metric == 'in_degree' else self.out_degree
# dM = [d for n, d in dist_fnc if self.nodes[n][self.class_attribute] == vM]
# dm = [d for n, d in dist_fnc if self.nodes[n][self.class_attribute] != vM]
#
# fit_M = powerlaw.Fit(data=dM, discrete=True, xmin=min(dM), xmax=max(dM), verbose=False)
# fit_m = powerlaw.Fit(data=dm, discrete=True, xmin=min(dm), xmax=max(dm), verbose=False)

return fit_M, fit_m

def calculate_powerlaw_exponents(self, metric: str) -> Tuple[float, float]:
def calculate_powerlaw_exponents(self, metric: str) -> tuple[float, float]:
"""
Returns the power law exponents for the ``metric`` distribution of the majority and minority class.
Expand Down Expand Up @@ -949,7 +941,7 @@ def copy(self) -> Union[nx.Graph, nx.DiGraph]:
# Static functions
######################################################################################################################

def fit_powerlaw_groups(g: Graph, metric: str) -> Tuple[powerlaw.Fit, powerlaw.Fit]:
def fit_powerlaw_groups(g: Graph, metric: str) -> tuple[powerlaw.Fit, powerlaw.Fit]:
"""
Fits a power law to the distribution given by 'metric' (the in- or out-degree of nodes in the graph).
Expand Down
3 changes: 1 addition & 2 deletions netin/generators/pa.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import Union
from typing import Tuple

import numpy as np

Expand Down Expand Up @@ -65,7 +64,7 @@ def get_target_probabilities(self, source: int, available_nodes: list[int],
probs: np.array
probabilities of the target nodes to be selected
target_list: set
available_nodes: set
set of target nodes (ids)
"""
probs = np.array([(self.degree(target) + const.EPSILON) for target in available_nodes])
Expand Down
23 changes: 12 additions & 11 deletions netin/generators/patch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Union, Set, Tuple
from typing import Union

import numpy as np

Expand Down Expand Up @@ -82,8 +82,9 @@ def get_metadata_as_dict(self) -> dict:
# Generation
############################################################

def get_target_probabilities(self, source: Union[None, int], available_nodes: Union[None, Set[int]],
special_targets: Union[None, object, iter] = None) -> Tuple[np.array, set[int]]:
def get_target_probabilities(self, source: int,
available_nodes: list[int],
special_targets: Union[None, object, iter] = None) -> tuple[np.array, list[int]]:
"""
Returns the probabilities of nodes to be selected as target nodes.
Expand All @@ -106,9 +107,9 @@ def get_target_probabilities(self, source: Union[None, int], available_nodes: Un
"""
return TriadicClosure.get_target_probabilities(self, source, available_nodes, special_targets)

def get_target_probabilities_regular(self, source: Union[None, int], target_list: Union[None, Set[int]],
special_targets: Union[None, object, iter] = None) -> Tuple[
np.ndarray, set[int]]:
def get_target_probabilities_regular(self, source: int,
available_nodes: list[int],
special_targets: Union[None, object, iter] = None) -> tuple[np.ndarray, list[int]]:
"""
Returns the probability of nodes to be selected as target nodes using the
preferential attachment with homophily mechanism.
Expand All @@ -118,7 +119,7 @@ def get_target_probabilities_regular(self, source: Union[None, int], target_list
source: int
source node id
target_list: set
available_nodes: set
set of target node ids
special_targets: dict
Expand All @@ -129,7 +130,7 @@ def get_target_probabilities_regular(self, source: Union[None, int], target_list
tuple
probabilities of nodes to be selected as target nodes, and set of target of nodes
"""
return PAH.get_target_probabilities(self, source, target_list, special_targets)
return PAH.get_target_probabilities(self, source, available_nodes, special_targets)

def get_special_targets(self, source: int) -> object:
"""
Expand Down Expand Up @@ -165,7 +166,7 @@ def info_computed(self):
PAH.info_computed(self)
TriadicClosure.info_computed(self)

def infer_homophily_values(self) -> Tuple[float, float]:
def infer_homophily_values(self) -> tuple[float, float]:
"""
Infers analytically the homophily values of the graph.
Expand All @@ -187,8 +188,8 @@ def infer_triadic_closure(self) -> float:
float
triadic closure probability of the graph
"""
tc = None
return tc
# @TODO: To be implemented
raise NotImplementedError("Inferring triadic closure not implemented yet.")

def makecopy(self):
"""
Expand Down
8 changes: 8 additions & 0 deletions netin/generators/tc.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,13 @@ def info_computed(self):
print("- Empirical triadic closure: {}".format(inferred_tc))

def infer_triadic_closure(self) -> float:
"""
Infers analytically the triadic closure value of the graph.
Returns
-------
float
triadic closure probability of the graph
"""
# @TODO: To be implemented
raise NotImplementedError("Inferring triadic closure not implemented yet.")

0 comments on commit a1f8cb8

Please sign in to comment.