mlnlib 0.2.35__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.
- mlnlib-0.2.35/LICENSE.md +40 -0
- mlnlib-0.2.35/PKG-INFO +126 -0
- mlnlib-0.2.35/README.md +106 -0
- mlnlib-0.2.35/pyproject.toml +30 -0
- mlnlib-0.2.35/setup.cfg +4 -0
- mlnlib-0.2.35/src/mlnlib/mln.py +1684 -0
- mlnlib-0.2.35/src/mlnlib/preparation.py +517 -0
- mlnlib-0.2.35/src/mlnlib.egg-info/PKG-INFO +126 -0
- mlnlib-0.2.35/src/mlnlib.egg-info/SOURCES.txt +10 -0
- mlnlib-0.2.35/src/mlnlib.egg-info/dependency_links.txt +1 -0
- mlnlib-0.2.35/src/mlnlib.egg-info/requires.txt +6 -0
- mlnlib-0.2.35/src/mlnlib.egg-info/top_level.txt +1 -0
mlnlib-0.2.35/LICENSE.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
### MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Eszter Bokányi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
In any academic work, the package should be cited as follows:
|
|
16
|
+
|
|
17
|
+
Bokányi, E., Kazmina, Y., & de Jong, R. (2023). POPNET MultiLayerNetwork Python Class (Version v2.0) [Computer software]. Zenodo. https://doi.org/10.5281/zenodo.10838865
|
|
18
|
+
|
|
19
|
+
The BibTeX entry for the citation is:
|
|
20
|
+
```
|
|
21
|
+
@software{bokanyi2023popnet,
|
|
22
|
+
title = {{{POPNET MultiLayerNetwork Python Class}}},
|
|
23
|
+
author = {Bok\'anyi, Eszter and Kazmina, Yuliia and family=Jong, given=Rachel, prefix=de, useprefix=true},
|
|
24
|
+
date = {2023},
|
|
25
|
+
doi = {10.5281/zenodo.10838865},
|
|
26
|
+
url = {https://zenodo.org/doi/10.5281/zenodo.10838865},
|
|
27
|
+
urldate = {2024-11-11},
|
|
28
|
+
abstract = {Library for working with large multilayer networks by the POPNET group.},
|
|
29
|
+
organization = {Zenodo},
|
|
30
|
+
version = {v2.0}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
35
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
36
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
37
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
38
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
39
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
40
|
+
SOFTWARE.
|
mlnlib-0.2.35/PKG-INFO
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mlnlib
|
|
3
|
+
Version: 0.2.35
|
|
4
|
+
Summary: Memory-efficient library for loading and working with large unweighted multilayer networks.
|
|
5
|
+
Author-email: Eszter Bokányi <e.bokanyi@uva.nl>
|
|
6
|
+
Project-URL: Homepage, https://github.com/popnet-io/popnet_mln
|
|
7
|
+
Project-URL: Issues, https://github.com/popnet-io/popnet_mln/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE.md
|
|
14
|
+
Requires-Dist: pandas>=1.4.4
|
|
15
|
+
Requires-Dist: polars>=0.20.6
|
|
16
|
+
Requires-Dist: numpy>=1.20.3
|
|
17
|
+
Requires-Dist: python-igraph>=0.9.9
|
|
18
|
+
Requires-Dist: networkx>=3.0
|
|
19
|
+
Requires-Dist: scipy>=1.10.1
|
|
20
|
+
|
|
21
|
+
# MLN
|
|
22
|
+
|
|
23
|
+
Library for working with large multilayer networks.
|
|
24
|
+
|
|
25
|
+
Authors:
|
|
26
|
+
* Eszter Bokányi
|
|
27
|
+
* Rachel de Jong
|
|
28
|
+
* Yuliia Kazmina
|
|
29
|
+
|
|
30
|
+
Contact:
|
|
31
|
+
`e.bokanyi@uva.nl`
|
|
32
|
+
|
|
33
|
+
The code is distirbuted under the MIT Licence and should be properly attributed and cited upon reuse - see LICENCE.md for details.
|
|
34
|
+
|
|
35
|
+
## MultiLayeredNetwork class
|
|
36
|
+
|
|
37
|
+
The `MultiLayeredNetwork` class from `src/mln.py` contains methods and attributes to work with a large
|
|
38
|
+
multilayer network using different edge types and layers efficiently.
|
|
39
|
+
|
|
40
|
+
The network has to be unweighted, but can be directed.
|
|
41
|
+
|
|
42
|
+
The network is either loaded from an already saved sparse matrix and a
|
|
43
|
+
node attribute CSV using the following attributes:
|
|
44
|
+
* adjacency_file: scipy.sparse.csr matrix saved as an `npz` file
|
|
45
|
+
* node_attribute_file: CSV to be loaded as a pd.DataFrame, rows in
|
|
46
|
+
order of previous matrix rows should contain a column called
|
|
47
|
+
"label" that is the primary key for node identification
|
|
48
|
+
|
|
49
|
+
Or in-memory objects can also be given to the constructor:
|
|
50
|
+
* adjacency_matrix: scipy.sparse.csr matrix
|
|
51
|
+
* node_attribute_dataframe: pd.DataFrame, rows in order of previous
|
|
52
|
+
matrix rows
|
|
53
|
+
|
|
54
|
+
Pre-stored files with standard names can be called with the shorthand:
|
|
55
|
+
* from_library: str
|
|
56
|
+
Then the npz and csv.gz files will be read from the
|
|
57
|
+
library_path/from_library folder similarly to the first method.
|
|
58
|
+
|
|
59
|
+
After loading these two key elements, class attributes and methods work
|
|
60
|
+
the same.
|
|
61
|
+
|
|
62
|
+
The adjacency matrix self.A is stored in a `scipy.sparse.csr_matrix`
|
|
63
|
+
class, that only saves nonzero elements, and on which scipy csgraph
|
|
64
|
+
algorithms run. People are indexed from 0 to N-1, where N is the total
|
|
65
|
+
number of nodes in this network.
|
|
66
|
+
|
|
67
|
+
Two dictionaries mapping user id (label) to integer node ids (NID) and
|
|
68
|
+
back are created based on the node attribute file in the
|
|
69
|
+
`self.map_label_to_nid` and `self.map_nid_to_label` attributes. These
|
|
70
|
+
mappings only refer to one instance of the class - if you create a
|
|
71
|
+
subgraph (see later) the coding is going to change, and the mapping
|
|
72
|
+
should be found in the new instance that represents the subgraph.
|
|
73
|
+
|
|
74
|
+
The adjacency matrix contains integers that encode linktypes if viewed
|
|
75
|
+
as binary numbers. Each possible linktype is assigned an integer of the
|
|
76
|
+
form 2\**i. For example, if both type i and type j edge is present
|
|
77
|
+
between two people, then the corresponding value in self.A would be
|
|
78
|
+
2\**i+2\**j. It means that we can test for a certain edgetype using
|
|
79
|
+
bitwise AND operation very cheaply. E.g. a certain element of self.A is
|
|
80
|
+
7, then 7=1+2+4 which means that edgetypes 0,1, and 2 are present
|
|
81
|
+
between the two people, and 7&2 = 2 in Python (it behaves like a mask
|
|
82
|
+
111 & 010 = 010).
|
|
83
|
+
|
|
84
|
+
scipy.csr matrices are cheap to slice rowwise, but beware, some
|
|
85
|
+
operation that seem straightforward in numpy might be costly (e.g.
|
|
86
|
+
getting random coordinates after each other or colwise slicing)! If
|
|
87
|
+
something is running too long, consult the scipy reference manual.
|
|
88
|
+
|
|
89
|
+
Node attributes are stored in `self.node_attributes` which is a
|
|
90
|
+
`pandas.DataFrame`. It is possible to store human-readable or longer
|
|
91
|
+
column names in `self.attribute_colnames`, and code tables for used
|
|
92
|
+
variables in `self.attribute_code_table`, keys of that variable are the
|
|
93
|
+
colnames in the values of `self.attribute_colnames`.
|
|
94
|
+
|
|
95
|
+
Example loadings:
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
# FROM FILES
|
|
99
|
+
# import custom class for the network from mln
|
|
100
|
+
import MultiLayeredNetwork
|
|
101
|
+
|
|
102
|
+
# read the whole network
|
|
103
|
+
popnet = MultiLayeredNetwork(
|
|
104
|
+
adjacency_file = 'path_to/adjacency.npz',
|
|
105
|
+
node_attribute_file = 'path_to/attributes.csv.gz'
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
# FROM MEMORY
|
|
109
|
+
# import custom class for the network
|
|
110
|
+
from mln import MultiLayeredNetwork
|
|
111
|
+
|
|
112
|
+
# read the whole network
|
|
113
|
+
popnet = MultiLayeredNetwork(
|
|
114
|
+
adjacency_matrix = A, # NxN scipy.sparse.csr_matrix
|
|
115
|
+
node_attribute_file = df # pd.DataFrame containing N rows in the order of the matrix
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
# FROM LIBRARY
|
|
119
|
+
# import custom class for the network
|
|
120
|
+
from mln import MultiLayeredNetwork
|
|
121
|
+
|
|
122
|
+
# read the whole network
|
|
123
|
+
popnet = MultiLayeredNetwork(
|
|
124
|
+
from_library="full"
|
|
125
|
+
)
|
|
126
|
+
```
|
mlnlib-0.2.35/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# MLN
|
|
2
|
+
|
|
3
|
+
Library for working with large multilayer networks.
|
|
4
|
+
|
|
5
|
+
Authors:
|
|
6
|
+
* Eszter Bokányi
|
|
7
|
+
* Rachel de Jong
|
|
8
|
+
* Yuliia Kazmina
|
|
9
|
+
|
|
10
|
+
Contact:
|
|
11
|
+
`e.bokanyi@uva.nl`
|
|
12
|
+
|
|
13
|
+
The code is distirbuted under the MIT Licence and should be properly attributed and cited upon reuse - see LICENCE.md for details.
|
|
14
|
+
|
|
15
|
+
## MultiLayeredNetwork class
|
|
16
|
+
|
|
17
|
+
The `MultiLayeredNetwork` class from `src/mln.py` contains methods and attributes to work with a large
|
|
18
|
+
multilayer network using different edge types and layers efficiently.
|
|
19
|
+
|
|
20
|
+
The network has to be unweighted, but can be directed.
|
|
21
|
+
|
|
22
|
+
The network is either loaded from an already saved sparse matrix and a
|
|
23
|
+
node attribute CSV using the following attributes:
|
|
24
|
+
* adjacency_file: scipy.sparse.csr matrix saved as an `npz` file
|
|
25
|
+
* node_attribute_file: CSV to be loaded as a pd.DataFrame, rows in
|
|
26
|
+
order of previous matrix rows should contain a column called
|
|
27
|
+
"label" that is the primary key for node identification
|
|
28
|
+
|
|
29
|
+
Or in-memory objects can also be given to the constructor:
|
|
30
|
+
* adjacency_matrix: scipy.sparse.csr matrix
|
|
31
|
+
* node_attribute_dataframe: pd.DataFrame, rows in order of previous
|
|
32
|
+
matrix rows
|
|
33
|
+
|
|
34
|
+
Pre-stored files with standard names can be called with the shorthand:
|
|
35
|
+
* from_library: str
|
|
36
|
+
Then the npz and csv.gz files will be read from the
|
|
37
|
+
library_path/from_library folder similarly to the first method.
|
|
38
|
+
|
|
39
|
+
After loading these two key elements, class attributes and methods work
|
|
40
|
+
the same.
|
|
41
|
+
|
|
42
|
+
The adjacency matrix self.A is stored in a `scipy.sparse.csr_matrix`
|
|
43
|
+
class, that only saves nonzero elements, and on which scipy csgraph
|
|
44
|
+
algorithms run. People are indexed from 0 to N-1, where N is the total
|
|
45
|
+
number of nodes in this network.
|
|
46
|
+
|
|
47
|
+
Two dictionaries mapping user id (label) to integer node ids (NID) and
|
|
48
|
+
back are created based on the node attribute file in the
|
|
49
|
+
`self.map_label_to_nid` and `self.map_nid_to_label` attributes. These
|
|
50
|
+
mappings only refer to one instance of the class - if you create a
|
|
51
|
+
subgraph (see later) the coding is going to change, and the mapping
|
|
52
|
+
should be found in the new instance that represents the subgraph.
|
|
53
|
+
|
|
54
|
+
The adjacency matrix contains integers that encode linktypes if viewed
|
|
55
|
+
as binary numbers. Each possible linktype is assigned an integer of the
|
|
56
|
+
form 2\**i. For example, if both type i and type j edge is present
|
|
57
|
+
between two people, then the corresponding value in self.A would be
|
|
58
|
+
2\**i+2\**j. It means that we can test for a certain edgetype using
|
|
59
|
+
bitwise AND operation very cheaply. E.g. a certain element of self.A is
|
|
60
|
+
7, then 7=1+2+4 which means that edgetypes 0,1, and 2 are present
|
|
61
|
+
between the two people, and 7&2 = 2 in Python (it behaves like a mask
|
|
62
|
+
111 & 010 = 010).
|
|
63
|
+
|
|
64
|
+
scipy.csr matrices are cheap to slice rowwise, but beware, some
|
|
65
|
+
operation that seem straightforward in numpy might be costly (e.g.
|
|
66
|
+
getting random coordinates after each other or colwise slicing)! If
|
|
67
|
+
something is running too long, consult the scipy reference manual.
|
|
68
|
+
|
|
69
|
+
Node attributes are stored in `self.node_attributes` which is a
|
|
70
|
+
`pandas.DataFrame`. It is possible to store human-readable or longer
|
|
71
|
+
column names in `self.attribute_colnames`, and code tables for used
|
|
72
|
+
variables in `self.attribute_code_table`, keys of that variable are the
|
|
73
|
+
colnames in the values of `self.attribute_colnames`.
|
|
74
|
+
|
|
75
|
+
Example loadings:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
# FROM FILES
|
|
79
|
+
# import custom class for the network from mln
|
|
80
|
+
import MultiLayeredNetwork
|
|
81
|
+
|
|
82
|
+
# read the whole network
|
|
83
|
+
popnet = MultiLayeredNetwork(
|
|
84
|
+
adjacency_file = 'path_to/adjacency.npz',
|
|
85
|
+
node_attribute_file = 'path_to/attributes.csv.gz'
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
# FROM MEMORY
|
|
89
|
+
# import custom class for the network
|
|
90
|
+
from mln import MultiLayeredNetwork
|
|
91
|
+
|
|
92
|
+
# read the whole network
|
|
93
|
+
popnet = MultiLayeredNetwork(
|
|
94
|
+
adjacency_matrix = A, # NxN scipy.sparse.csr_matrix
|
|
95
|
+
node_attribute_file = df # pd.DataFrame containing N rows in the order of the matrix
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
# FROM LIBRARY
|
|
99
|
+
# import custom class for the network
|
|
100
|
+
from mln import MultiLayeredNetwork
|
|
101
|
+
|
|
102
|
+
# read the whole network
|
|
103
|
+
popnet = MultiLayeredNetwork(
|
|
104
|
+
from_library="full"
|
|
105
|
+
)
|
|
106
|
+
```
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mlnlib"
|
|
7
|
+
version = "0.2.35"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Eszter Bokányi", email="e.bokanyi@uva.nl" },
|
|
10
|
+
]
|
|
11
|
+
description = "Memory-efficient library for loading and working with large unweighted multilayer networks."
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.8"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
dependencies = [
|
|
20
|
+
"pandas>=1.4.4",
|
|
21
|
+
"polars>=0.20.6",
|
|
22
|
+
"numpy>=1.20.3",
|
|
23
|
+
"python-igraph>=0.9.9",
|
|
24
|
+
"networkx>=3.0",
|
|
25
|
+
"scipy>=1.10.1"
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/popnet-io/popnet_mln"
|
|
30
|
+
Issues = "https://github.com/popnet-io/popnet_mln/issues"
|
mlnlib-0.2.35/setup.cfg
ADDED