algorithms

Algorithmic functions that can be run on Raphtory graphs

Classes

ClassDescription
Infected
MatchingA Matching (i.e., a set of edges that do not share any nodes)

Functions

FunctionDescription
all_local_reciprocityLocal reciprocity - measure of the symmetry of relationships associated with a node
average_degreeThe average (undirected) degree of all nodes in the graph.
balanceSums the weights of edges in the graph based on the specified direction.
betweenness_centralityComputes the betweenness centrality for nodes in a given graph.
cohesive_fruchterman_reingoldCohesive version of fruchterman_reingold that adds virtual edges between isolated nodes
degree_centralityComputes the degree centrality of all nodes in the graph. The values are normalized
dijkstra_single_source_shortest_pathsFinds the shortest paths from a single source to multiple targets in a graph.
directed_graph_densityGraph density - measures how dense or sparse a graph is.
fast_rpComputes embedding vectors for each vertex of an undirected/bidirectional graph according to the Fast RP algorithm.
fruchterman_reingoldFruchterman Reingold layout algorithm
global_clustering_coefficientComputes the global clustering coefficient of a graph. The global clustering coefficient is
global_reciprocityReciprocity - measure of the symmetry of relationships in a graph, the global reciprocity of
global_temporal_three_node_motifComputes the number of three edge, up-to-three node delta-temporal motifs in the graph, using the algorithm of Paranjape et al, Motifs in Temporal Networks (2017).
global_temporal_three_node_motif_multiComputes the global counts of three-edge up-to-three node temporal motifs for a range of timescales. See global_temporal_three_node_motif for an interpretation of each row returned.
hitsHITS (Hubs and Authority) Algorithm:
in_componentIn component -- Finding the "in-component" of a node in a directed graph involves identifying all nodes that can be reached following only incoming edges.
in_componentsIn components -- Finding the "in-component" of a node in a directed graph involves identifying all nodes that can be reached following only incoming edges.
k_coreDetermines which nodes are in the k-core for a given value of k
label_propagationComputes components using a label propagation algorithm
local_clustering_coefficientLocal clustering coefficient - measures the degree to which nodes in a graph tend to cluster together.
local_clustering_coefficient_batchReturns the Local clustering coefficient (batch, intersection) for each specified node in a graph. This measures the degree to which one or multiple nodes in a graph tend to cluster together.
local_temporal_three_node_motifsComputes the number of each type of motif that each node participates in. See global_temporal_three_node_motifs for a summary of the motifs involved.
local_triangle_countImplementations of various graph algorithms that can be run on a graph.
louvainLouvain algorithm for community detection
max_degreeReturns the largest degree found in the graph
max_in_degreeThe maximum in degree of any node in the graph.
max_out_degreeThe maximum out degree of any node in the graph.
max_weight_matchingCompute a maximum-weighted matching in the general undirected weighted
min_degreeReturns the smallest degree found in the graph
min_in_degreeThe minimum in degree of any node in the graph.
min_out_degreeThe minimum out degree of any node in the graph.
out_componentOut component -- Finding the "out-component" of a node in a directed graph involves identifying all nodes that can be reached following only outgoing edges.
out_componentsOut components -- Finding the "out-component" of a node in a directed graph involves identifying all nodes that can be reached following only outgoing edges.
pagerankPagerank -- pagerank centrality value of the nodes in a graph
single_source_shortest_pathCalculates the single source shortest paths from a given source node.
strongly_connected_componentsStrongly connected components
temporal_SEIRSimulate an SEIR dynamic on the network
temporal_bipartite_graph_projectionProjects a temporal bipartite graph into an undirected temporal graph over the pivot node type. Let G be a bipartite graph with node types A and B. Given delta > 0, the projection graph G' pivoting over type B nodes,
temporally_reachable_nodesTemporally reachable nodes -- the nodes that are reachable by a time respecting path followed out from a set of seed nodes at a starting time.
triplet_countComputes the number of connected triplets within a graph
weakly_connected_componentsWeakly connected components -- partitions the graph into node sets which are mutually reachable by an undirected path

Function Details

all_local_reciprocity

Signature: all_local_reciprocity(graph)

