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 typeTime: Time type (Float64,Int,DateTime,Date, ...)D::Bool: directedness, as inNetwork{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 att. - An element with no spell record is active (R's
active.default = TRUE). Every query and extraction takesactive_default=true; passactive_default=falseto treat such elements as inactive. An element whose spells were all removed (bydeactivate!orremove_spell!) has an empty record and is inactive. activate!andadd_spell!merge overlapping and adjacent spells on insertion, as R'sactivate.*do.- The observation window is the one given at construction or by
set_observation_period!; when none was given,get_observation_periodreturnsnothing(see there for what TSNA.jl and NDTV.jl do then). A window has two ends, as R'snet.obs.perioddoes: give bothobservation_startandobservation_end, or neither. Giving only one raises anArgumentErrorrather than inventing the other end; for an open-ended window pass the axis extreme explicitly (Inf, or the bounds ofDynamicNetworks.unbounded_spellon 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 verticesedge_spells::Dict{Tuple{T,T}, Vector{Spell{Time}}}: Activity periods for edgesvertex_tea,edge_tea: Time-varying vertex and edge attributesobservation_period::Tuple{Time, Time}: the stored observation window; meaningless whenobservation_period_setis false (read the window withget_observation_period, which returnsnothingthen)observation_period_set::Bool: whether a window was given explicitlymutation_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)) # falseSpell 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 earlierterminus_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 comparedTimeVaryingAttribute
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)])Spell Utilities
spell_overlap
DynamicNetworks.spell_overlap — Function
spell_overlap(s1::Spell, s2::Spell) -> BoolCheck 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 insidespell_duration
DynamicNetworks.spell_duration — Function
spell_duration(s::Spell) -> durationThe 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 axis | Duration of an unbounded spell |
|---|---|
| floating point | Inf |
other Real (integers, rationals) | typemax(Time) |
DateTime | Millisecond(typemax(Int64)) |
Date | Day(typemax(Int64)) |
| anything else | ArgumentError |
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 overflowUnbounded 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