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.

To allow creation of continuous graphs with a maximum time capacity, when edges with older timestamps are automatically deleted.


Definitions

A temporal network represents a dynamic system where edges or interactions between nodes vary over time. In contrast to static networks, temporal networks capture changes and sequences in connectivity, which is essential in understanding real-world phenomena like social interactions, information spread, and transportation flows over time.

A temporal walk is a path through a temporal network that respects the order of timestamps on edges, ensuring causality. Temporal walks are particularly useful for applications in graph neural networks (GNNs), where learning temporal dependencies enhances the model's ability to predict or understand evolving network structures.


Example

For a given temporal network with following edges (upstream node, downstream node, timestamp),

[
    (4, 5, 71),
    (3, 5, 82),
    (1, 3, 19),
    (4, 2, 34),
    (4, 3, 79),
    (2, 5, 19),
    (2, 3, 70),
    (5, 4, 97),
    (4, 6, 57),
    (6, 4, 27),
    (2, 6, 80),
    (6, 1, 42),
    (4, 6, 98),
    (1, 4, 17),
    (5, 4, 32)
]
Sample Temporal Graph

Five walks staring at node 2 with linear probability along with their timestamps,

(2, -9223372036854775808), (3, 70), (5, 82), (4, 97), (6, 98)
(2, -9223372036854775808), (5, 19), (4, 32), (5, 71), (4, 97), (6, 98)
(2, -9223372036854775808), (5, 19), (4, 32), (2, 34), (3, 70), (5, 82), (4, 97), (6, 98)
(2, -9223372036854775808), (5, 19), (4, 97), (6, 98)
(2, -9223372036854775808), (3, 70), (5, 82), (4, 97), (6, 98)

Five walks ending at node 2 with linear probability,

(6, 27), (4, 34), (2, 9223372036854775807)
(2, 19), (5, 32), (4, 34), (2, 9223372036854775807)
(6, 27), (4, 34), (2, 9223372036854775807)
(6, 27), (4, 34), (2, 9223372036854775807)
(1, 17), (4, 34), (2, 9223372036854775807)

Five walks staring at node 2 with exponential probability,

(2, -9223372036854775808), (6, 80)
(2, -9223372036854775808), (5, 19), (4, 32), (2, 34), (3, 70), (5, 82), (4, 97), (6, 98)
(2, -9223372036854775808), (5, 19), (4, 32), (2, 34), (6, 80)
(2, -9223372036854775808), (5, 19), (4, 32), (5, 71), (4, 97), (6, 98)
(2, -9223372036854775808), (5, 19), (4, 32), (2, 34), (6, 80)

Five walks ending at node 2 with exponential probability,

(2, 19), (5, 32), (4, 34), (2, 9223372036854775807)
(2, 19), (5, 32), (4, 34), (2, 9223372036854775807)
(6, 27), (4, 34), (2, 9223372036854775807)
(2, 19), (5, 32), (4, 34), (2, 9223372036854775807)
(2, 19), (5, 32), (4, 34), (2, 9223372036854775807)

Five walks staring at node 2 with uniform probability,

(2, -9223372036854775808), (3, 70), (5, 82), (4, 97), (6, 98)
(2, -9223372036854775808), (5, 19), (4, 97), (6, 98)
(2, -9223372036854775808), (5, 19), (4, 97), (6, 98)
(2, -9223372036854775808), (6, 80)
(2, -9223372036854775808), (5, 19), (4, 32), (2, 34), (6, 80)

Five walks ending at node 2 with uniform probability,

(6, 27), (4, 34), (2, 9223372036854775807)
(6, 27), (4, 34), (2, 9223372036854775807)
(2, 19), (5, 32), (4, 34), (2, 9223372036854775807)
(1, 17), (4, 34), (2, 9223372036854775807)
(6, 27), (4, 34), (2, 9223372036854775807)

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, int64_t max_time_capacity=-1);

Initializes a TemporalWalk object with the specified number of walks, length of each walk, the type of random picker to be used and the maximum time capacity of the graph. Three random pickers are available Exponential, Linear and Uniform. The default value of max_time_capacity is -1, which means unlimited capacity. If set then edges older than max_time_capacity from the latest timestamp are deleted automatically.

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,  max_time_capacity: int=-1):

Initializes a TemporalWalk object with the specified number of walks, length of each walk, the type of random picker to be used and the maximum time capacity of the graph. The picker_type should be one of the following strings: "Uniform", "Linear", or "Exponential". The default value of max_time_capacity is -1, which means unlimited capacity. If set then edges older than max_time_capacity from the latest timestamp are deleted automatically.

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.8-cp312-cp312-manylinux_2_35_x86_64.whl (212.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

temporal_walk-0.1.8-cp312-cp312-macosx_14_0_arm64.whl (184.4 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

temporal_walk-0.1.8-cp311-cp311-manylinux_2_35_x86_64.whl (212.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

temporal_walk-0.1.8-cp311-cp311-macosx_14_0_arm64.whl (185.2 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

temporal_walk-0.1.8-cp310-cp310-manylinux_2_35_x86_64.whl (212.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

temporal_walk-0.1.8-cp310-cp310-macosx_14_0_arm64.whl (184.7 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

Details for the file temporal_walk-0.1.8-cp312-cp312-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for temporal_walk-0.1.8-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 79eaff026396c1218c410705bfcfef1baeef8d17dd6852f69512882aa4ba5af5
MD5 8eef400164ca7705aaa33e18fba0c1a0
BLAKE2b-256 400f4f376574486d80fca1769f398424c3cdf24cbaa3be68d965d15899abc977

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for temporal_walk-0.1.8-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 aabbb9219ee98fd88a08f6b583ed9eeec1d088ce8347cf93fd6d732161e54dff
MD5 2bab8988cbf45651782cee656a95bfc7
BLAKE2b-256 45baa1acad928c1654fd58cff637e920dba376e5dd387e800b849cf5b314797f

See more details on using hashes here.

File details

Details for the file temporal_walk-0.1.8-cp311-cp311-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for temporal_walk-0.1.8-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 ed605a58964005f05a957c66b04fd82fd44294073a740c882b0f2b223573ad2d
MD5 50a659f5d740e40ba370036b2ebf311f
BLAKE2b-256 4d7f82be2cdec5744d71149fbf688cb7255beefd9dd1dcc2b1ac6eeb63503ca9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for temporal_walk-0.1.8-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 857c308cd6cc81394de20ad306aacf321d7e4a7fd6da992082282c780d24aed2
MD5 ffd92a78c7dfc5c8064a1b70fbe2fd6a
BLAKE2b-256 b352e13916266b6c31d4c9c19de40698a358780e0dfe0623394615c13a6db5da

See more details on using hashes here.

File details

Details for the file temporal_walk-0.1.8-cp310-cp310-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for temporal_walk-0.1.8-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 3f38621d5e79bd1b4eb13aba9c7bd689b923fa872b858081aa1bba0407119175
MD5 f0f4a04d62de906425ff112bf74bc978
BLAKE2b-256 b1a2ce176d57ed378745c054f8dec2ac3805e1069ebaf012152e566b3ee49bd8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for temporal_walk-0.1.8-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d302929bb4902bd3c8aac243b2a5f064b582eeab0bae7377c7dceccb63c2be2d
MD5 6cf7e9ae003a2dbee9e7aff9e905cfd2
BLAKE2b-256 4090349f885e4964385c9c927523d59123748948783cdb64469de711a20a6a08

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