Skip to main content

A library to sample temporal walks from an in-memory temporal graph

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

Temporal Walk

PyPI Latest Release PyPI Downloads

A modified implementation of temporal walk algorithm from "Continuous-Time Dynamic Network Embeddings" paper.


Introduction

This project enables the construction of large temporal networks in memory, from which temporal walks can be sampled. Temporal walks are invaluable in graph neural networks (GNNs) for learning network dynamics.

This library facilitates the creation of temporal graphs and the incremental sampling of temporal walks based on the current graph state, making it especially useful for training GNNs. PyBind is interfaced which let's the functions to be called from Python. For convenience the walks are returned as numpy arrays.


Installation

This project can be installed using pip.

pip install temporal-walk

Functions

TemporalWalk class contains the public facing functions.

Constructor

TemporalWalk(int num_walks, int len_walk, RandomPickerType picker_type);

Initializes a TemporalWalk object with the specified number of walks, length of each walk, and the type of random picker to be used. Three random pickers are available Exponential, Linear and Uniform.

add_edge

void add_edge(int u, int i, int64_t t);

Adds a directed edge from node u to node i at the specified timestamp t in the temporal graph.

add_multiple_edges

void add_multiple_edges(const std::vector<EdgeInfo>& edge_infos);

Adds multiple edges to the temporal graph based on the provided vector of EdgeInfo structures, where each structure contains the source node u, destination node i, and timestamp t.

get_random_walks

std::vector<std::vector<int>> get_random_walks(WalkStartAt walk_start_at, int end_node=-1);

Generates a specified number of random walks from the temporal graph. The walks can be sampled from destination to source or source to destination. This can be controlled using walk_start_at, which can have values Begin, End or Random. An end-node can be specified to start or end the walks. The default value -1 picks the end-node randomly.

get_random_walks_for_nodes

std::unordered_map<int, std::vector<std::vector<int>>> get_random_walks_for_nodes(WalkStartAt walk_start_at, const std::vector<int>& end_nodes);

Generates random walks for multiple specified nodes in the temporal graph. The walks can be sampled from destination to source or source to destination, controlled by the walk_start_at parameter, which can take the values Begin, End, or Random. The end_nodes parameter is a vector containing the IDs of the nodes for which the walks will be generated. For each node in end_nodes, the function produces random walks based on the specified starting point, returning the walks as a mapping of node IDs to their corresponding random walks.

get_random_walks_with_times

std::vector<std::vector<std::pair<int, int64_t>>> get_random_walks_with_times(WalkStartAt walk_start_at, int end_node=-1)

This method generates random walks from the temporal graph where each step in the walk includes the node ID and its corresponding timestamp. The walk_start_at parameter specifies whether to sample the walks from the beginning, end, or randomly. An optional end_node can be specified to control the endpoint of each walk. If -1 is provided, the endpoint is selected randomly. This function returns a vector of walks, where each walk is represented as a sequence of pairs containing the node ID and timestamp.

get_random_walks_for_nodes_with_times

std::unordered_map<int, std::vector<std::vector<std::pair<int, int64_t>>>> get_random_walks_for_nodes_with_times(WalkStartAt walk_start_at, const std::vector<int>& end_nodes)

This method generates timestamped random walks for each specified node in the graph. The walk_start_at parameter indicates the walk's starting point (Begin, End, or Random), and end_nodes is a vector of node IDs for which to generate the walks. The output is a map associating each node ID with a vector of random walks, where each walk contains pairs of node IDs and timestamps.

get_len_walk

int get_len_walk();

Returns the length of the random walks that will be generated by the TemporalWalk object.

get_edge_count

size_t get_edge_count();

Returns the total number of directed edges in the temporal graph.

get_node_count

size_t get_node_count();

Returns the total number of nodes present in the temporal graph.

get_node_ids

std::vector<int> get_node_ids();

Returns a vector containing the IDs of all nodes in the temporal graph.


Python Interfaces

The Python bindings for the TemporalWalk class provide a seamless way to interact with the C++ implementation from Python. The bindings are created using the pybind11 library, enabling easy access to the functionality of the TemporalWalk class.

Constructor

TemporalWalk(num_walks: int, len_walk: int, picker_type: str):

Initializes a TemporalWalk object with the specified number of walks, length of each walk, and the type of random picker to be used. The picker_type should be one of the following strings: "Uniform", "Linear", or "Exponential".

add_edge

