Centrality API Reference

This page documents the temporal centrality functions in TSNA.jl.

Vertex Centrality

Centrality measures computed on network snapshots at specific time points.

TSNA.t_degree — Function
t_degree(dnet::DynamicNetwork, at; mode=:total, active_only=true, missing=:error, kwargs...)
    -> Vector{Float64}

Degree of each actor at time at (SNA.degreecent, R's sna::degree: mode=:total is sna's cmode = "freeman", :in/:out its "indegree"/"outdegree"), computed on the network of the vertices active at at (as tsna's tSnaStats(nd, "degree") does) and indexed by the dynamic network's vertex IDs: an actor absent at at gets NaN, and normalized=true divides by the number of active actors. With active_only=false the whole vertex universe is used (absent actors as isolates scoring 0). Further keywords go to SNA.degreecent: rescale, normalized, diag, ignore_eval, attr.

Example

using TSNA, DynamicNetworks
dnet = DynamicNetwork(4; observation_start=0.0, observation_end=10.0)
activate!(dnet, 0.0, 10.0; edge=(1, 2))
activate!(dnet, 0.0, 10.0; edge=(2, 3))
activate!(dnet, 6.0, 10.0; vertex=4)       # actor 4 joins at t = 6
t_degree(dnet, 2.0)                 # [1.0, 2.0, 1.0, NaN]
source
TSNA.t_betweenness — Function
t_betweenness(dnet::DynamicNetwork, at; normalized=false, active_only=true,
              missing=:error, kwargs...) -> Vector{Float64}

Betweenness of each actor at time at (SNA.betweenness, raw scores by default as in sna), computed on the active network and scattered back with NaN for absent actors (see t_degree). Further keywords go to SNA.betweenness: cmode (:directed/:undirected) and rescale.

Example

using TSNA, DynamicNetworks
dnet = DynamicNetwork(4; directed=false, observation_start=0.0, observation_end=10.0)
activate!(dnet, 0.0, 10.0; edge=(1, 2))
activate!(dnet, 0.0, 10.0; edge=(2, 3))
activate!(dnet, 6.0, 10.0; vertex=4)
t_betweenness(dnet, 2.0)            # [0.0, 1.0, 0.0, NaN]
source
TSNA.t_closeness — Function
t_closeness(dnet::DynamicNetwork, at; active_only=true, missing=:error, kwargs...)
    -> Vector{Float64}

Closeness of each actor at time at (SNA.closeness, R's sna::closeness: (n−1)/Σd, and 0 for an actor that cannot reach every other active actor), computed on the active network and scattered back with NaN for absent actors. Absent actors used to enter as isolates and zero every score. Further keywords go to SNA.closeness: cmode (:directed, :undirected, :suminvdir, :suminvundir) and rescale.

Example

using TSNA, DynamicNetworks
dnet = DynamicNetwork(4; directed=false, observation_start=0.0, observation_end=10.0)
activate!(dnet, 0.0, 10.0; edge=(1, 2))
activate!(dnet, 0.0, 10.0; edge=(2, 3))
activate!(dnet, 6.0, 10.0; vertex=4)
round.(t_closeness(dnet, 2.0); digits=3)   # [0.667, 1.0, 0.667, NaN]
source
TSNA.t_eigenvector — Function
t_eigenvector(dnet::DynamicNetwork, at; active_only=true, missing=:error, kwargs...)
    -> Vector{Float64}

Eigenvector centrality of each actor at time at (SNA.evcent), computed on the active network and scattered back with NaN for absent actors. Further keywords go to SNA.evcent: rescale, tol, ignore_eval, attr, diag.

Example

using TSNA, DynamicNetworks
dnet = DynamicNetwork(3; directed=false, observation_start=0.0, observation_end=10.0)
activate!(dnet, 0.0, 10.0; edge=(1, 2))
activate!(dnet, 0.0, 10.0; edge=(2, 3))
ev = t_eigenvector(dnet, 2.0)
ev[2] > ev[1]                       # true: the broker is most central
source
TSNA.t_pagerank — Function
t_pagerank(dnet::DynamicNetwork, at; damping=0.85, active_only=true, missing=:error)
    -> Vector{Float64}

PageRank of each actor at time at (Graphs.jl's pagerank; not an sna measure), computed on the active network (absent actors receive no teleport mass) and scattered back with NaN for them.

Example

using TSNA, DynamicNetworks
dnet = DynamicNetwork(4; observation_start=0.0, observation_end=10.0)
activate!(dnet, 0.0, 10.0; edge=(1, 2))
activate!(dnet, 0.0, 10.0; edge=(3, 2))
activate!(dnet, 6.0, 10.0; vertex=4)
pr = t_pagerank(dnet, 2.0)
isnan(pr[4]), sum(pr[1:3]) ≈ 1      # (true, true)
source

Network-Level Measures

Global network statistics computed at specific time points.

TSNA.t_density — Function
t_density(dnet::DynamicNetwork, at; active_only=true, missing=:error, diag=false) -> Float64

Density at time at (SNA.gden, R's sna::gden), over the active vertices by default. Pass active_only=false to use the complete vertex universe. The missing-data policy is checked on the original network before inactive vertices are removed.

Example

using TSNA, DynamicNetworks
dnet = DynamicNetwork(4; observation_start=0.0, observation_end=10.0)
activate!(dnet, 0.0, 10.0; edge=(1, 2))
activate!(dnet, 6.0, 10.0; vertex=4)
t_density(dnet, 2.0)                # 1/6: three active actors
source
TSNA.t_reciprocity — Function
t_reciprocity(dnet::DynamicNetwork, at; method=:dyadic, active_only=true, missing=:error)
    -> Float64

Dyadic reciprocity at time at (SNA.grecip, R's grecip(measure = "dyadic")), over the active vertices by default. Pass method=:edgewise for the fraction of edges that are reciprocated.

Example

using TSNA, DynamicNetworks
dnet = DynamicNetwork(3; observation_start=0.0, observation_end=10.0)
activate!(dnet, 0.0, 10.0; edge=(1, 2))
activate!(dnet, 0.0, 10.0; edge=(2, 1))
activate!(dnet, 0.0, 10.0; edge=(2, 3))
t_reciprocity(dnet, 5.0; method=:edgewise)   # 2/3
source
TSNA.t_transitivity — Function
t_transitivity(dnet::DynamicNetwork, at; measure=:weak, type=:global, cmode=:total,
               active_only=true, missing=:error) -> Float64

Transitivity at time at, over the active vertices by default.

  • type=:global (default): SNA.gtrans (R's sna::gtrans) with its measure — :weak (default: the share of two-paths that are closed), :strong, or the counts :weakcensus/:strongcensus.
  • type=:average: the mean local clustering coefficient, SNA.transitivity(net; type=:average, cmode) (cmode=:total is Fagiolo's directed coefficient, :weak the coefficient of the symmetrised graph).

The per-vertex type=:local is not a scalar and is refused; take SNA.transitivity(network_extract(dnet, at); type=:local) instead.

Example

using TSNA, DynamicNetworks
dnet = DynamicNetwork(4; directed=false, observation_start=0.0, observation_end=10.0)
activate_edges!(dnet, [(1, 2), (2, 3), (1, 3), (3, 4)], 0.0, 10.0)
t_transitivity(dnet, 5.0)                    # 0.6: 6 of 10 two-paths closed
t_transitivity(dnet, 5.0; type=:average)     # (1 + 1 + 1/3) / 3 ≈ 0.778
source

Time Series

Functions for computing statistics at multiple time points or in sliding windows.

TSNA.t_sna_stats — Function
t_sna_stats(dnet::DynamicNetwork, times; measures=[:density, :reciprocity,
            :transitivity, :mean_degree], active_only=true, missing=:error,
            reciprocity_method=:dyadic) -> Vector{NamedTuple}

Network-level statistics of the snapshot at each time point (one row per time, fields time and the requested measures, in alphabetical order). Each snapshot is extracted once, over the active vertices by default, and reused for all measures; :mean_degree counts each edge appropriately for the network's directedness and :n_edges is the edge count. This is not tsna's tSnaStats (which applies one sna function over a regular time grid); see the R concordance in the documentation.

Example

using TSNA, DynamicNetworks
dnet = DynamicNetwork(3; observation_start=0.0, observation_end=10.0)
activate!(dnet, 0.0, 10.0; edge=(1, 2))
activate!(dnet, 5.0, 10.0; edge=(2, 3))
rows = t_sna_stats(dnet, [1.0, 6.0]; measures=[:n_edges, :density])
[r.n_edges for r in rows]           # [1.0, 2.0]
source
TSNA.window_sna_stats — Function
window_sna_stats(dnet::DynamicNetwork, window_size; kwargs...) -> Vector{NamedTuple}

t_sna_stats sampled at the start of each window of length window_size across the observation period; without a window, at every window_size step of the closed range [first, last] of the change times (tsna::tSnaStats's default seq(start, end)).

Example

using TSNA, DynamicNetworks
dnet = DynamicNetwork(3; observation_start=0.0, observation_end=20.0)
activate!(dnet, 0.0, 20.0; edge=(1, 2))
activate!(dnet, 10.0, 20.0; edge=(2, 3))
[r.n_edges for r in window_sna_stats(dnet, 10.0; measures=[:n_edges])]   # [1.0, 2.0]
source