TemporalNetwork

class TemporalNetwork(N=None, T=None, nettype=None, from_df=None, from_array=None, from_dict=None, from_edgelist=None, timetype=None, diagonal=False, timeunit=None, desc=None, starttime=None, nodelabels=None, timelabels=None, hdf5=False, hdf5path=None, forcesparse=False, dense_threshold=0.25)[source]

Bases: object

A class for temporal networks.

This class allows to call different teneto functions within the class and store the network representation.

Parameters:
  • N (int) – number of nodes in network
  • T (int) – number of time-points in network
  • nettype (str) – description of network. Can be: bu, bd, wu, wd where the letters stand for binary, weighted, undirected and directed. Default is weighted and undirected.
  • from_df (pandas df) – input data frame with i,j,t,[weight] columns
  • from_array (array) – input data from an array with dimesnions node,node,time
  • from_dict (dict) – input data is a contact sequence dictionary.
  • from_edgelist (list) – input data is a list of lists where each item in main list consists of [i,j,t,[weight]].
  • timetype (str) – discrete or continuous
  • diagonal (bool) – if the diagonal should be included in the edge list.
  • timeunit (str) – string (used in plots)
  • desc (str) – string to describe network.
  • startime (int) – integer represents time of first index.
  • nodelabels (list) – list of labels for naming the nodes
  • timelabels (list) – list of labels for time-points
  • hdf5 (bool) – if true, pandas dataframe is stored and queried as a h5 file.
  • hdf5path (str) – Where the h5 files is saved if hdf5 is True. If left unset, the default is ./teneto_temporalnetwork.h5
  • forcesparse (bool) – When forsesparse if False (default), if importing array and if dense_threshold% (default%) edges are present, tnet.network is an array. If forsesparse is True, then this inhibts arrays being created.
  • dense_threshold (float) – If forsesparse == False, what percentage (as a decimal) of edges need to be present in order for representation to be dense.

Methods Summary

add_edge(edgelist) Adds an edge from network.
binarize(threshold_type, threshold_level, …) Binarizes the network.
calc_networkmeasure(networkmeasure, …) Calculate network measure.
df_to_array([start_at]) Turns datafram to array.
drop_edge(edgelist) Removes an edge from network.
generatenetwork(networktype, **networkparams) Generate a network
get_network_when(**kwargs)
hdf5_setup(hdf5path)
network_from_array(array[, forcesparse, …]) Defines a network from an array.
network_from_df(df) Defines a network from an array.
network_from_dict(contact)
network_from_edgelist(edgelist) Defines a network from an array.
plot(plottype[, ij, t, ax])

Methods Documentation

add_edge(edgelist)[source]

Adds an edge from network.

Parameters:edgelist (list) – a list (or list of lists) containing the i,j and t indicies to be added. For weighted networks list should also contain a ‘weight’ key.
Returns:
Return type:Updates TenetoBIDS.network dataframe with new edge
binarize(threshold_type, threshold_level, **kwargs)[source]

Binarizes the network.

Parameters:
  • threshold_type (str) – What type of thresholds to make binarization. Options: ‘rdp’, ‘percent’, ‘magnitude’.
  • threshold_level (str) – Paramter dependent on threshold type. If ‘rdp’, it is the delta (i.e. error allowed in compression). If ‘percent’, it is the percentage to keep (e.g. 0.1, means keep 10% of signal). If ‘magnitude’, it is the amplitude of signal to keep.
  • teneto.utils.binarize for kwarg arguments. (See) –
Returns:

Return type:

Updates tnet.network to be binarized

calc_networkmeasure(networkmeasure, **measureparams)[source]

Calculate network measure.

Parameters:
  • networkmeasure (str) – Function to call. Functions available are in teneto.networkmeasures
  • measureparams (kwargs) – kwargs for teneto.networkmeasure.[networkmeasure]
df_to_array(start_at='auto')[source]

Turns datafram to array. See teneto.utils.df_to_array for more information.

Parameters:start_at (str) – ‘min’ or ‘zero’. If auto, the 0th time-point is tnet.starttime. If min, the 0th time-point in the array is the minimum time-point found. If zero, the 0th time-point in the array is 0.
drop_edge(edgelist)[source]

Removes an edge from network.

Parameters:edgelist (list) – a list (or list of lists) containing the i,j and t indicies to be removes.
Returns:
Return type:Updates TenetoBIDS.network dataframe
generatenetwork(networktype, **networkparams)[source]

Generate a network

Parameters:
  • networktype (str) – Function to call. Functions available are in teneto.generatenetwork
  • measureparams (kwargs) – kwargs for teneto.generatenetwork.[networktype]
Returns:

Return type:

TenetoBIDS.network is made with the generated network.

get_network_when(**kwargs)[source]
hdf5_setup(hdf5path)[source]
network_from_array(array, forcesparse=False, dense_threshold=0.25)[source]

Defines a network from an array.

Parameters:
  • array (array) – 3D numpy array.
  • forcespace (bool) – If true, will always make the array sparse (can be slow). If false, dense form will be kept if more than dense_threshold% of edges are present.
  • dense_threshold (float) – Threshold for when array representation is kept as an array instead of sparse. Only done if forcesparse is False.
network_from_df(df)[source]

Defines a network from an array.

Parameters:array (array) – Pandas dataframe. Should have columns: ‘i’, ‘j’, ‘t’ where i and j are node indicies and t is the temporal index. If weighted, should also include ‘weight’. Each row is an edge.
network_from_dict(contact)[source]
network_from_edgelist(edgelist)[source]

Defines a network from an array.

Parameters:edgelist (list of lists.) – A list of lists which are 3 or 4 in length. For binary networks each sublist should be [i, j ,t] where i and j are node indicies and t is the temporal index. For weighted networks each sublist should be [i, j, t, weight].
plot(plottype, ij=None, t=None, ax=None, **plotparams)[source]