Skip to content

gnm.defaults

defaults

Default data and resources for generative network models.

This subpackage provides access to pre-packaged datasets that can be used for experimenting with generative network models without requiring external data. These defaults include:

  • Distance matrices: Physical distances between brain regions
  • Coordinates: 3D spatial positions of brain regions
  • Binary networks: Example binary connectivity networks (presence/absence of connections)
  • Weighted networks: Example weighted connectivity networks

The module provides simple functions to list available datasets and load them with appropriate tensor formats for immediate use in network modeling.

Functions:

Name Description
display_available_defaults

Show all available default datasets

get_distance_matrix

Load a default distance matrix

get_coordinates

Load default 3D coordinates

get_binary_network

Load a default binary network

get_weighted_network

Load a default weighted network

gnm.defaults.display_available_defaults()

Print all available default datasets that can be loaded.

This function prints a formatted list of all available default datasets organized by category:

  • Distance matrices
  • Coordinates
  • Binary networks
  • Weighted networks

Each category displays the names of available files that can be loaded with the corresponding get_* functions.

Examples:

>>> from gnm.defaults import display_available_defaults
>>> display_available_defaults()
=== Distance matrices ===
AAL_DISTANCES
=== Coordinates ===
AAL_COORDINATES
=== Binary networks ===
CALM_BINARY_CONSENSUS
=== Weighted networks ===
CALM_WEIGHTED_CONSENSUS
See Also
Source code in src/gnm/defaults/get_defaults.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def display_available_defaults():
    r"""Print all available default datasets that can be loaded.

    This function prints a formatted list of all available default datasets organized
    by category:

    - Distance matrices
    - Coordinates
    - Binary networks
    - Weighted networks

    Each category displays the names of available files that can be loaded with the
    corresponding get_* functions.

    Examples:
        >>> from gnm.defaults import display_available_defaults
        >>> display_available_defaults()
        === Distance matrices ===
        AAL_DISTANCES
        === Coordinates ===
        AAL_COORDINATES
        === Binary networks ===
        CALM_BINARY_CONSENSUS
        === Weighted networks ===
        CALM_WEIGHTED_CONSENSUS

    See Also:
        - [`defaults.get_distance_matrix`][gnm.defaults.get_distance_matrix]: Load a specific distance matrix
        - [`defaults.get_coordinates`][gnm.defaults.get_coordinates]: Load specific coordinate data
        - [`defaults.get_binary_network`][gnm.defaults.get_binary_network]: Load a specific binary network
        - [`defaults.get_weighted_network`][gnm.defaults.get_weighted_network]: Load a specific weighted network
    """

    print("=== Distance matrices ===")
    distance_matrices_path = os.path.join(BASE_PATH, "distance_matrices")
    for file in os.listdir(distance_matrices_path):
        print(file.split(".")[0])
    print("=== Coordinates ===")
    coordinates_path = os.path.join(BASE_PATH, "coordinates")
    for file in os.listdir(coordinates_path):
        print(file.split(".")[0])
    print("=== Binary networks ===")
    binary_consensus_networks_path = os.path.join(BASE_PATH, "binary_networks")
    for file in os.listdir(binary_consensus_networks_path):
        print(file.split(".")[0])
    print("=== Weighted networks ===")
    weighted_consensus_networks_path = os.path.join(BASE_PATH, "weighted_networks")
    for file in os.listdir(weighted_consensus_networks_path):
        print(file.split(".")[0])

gnm.defaults.get_distance_matrix(name=None, device=None)

Load a default distance matrix.

Provides access to pre-packaged distance matrices that represent physical distances between brain regions in standard atlas parcellations.

Available distance matrices:

  • AAL_DISTANCES: Distance matrix for the Automated Anatomical Labeling atlas

Parameters:

Name Type Description Default
name Optional[str]

Name of the distance matrix to load. If unspecified, the AAL_DISTANCES distance matrix is loaded.

None
device Optional[device]

Device to load the distance matrix on. If unspecified, automatically uses CUDA if available, otherwise CPU.

None

Returns:

Type Description
Float[Tensor, 'num_nodes num_nodes']

A Pytorch tensor containing the requested distance matrix with shape [num_nodes, num_nodes].

Examples:

