hari_plotter.node_gatherer module

class hari_plotter.node_gatherer.ActivityDefaultNodeEdgeGatherer(G: Graph)[source]

Bases: DefaultNodeEdgeGatherer

Extends the DefaultNodeEdgeGatherer with functionality to handle node activity. It adds the ability to merge nodes based on activity levels in addition to the default parameters.

activity() dict[tuple[int], float][source]

Returns a mapping of node IDs to their activity levels.

edge_parameter_logger = <hari_plotter.node_gatherer.NodeEdgeGatherer.ParameterLogger object>
edge_parameters_in_mean_graph = {'Influence': 'mean'}
merge(node_ids: list[dict]) dict[str, int | float | dict][source]

Extends the merge function to include activity in the merged node attributes.

Parameters:

node_ids (list[dict]) – A list of node dictionaries to be merged.

Returns:

A dictionary containing the merged attributes, including activity.

Return type:

dict[str, Union[int, float, dict]]

node_parameter_logger = <hari_plotter.node_gatherer.NodeEdgeGatherer.ParameterLogger object>
node_parameters_in_mean_graph = {'Activity': 'mean', 'Opinion': 'mean'}
class hari_plotter.node_gatherer.ActivityDrivenNodeEdgeGatherer(G: Graph)[source]

Bases: ActivityDefaultNodeEdgeGatherer

Extends the ActivityDefaultNodeEdgeGatherer with functionality to accommodate ActivityDrivenModel.

edge_parameter_logger = <hari_plotter.node_gatherer.NodeEdgeGatherer.ParameterLogger object>
merge(node_ids: list[dict]) dict[str, int | float | dict][source]

Merges a list of nodes based on their identifiers, calculating combined attributes such as inner opinions, cluster size, aggregate opinions, and activity.

Parameters:

node_ids (list[dict]) – A list of node attribute dictionaries to be merged.

Returns:

A dictionary containing the merged attributes of the nodes, including activity.

Return type:

dict[str, Union[int, float, dict]]

merge_clusters(clusters: list[list[tuple[int]]], labels: list[str] | None = None, merge_remaining: bool = False) None[source]

Merges groups of nodes (clusters) into single nodes, optionally merging unclustered nodes into an additional node. Each new node represents its constituent cluster.

Parameters:
  • clusters (list[list[tuple[int]]]) – A list of clusters, each represented as a list of node identifiers.

  • labels (Union[list[str], None], optional) – Labels for the new nodes created from each cluster. Defaults to None.

  • merge_remaining (bool, optional) – If True, merges nodes not included in any cluster into a separate new node. Defaults to False.

merge_nodes(i: tuple[int], j: tuple[int]) None[source]

Merges two specified nodes into a single new node within the graph. The new node’s attributes are determined by the attributes of the merged nodes, and the edges are updated accordingly.

Parameters:
  • i (tuple[int]) – Identifier for the first node to be merged.

  • j (tuple[int]) – Identifier for the second node to be merged.

node_parameter_logger = <hari_plotter.node_gatherer.NodeEdgeGatherer.ParameterLogger object>
node_parameters_in_mean_graph = {'Activity': 'mean', 'Opinion': 'mean', 'Type': 'all'}
class hari_plotter.node_gatherer.DefaultNodeEdgeGatherer(G: Graph)[source]

Bases: NodeEdgeGatherer

Provides a default implementation for the NodeEdgeGatherer abstract base class. This class implements methods to extract and manipulate default parameters from nodes within a graph, such as merging nodes and clusters based on specific criteria.

cluster_size() dict[tuple[int], int][source]

Returns a mapping of node IDs to their cluster sizes.

edge_parameter_logger = <hari_plotter.node_gatherer.NodeEdgeGatherer.ParameterLogger object>
edge_parameters_in_mean_graph = {'Influence': 'mean'}
importance() dict[tuple[int], float][source]

Calculates and returns a mapping of node IDs to their importance, based on influence and size.

inner_opinions() dict[tuple[int], dict][source]

Returns a mapping of node IDs to their inner opinions.

static kde_scipy(x, x_grid, bandwidth=0.2, **kwargs)[source]

Kernel Density Estimation with Scipy

label() dict[tuple[int], str][source]

Returns a mapping of node IDs to their labels.

max_opinion() dict[tuple[int], float][source]

Returns a mapping of node IDs to the maximum opinion value among their inner opinions.

mean_graph(images: list[Graph]) Graph[source]

Calculates the mean graph from a list of Graph instances. The mean graph’s nodes and edges have attributes that are the average of the corresponding attributes in the input graphs.

Parameters:

images (list[nx.Graph]) – A list of Graph instances from which to calculate the mean graph.

Returns:

A new Graph instance representing the mean of the input graphs.

Return type:

