galib 2.0.dev0__tar.gz → 2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: galib
3
- Version: 2.0.dev0
3
+ Version: 2.1
4
4
  Summary: A library for graph analysis in Python / NumPy.
5
5
  Project-URL: Homepage, https://github.com/gorkazl/pyGAlib
6
6
  Project-URL: Source Code, https://github.com/gorkazl/pyGAlib/tree/master/src/galib
@@ -36,8 +36,6 @@ https://pypi.org/project/galib/)
36
36
 
37
37
  # pyGAlib – Graph Analysis Library in Python / NumPy
38
38
 
39
- > **Development branch**. Version 2 of pyGAlib under construction. Heavy changes expected in this branch. For download, please install the PyPI version or the one in the master branch of this repository. Both are installed via `pip`, see instructions in the corresponding README.md file.
40
-
41
39
  pyGAlib is a library to generate and study graphs and complex networks in Python. It treats networks as adjacency matrices in order to take advantage of faster NumPy
42
40
  array manipulations. The library is easy to install, use, modify and extend.
43
41
 
@@ -253,6 +251,27 @@ limitations under the License.
253
251
  -----------------------------------------------------------------
254
252
  ### WHAT IS NEW
255
253
 
254
+ ##### June 26, 2026 (Release of Version 2.1)
255
+
256
+ * **New functions** added:
257
+ * Support functions `is_directed()` and `is_weighted()` added to _metrics.py_ module, to facilitate working with weighted graphs.
258
+ * **Support to generate and randomize weigthed networks** added. New functions included to _models.py_ module:
259
+ * `SeedRandomWeights()` adds random weights (sampled from a distribution of choice) to the links of an existing (di)graph.
260
+ * `ShuffleWeights()` conserves the links of a (di)graph in-place, but randomly reassigns their weights.
261
+ * **"Syntactic sugar" functions** were added to generate some common random / weighted graphs (_models.py_):
262
+ * `ErdosRenyiGraph_Like()` generates an Erdös-Rényi (random) graph of same size and link probability as a given input network. Optionally, it also seeds random weights to the links, from a distribution of choice.
263
+ * `RandomGraph_Like()` generates a random graph of same size and number of links as a given input network. Optionally, it also seeds random weights to the links, from a distribution of choice.
264
+ * `WeightedErdosRenyiGraph()` generates a weighted Erdos-Renyi graph with link weights sampled from a distribution of choice.
265
+ * `WeightedRandomGraph()` generates a weighted random graph with link weights sampled from a distribution of choice.
266
+ * New **example notebooks** added:
267
+ * [RichClub_Undirected.ipynb](Examples/RichClub_Undirected.ipynb) shows how to identify the presence of a rich-club in empirical (di)graphs.
268
+ * [WeightedGraphs_Intro.ipynb](Examples/WeightedGraphs_Intro.ipynb) illustrates how to use the new functions to work with weighted (di)graphs.
269
+ * Minor changes and bug fixes:
270
+ * In *models.py* module, function renamed from `ModularHeterogeneousGraph()` to `ModularGraph()`.
271
+ * Bug fix in `ErdosRenyiGraph()` function that prevented addition of self-loops even with `selfloops = True` option set.
272
+ * `outdtype` option removed from graph generation functions in *models.py* module. For consistency, all graph generators return 2D arrays of `np.uint8` type, for the binary cases and `np.float64` for the weighted (di)graphs.
273
+
274
+
256
275
  ##### November 10, 2025 (Release of Version 2)
257
276
 
258
277
  Stable version 2.0 checked, validated and released.
@@ -263,42 +282,6 @@ Stable version 2.0 checked, validated and released.
263
282
  * Bug fixes to adapt to the various changes in Python and NumPy since last release.
264
283
  * Sample and validation scripts in the "*Examples/*" folder revised and adapted to recent changes in Python and NumPy.
265
284
 