>>> from gnm.defaults import get_distance_matrix
>>> # Load default distance matrix
>>> dist_matrix = get_distance_matrix()
>>> # Load a specific distance matrix and place on CPU
>>> import torch
>>> dist_matrix = get_distance_matrix(name="AAL_DISTANCES", device=torch.device("cpu"))
>>> dist_matrix.shape
torch.Size([90, 90])
See Also
Source code in src/gnm/defaults/get_defaults.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
@jaxtyped(typechecker=typechecked)
def get_distance_matrix(
    name: Optional[str] = None, device: Optional[torch.device] = None
) -> Float[torch.Tensor, "num_nodes num_nodes"]:
    r"""Load a default distance matrix.

    Provides access to pre-packaged distance matrices that represent physical distances
    between brain regions in standard atlas parcellations.

    Available distance matrices:

    - AAL_DISTANCES: Distance matrix for the Automated Anatomical Labeling atlas

    Args:
        name: Name of the distance matrix to load. If unspecified,
            the AAL_DISTANCES distance matrix is loaded.
        device: Device to load the distance matrix on. If unspecified,
            automatically uses CUDA if available, otherwise CPU.

    Returns:
        A Pytorch tensor containing the requested distance matrix with shape [num_nodes, num_nodes].

    Examples:
        >>> from gnm.defaults import get_distance_matrix
        >>> # Load default distance matrix
        >>> dist_matrix = get_distance_matrix()
        >>> # Load a specific distance matrix and place on CPU
        >>> import torch
        >>> dist_matrix = get_distance_matrix(name="AAL_DISTANCES", device=torch.device("cpu"))
        >>> dist_matrix.shape
        torch.Size([90, 90])

    See Also:
        - [`defaults.get_coordinates`][gnm.defaults.get_coordinates]: For loading spatial coordinates of nodes
        - [`defaults.get_binary_network`][gnm.defaults.get_binary_network]: For loading binary connectivity networks
    """
    if device is None:
        device = DEVICE

    if name is None:
        name = "AAL_DISTANCES"

    distance_matrix = torch.load(
        os.path.join(BASE_PATH, f"distance_matrices/{name.split('.')[0].upper()}.pt"),
        map_location=device,
        weights_only=True,
    )

    weighted_checks(distance_matrix.unsqueeze(0))

    return distance_matrix

gnm.defaults.get_coordinates(name=None, device=None)

Load a default set of 3D coordinates.

Provides access to pre-packaged coordinate sets that represent the spatial positions of brain regions in standard atlas parcellations.

Available coordinate sets:

  • AAL_COORDINATES: 3D coordinates for the Automated Anatomical Labeling atlas

Parameters:

Name Type Description Default
name Optional[str]

Name of the coordinates to load. If unspecified, the AAL_COORDINATES coordinates are loaded.

None
device Optional[device]

Device to load the coordinates on. If unspecified, automatically uses CUDA if available, otherwise CPU.

None

Returns:

Type Description
Float[Tensor, 'num_nodes 3']

A tensor containing the requested coordinates with shape [num_nodes, 3].

Examples:

>>> from gnm.defaults import get_coordinates
>>> # Load default coordinates
>>> coords = get_coordinates()
>>> # Load a specific coordinate set
>>> coords = get_coordinates(name="AAL_COORDINATES")
>>> coords.shape
torch.Size([90, 3])
See Also
Source code in src/gnm/defaults/get_defaults.py
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
@jaxtyped(typechecker=typechecked)
def get_coordinates(
    name: Optional[str] = None, device: Optional[torch.device] = None
) -> Float[torch.Tensor, "num_nodes 3"]:
    r"""Load a default set of 3D coordinates.

    Provides access to pre-packaged coordinate sets that represent the spatial positions
    of brain regions in standard atlas parcellations.

    Available coordinate sets:

    - AAL_COORDINATES: 3D coordinates for the Automated Anatomical Labeling atlas

    Args:
        name: Name of the coordinates to load. If unspecified,
            the AAL_COORDINATES coordinates are loaded.
        device: Device to load the coordinates on. If unspecified,
            automatically uses CUDA if available, otherwise CPU.

    Returns:
        A tensor containing the requested coordinates with shape [num_nodes, 3].

    Examples:
        >>> from gnm.defaults import get_coordinates
        >>> # Load default coordinates
        >>> coords = get_coordinates()
        >>> # Load a specific coordinate set
        >>> coords = get_coordinates(name="AAL_COORDINATES")
        >>> coords.shape
        torch.Size([90, 3])

    See Also:
        - [`defaults.get_distance_matrix`][gnm.defaults.get_distance_matrix]: For loading distance matrices between nodes
    """
    if device is None:
        device = DEVICE

    if name is None:
        name = "AAL_COORDINATES"

    return torch.load(
        os.path.join(BASE_PATH, f"coordinates/{name.split('.')[0].upper()}.pt"),
        map_location=device,
        weights_only=True,
    )

gnm.defaults.get_binary_network(name=None, device=None)

Load a default binary network.

Provides access to pre-packaged binary networks that represent structural connectivity with edges indicated as either present (1) or absent (0).

Available binary networks:

  • CALM_BINARY_CONSENSUS: Binary consensus network from the CALM dataset

Parameters:

Name Type Description Default
name Optional[str]

Name of the binary network to load. If unspecified, the CALM_BINARY_CONSENSUS binary network is loaded.

None
device Optional[device]

Device to load the binary network on. If unspecified, automatically uses CUDA if available, otherwise CPU.

None

Returns:

Type Description
Float[Tensor, 'dataset_size num_nodes num_nodes']

A tensor containing the requested binary network with shape

Float[Tensor, 'dataset_size num_nodes num_nodes']

[dataset_size, num_nodes, num_nodes].

Examples:

