graphtoolbox.utils.helper_functions

Functions

batch_x_to_tensor(batch, **kwargs)

Converts a batch of data to a tensor, organizing elements by modulo num_nodes without detaching gradients.

batch_y_to_tensor(batch, **kwargs)

Converts a batch of data to a tensor, organizing elements by modulo num_nodes without detaching gradients.

build_adjacency_matrix(edge_index, edge_weight)

change_cwd([target_directory, verbose])

Change the current working directory to the specified directory by traversing up the directory tree until the target directory is found.

clean_dir(directory)

Deletes and recreates a specified directory.

extract_parameters(model_string)

get_exponential_similarity(...)

get_geodesic_distance(point_1, point_2)

Calculate the great circle distance (in km) between two points on the earth (specified in decimal degrees)

load_config(folder_config)

Loads configuration dictionaries.

load_kwargs(folder_config, kwargs)

Load keyword arguments.

parser_config(config)

Parse a configuration string into a dictionary.

save_config(folder_config, kwargs, new_values)

Save new values to a specified dictionary in a module.

update_config(folder_config, kwargs, new_config)

Update a specified dictionary in a module with new configuration values.

graphtoolbox.utils.helper_functions.clean_dir(directory: str) None[source][source]

Deletes and recreates a specified directory.

Parameters:

directory (str) – The path to the directory to clean.

graphtoolbox.utils.helper_functions.batch_y_to_tensor(batch: Tensor, **kwargs) Tensor[source][source]

Converts a batch of data to a tensor, organizing elements by modulo num_nodes without detaching gradients.

Parameters:
  • batch (torch.Tensor) – The batch of data containing the specified attribute.

  • **kwargs – num_nodes (int): Number of nodes in the graph. Defaults to 12.

Returns:

A tensor where data is organized into num_nodes groups.

Return type:

torch.Tensor

graphtoolbox.utils.helper_functions.batch_x_to_tensor(batch: Tensor, **kwargs) Tensor[source][source]

Converts a batch of data to a tensor, organizing elements by modulo num_nodes without detaching gradients.

Parameters:
  • batch (torch.Tensor) – The batch of data containing the specified attribute.

  • **kwargs – num_nodes (int): Number of nodes in the graph. Defaults to 12.

Returns:

A tensor where data is organized into num_nodes groups.

Return type:

torch.Tensor

graphtoolbox.utils.helper_functions.load_config(folder_config: str)[source][source]

Loads configuration dictionaries.

Parameters:

folder_config (str) – Path to the configuration file.

Returns:

Configuration file.

graphtoolbox.utils.helper_functions.load_kwargs(folder_config: str, kwargs: str) Dict[str, Any][source][source]

Load keyword arguments.

Parameters:

kwargs (str) – The name of the attribute (dictionary) to retrieve from the module.

Returns:

The dictionary retrieved from the module, or an empty dictionary if not found.

Return type:

Dict[str, Any]

graphtoolbox.utils.helper_functions.save_config(folder_config: str, kwargs: str, new_values: Dict[str, Any]) None[source][source]

Save new values to a specified dictionary in a module.

Parameters:
  • kwargs (str) – The name of the dictionary to update in the module.

  • new_values (Dict[str, Any]) – The new key-value pairs to add to the dictionary.

Raises:

ValueError – If the specified dictionary is not found in the module.

graphtoolbox.utils.helper_functions.update_config(folder_config: str, kwargs: str, new_config: Dict[str, Any]) None[source][source]

Update a specified dictionary in a module with new configuration values.

Parameters:
  • kwargs (str) – The name of the dictionary to update in the module.

  • new_config (Dict[str, Any]) – The new key-value pairs to update the dictionary with.

Raises:

ValueError – If the specified dictionary is not found in the module.

graphtoolbox.utils.helper_functions.parser_config(config: str) Dict[str, Any][source][source]

Parse a configuration string into a dictionary.

Parameters:

config (str) – The configuration string, formatted as ‘{“key”: “value”, “key2”: “value2”,…}’.

Returns:

The parsed dictionary.

Return type:

Dict[str, Any]

Example

>>> parser_config('{"model_name": "GCN", "num_epochs": "100"})
{'model_name': 'GCN', 'num_epochs': 100}
graphtoolbox.utils.helper_functions.extract_parameters(model_string)[source][source]
graphtoolbox.utils.helper_functions.change_cwd(target_directory: str | None = 'GraphToolbox', verbose: bool = False) None[source][source]

Change the current working directory to the specified directory by traversing up the directory tree until the target directory is found.

Parameters:

target_directory (Optional[str]) – The target directory to change to. Defaults to “GraphToolbox”.

Raises:

FileNotFoundError – If the target directory does not exist in the path hierarchy.

graphtoolbox.utils.helper_functions.get_geodesic_distance(point_1, point_2) float[source][source]

Calculate the great circle distance (in km) between two points on the earth (specified in decimal degrees)

https://stackoverflow.com/a/4913653

graphtoolbox.utils.helper_functions.get_exponential_similarity(condensed_distance_matrix, bandwidth, threshold)[source][source]
graphtoolbox.utils.helper_functions.build_adjacency_matrix(edge_index, edge_weight)[source][source]