Types API Reference

This page documents the core data types in DynamicNetworks.jl.

Dynamic Network

DynamicNetwork

DynamicNetworks.DynamicNetwork — Type
DynamicNetwork{T, Time, D}

A network whose vertices and edges are active during spells of time.

Type Parameters

  • T: Vertex ID type
  • Time: Time type (Float64, Int, DateTime, Date, ...)
  • D::Bool: directedness, as in Network{T,D} (so the wrapped network is concretely typed)

Constructors

DynamicNetwork(n=0; directed=true, observation_start=nothing, observation_end=nothing)
DynamicNetwork{T,Time}(n=0; directed=true, observation_start=nothing, observation_end=nothing)
DynamicNetwork(networks::AbstractVector{<:Network}; onsets, termini, start)

The last builds a dynamic network from a panel of static networks, as R's networkDynamic(network.list = ...) does; see as_dynamic_network (its panel method).

Activity semantics (R networkDynamic)

  • Spells are half-open [onset, terminus); a point spell [t,t) is active exactly at t.
  • An element with no spell record is active (R's active.default = TRUE). Every query and extraction takes active_default=true; pass active_default=false to treat such elements as inactive. An element whose spells were all removed (by deactivate! or remove_spell!) has an empty record and is inactive.
  • activate! and add_spell! merge overlapping and adjacent spells on insertion, as R's activate.* do.
  • The observation window is the one given at construction or by set_observation_period!; when none was given, get_observation_period returns nothing (see there for what TSNA.jl and NDTV.jl do then). A window has two ends, as R's net.obs.period does: give both observation_start and observation_end, or neither. Giving only one raises an ArgumentError rather than inventing the other end; for an open-ended window pass the axis extreme explicitly (Inf, or the bounds of DynamicNetworks.unbounded_spell on axes without infinities).

Fields

  • network::Network{T,D}: Base network structure (maximum set of vertices/edges)
  • vertex_spells::Dict{T, Vector{Spell{Time}}}: Activity periods for vertices
  • edge_spells::Dict{Tuple{T,T}, Vector{Spell{Time}}}: Activity periods for edges
  • vertex_tea, edge_tea: Time-varying vertex and edge attributes
  • observation_period::Tuple{Time, Time}: the stored observation window; meaningless when observation_period_set is false (read the window with get_observation_period, which returns nothing then)
  • observation_period_set::Bool: whether a window was given explicitly
  • mutation_count::Int: Bumped on every spell/observation-window mutation (lets downstream packages memoize derived indexes safely)

Example

using DynamicNetworks
dnet = DynamicNetwork(3; observation_start=0.0, observation_end=10.0)
activate!(dnet, 0.0, 5.0; edge=(1, 2))
is_active(dnet, 2.0; vertex=3)    # true: no vertex spells, active by default
is_active(dnet, 6.0; edge=(1, 2)) # false
source

Spell Types

Spell

DynamicNetworks.Spell — Type
Spell{T}

An activity spell: the half-open time interval [onset, terminus) during which a vertex or edge is active. A point spell [t, t) (onset == terminus) is an instantaneous event, active exactly at t (R networkDynamic's convention).

Fields

  • onset::T: Start time (inclusive)
  • terminus::T: End time (exclusive)
  • onset_censored::Bool: True if the spell may have started earlier
  • terminus_censored::Bool: True if the spell may continue beyond terminus

Equality and hashing look at onset and terminus only.

Example

using DynamicNetworks
s = Spell(0.0, 5.0)
p = Spell(3.0, 3.0)                          # instantaneous event at t = 3
c = Spell(0.0, 5.0; onset_censored=true)     # began before observation
spell_duration(s)                            # 5.0
c == s                                       # true: flags are not compared
source

TimeVaryingAttribute

DynamicNetworks.TimeVaryingAttribute — Type
TimeVaryingAttribute{Time, V}

An attribute that changes over time (a TEA, after networkDynamic's "temporally extended attribute"): parallel vectors of values and of the spells during which each value holds. Created by set_vertex_attribute_active! / set_edge_attribute_active!; read with get_vertex_attribute_active / get_edge_attribute_active.

Example

using DynamicNetworks
dnet = DynamicNetwork(2; observation_start=0.0, observation_end=10.0)
set_vertex_attribute_active!(dnet, 1, :status, "S", 0.0, 4.0)
tea = dnet.vertex_tea[(1, :status)]
tea isa TimeVaryingAttribute       # true
tea.values, tea.spells             # (["S"], [Spell[0.0, 4.0)])
source

Spell Utilities

spell_overlap

DynamicNetworks.spell_overlap — Function
spell_overlap(s1::Spell, s2::Spell) -> Bool

Check if two spells overlap. Half-open interval semantics: touching spells [0,10) and [10,20) do not overlap. Point (zero-duration) spells [t,t) are instantaneous events: they overlap an interval containing t and another point spell only at the identical time.

Example

using DynamicNetworks
spell_overlap(Spell(0.0, 10.0), Spell(5.0, 15.0))    # true
spell_overlap(Spell(0.0, 10.0), Spell(10.0, 20.0))   # false: half-open
spell_overlap(Spell(3.0, 3.0), Spell(0.0, 10.0))     # true: point inside
source

spell_duration

DynamicNetworks.spell_duration — Function
spell_duration(s::Spell) -> duration

The length terminus - onset of a spell: zero for a point spell, a Period on a DateTime/Date axis.

A spell with an unbounded side — onset -Inf or terminus Inf, or, on axes without infinities, the extreme value that stands for them (typemin/typemax; see DynamicNetworks.unbounded_spell) — has unbounded duration, and no subtraction is done (subtracting the integer or calendar extremes would overflow and wrap around):

Time axisDuration of an unbounded spell
floating pointInf
other Real (integers, rationals)typemax(Time)
DateTimeMillisecond(typemax(Int64))
DateDay(typemax(Int64))
anything elseArgumentError

An element with no spell record is active over the unbounded spell (get_edge_activity), so its duration is unbounded too.

Example

using DynamicNetworks
spell_duration(Spell(2.0, 7.5))      # 5.5
spell_duration(Spell(3.0, 3.0))      # 0.0
spell_duration(Spell(2.0, Inf))      # Inf
spell_duration(Spell(typemin(Int), 5))   # typemax(Int): unbounded, no overflow
source

Unbounded spells

DynamicNetworks.unbounded_spell — Function
DynamicNetworks.unbounded_spell(Time) -> Spell{Time}

The spell covering the whole time axis, (-Inf, Inf). Axes without infinities use their extreme values instead: typemin(Time)/typemax(Time) on integer axes and on DateTime/Date. An element with no spell record is equivalent to this spell under R's active.default = TRUE (get_vertex_activity reports it), and a bound equal to one of its bounds means "unbounded" (spell_duration treats it so). Public so that consumers (TSNA.jl, NDTV.jl) share one convention.

Example

using DynamicNetworks, Dates
DynamicNetworks.unbounded_spell(Float64)    # Spell[-Inf, Inf)
DynamicNetworks.unbounded_spell(Int).terminus == typemax(Int)   # true
source