Local reciprocity - measure of the symmetry of relationships associated with a node

This measures the proportion of a node's outgoing edges which are reciprocated with an incoming edge.

Parameters

NameTypeDefaultDescription
graphGraphView-a directed Raphtory graph

Returns

TypeDescription
NodeStateF64Mapping of nodes to their reciprocity value.

average_degree

Signature: average_degree(graph)

The average (undirected) degree of all nodes in the graph.

Note that this treats the graph as simple and undirected and is equal to twice the number of undirected edges divided by the number of nodes.

Parameters

NameTypeDefaultDescription
graphGraphView-a Raphtory graph

Returns

TypeDescription
floatthe average degree of the nodes in the graph

balance

Signature: balance(graph, name='weight', direction='both')

Sums the weights of edges in the graph based on the specified direction.

This function computes the sum of edge weights based on the direction provided, and can be executed in parallel using a given number of threads.

Parameters

NameTypeDefaultDescription
directionDirection, optional'both'Specifies the direction of the edges to be considered for summation. Defaults to "both". * "out": Only consider outgoing edges. * "in": Only consider incoming edges. * "both": Consider both outgoing and incoming edges. This is the default.
graphGraphView-The graph view on which the operation is to be performed.
namestr, optional'weight'The name of the edge property used as the weight. Defaults to "weight".

Returns

TypeDescription
NodeStateF64Mapping of nodes to the computed sum of their associated edge weights.

betweenness_centrality

Signature: betweenness_centrality(graph, k=None, normalized=True)

Computes the betweenness centrality for nodes in a given graph.

Parameters

NameTypeDefaultDescription
graphGraphView-A reference to the graph.
kint, optionalNoneSpecifies the number of nodes to consider for the centrality computation. All nodes are considered by default.
normalizedbool, optionalTrueIndicates whether to normalize the centrality values. Defaults to True.

Returns

TypeDescription
NodeStateF64Mapping from nodes to their betweenness centrality.

cohesive_fruchterman_reingold

Signature: cohesive_fruchterman_reingold(graph, iter_count=100, scale=1.0, node_start_size=1.0, cooloff_factor=0.95, dt=0.1)

Cohesive version of fruchterman_reingold that adds virtual edges between isolated nodes

Parameters

NameTypeDefaultDescription
cooloff_factorfloat, optional0.95Factor to reduce node movement in later iterations, helping stabilize the layout. Defaults to 0.95.
dtfloat, optional0.1Time step or movement factor in each iteration. Defaults to 0.1.
graphGraphView-A reference to the graph
iter_countint, optional100The number of iterations to run. Defaults to 100.
node_start_sizefloat, optional1.0Initial size or movement range for nodes. Defaults to 1.0.
scalefloat, optional1.0Global scaling factor to control the overall spread of the graph. Defaults to 1.0.

Returns

TypeDescription
NodeLayoutA mapping from nodes to their [x, y] positions

degree_centrality

Signature: degree_centrality(graph)

Computes the degree centrality of all nodes in the graph. The values are normalized by dividing each result with the maximum possible degree. Graphs with self-loops can have values of centrality greater than 1.

Parameters

NameTypeDefaultDescription
graphGraphView-The graph view on which the operation is to be performed.

Returns

TypeDescription
NodeStateF64Mapping of nodes to their associated degree centrality.

dijkstra_single_source_shortest_paths

Signature: dijkstra_single_source_shortest_paths(graph, source, targets, direction='both', weight='weight')

Finds the shortest paths from a single source to multiple targets in a graph.

Parameters

NameTypeDefaultDescription
directionDirection, optional'both'The direction of the edges to be considered for the shortest path. Defaults to "both".
graphGraphView-The graph to search in.
sourceNodeInput-The source node.
targetslist[NodeInput]-A list of target nodes.
weightstr, optional'weight'The name of the weight property for the edges. Defaults to "weight".

Returns

TypeDescription
NodeStateWeightedSPMapping from nodes to a tuple containing the total cost and the nodes representing the shortest path.

directed_graph_density

Signature: directed_graph_density(graph)

Graph density - measures how dense or sparse a graph is.

The ratio of the number of directed edges in the graph to the total number of possible directed edges (given by N * (N-1) where N is the number of nodes).

