Skip to content

Commit

Permalink
timeline shuffling: don't fail for empty networks
Browse files Browse the repository at this point in the history
  • Loading branch information
arashbm committed Oct 10, 2024
1 parent 1367f53 commit 4537fa7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
25 changes: 25 additions & 0 deletions include/reticula/microcanonical_reference_models.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,38 @@ namespace reticula {
network<EdgeT> topology_constrained_link_shuffling(
const network<EdgeT>& temp, Gen& generator);

/**
Produces a random shuffling of the temporal network where the events are
shuffled by assigning new, uniformly random timetamps and moving it to a
randomly selected link with a non-empty timeline. Equivalent to
micocanonical reference model with the canonical name $P[\mathcal{L}, E]$.
The observation window, the window where the original measurement of the
temporal network was made, is passed through parameters `t_start` and
`t_end`.
The set of vertices, total number of events and the static projection of
the temporal network are conserved.
*/
template <
temporal_network_edge EdgeT,
std::uniform_random_bit_generator Gen>
requires is_dyadic_v<EdgeT>
network<EdgeT> timeline_shuffling(
const network<EdgeT>& temp, Gen& generator,
typename EdgeT::TimeType t_start, typename EdgeT::TimeType t_end);


/**
Produces a random shuffling of the temporal network where the events are
shuffled by assigning new, uniformly random timetamps and moving it to a
randomly selected link with a non-empty timeline. Equivalent to
micocanonical reference model with the canonical name $P[\mathcal{L}, E]$.
The observation window, the window where the original measurement of the
temporal network was made, is derived by minimum and maximum cause time of
the events.
The set of vertices, total number of events and the static projection of
the temporal network are conserved.
*/
Expand Down
9 changes: 9 additions & 0 deletions src/microcanonical_reference_models.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ namespace reticula {
network<EdgeT> timeline_shuffling(
const network<EdgeT>& temp, Gen& generator,
typename EdgeT::TimeType t_start, typename EdgeT::TimeType t_end) {
if (temp.vertices().empty() || temp.edges().empty())
return temp;

auto [t0, t1] = cause_time_window(temp);
if (t0 < t_start || t1 > t_end)
throw std::invalid_argument("observation window does not cover "
Expand Down Expand Up @@ -331,6 +334,9 @@ namespace reticula {
requires is_dyadic_v<EdgeT>
network<EdgeT> timeline_shuffling(
const network<EdgeT>& temp, Gen& generator) {
if (temp.vertices().empty() || temp.edges().empty())
return temp;

auto [t0, t1] = cause_time_window(temp);
return timeline_shuffling(temp, generator, t0, t1);
}
Expand Down Expand Up @@ -377,6 +383,9 @@ namespace reticula {
requires is_dyadic_v<EdgeT>
network<EdgeT> weight_constrained_timeline_shuffling(
const network<EdgeT>& temp, Gen& generator) {
if (temp.vertices().empty() || temp.edges().empty())
return temp;

auto [t0, t1] = cause_time_window(temp);
return weight_constrained_timeline_shuffling(temp, generator, t0, t1);
}
Expand Down

0 comments on commit 4537fa7

Please sign in to comment.