>>> from gnm.defaults import get_binary_network
>>> # Load default binary network
>>> bin_net = get_binary_network()
>>> # Load a specific binary network
>>> bin_net = get_binary_network(name="CALM_BINARY_CONSENSUS")
>>> bin_net.shape
torch.Size([1, 90, 90])
See Also
Source code in src/gnm/defaults/get_defaults.py
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
@jaxtyped(typechecker=typechecked)
def get_binary_network(
    name: Optional[str] = None, device: Optional[torch.device] = None
) -> Float[torch.Tensor, "dataset_size num_nodes num_nodes"]:
    r"""Load a default binary network.

    Provides access to pre-packaged binary networks that represent structural
    connectivity with edges indicated as either present (1) or absent (0).

    Available binary networks:

    - CALM_BINARY_CONSENSUS: Binary consensus network from the CALM dataset

    Args:
        name: Name of the binary network to load. If unspecified,
            the CALM_BINARY_CONSENSUS binary network is loaded.
        device: Device to load the binary network on. If unspecified,
            automatically uses CUDA if available, otherwise CPU.

    Returns:
        A tensor containing the requested binary network with shape
        [dataset_size, num_nodes, num_nodes].

    Examples:
        >>> from gnm.defaults import get_binary_network
        >>> # Load default binary network
        >>> bin_net = get_binary_network()
        >>> # Load a specific binary network
        >>> bin_net = get_binary_network(name="CALM_BINARY_CONSENSUS")
        >>> bin_net.shape
        torch.Size([1, 90, 90])

    See Also:
        - [`defaults.get_weighted_network`][gnm.defaults.get_weighted_network]: For loading weighted connectivity networks
        - [`utils.binary_checks`][gnm.utils.binary_checks]: For validating binary networks
    """
    if device is None:
        device = DEVICE

    if name is None:
        name = "CALM_BINARY_CONSENSUS"

    binary_networks = torch.load(
        os.path.join(BASE_PATH, f"binary_networks/{name.split('.')[0].upper()}.pt"),
        map_location=device,
        weights_only=True,
    )

    binary_checks(binary_networks)

    return binary_networks

gnm.defaults.get_weighted_network(name=None, device=None)

Load a default weighted network.

Provides access to pre-packaged weighted networks that represent structural connectivity with connections represented by continuous weights.

Available weighted networks:

  • CALM_WEIGHTED_CONSENSUS: Weighted consensus network from the CALM dataset

Parameters:

Name Type Description Default
name Optional[str]

Name of the weighted network to load. If unspecified, the CALM_WEIGHTED_CONSENSUS weighted network is loaded.

None
device Optional[device]

Device to load the weighted network on. If unspecified, automatically uses CUDA if available, otherwise CPU.

None

Returns:

Type Description
Float[Tensor, 'dataset_size num_nodes num_nodes']

A tensor containing the requested weighted network with shape

Float[Tensor, 'dataset_size num_nodes num_nodes']

[dataset_size, num_nodes, num_nodes].

Examples:

>>> from gnm.defaults import get_weighted_network
>>> # Load default weighted network
>>> wt_net = get_weighted_network()
>>> # Load a specific weighted network
>>> wt_net = get_weighted_network(name="CALM_WEIGHTED_CONSENSUS")
>>> wt_net.shape
torch.Size([1, 90, 90])
See Also
Source code in src/gnm/defaults/get_defaults.py
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
@jaxtyped(typechecker=typechecked)
def get_weighted_network(
    name: Optional[str] = None, device: Optional[torch.device] = None
) -> Float[torch.Tensor, "dataset_size num_nodes num_nodes"]:
    r"""Load a default weighted network.

    Provides access to pre-packaged weighted networks that represent structural
    connectivity with connections represented by continuous weights.

    Available weighted networks:

    - CALM_WEIGHTED_CONSENSUS: Weighted consensus network from the CALM dataset

    Args:
        name: Name of the weighted network to load. If unspecified,
            the CALM_WEIGHTED_CONSENSUS weighted network is loaded.
        device: Device to load the weighted network on. If unspecified,
            automatically uses CUDA if available, otherwise CPU.

    Returns:
        A tensor containing the requested weighted network with shape
        [dataset_size, num_nodes, num_nodes].

    Examples:
        >>> from gnm.defaults import get_weighted_network
        >>> # Load default weighted network
        >>> wt_net = get_weighted_network()
        >>> # Load a specific weighted network
        >>> wt_net = get_weighted_network(name="CALM_WEIGHTED_CONSENSUS")
        >>> wt_net.shape
        torch.Size([1, 90, 90])

    See Also:
        - [`defaults.get_binary_network`][gnm.defaults.get_binary_network]: For loading binary connectivity networks
        - [`utils.weighted_checks`][gnm.utils.weighted_checks]: For validating weighted networks
    """
    if device is None:
        device = DEVICE

    if name is None:
        name = "CALM_WEIGHTED_CONSENSUS"

    weighted_networks = torch.load(
        os.path.join(BASE_PATH, f"weighted_networks/{name.split('.')[0].upper()}.pt"),
        map_location=device,
        weights_only=True,
    )

    weighted_checks(weighted_networks)

    return weighted_networks