Parameters

NameTypeDefaultDescription
graphGraphView-a directed Raphtory graph

Returns

TypeDescription
floatDirected graph density of graph.

fast_rp

Signature: fast_rp(graph, embedding_dim, normalization_strength, iter_weights, seed=None, threads=None)

Computes embedding vectors for each vertex of an undirected/bidirectional graph according to the Fast RP algorithm. Original Paper: https://doi.org/10.48550/arXiv.1908.11512

Parameters

NameTypeDefaultDescription
embedding_dimint-The size (dimension) of the generated embeddings.
graphGraphView-The graph view on which embeddings are generated.
iter_weightslist[float]-The scalar weights to apply to the results of each iteration
normalization_strengthfloat-The extent to which high-degree vertices should be discounted (range: 1-0)
seedint, optionalNoneThe seed for initialisation of random vectors
threadsint, optionalNoneThe number of threads to be used for parallel execution.

Returns

TypeDescription
NodeStateListF64Mapping from nodes to embedding vectors.

fruchterman_reingold

Signature: fruchterman_reingold(graph, iterations=100, scale=1.0, node_start_size=1.0, cooloff_factor=0.95, dt=0.1)

Fruchterman Reingold layout algorithm

Parameters

NameTypeDefaultDescription
cooloff_factorfloat | None, optional0.95the cool off factor for the algorithm. Defaults to 0.95.
dtfloat | None, optional0.1the time increment between iterations. Defaults to 0.1.
graphGraphView-the graph view
iterationsint | None, optional100the number of iterations to run. Defaults to 100.
node_start_sizefloat | None, optional1.0the start node size to assign random positions. Defaults to 1.0.
scalefloat | None, optional1.0the scale to apply. Defaults to 1.0.

Returns

TypeDescription
NodeLayoutA mapping from nodes to their [x, y] positions

global_clustering_coefficient

Signature: global_clustering_coefficient(graph)

Computes the global clustering coefficient of a graph. The global clustering coefficient is defined as the number of triangles in the graph divided by the number of triplets in the graph.

Note that this is also known as transitivity and is different to the average clustering coefficient.

Parameters

NameTypeDefaultDescription
graphGraphView-a Raphtory graph, treated as undirected

Returns

TypeDescription
floatthe global clustering coefficient of the graph

global_reciprocity

Signature: global_reciprocity(graph)

Reciprocity - measure of the symmetry of relationships in a graph, the global reciprocity of the entire graph. This calculates the number of reciprocal connections (edges that go in both directions) in a graph and normalizes it by the total number of directed edges.

Parameters

NameTypeDefaultDescription
graphGraphView-a directed Raphtory graph

Returns

TypeDescription
floatreciprocity of the graph between 0 and 1.

global_temporal_three_node_motif

Signature: global_temporal_three_node_motif(graph, delta, threads=None)

Computes the number of three edge, up-to-three node delta-temporal motifs in the graph, using the algorithm of Paranjape et al, Motifs in Temporal Networks (2017). We point the reader to this reference for more information on the algorithm and background, but provide a short summary below.

Motifs included:

Stars

There are three classes (in the order they are outputted) of star motif on three nodes based on the switching behaviour of the edges between the two leaf nodes.

  • PRE: Stars of the form i↔j, i↔j, i↔k (ie two interactions with leaf j followed by one with leaf k)
  • MID: Stars of the form i↔j, i↔k, i↔j (ie switching interactions from leaf j to leaf k, back to j again)
  • POST: Stars of the form i↔j, i↔k, i↔k (ie one interaction with leaf j followed by two with leaf k)

Within each of these classes is 8 motifs depending on the direction of the first to the last edge -- incoming "I" or outgoing "O". These are enumerated in the order III, IIO, IOI, IOO, OII, OIO, OOI, OOO (like binary with "I"-0 and "O"-1).

Two node motifs:

Also included are two node motifs, of which there are 8 when counted from the perspective of each node. These are characterised by the direction of each edge, enumerated in the above order. Note that for the global graph counts, each motif is counted in both directions (a single III motif for one node is an OOO motif for the other node).

Triangles:

