Mechanisms

class netin.TriadicClosure(n: int, f_m: float, tc: float, seed: object | None = None)

Class to model triadic closure as a mechanism of edge formation given a source and a target node.

Parameters

n: int

number of nodes (minimum=2)

f_m: float

fraction of minorities (minimum=1/n, maximum=(n-1)/n)

tc: float

triadic closure probability (minimum=0, maximum=1)

seed: object

seed for random number generator

Notes

This class does not generate a graph.

get_metadata_as_dict() Dict[str, Any]

Returns the metadata (parameters) of the model as a dictionary.

Returns

dict

metadata of the model

get_target_probabilities(source: int, available_nodes: List[int]) Tuple[array, List[int]]

Returns the probabilities of selecting a target node from a set of nodes based on triadic closure, or a regular mechanism,

Parameters

sourceint

source node

available_nodesList[int]

list of available target nodes

Returns

Tuple[np.array, List[int]]

Tuple of two equally sizes lists. The first list contains the probabilities and the second list the available nodes.

get_triadic_closure() float

Returns the triadic closure probability tc.

Returns

tc: float

triadic closure probability (minimum=0, maximum=1)

infer_triadic_closure() float

Infers analytically the triadic closure value of the graph.

Returns

float

triadic closure probability of the graph

info_computed()

Shows the computed properties of the graph.

info_params()

Shows the parameters of the model.

init_special_targets(source: int) object

Returns an empty dictionary (source node ids)

Parameters

sourceint

Newly added node

Returns

object

Return an empty dictionary (source node ids)

initialize(class_attribute: str = 'm', class_values: List[Any] | None = None, class_labels: List[str] | None = None)

Initializes the model.

Parameters

class_attribute: str

name of the attribute that represents the class

class_values: list

values of the class attribute

class_labels: list

labels of the class attribute mapping the class_values.

on_edge_added(source: int, target: int)

Updates the set of special available_nodes based on the triadic closure mechanism. When an edge is created, multiple potential triadic closures emerge (i.e., two-hop neighbors that are not yet directly connected). These are added to the set of special available_nodes.

Parameters

idx_target: int

index of the target node

source: int

source node

target: int

target node

available_nodes: List[int]

list of target nodes

special_targets: Union[None, Dict[int, int]]

special available_nodes

Returns

Union[None, Dict[int, int]

updated special available_nodes

set_triadic_closure(tc: float)

Sets the triadic closure probability tc.

Parameters

tc: float

triadic closure probability (minimum=0, maximum=1)

validate_parameters()

Validates the parameters of the undirected.

class netin.Homophily(n: int, f_m: float, h_MM: float, h_mm: float, seed: object | None = None)

Class to model homophily as a mechanism of edge formation given a source and a target node.

Parameters

n: int

number of nodes (minimum=2)

f_m: float

fraction of minorities (minimum=1/n, maximum=(n-1)/n)

h_MM: float

homophily (similarity) between majority nodes (minimum=0, maximum=1.)

h_mm: float

homophily (similarity) between minority nodes (minimum=0, maximum=1.)

Notes

This class does not generate a graph.

get_homophily_between_source_and_target(source: int, target: int) float

Returns the homophily value between a source and a target node based on their class values. This homophily value is inferred from the mixing matrix.

Parameters

source: int

Source node id

target: int

Target node id

Returns

h: float

homophily (similarity) between source and target nodes (minimum=0, maximum=1.)

get_homophily_majority() float

Returns the homophily value between majority nodes.

Returns

h_MM: float

homophily (similarity) between majority nodes (minimum=0, maximum=1.)

get_homophily_minority() float

Returns the homophily value between minority nodes.

Returns

h_mm: float

homophily (similarity) between minority nodes (minimum=0, maximum=1.)

get_metadata_as_dict() dict

Returns the metadata info (input parameters of the model) of the graph as a dictionary.

Returns

obj dict

dictionary with the metadata info of the graph.

get_target(source: int, available_nodes: list[int], special_targets: None | object | iter) int

Picks a random target node based on the homophily dynamic.

Parameters

source: int

Newly added node

available_nodes: Set[int]

Potential target nodes in the graph

special_targets: object

Special target nodes in the graph

Returns

int: Target node that an edge should be added to from source

get_target_probabilities(source: int, available_nodes: list[int] | array) tuple[array, list[int]]

Returns the probabilities of selecting a target node from a set of nodes based on homophily. Homophily is inferred from the mixing matrix.

Parameters

source: int

source node

available_nodes: set[int]

set of target nodes

special_targets: object

special available_nodes

Returns

tuple[np.array, set[int]]

probabilities of selecting a target node from a set of nodes, and the set of target nodes`

infer_homophily_values() tuple[float, float]

Infers analytically the homophily values for the majority and minority classes.

Returns

h_MM: float

homophily within majority group

h_mm: float

homophily within minority group

info_computed()

Shows the computed properties of the graph.

info_params()

Shows the parameters of the model.

initialize(class_attribute: str = 'm', class_values: list | None = None, class_labels: list | None = None)

Initializes the model.

Parameters

class_attribute: str

name of the attribute that represents the class

class_values: list

values of the class attribute

class_labels: list

labels of the class attribute mapping the class_values.

set_homophily_majority(h_MM: float)

Sets the homophily value between majority nodes.

Parameters

h_MM: float

homophily (similarity) between majority nodes (minimum=0, maximum=1.)

set_homophily_minority(h_mm: float)

Sets the homophily value between minority nodes.

Parameters

h_mm: float

homophily (similarity) between minority nodes (minimum=0, maximum=1.)

validate_parameters()

Validates the parameters of the graph.