nx.Graph

merge(node_ids: list[dict]) dict[str, int | float | dict][source]

Merges a list of nodes based on their identifiers, calculating combined attributes such as inner opinions, cluster size, and aggregate opinions.

Parameters:

node_ids (list[dict]) – A list of node attribute dictionaries to be merged.

Returns:

A dictionary containing the merged attributes of the nodes.

Return type:

dict[str, Union[int, float, dict]]

merge_clusters(clusters: list[list[tuple[int]]], labels: list[str] | None = None, merge_remaining: bool = False) None[source]

Merges groups of nodes (clusters) into single nodes, optionally merging unclustered nodes into an additional node. Each new node represents its constituent cluster.

Parameters:
  • clusters (list[list[tuple[int]]]) – A list of clusters, each represented as a list of node identifiers.

  • labels (Union[list[str], None], optional) – Labels for the new nodes created from each cluster. Defaults to None.

  • merge_remaining (bool, optional) – If True, merges nodes not included in any cluster into a separate new node. Defaults to False.

merge_nodes(i: tuple[int], j: tuple[int]) None[source]

Merges two specified nodes into a single new node within the graph. The new node’s attributes are determined by the attributes of the merged nodes, and the edges are updated accordingly.

Parameters:
  • i (tuple[int]) – Identifier for the first node to be merged.

  • j (tuple[int]) – Identifier for the second node to be merged.

min_opinion() dict[tuple[int], float][source]

Returns a mapping of node IDs to the minimum opinion value among their inner opinions.

neighbor_mean_opinion() dict[tuple[int], float][source]

Returns a mapping of node IDs to the average opinion of their neighbors.

node_parameter_logger = <hari_plotter.node_gatherer.NodeEdgeGatherer.ParameterLogger object>
node_parameters_in_mean_graph = {'Opinion': 'mean'}
opinion() dict[tuple[int], float][source]

Returns a mapping of node IDs to their opinions.

opinion_density() dict[tuple[int], float][source]

Returns a mapping of node IDs to their opinion distribution density.

std_opinion() dict[tuple[int], float][source]

Returns a mapping of node IDs to the standard deviation of opinion values among their inner opinions.

type() dict[tuple[int], str][source]

Returns a mapping of node IDs to their types for all nodes including bots.

class hari_plotter.node_gatherer.NodeEdgeGatherer(G: Graph)[source]

Bases: ABC

Abstract base class for gathering node and edge attributes within a graph. It defines a framework for extracting specific attributes or parameters of nodes and edges, facilitating customized data collection and analysis on graph-based structures.

node_parameter_logger

A logger for registering and tracking node parameters.

Type:

ParameterLogger

edge_parameter_logger

A logger for registering and tracking edge parameters.

Type:

ParameterLogger

G

The graph instance from NetworkX containing the nodes and edges for analysis.

Type:

Graph

class ParameterLogger[source]

Bases: object

A utility class used within NodeEdgeGatherer to log and manage parameters associated with nodes or edges. It allows for the dynamic registration of parameters to be gathered from the graph.

parameters

A dictionary mapping parameter names to their corresponding functions or values within the graph structure.

Type:

dict[str, Any]

copy() ParameterLogger[source]

Creates a deep copy of the ParameterLogger instance, including its parameters.

Returns:

A new instance of ParameterLogger with copied parameters.

Return type:

NodeEdgeGatherer.ParameterLogger

keys() list[source]

Returns a list of all registered parameter names.

edge_parameter_logger = <hari_plotter.node_gatherer.NodeEdgeGatherer.ParameterLogger object>
property edge_parameters: list[str]

Returns a list of all registered edge parameter names.

gather(param: str | list[str]) dict[str, Any][source]

Gathers and organizes parameter data for all nodes or edges in the graph based on the specified parameter(s).

Parameters:

param (Union[str, list[str]]) – The parameter name(s) to extract data for.

Returns:

A dictionary containing organized data for the requested parameter(s), including

a ‘Nodes’ key with a list of node names/IDs.

Return type:

dict[str, Any]

gather_everything() dict[str, Any][source]

Gathers data for all registered parameters for nodes or edges in the graph.

Returns:

A dictionary containing data for all registered parameters.

Return type:

dict[str, Any]

gather_unprocessed(param: str | list[str]) dict[str, Any][source]

Gathers unprocessed parameter data for all nodes or edges in the graph based on the specified parameter(s).

Parameters:

param (Union[str, list[str]]) – The parameter name(s) to extract data for.

Returns:

A dictionary containing the raw data for the requested parameter(s).

Return type:

dict[str, Any]

node_parameter_logger = <hari_plotter.node_gatherer.NodeEdgeGatherer.ParameterLogger object>
property node_parameters: list[str]

Returns a list of all registered node parameter names.