There are 8 triangle motifs:

  1. i → j, k → j, i → k
  2. i → j, k → j, k → i
  3. i → j, j → k, i → k
  4. i → j, j → k, k → i
  5. i → j, k → i, j → k
  6. i → j, k → i, k → j
  7. i → j, i → k, j → k
  8. i → j, i → k, k → j

Parameters

NameTypeDefaultDescription
deltaint-Maximum time difference between the first and last edge of the motif. NB if time for edges was given as a UNIX epoch, this should be given in seconds, otherwise milliseconds should be used (if edge times were given as string)
graphGraphView-A directed raphtory graph
threadsint, optionalNoneThe number of threads to use when running the algorithm.

Returns

TypeDescription
list[int]A 40 dimensional array with the counts of each motif, given in the same order as described above. Note that the two-node motif counts are symmetrical so it may be more useful just to consider the first four elements.

global_temporal_three_node_motif_multi

Signature: global_temporal_three_node_motif_multi(graph, deltas, threads=None)

Computes the global counts of three-edge up-to-three node temporal motifs for a range of timescales. See global_temporal_three_node_motif for an interpretation of each row returned.

Parameters

NameTypeDefaultDescription
deltaslist[int]-A list of delta values to use.
graphGraphView-A directed raphtory graph
threadsint, optionalNoneThe number of threads to use.

Returns

TypeDescription
list[list[int]]A list of 40d arrays, each array is the motif count for a particular value of delta, returned in the order that the deltas were given as input.

hits

Signature: hits(graph, iter_count=20, threads=None)

HITS (Hubs and Authority) Algorithm:

AuthScore of a node (A) = Sum of HubScore of all nodes pointing at node (A) from previous iteration / Sum of HubScore of all nodes in the current iteration

HubScore of a node (A) = Sum of AuthScore of all nodes pointing away from node (A) from previous iteration / Sum of AuthScore of all nodes in the current iteration

Parameters

NameTypeDefaultDescription
graphGraphView-Graph to run the algorithm on
iter_countint, optional20How many iterations to run the algorithm. Defaults to 20.
threadsint, optionalNoneNumber of threads to use

Returns

TypeDescription
NodeStateHitsA mapping from nodes their hub and authority scores

in_component

Signature: in_component(node, filter=None)

In component -- Finding the "in-component" of a node in a directed graph involves identifying all nodes that can be reached following only incoming edges.

Parameters

NameTypeDefaultDescription
filterfilter.FilterExpr, optionalNoneOptional filter
nodeNode-The node whose in-component we wish to calculate

Returns

TypeDescription
NodeStateUsizeMapping of nodes in the in-component to the distance from the starting node.

in_components

Signature: in_components(graph, filter=None)

In components -- Finding the "in-component" of a node in a directed graph involves identifying all nodes that can be reached following only incoming edges.

Parameters

NameTypeDefaultDescription
filterfilter.FilterExpr, optionalNoneOptional filter
graphGraphView-Raphtory graph

Returns

TypeDescription
NodeStateNodesMapping of nodes to the nodes in their 'in-component'

k_core

Signature: k_core(graph, k, iter_count, threads=None)

Determines which nodes are in the k-core for a given value of k

Parameters

NameTypeDefaultDescription
graphGraphView-A reference to the graph
iter_countint-The number of iterations to run
kint-Value of k such that the returned nodes have degree > k (recursively)
threadsint, optionalNonenumber of threads to run on

Returns

TypeDescription
list[Node]A list of nodes in the k core

label_propagation

Signature: label_propagation(graph, seed=None)

Computes components using a label propagation algorithm

Parameters

NameTypeDefaultDescription
graphGraphView-A reference to the graph
seedbytes, optionalNoneArray of 32 bytes of u8 which is set as the rng seed

Returns

TypeDescription
list[set]A list of sets each containing nodes that have been grouped

local_clustering_coefficient

Signature: local_clustering_coefficient(graph, v)

Local clustering coefficient - measures the degree to which nodes in a graph tend to cluster together.

The proportion of pairs of neighbours of a node who are themselves connected.

Parameters

NameTypeDefaultDescription
graphGraphView-Raphtory graph, can be directed or undirected but will be treated as undirected.
vNodeInput-node id or name