add_edge(u: int, i: int, t: int):

Adds a directed edge from node u to node i at the specified timestamp t in the temporal graph.

add_multiple_edges

def add_multiple_edges(edge_infos: List[Tuple[int, int, int64_t]]):

Adds multiple directed edges to the temporal graph based on the provided list of tuples. Each tuple should contain three elements: the source node u, the destination node i, and the timestamp t.

get_random_walks

get_random_walks(walk_start_at: str, end_node: int = -1, fill_value: int = 0) -> np.ndarray:

Generates random walks from the temporal graph. The walks can be sampled from destination to source or source to destination, controlled by the walk_start_at parameter, which can be "Begin", "End", or "Random". An end_node can be specified to start or end the walks. The default value -1 picks the end-node randomly. Returns a 2D NumPy array containing the generated walks, padded with fill_value where necessary.

get_random_walks_for_nodes

get_random_walks_for_nodes(walk_start_at: str, end_nodes: List[int], fill_value: int = 0) -> Dict[int, np.ndarray]:

Generates random walks for multiple specified nodes in the temporal graph. Similar to get_random_walks, the walks can be sampled from destination to source or source to destination, controlled by the walk_start_at parameter. The end_nodes parameter is a list of integers representing the IDs of the nodes for which the walks will be generated. Returns a dictionary of 2D NumPy arrays, each corresponding to the walks for a specific node, padded with fill_value where necessary.

get_random_walks_with_times

get_random_walks_with_times(walk_start_at: str, end_node: int = -1) -> List[List[Tuple[int, int]]]:

Generates timestamped random walks in the temporal graph, where each step contains the node ID and timestamp. The walk_start_at argument controls the sampling point ("Begin", "End", or "Random"), while end_node specifies an optional endpoint. If -1, an endpoint is randomly selected. Returns a list of walks, each represented as a list of tuples containing node IDs and timestamps.

get_random_walks_for_nodes_with_times

get_random_walks_for_nodes_with_times(walk_start_at: str, end_nodes: List[int]) -> Dict[int, List[List[Tuple[int, int]]]]:

Generates timestamped random walks for each specified node in end_nodes. The walk_start_at argument determines the starting point of the walks ("Begin", "End", or "Random"). Returns a dictionary mapping each node ID to a list of walks, where each walk is a list of tuples, with each tuple containing the node ID and timestamp.

get_node_count

get_node_count() -> int:

Returns the total number of nodes present in the temporal graph.

get_edge_count

get_edge_count() -> int:

Returns the total number of directed edges in the temporal graph.

get_node_ids

get_node_ids() -> np.ndarray:

Returns a numpy array containing the IDs of all nodes in the temporal graph.


Nguyen, Giang Hoang et al. “Continuous-Time Dynamic Network Embeddings.” Companion Proceedings of the The Web Conference 2018 (2018).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

temporal_walk-0.1.6-cp312-cp312-macosx_14_0_arm64.whl (180.9 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

temporal_walk-0.1.6-cp311-cp311-macosx_14_0_arm64.whl (181.9 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

temporal_walk-0.1.6-cp310-cp310-macosx_14_0_arm64.whl (181.3 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

Details for the file temporal_walk-0.1.6-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for temporal_walk-0.1.6-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a7982135b60bcb3d59fa305a5951e0a8da73f0df2513e951722ad8fea03b8c12
MD5 60057e7072e711c0fddacb548cb05e24
BLAKE2b-256 af5d0dbb6ae1e12010fca881b5109158a30b58974faeeb92320e5f0122538196

See more details on using hashes here.

File details

Details for the file temporal_walk-0.1.6-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for temporal_walk-0.1.6-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 fd2c2d765cffe1d9c8b02438d2ac396d6c474f22e208d3ecb1f0b89f263472cb
MD5 a32ab0119ec81ba953be633df4fc6060
BLAKE2b-256 572a23c6b2c37215edd2a786703ef5031c0a1247770ed61bda825d9a34e26a72

See more details on using hashes here.

File details

Details for the file temporal_walk-0.1.6-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for temporal_walk-0.1.6-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 aafe732a89341ca10d9e8cc9bbd83a69737cfa7e8b7a50e0a4c3ad26b50bd2c0
MD5 e4ef05c6380380e1cc0eb939bdbd57b4
BLAKE2b-256 9040e87b828d34cd6a7ac51a82956e68532802932ea9c2520ab0264d8c6e80e9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page