266
- ##### March 14, 2024
267
- Small bugs fixed:
268
-
269
- - Normalization of `galib.metrics.Modularity()` function corrected.
270
- - Fixed the new aliases for `int` and `float` in *Numpy*. All arrays are now declared as `np.int64` or `np.float64`, and individual numbers as standard Python `int` or `float`.
271
-
272
- ##### February 7, 2022
273
- Minor bug fixes. A remaining Python 2 to Python 3 conversion error was fixed, since standard library function `range()` no longer returns a list, but an iterator object.
274
-
275
- ##### June 15, 2020
276
- Docstrings corrected. Function `k_DensityW()` was added in module *metrics.py* to calculate the k-density in networks with weighted links, which is needed to evaluate potential formation of rich-club structures in weigthed networks.
277
-
278
- ##### July 12, 2019
279
- Version 1.1.0 released. Section for classic and deterministic graphs added to the *models.py* module. New generators `PathGraph()`, `StarGraph()` and `CompleteGraph()` included.
280
-
281
- ##### July 6, 2019
282
- For clarity, function `RichClub()` has been splitted into two functions: `RichClub()`and `k_Density()`. The reason is that the output of old `RichClub()` was basically the k-density for all degrees, from 0 to kmax. Now this is done by `k_Density()` and the new `RichClub()` function identifies the set of nodes (hubs) for which k-density overcomes a given value.
283
-
284
- ##### June 15, 2019
285
- GAlib has been registered in PyPI ([https://pypi.org/project/galib/](https://pypi.org/project/galib/)). Direct installation and version management using `pip` is thus available.
286
-
287
- ##### January 29, 2019
288
- New in Version 1.0.1:
289
-
290
- - Minor corrections overall.
291
- - Function to generate Ravasz-Barabási hierarchical networks added to *models.py* module.
292
-
293
- ##### December 3, 2018
294
- Release of Version 1.0.0 of pyGAlib. The library is now shaped as a proper Python package and is installable using standard tools. The structure of the package has been renewed and contains the following modules:
295
-
296
- - *metrics.py*: Common graph metrics (degrees, clustering, graph distance, etc)
297
- - *models.py*: Generation of synthetic networks and randomization.
298
- - *tools.py*: Miscelaneous helper functions.
299
- - *metrics_numba.py*: Uses the Numba package to accelerate calculation of some metrics.
300
- - *models_numba.py*: Uses the Numba package to accelerate generation of some graph models.
301
- - *extra.py*: Additional measures and functionalities related to network analysis.
302
285
 
303
286
  See the file *CHANGELOG.md* for a complete history of changes.
304
287
 
@@ -6,8 +6,6 @@ https://pypi.org/project/galib/)
6
6
 
7
7
  # pyGAlib – Graph Analysis Library in Python / NumPy
8
8
 
9
- > **Development branch**. Version 2 of pyGAlib under construction. Heavy changes expected in this branch. For download, please install the PyPI version or the one in the master branch of this repository. Both are installed via `pip`, see instructions in the corresponding README.md file.
10
-
11
9
  pyGAlib is a library to generate and study graphs and complex networks in Python. It treats networks as adjacency matrices in order to take advantage of faster NumPy
12
10
  array manipulations. The library is easy to install, use, modify and extend.
13
11
 
@@ -223,6 +221,27 @@ limitations under the License.
223
221
  -----------------------------------------------------------------
224
222
  ### WHAT IS NEW
225
223
 
224
+ ##### June 26, 2026 (Release of Version 2.1)
225
+
226
+ * **New functions** added:
227
+ * Support functions `is_directed()` and `is_weighted()` added to _metrics.py_ module, to facilitate working with weighted graphs.
228
+ * **Support to generate and randomize weigthed networks** added. New functions included to _models.py_ module:
229
+ * `SeedRandomWeights()` adds random weights (sampled from a distribution of choice) to the links of an existing (di)graph.
230
+ * `ShuffleWeights()` conserves the links of a (di)graph in-place, but randomly reassigns their weights.
231
+ * **"Syntactic sugar" functions** were added to generate some common random / weighted graphs (_models.py_):
232
+ * `ErdosRenyiGraph_Like()` generates an Erdös-Rényi (random) graph of same size and link probability as a given input network. Optionally, it also seeds random weights to the links, from a distribution of choice.
233
+ * `RandomGraph_Like()` generates a random graph of same size and number of links as a given input network. Optionally, it also seeds random weights to the links, from a distribution of choice.
234
+ * `WeightedErdosRenyiGraph()` generates a weighted Erdos-Renyi graph with link weights sampled from a distribution of choice.
235
+ * `WeightedRandomGraph()` generates a weighted random graph with link weights sampled from a distribution of choice.
236
+ * New **example notebooks** added:
237
+ * [RichClub_Undirected.ipynb](Examples/RichClub_Undirected.ipynb) shows how to identify the presence of a rich-club in empirical (di)graphs.
238
+ * [WeightedGraphs_Intro.ipynb](Examples/WeightedGraphs_Intro.ipynb) illustrates how to use the new functions to work with weighted (di)graphs.
239
+ * Minor changes and bug fixes:
240
+ * In *models.py* module, function renamed from `ModularHeterogeneousGraph()` to `ModularGraph()`.
241
+ * Bug fix in `ErdosRenyiGraph()` function that prevented addition of self-loops even with `selfloops = True` option set.
242
+ * `outdtype` option removed from graph generation functions in *models.py* module. For consistency, all graph generators return 2D arrays of `np.uint8` type, for the binary cases and `np.float64` for the weighted (di)graphs.
243
+
244
+
226
245
  ##### November 10, 2025 (Release of Version 2)
227
246
 
228
247
  Stable version 2.0 checked, validated and released.
@@ -233,42 +252,6 @@ Stable version 2.0 checked, validated and released.
233
252
  * Bug fixes to adapt to the various changes in Python and NumPy since last release.
234
253
  * Sample and validation scripts in the "*Examples/*" folder revised and adapted to recent changes in Python and NumPy.
235
254
 
236
- ##### March 14, 2024
237
- Small bugs fixed:
238
-
239
- - Normalization of `galib.metrics.Modularity()` function corrected.
240
- - Fixed the new aliases for `int` and `float` in *Numpy*. All arrays are now declared as `np.int64` or `np.float64`, and individual numbers as standard Python `int` or `float`.
241
-
242
- ##### February 7, 2022
243
- Minor bug fixes. A remaining Python 2 to Python 3 conversion error was fixed, since standard library function `range()` no longer returns a list, but an iterator object.
244
-
245
- ##### June 15, 2020
246
- Docstrings corrected. Function `k_DensityW()` was added in module *metrics.py* to calculate the k-density in networks with weighted links, which is needed to evaluate potential formation of rich-club structures in weigthed networks.
247
-
248
- ##### July 12, 2019
249
- Version 1.1.0 released. Section for classic and deterministic graphs added to the *models.py* module. New generators `PathGraph()`, `StarGraph()` and `CompleteGraph()` included.
250
-
251
- ##### July 6, 2019
252
- For clarity, function `RichClub()` has been splitted into two functions: `RichClub()`and `k_Density()`. The reason is that the output of old `RichClub()` was basically the k-density for all degrees, from 0 to kmax. Now this is done by `k_Density()` and the new `RichClub()` function identifies the set of nodes (hubs) for which k-density overcomes a given value.
253
-
254
- ##### June 15, 2019
255
- GAlib has been registered in PyPI ([https://pypi.org/project/galib/](https://pypi.org/project/galib/)). Direct installation and version management using `pip` is thus available.
256
-
257
- ##### January 29, 2019
258
- New in Version 1.0.1:
259
-
260
- - Minor corrections overall.
261
- - Function to generate Ravasz-Barabási hierarchical networks added to *models.py* module.
262
-
263
- ##### December 3, 2018
264
- Release of Version 1.0.0 of pyGAlib. The library is now shaped as a proper Python package and is installable using standard tools. The structure of the package has been renewed and contains the following modules:
265
-
266
- - *metrics.py*: Common graph metrics (degrees, clustering, graph distance, etc)
267
- - *models.py*: Generation of synthetic networks and randomization.
268
- - *tools.py*: Miscelaneous helper functions.
269
- - *metrics_numba.py*: Uses the Numba package to accelerate calculation of some metrics.
270
- - *models_numba.py*: Uses the Numba package to accelerate generation of some graph models.
271
- - *extra.py*: Additional measures and functionalities related to network analysis.
272
255
 
273
256
  See the file *CHANGELOG.md* for a complete history of changes.
274
257
 
@@ -219,7 +219,7 @@ from .models import*
219
219
 
220
220
 
221
221
  # Some metadata
222
- __version__ = "2.0.dev0"
222
+ __version__ = "2.1"
223
223
 
224
224
 
225
225
 
@@ -338,7 +338,7 @@ def FunctionalComplexity(corrmatrix, nbins=50, datarange=[0,1]):
338
338
 
339
339
  """
340
340
  # 0) Security checks
341
- if len(np.shape(corrmatrix)) != 2:
341
+ if corrmatrix.ndim != 2:
342
342
  raise ValueError('Input data not a correlation matrix. Data not alligned.')
343
343
  if corrmatrix.min() < datarange[0]:
344
344
  raise ValueError('Input data not in range. Values smaller than range found.')
@@ -19,39 +19,44 @@ measures will be added to GAlib in future releases.
19
19
 
20
20
  BASIC CONNECTIVITY DESCRIPTORS
21
21
  ------------------------------
22
- Density
23
- Returns the density of links in a network.
24
- Degree
25
- Computes the number of neighbours of every node.
26
- Intensity
27
- The total strength of a node in a weighted network.
28
- Reciprocity
29
- Computes the fraction of reciprocal links to total number of links.
30
- ReciprocalDegree
31
- Returns the reciprocal degree and excess degrees of every nodes.
22
+ is_directed
23
+ Checks whether a (weighted) matrix represents a directed or undirected graph.
24
+ is_symmetric
25
+ Checks whether a (weighted) matrix is symmetric or not.
26
+
32
27
  AvNeighboursDegree
33
28
  Average neighbours' degree of nodes with given degree k, for all k.
34
29
  Clustering
35
30
  Returns the clustering coefficient and the local clustering of every node.
31
+ Degree
32
+ Computes the number of neighbours of every node.
33
+ Density
34
+ Returns the density of links in a network.
35
+ Intensity
36
+ The total strength of a node in a weighted network.
36
37
  k_Density
37
38
  Computes the density of subnetworks made of nodes with degree >= k',
38
39
  for all k' = 0 to kmax.
39
- RichClub
40
- Identifies the subset of hubs with dense interconnectivity.
41
40
  k_DensityW
42
41
  Computes the ratio of link weights among the nodes with strength > s',
43
42
  for s' = 0 to s' = smax.
44
43
  MatchingIndex
45
44
  Computes the number of common neighbours of every pair of nodes.
45
+ Reciprocity
46
+ Computes the fraction of reciprocal links to total number of links.
47
+ ReciprocalDegree
48
+ Returns the reciprocal degree and excess degrees of every nodes.
49
+ RichClub
50
+ Identifies the subset of hubs with dense interconnectivity.
46
51
 
47
52
  PATHS AND GRAPH DISTANCE FUNCTIONS
48
53
  ----------------------------------
54
+ AllShortestPaths
55
+ Finds all the shortest paths between two nodes.
49
56
  FloydWarshall
50
57
  Computes the pathlength between all pairs of nodes in a network.
51
58
  PathsAllinOne
52
59
  Returns pathlength and betweenness. Finds all shortest paths and cycles.
53
- AllShortestPaths
54
- Finds all the shortest paths between two nodes.
55
60
 
56
61
  COMMUNITIES, COMPONENTS, K-CORES, ...
57
62
  -------------------------------------
@@ -59,12 +64,12 @@ AssortativityMatrix
59
64
  Returns the assortativity matrix of network given a partition of nodes.
60
65
  ConnectedComponents
61
66
  Finds all the connected components in a network out of a distance matrix.
62
- Modularity
63
- Computes the Newman modularity given a partition of nodes.
64
67
  K_Core
65
68
  Finds the K-core of a network with degree k >= kmin.
66
69
  K_Shells
67
70
  Returns the K-shells of a network for all k from kmin to kmax.
71
+ Modularity
72
+ Computes the Newman modularity given a partition of nodes.
68
73
 
69
74
  ROLES OF NODES IN NETWORKS WITH MODULAR ORGANIZATION
70
75
  ----------------------------------------------------
@@ -92,7 +97,6 @@ Hubness_GA
92
97
 
93
98
  """
94
99
  # Standard library imports
95
- import types
96
100
  # Third party imports
97
101
  import numpy as np
98
102
  # Local imports
@@ -101,6 +105,45 @@ from . import tools
101
105
 
102
106
  ############################################################################
103
107
  """CONNECTIVITY AND DEGREE STATISTICS"""
108
+ def is_directed(adjmatrix):
109
+ """Checks whether a (weighted) matrix represents a directed or undirected graph.
110
+
111
+ Parameters
112
+ ----------
113
+ adjmatrix : ndarray of rank-2
114
+ A (weighted) adjacency matrix of a network. Weighted links are ignored.
115
+
116
+ Returns
117
+ -------
118
+ out : boolean
119
+ True if `adjmatrix` represents a directed graph, and False if `adjmatrix`
120
+ represents an undirected graph.
121
+ """
122
+ mask = adjmatrix.astype(bool)
123
+ out = (mask ^ mask.T).any()
124
+ return out.item()
125
+
126
+ def is_symmetric(adjmatrix):
127
+ """Checks whether a (weighted) matrix is symmetric or not.
128
+
129
+ Parameters
130
+ ----------
131
+ adjmatrix : ndarray of rank-2
132
+ A (weighted) adjacency matrix of a network.
133
+
134
+ Returns
135
+ -------
136
+ out : boolean
137
+ True if `adjmatrix` represents a (weighted) undirected graph whose
138
+ link weights are all symmetric. False if any link weight `adjmatrix[i,j]`
139
+ differs from its reciprocal `adjmatrix[j,i]`. This can happen both if
140
+ the network is undirected but weights are not symmetrics, or if the
141
+ network is directed.
142
+ """
143
+ out = np.allclose(adjmatrix, adjmatrix.T)
144
+ return out
145
+
146
+
104
147
  def Density(adjmatrix):
105
148
  """Returns the density of links in a network.
106
149