Returns

TypeDescription
floatthe local clustering coefficient of node v in graph.

local_clustering_coefficient_batch

Signature: local_clustering_coefficient_batch(graph, v)

Returns the Local clustering coefficient (batch, intersection) for each specified node in a graph. This measures the degree to which one or multiple nodes in a graph tend to cluster together.

Uses path-counting for its triangle-counting step.

Parameters

NameTypeDefaultDescription
graphAny-
vAny-

Returns

TypeDescription
dict

local_temporal_three_node_motifs

Signature: local_temporal_three_node_motifs(graph, delta, threads=None)

Computes the number of each type of motif that each node participates in. See global_temporal_three_node_motifs for a summary of the motifs involved.

Parameters

NameTypeDefaultDescription
deltaint-Maximum time difference between the first and last edge of the motif. NB if time for edges was given as a UNIX epoch, this should be given in seconds, otherwise milliseconds should be used (if edge times were given as string)
graphGraphView-A directed raphtory graph
threadsoptionalNone

Returns

TypeDescription
NodeStateMotifsA mapping from nodes to lists of motif counts (40 counts in the same order as the global motif counts) with the number of each motif that node participates in.

local_triangle_count

Signature: local_triangle_count(graph, v)

Implementations of various graph algorithms that can be run on a graph.

To run an algorithm simply import the module and call the function with the graph as the argument

Local triangle count - calculates the number of triangles (a cycle of length 3) a node participates in.

This function returns the number of pairs of neighbours of a given node which are themselves connected.

Parameters

NameTypeDefaultDescription
graphGraphView-Raphtory graph, this can be directed or undirected but will be treated as undirected
vNodeInput-node id or name

Returns

TypeDescription
intnumber of triangles associated with node v

louvain

Signature: louvain(graph, resolution=1.0, weight_prop=None, tol=None)

Louvain algorithm for community detection

Parameters

NameTypeDefaultDescription
graphGraphView-the graph view
resolutionfloat, optional1.0the resolution parameter for modularity. Defaults to 1.0.
tolNone | float, optionalNonethe floating point tolerance for deciding if improvements are significant (default: 1e-8)
weight_propstr | None, optionalNonethe edge property to use for weights (has to be float)

Returns

TypeDescription
NodeStateUsizeMapping of nodes to their community assignment

max_degree

Signature: max_degree(graph)

Returns the largest degree found in the graph

Parameters

NameTypeDefaultDescription
graphGraphView-The graph view on which the operation is to be performed.

Returns

TypeDescription
intThe largest degree

max_in_degree

Signature: max_in_degree(graph)

The maximum in degree of any node in the graph.

Parameters

NameTypeDefaultDescription
graphGraphView-a directed Raphtory graph

Returns

TypeDescription
intvalue of the largest indegree

max_out_degree

Signature: max_out_degree(graph)

The maximum out degree of any node in the graph.

Parameters

NameTypeDefaultDescription
graphGraphView-a directed Raphtory graph

Returns

TypeDescription
intvalue of the largest outdegree

max_weight_matching

Signature: max_weight_matching(graph, weight_prop=None, max_cardinality=True, verify_optimum_flag=False)

Compute a maximum-weighted matching in the general undirected weighted graph given by "edges". If max_cardinality is true, only maximum-cardinality matchings are considered as solutions.

The algorithm is based on "Efficient Algorithms for Finding Maximum Matching in Graphs" by Zvi Galil, ACM Computing Surveys, 1986.

Based on networkx implementation https://github.com/networkx/networkx/blob/3351206a3ce5b3a39bb2fc451e93ef545b96c95b/networkx/algorithms/matching.py

With reference to the standalone protoype implementation from: http://jorisvr.nl/article/maximum-matching

http://jorisvr.nl/files/graphmatching/20130407/mwmatching.py

The function takes time O(n**3)

Parameters

