Tools module¶
-
tacoma.tools.
bin_a_function
(x, y, bins, mode='mean')[source]¶ Bin a step function \(y(t)\) over time bins. Binning can be done using either
numpy.sum
ornumpy.mean
.Parameters: - x (numpy.ndarray) – domain values at which y changes
- y (numpy.ndarray) – values of the cunt
- bins (numpy.ndarray) – Bin to those bin edges
- mode (string, default : mean) – Build either a
mean
over the bins or asum
.
Returns: new_y – binned observable
Return type: numpy.ndarray
-
tacoma.tools.
complete_graph
(N, tmax=1.0)[source]¶ Get a single frame which consists of a complete network.
Parameters: Returns: An instance of tacoma.edge_lists with t = [0.0], tmax =
tmax
.Return type:
-
tacoma.tools.
contact_coverage
(temporal_network)[source]¶ Get the total number of discovered unique edges C(t), i.e. the contact coverage.
Parameters: temporal_network ( _tacoma.edge_trajectories
,_tacoma.edge_lists
,_tacoma.edge_changes
orlist
of_tacoma.edge_trajectory_entry
) –Returns: - t (numpy.ndarray) – Time points at which new edges have been discovered
- C (numpy.ndarray) – total number of edges discovered up to time t.
-
tacoma.tools.
convert_static_network
(N, edge_list, tmax=1.0)[source]¶ Get a single frame which consists of the static network.
Parameters: Returns: An instance of tacoma.edge_lists with t = [0.0], tmax =
tmax
.Return type:
-
tacoma.tools.
fit_contact_coverage
(N, time, contact_coverage, intervals_to_discard_for_fit=[], kind='gamma')[source]¶ Fit the contact coverage \(C(t)\) to an edge activity rate distribution of kind
kind
.Parameters: - N (int) – Number of nodes.
- time (numpy.ndarray) – Time points at which the contact converage changed.
- contact_coverage (numpy.ndarray) – Contact coverage at the corresponding times in
time
. - intervals_to_discard_for_fit (list of tuple of float) – a list of time intervals which have to be discarded for the fit
- kind (string, default : 'gamma') – Rate distribution model for fit. Can be
gamma
,exponential
,uniform
,normal
,delta
,power-law
.
Returns: - fit_function (function) – The fit function
- popt (tuple of float) – The found optimal parameters to pass to
fit_function
- pstd (tuple of float) – standard uncertainty of the parameters
-
tacoma.tools.
get_edge_life_times
(temporal_network)[source]¶ For each edge compute the probability that it is active and the rate with which it is activated.
Parameters: temporal_network ( _tacoma.edge_lists
,_tacoma.edge_changes
or_tacoma.edge_trajectories
) –Returns: - p (numpy.ndarray) – The probability to be switched on for each observed edge of the network (the remaining un-observed edges have probability p = 0).
- omega (numpy.ndarray) – The rate with which the observed edges are switched on \(\omega = \left(\frac{1}{\tau^+} + \frac{1}{\tau^{-}}\right)^{-1}\) (the remaining un-observed edges have rate \(\omega = 0\)).
-
tacoma.tools.
get_edge_probability_and_rate
(temporal_network)[source]¶ For each edge compute the probability that it is active and the rate with which it is activated.
Parameters: temporal_network ( _tacoma.edge_lists
,_tacoma.edge_changes
or_tacoma.edge_trajectories
) –Returns: - p (numpy.ndarray) – The probability to be switched on for each observed edge of the network (the remaining un-observed edges have probability p = 0).
- omega (numpy.ndarray) – The rate with which the observed edges are switched on \(\omega = \left(\frac{1}{\tau^+} + \frac{1}{\tau^{-}}\right)^{-1}\) (the remaining un-observed edges have rate \(\omega = 0\)).
-
tacoma.tools.
get_logarithmic_histogram
(data, bins, return_bin_means=True, density=True)[source]¶ Get a logarithmic histogram.
Parameters: Returns: - x (numpy.ndarray) – Either geometric intervals or interval edges
- y (numpy.ndarray) – Either probability density or counts.
-
tacoma.tools.
get_reduced_time
(t, intervals_to_discard)[source]¶ Reduce the provided time in a way that intervals are cut out.
Parameters: - t (numpy.ndarray) – time array to reduce
- intervals_to_discard (list of tuple of float) – The time intervals which have to be discarded.
Returns: new_t – reduced time with equal shape to
t
. Each time in intervals which have to be discarded are remapped to the beginning of the intervals.Return type: numpy.ndarray
-
tacoma.tools.
group_size_histogram
(group_sizes_and_durations)[source]¶ Returns the mean number of groups of size g (mean over both ensemble and time).
Parameters: group_sizes_and_durations ( group_sizes_and_durations
) – Result from the functionmeasure_group_sizes_and_durations
Returns: - g (
numpy.ndarray
of float) – Group sizes - N (
numpy.ndarray
of float) – Mean number of groups of the corresponding size in g.
- g (
-
tacoma.tools.
mean_coordination_number
(group_sizes_and_durations)[source]¶ Returns the mean coordination number (mean over both ensemble and time). Following the definition by Zhao, Stehle, Bianconi, Barrat, the coordination number of node i is equal to the size of the group it is part of.
Parameters: group_sizes_and_durations ( group_sizes_and_durations
) – Result from the functionmeasure_group_sizes_and_durations
Returns: mean_coordination_number – Temporal and ensemble mean of a node’s group size. Return type: float
-
tacoma.tools.
mean_group_size
(group_sizes_and_durations)[source]¶ Returns the mean group size (mean over both ensemble and time).
Parameters: group_sizes_and_durations ( group_sizes_and_durations
) – Result from the functionmeasure_group_sizes_and_durations
Returns: mean_group_size – Temporal and ensemble mean of the group size of all groups a network consists of at a certain time. Return type: float
-
tacoma.tools.
mean_number_of_groups
(group_sizes_and_durations)[source]¶ Returns the mean number of groups (mean over both ensemble and time).
Parameters: group_sizes_and_durations ( group_sizes_and_durations
) – Result from the functionmeasure_group_sizes_and_durations
Returns: mean_number_of_groups – Temporal and ensemble mean of the total number of groups a network consists of at a certain time. Return type: float
-
tacoma.tools.
rescale_time
(temporal_network, new_t0, new_tmax)[source]¶ Rescale the time in this temporal network (inplace).
Parameters: Returns: temporal_network – Same instance as input.
Return type: edge_lists
oredge_changes
-
tacoma.tools.
sample_a_function
(t, y, time_points, sample_width=0)[source]¶ Sample an observable \(y\) which is a step function and changes at corresponding values \(t\).
Parameters: - t (numpy.ndarray) – domain values at which y changes
- y (numpy.ndarray) – observable to sample
- time_points (numpy.ndarray) – time points for which to sample.
- sample_width (float, default : 0.0) – sample as a temporal average over [t-sample_width/2, t+sample_width/2].
Returns: new_y – values of y sampled at time_points.
Return type: numpy.ndarray
-
tacoma.tools.
slow_mean_degree
(temporal_network)[source]¶ Returns the mean degree (mean over ensemble) but it takes ages to compute. You should instead use
mean_degree
.Parameters: temporal_network ( edge_lists
oredge_changes
) –Returns: - t (float) – Temporal and ensemble mean of the node degree.
- mean_degree (float) – Temporal and ensemble mean of the node degree.
-
tacoma.tools.
time_RMSE
(t, x1, x2, tmax=None)[source]¶ Get the root mean squared error (RMSE) of two observables over the same time. Combine with
tacoma.tools.sample_a_function()
.\[\mathrm{RMSE} = \left( \frac{1}{t_\mathrm{max}-t_0} \int\limits_{t_0}^{t_\mathrm{max}} dt\, \left( x_1(t) - x_2(t) \right)^2. \right)^{1/2}\]Parameters: - t (numpy.ndarray) – times at which
x1
andx2
change - x1 (numpy.ndarray) – The first observable to compute the RMSE.
- x2 (numpy.ndarray) – The second observable to compute the RMSE.
- tmax (float, default : None) – If this is None, the integral is computed until time t[-1], otherwise it’s evaluated until tmax.
Returns: RMSE – The root mean squared error.
Return type: - t (numpy.ndarray) – times at which
-
tacoma.tools.
time_average
(t, x, tmax=None)[source]¶ Return a temporal average of an observable x(t),
\[\overline x = \frac{1}{t_\mathrm{max}-t_0} \int\limits_{t_0}^{t_\mathrm{max}} dt\, x(t).\]Where it’s assumed that x changes as a step function, such that
\[\overline x = \frac{1}{t_\mathrm{max}-t_0} \left( (t_\mathrm{max} - t_{N_t-1}) x(t_{N_t-1}) + \sum_{i=1}^{N_t-1} (t_{i}-t_{i-1})x(t_{i-1}) \right).\]Parameters: - t (numpy.ndarray) – Times at which x changes
- x (numpy.ndarray) – Value of the observable at the corresponding times.
- tmax (float, default : None) – If this is None, the integral is computed until time t[-1], otherwise it’s evaluated until tmax.
Returns: average_x – The temporal average of x.
Return type: