numgraph.utils
Utility functions
- numgraph.utils.coalesce(edge_list)[source]
Polishes an edge list by removing duplicates and by sorting the edges
- Parameters
edge_list (NDArray) – An edge list
(num_edges x 2)- Returns
NDArray – A sorted edge list with no duplicated edges
(new_num_edges x 2)
- numgraph.utils.dense(generator)[source]
Transforms a sparse generator into its dense version
- Parameters
generator (Callable) – A callable that generates graphs
- Returns
Callable – A callable that generates the squared adjacency matrix
(num_nodes x num_nodes)of a graph
- numgraph.utils.to_dense(edge_list, num_nodes=None)[source]
Converts a list of edges in a squared adjacency matrix
- numgraph.utils.to_sparse(adj_matrix)[source]
Converts an adjacency matrix to a list of edges
- Parameters
adj_matrix (NDArray) – The squared adjacency matrix
(num_nodes x num_nodes)- Returns
NDArray – The list of edges
(num_edges x 2)
- numgraph.utils.to_undirected(adj)[source]
Turns a directed edge_list into a non-directed one
- Parameters
adj (NDArray) – A directed adjacency matrix
(num_nodes x num_nodes), or edge list(num_edges x 2)- Returns
NDArray – An undirected adjacency matrix
(num_nodes x num_nodes), or the edge list((2*num_edges) x 2)
- numgraph.utils.remove_self_loops(adj)[source]
Removes every self-loop in the graph given by adj
- Parameters
adj (NDArray) – The adjancency matrix
(num_nodes x num_nodes), or the edge_list(num_edges x 2)- Returns
NDAarray – The adjacency matrix
(num_nodes x num_nodes), or the list of edges(new_num_edges x 2), without self-loops.
- numgraph.utils.unsorted_coalesce(edge_list, weights=None)[source]
Polishes an edge list by removing duplicates and by sorting the edges
- Parameters
edge_list (NDArray) – An edge list
(num_edges x 2)weights (NDArray) – The weights
(num_edges x 1)
- Returns
NDArray – An unsorted edge list with no duplicated edges
(new_num_edges x 2)NDArray – The unsorted weigths associated to the new edge list
(new_num_edges x 1)
Spikes Generator
- class numgraph.utils.spikes_generator.SpikeGenerator(t_max=10, heat_spike=(0.7, 2.0), num_spikes=1, rng=None)[source]
Bases:
objectThe generator of the spikes in the heat diffusion over a graph. To each spike is associated an increase of temperature of the node. This class identify at each step the node with injected temperature and the new temperature.
- Parameters
t_max (int, optional) – The maximum number of timesteps in the simulation, by default
10heat_spike (Tuple[float, float], optional) – A tuple containing the min and max temperature of a spike, by default
(0.7, 2.)num_spikes (int, optional) – The number of heat spikes during the process, by default
1rng (Generator, optional) – Numpy random number generator, by default
None
- class numgraph.utils.spikes_generator.HeatSpikeGenerator(t_max=10, heat_spike=(0.7, 2.0), num_spikes=1, rng=None)[source]
Bases:
numgraph.utils.spikes_generator.SpikeGeneratorThe generator of the spikes in the heat diffusion over a graph. To each spike is associated an increase of temperature of the node. This class identify at each step the node with injected temperature and the new temperature.
- Parameters
t_max (int, optional) – The maximum number of timesteps in the simulation, by default
10heat_spike (Tuple[float, float], optional) – A tuple containing the min and max temperature of a spike, by default
(0.7, 2.)num_spikes (int, optional) – The number of heat spikes during the process, by default
1rng (Generator, optional) – Numpy random number generator, by default
None
- class numgraph.utils.spikes_generator.ColdHeatSpikeGenerator(t_max=10, heat_spike=(0.7, 2.0), cold_spike=(- 1.0, 0.0), prob_cold_spike=0.2, num_spikes=2, rng=None)[source]
Bases:
numgraph.utils.spikes_generator.SpikeGeneratorThe generator of the spikes in the heat diffusion over a graph. To each spike is associated an increase (or decrease) of temperature of the node. This class identify at each step the node with injected temperature and the new temperature.
- Parameters
t_max (int, optional) – The maximum number of timesteps in the simulation, by default
10heat_spike (Tuple[float, float], optional) – A tuple containing the min and max temperature of a hot spike, by default
(0.7, 2.)cold_spike (Tuple[float, float], optional) – A tuple containing the min and max temperature of a cold spike, by default
(-1., 0.)prob_cold_spike (float, optional) – The probability of a cold spike to happen, by default
0.2num_spikes (int, optional) – The number of heat spikes during the process, by default
1rng (Generator, optional) – Numpy random number generator, by default
None