NameTypeDefaultDescription
graphGraphView-The graph to compute the maximum weight matching for
max_cardinalitybool, optionalTrueIf set to True, consider only maximum-cardinality matchings. Defaults to True. If True, finds the maximum-cardinality matching with maximum weight among all maximum-cardinality matchings, otherwise, finds the maximum weight matching irrespective of cardinality.
verify_optimum_flagbool, optionalFalseWhether the optimum should be verified. Defaults to False. If true prior to returning, an additional routine to verify the optimal solution was found will be run after computing the maximum weight matching. If it's true and the found matching is not an optimal solution this function will panic. This option should normally be only set true during testing.
weight_propstr, optionalNoneThe property on the edge to use for the weight. If not provided,

Returns

TypeDescription
MatchingThe matching

min_degree

Signature: min_degree(graph)

Returns the smallest degree found in the graph

Parameters

NameTypeDefaultDescription
graphGraphView-The graph view on which the operation is to be performed.

Returns

TypeDescription
intThe smallest degree found

min_in_degree

Signature: min_in_degree(graph)

The minimum in degree of any node in the graph.

Parameters

NameTypeDefaultDescription
graphGraphView-a directed Raphtory graph

Returns

TypeDescription
intvalue of the smallest indegree

min_out_degree

Signature: min_out_degree(graph)

The minimum out degree of any node in the graph.

Parameters

NameTypeDefaultDescription
graphGraphView-a directed Raphtory graph

Returns

TypeDescription
intvalue of the smallest outdegree

out_component

Signature: out_component(node, filter=None)

Out component -- Finding the "out-component" of a node in a directed graph involves identifying all nodes that can be reached following only outgoing edges.

Parameters

NameTypeDefaultDescription
filterfilter.FilterExpr, optionalNoneOptional filter
nodeNode-The node whose out-component we wish to calculate

Returns

TypeDescription
NodeStateUsizeA NodeState mapping the nodes in the out-component to their distance from the starting node.

out_components

Signature: out_components(graph, filter=None)

Out components -- Finding the "out-component" of a node in a directed graph involves identifying all nodes that can be reached following only outgoing edges.

Parameters

NameTypeDefaultDescription
filterfilter.FilterExpr, optionalNoneOptional filter
graphGraphView-Raphtory graph

Returns

TypeDescription
NodeStateNodesMapping of nodes to the nodes within their 'out-component'

pagerank

Signature: pagerank(graph, iter_count=20, max_diff=None, use_l2_norm=True, damping_factor=0.85)

Pagerank -- pagerank centrality value of the nodes in a graph

This function calculates the Pagerank value of each node in a graph. See https://en.wikipedia.org/wiki/PageRank for more information on PageRank centrality. A default damping factor of 0.85 is used. This is an iterative algorithm which terminates if the sum of the absolute difference in pagerank values between iterations is less than the max diff value given.

Parameters

NameTypeDefaultDescription
damping_factorfloat, optional0.85The damping factor for the PageRank calculation. Defaults to 0.85.
graphGraphView-Raphtory graph
iter_countint, optional20Maximum number of iterations to run. Note that this will terminate early if convergence is reached. Defaults to 20.
max_difffloat, optionalNoneOptional parameter providing an alternative stopping condition. The algorithm will terminate if the sum of the absolute difference in pagerank values between iterations is less than the max diff value given.
use_l2_normbool, optionalTrueFlag for choosing the norm to use for convergence checks, True for l2 norm, False for l1 norm. Defaults to True.

Returns

TypeDescription
NodeStateF64Mapping of nodes to their pagerank value.

single_source_shortest_path

Signature: single_source_shortest_path(graph, source, cutoff=None)

Calculates the single source shortest paths from a given source node.

Parameters

NameTypeDefaultDescription
cutoffint, optionalNoneAn optional cutoff level. The algorithm will stop if this level is reached.
graphGraphView-A reference to the graph. Must implement GraphViewOps.
sourceNodeInput-The source node.

Returns

TypeDescription
NodeStateNodesMapping from end node to shortest path from the source node.

strongly_connected_components

Signature: strongly_connected_components(graph)

Strongly connected components

Partitions the graph into node sets which are mutually reachable by an directed path

Parameters

NameTypeDefaultDescription
graphGraphView-Raphtory graph

Returns

TypeDescription
NodeStateUsizeMapping of nodes to their component ids

temporal_SEIR

Signature: temporal_SEIR(graph, seeds, infection_prob, initial_infection, recovery_rate=None, incubation_rate=None, rng_seed=None)

