hari_plotter.dynamics module

class hari_plotter.dynamics.Dynamics[source]

Bases: object

HariDynamics manages a list of LazyHariGraph objects that represent HariGraph instances.

This class facilitates the batch processing of multiple LazyHariGraph instances. It allows for reading multiple networks and opinions, and provides a unified interface to access and manipulate each LazyHariGraph.

lazy_hari_graphs

A list of LazyHariGraph objects.

Type:

list[LazyHariGraph]

groups

A list where each element is a list of indices representing a group.

Type:

list[list[int]]

initialized()

Returns indices of initialized LazyHariGraph instances.

uncluster()[source]

Resets clustering for all LazyHariGraph instances.

read_network()[source]

Reads network and opinion files to create and add LazyHariGraph objects.

__getitem__()[source]

Allows indexing to access individual LazyHariGraph instances.

__iter__()[source]

Allows iteration over LazyHariGraph instances.

__getattr__()[source]

Allows dynamic attribute access, attempting to get the attribute from LazyHariGraph instances.

Note

Any attribute that isn’t directly found on a HariDynamics object will attempt to be retrieved from its LazyHariGraph objects. If the attribute is callable, a function will be returned that when called, will apply the method on all LazyHariGraph instances. If the attribute is not callable, a list of its values from all LazyHariGraph instances will be returned.

get_grouped_graphs() list[list[LazyGraph]][source]

Retrieves grouped LazyHariGraph objects based on the indices in self.groups.

Returns:

list of lists where each sublist contains LazyHariGraph objects.

Return type:

list[list[LazyHariGraph]]

group(num_intervals: int, interval_size: int = 1, offset: int = 0)[source]

Groups indices of LazyHariGraphs objects based on provided intervals, interval size, and an offset. Indices might show up multiple times or might never show up, depending on the parameters.

Parameters:
  • num_intervals (int) – The number of intervals.

  • interval_size (int) – The size of each interval.

  • offset (int) – Starting offset for the grouping.

property initialized: list[int]

list of indices of initialized LazyHariGraph instances.

Iterates over each LazyHariGraph in the list lazy_hari_graphs and checks if it’s initialized. Returns a list containing the indices of all the LazyHariGraphs that are initialized.

Returns:

Indices of all initialized LazyHariGraph instances.

Return type:

list[int]

merge_nodes_by_index(index: int)[source]

Merges nodes in each LazyHariGraph based on the cluster mapping of the graph at the provided index. The graph at the provided index is skipped during merging.

Parameters:

index (int) – The index of the LazyHariGraph whose cluster mapping should be used for merging nodes.

merge_nodes_by_mapping(mapping: tuple[int])[source]

Merge nodes in each LazyHariGraph based on the provided mapping. If a graph was already initialized, uninitialize it first.

Parameters:

mapping (tuple[int]) – A dictionary representing how nodes should be merged.

plot_initialized()[source]
classmethod read_json(json_files: str | list[str], load_request: dict[str, Any] = {}) Dynamics[source]

Reads a list of network files and a list of opinion files to create LazyHariGraph objects and appends them to the lazy_hari_graphs list of a HariDynamics instance.

Parameters:
  • network_files (Union[str, list[str]]) – Either a single path or a list of paths to the network files.

  • opinion_files (list[str]) – A list of paths to the opinion files.

Returns:

An instance of HariDynamics with lazy_hari_graphs populated.

Return type:

HariDynamics

Raises:

ValueError – If the length of network_files is not equal to the length of opinion_files or other invalid cases.

classmethod read_network(network_files: str | list[str], opinion_files: list[str], load_request: dict[str, Any] = {}) Dynamics[source]

Reads a list of network files and a list of opinion files to create LazyHariGraph objects and appends them to the lazy_hari_graphs list of a HariDynamics instance.

Parameters:
  • network_files (Union[str, list[str]]) – Either a single path or a list of paths to the network files.

  • opinion_files (list[str]) – A list of paths to the opinion files.

Returns:

An instance of HariDynamics with lazy_hari_graphs populated.

Return type:

HariDynamics

Raises:

ValueError – If the length of network_files is not equal to the length of opinion_files or other invalid cases.

uncluster()[source]

Resets the clustering and uninitializes all LazyHariGraph instances.

For each LazyHariGraph in lazy_hari_graphs, resets its clustering by setting its mapping to None and then uninitializes the graph.