Simulate an SEIR dynamic on the network

The algorithm uses the event-based sampling strategy from https://doi.org/10.1371/journal.pone.0246961

Parameters

NameTypeDefaultDescription
graphGraphView-the graph view
incubation_ratefloat | None, optionalNoneoptional incubation rate (if None, simulates SI or SIR dynamics where infected nodes are infectious at the next time step) the actual incubation time is sampled from an exponential distribution with this rate
infection_probfloat-the probability for a contact between infected and susceptible nodes to lead to a transmission
initial_infectionint | str | datetime-the time of the initial infection
recovery_ratefloat | None, optionalNoneoptional recovery rate (if None, simulates SEI dynamic where nodes never recover) the actual recovery time is sampled from an exponential distribution with this rate
rng_seedint | None, optionalNoneoptional seed for the random number generator
seedsint | float | list[NodeInput]-the seeding strategy to use for the initial infection (if int, choose fixed number of nodes at random, if float infect each node with this probability, if list initially infect the specified nodes

Returns

TypeDescription
NodeStateSEIRMapping from nodes to Infected objects for each infected node with attributes infected: the time stamp of the infection event active: the time stamp at which the node actively starts spreading the infection (i.e., the end of the incubation period) recovered: the time stamp at which the node recovered (i.e., stopped spreading the infection)

temporal_bipartite_graph_projection

Signature: temporal_bipartite_graph_projection(graph, delta, pivot_type)

Projects a temporal bipartite graph into an undirected temporal graph over the pivot node type. Let G be a bipartite graph with node types A and B. Given delta > 0, the projection graph G' pivoting over type B nodes, will make a connection between nodes n1 and n2 (of type A) at time (t1 + t2)/2 if they respectively have an edge at time t1, t2 with the same node of type B in G, and |t2-t1| < delta.

Parameters

NameTypeDefaultDescription
deltaint-Time period
graphGraphView-A directed raphtory graph
pivot_typestr-node type to pivot over. If a bipartite graph has types A and B, and B is the pivot type, the new graph will consist of type A nodes.

Returns

TypeDescription
GraphProjected (unipartite) temporal graph.

temporally_reachable_nodes

Signature: temporally_reachable_nodes(graph, max_hops, start_time, seed_nodes, stop_nodes=None)

Temporally reachable nodes -- the nodes that are reachable by a time respecting path followed out from a set of seed nodes at a starting time.

This function starts at a set of seed nodes and follows all time respecting paths until either a) a maximum number of hops is reached, b) one of a set of stop nodes is reached, or c) no further time respecting edges exist. A time respecting path is a sequence of nodes v_1, v_2, ... , v_k such that there exists a sequence of edges (v_i, v_i+1, t_i) with t_i < t_i+1 for i = 1, ... , k - 1.

Parameters

NameTypeDefaultDescription
graphGraphView-directed Raphtory graph
max_hopsint-maximum number of hops to propagate out
seed_nodeslist[NodeInput]-list of node names or ids which should be the starting nodes
start_timeint-time at which to start the path (such that t_1 > start_time for any path starting from these seed nodes)
stop_nodeslist[NodeInput], optionalNonenodes at which a path shouldn't go any further

Returns

TypeDescription
NodeStateReachabilityMapping of nodes to their reachability history.

triplet_count

Signature: triplet_count(graph)

Computes the number of connected triplets within a graph

A connected triplet (also known as a wedge, 2-hop path) is a pair of edges with one node in common. For example, the triangle made up of edges A-B, B-C, C-A is formed of three connected triplets.

Parameters

NameTypeDefaultDescription
graphGraphView-a Raphtory graph, treated as undirected

Returns

TypeDescription
intthe number of triplets in the graph

weakly_connected_components

Signature: weakly_connected_components(graph)

Weakly connected components -- partitions the graph into node sets which are mutually reachable by an undirected path

This function assigns a component id to each node such that nodes with the same component id are mutually reachable by an undirected path.

Parameters

NameTypeDefaultDescription
graphGraphView-Raphtory graph

Returns

TypeDescription
NodeStateUsizeMapping of nodes to their component ids.