vbi 0.1.3__cp310-cp310-manylinux2014_x86_64.whl

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.
Files changed (121) hide show
  1. vbi/__init__.py +37 -0
  2. vbi/_version.py +17 -0
  3. vbi/dataset/__init__.py +0 -0
  4. vbi/dataset/connectivity_84/centers.txt +84 -0
  5. vbi/dataset/connectivity_84/centres.txt +84 -0
  6. vbi/dataset/connectivity_84/cortical.txt +84 -0
  7. vbi/dataset/connectivity_84/tract_lengths.txt +84 -0
  8. vbi/dataset/connectivity_84/weights.txt +84 -0
  9. vbi/dataset/connectivity_88/Aud_88.txt +88 -0
  10. vbi/dataset/connectivity_88/Bold.npz +0 -0
  11. vbi/dataset/connectivity_88/Labels.txt +17 -0
  12. vbi/dataset/connectivity_88/Region_labels.txt +88 -0
  13. vbi/dataset/connectivity_88/tract_lengths.txt +88 -0
  14. vbi/dataset/connectivity_88/weights.txt +88 -0
  15. vbi/feature_extraction/__init__.py +1 -0
  16. vbi/feature_extraction/calc_features.py +293 -0
  17. vbi/feature_extraction/features.json +535 -0
  18. vbi/feature_extraction/features.py +2124 -0
  19. vbi/feature_extraction/features_settings.py +374 -0
  20. vbi/feature_extraction/features_utils.py +1357 -0
  21. vbi/feature_extraction/infodynamics.jar +0 -0
  22. vbi/feature_extraction/utility.py +507 -0
  23. vbi/inference.py +98 -0
  24. vbi/models/__init__.py +0 -0
  25. vbi/models/cpp/__init__.py +0 -0
  26. vbi/models/cpp/_src/__init__.py +0 -0
  27. vbi/models/cpp/_src/__pycache__/mpr_sde.cpython-310.pyc +0 -0
  28. vbi/models/cpp/_src/_do.cpython-310-x86_64-linux-gnu.so +0 -0
  29. vbi/models/cpp/_src/_jr_sdde.cpython-310-x86_64-linux-gnu.so +0 -0
  30. vbi/models/cpp/_src/_jr_sde.cpython-310-x86_64-linux-gnu.so +0 -0
  31. vbi/models/cpp/_src/_km_sde.cpython-310-x86_64-linux-gnu.so +0 -0
  32. vbi/models/cpp/_src/_mpr_sde.cpython-310-x86_64-linux-gnu.so +0 -0
  33. vbi/models/cpp/_src/_vep.cpython-310-x86_64-linux-gnu.so +0 -0
  34. vbi/models/cpp/_src/_wc_ode.cpython-310-x86_64-linux-gnu.so +0 -0
  35. vbi/models/cpp/_src/bold.hpp +303 -0
  36. vbi/models/cpp/_src/do.hpp +167 -0
  37. vbi/models/cpp/_src/do.i +17 -0
  38. vbi/models/cpp/_src/do.py +467 -0
  39. vbi/models/cpp/_src/do_wrap.cxx +12811 -0
  40. vbi/models/cpp/_src/jr_sdde.hpp +352 -0
  41. vbi/models/cpp/_src/jr_sdde.i +19 -0
  42. vbi/models/cpp/_src/jr_sdde.py +688 -0
  43. vbi/models/cpp/_src/jr_sdde_wrap.cxx +18718 -0
  44. vbi/models/cpp/_src/jr_sde.hpp +264 -0
  45. vbi/models/cpp/_src/jr_sde.i +17 -0
  46. vbi/models/cpp/_src/jr_sde.py +470 -0
  47. vbi/models/cpp/_src/jr_sde_wrap.cxx +13406 -0
  48. vbi/models/cpp/_src/km_sde.hpp +158 -0
  49. vbi/models/cpp/_src/km_sde.i +19 -0
  50. vbi/models/cpp/_src/km_sde.py +671 -0
  51. vbi/models/cpp/_src/km_sde_wrap.cxx +17367 -0
  52. vbi/models/cpp/_src/makefile +52 -0
  53. vbi/models/cpp/_src/mpr_sde.hpp +327 -0
  54. vbi/models/cpp/_src/mpr_sde.i +19 -0
  55. vbi/models/cpp/_src/mpr_sde.py +711 -0
  56. vbi/models/cpp/_src/mpr_sde_wrap.cxx +18618 -0
  57. vbi/models/cpp/_src/utility.hpp +307 -0
  58. vbi/models/cpp/_src/vep.hpp +171 -0
  59. vbi/models/cpp/_src/vep.i +16 -0
  60. vbi/models/cpp/_src/vep.py +464 -0
  61. vbi/models/cpp/_src/vep_wrap.cxx +12968 -0
  62. vbi/models/cpp/_src/wc_ode.hpp +294 -0
  63. vbi/models/cpp/_src/wc_ode.i +19 -0
  64. vbi/models/cpp/_src/wc_ode.py +686 -0
  65. vbi/models/cpp/_src/wc_ode_wrap.cxx +24263 -0
  66. vbi/models/cpp/damp_oscillator.py +143 -0
  67. vbi/models/cpp/jansen_rit.py +543 -0
  68. vbi/models/cpp/km.py +187 -0
  69. vbi/models/cpp/mpr.py +289 -0
  70. vbi/models/cpp/vep.py +150 -0
  71. vbi/models/cpp/wc.py +216 -0
  72. vbi/models/cupy/__init__.py +0 -0
  73. vbi/models/cupy/bold.py +111 -0
  74. vbi/models/cupy/ghb.py +284 -0
  75. vbi/models/cupy/jansen_rit.py +473 -0
  76. vbi/models/cupy/km.py +224 -0
  77. vbi/models/cupy/mpr.py +475 -0
  78. vbi/models/cupy/mpr_modified_bold.py +12 -0
  79. vbi/models/cupy/utils.py +184 -0
  80. vbi/models/numba/__init__.py +0 -0
  81. vbi/models/numba/_ww_EI.py +444 -0
  82. vbi/models/numba/damp_oscillator.py +162 -0
  83. vbi/models/numba/ghb.py +208 -0
  84. vbi/models/numba/mpr.py +383 -0
  85. vbi/models/pytorch/__init__.py +0 -0
  86. vbi/models/pytorch/data/default_parameters.npz +0 -0
  87. vbi/models/pytorch/data/input/ROI_sim.mat +0 -0
  88. vbi/models/pytorch/data/input/fc_test.csv +68 -0
  89. vbi/models/pytorch/data/input/fc_train.csv +68 -0
  90. vbi/models/pytorch/data/input/fc_vali.csv +68 -0
  91. vbi/models/pytorch/data/input/fcd_test.mat +0 -0
  92. vbi/models/pytorch/data/input/fcd_test_high_window.mat +0 -0
  93. vbi/models/pytorch/data/input/fcd_test_low_window.mat +0 -0
  94. vbi/models/pytorch/data/input/fcd_train.mat +0 -0
  95. vbi/models/pytorch/data/input/fcd_vali.mat +0 -0
  96. vbi/models/pytorch/data/input/myelin.csv +68 -0
  97. vbi/models/pytorch/data/input/rsfc_gradient.csv +68 -0
  98. vbi/models/pytorch/data/input/run_label_testset.mat +0 -0
  99. vbi/models/pytorch/data/input/sc_test.csv +68 -0
  100. vbi/models/pytorch/data/input/sc_train.csv +68 -0
  101. vbi/models/pytorch/data/input/sc_vali.csv +68 -0
  102. vbi/models/pytorch/data/obs_kong0.npz +0 -0
  103. vbi/models/pytorch/ww_sde_kong.py +570 -0
  104. vbi/models/tvbk/__init__.py +9 -0
  105. vbi/models/tvbk/tvbk_wrapper.py +166 -0
  106. vbi/models/tvbk/utils.py +72 -0
  107. vbi/papers/__init__.py +0 -0
  108. vbi/papers/pavlides_pcb_2015/pavlides.py +211 -0
  109. vbi/tests/__init__.py +0 -0
  110. vbi/tests/_test_mpr_nb.py +36 -0
  111. vbi/tests/test_features.py +355 -0
  112. vbi/tests/test_ghb_cupy.py +90 -0
  113. vbi/tests/test_mpr_cupy.py +49 -0
  114. vbi/tests/test_mpr_numba.py +84 -0
  115. vbi/tests/test_suite.py +19 -0
  116. vbi/utils.py +402 -0
  117. vbi-0.1.3.dist-info/METADATA +166 -0
  118. vbi-0.1.3.dist-info/RECORD +121 -0
  119. vbi-0.1.3.dist-info/WHEEL +5 -0
  120. vbi-0.1.3.dist-info/licenses/LICENSE +201 -0
  121. vbi-0.1.3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,374 @@
1
+ import json
2
+ import vbi
3
+ import types
4
+ from copy import deepcopy
5
+ from typing import Union
6
+
7
+ import inspect
8
+ import importlib
9
+
10
+
11
+ def load_json(path):
12
+ """
13
+ Load json file
14
+
15
+ Parameters
16
+ ----------
17
+ path : string
18
+ Path to json file
19
+
20
+ Returns
21
+ -------
22
+ json_data : dictionary
23
+ Dictionary with the json data
24
+ """
25
+ with open(path) as json_file:
26
+ json_data = json.load(json_file)
27
+ return json_data
28
+
29
+
30
+ def get_features_by_domain(domain=None, json_path=None):
31
+ """
32
+ Create a dictionary of features in given domain(s).
33
+
34
+ Parameters
35
+ ----------
36
+ domain : string or list of strings
37
+ Domain of features to extract, including:
38
+ 'temporal',
39
+ 'statistical',
40
+ 'connectivity',
41
+ 'spectral',
42
+ 'hmm',
43
+ 'catch22',
44
+ 'information'
45
+ path : string (optional)
46
+ Path to json file, if None, the default json file is used
47
+ """
48
+ _domains = [
49
+ "hmm",
50
+ "spectral",
51
+ "connectivity",
52
+ "temporal",
53
+ "statistical",
54
+ "information",
55
+ 'catch22',
56
+ ]
57
+
58
+ if json_path is None:
59
+ json_path = vbi.__path__[0] + "/feature_extraction/features.json"
60
+
61
+ if not isinstance(domain, (list, tuple)):
62
+ domain = [domain]
63
+
64
+ domain = list(set(domain))
65
+ domain = [d.lower() for d in domain if d is not None] # lower case
66
+
67
+ # for d in domain:
68
+ # if d not in valid_domains:
69
+ # raise SystemExit(
70
+ # f'Domain not valid. Please choose between: {" ".join(valid_domains)}')
71
+
72
+ dict_features = load_json(json_path)
73
+ if len(domain) == 0:
74
+ return dict_features
75
+
76
+ for d in _domains:
77
+ if d not in domain:
78
+ dict_features.pop(d)
79
+ return dict_features
80
+
81
+
82
+ def get_features_by_given_names(cfg, names=None):
83
+ """
84
+ filter features by given names from cfg (a dictionary of features)
85
+ """
86
+
87
+ cfg = deepcopy(cfg)
88
+
89
+ if names is None:
90
+ return cfg
91
+
92
+ if not isinstance(names, (list, tuple)):
93
+ names = [names]
94
+
95
+ names = [n.lower() for n in names] # lower case
96
+
97
+ # check if names are valid
98
+ avail_names = []
99
+ for d in cfg:
100
+ avail_names += list(cfg[d].keys())
101
+
102
+ for n in names:
103
+ if n not in avail_names:
104
+ print(f"Warning: {n} is not a valid in provided feature names.")
105
+
106
+ # filter cfg
107
+ for d in cfg:
108
+ for f in list(cfg[d].keys()):
109
+ if f not in names:
110
+ cfg[d].pop(f)
111
+
112
+ return cfg
113
+
114
+
115
+ def get_features_by_tag(tag=None, json_path=None): #! TODO: not tested
116
+ """
117
+ Create a dictionary of features in given tag.
118
+
119
+ Parameters
120
+ ----------
121
+ tag : string
122
+ Tag of features to extract
123
+ path : string
124
+ Path to json file
125
+ """
126
+
127
+ available_tags = ["fmri", "audio", "eeg", "ecg", None]
128
+
129
+ if path is None:
130
+ path = vbi.__path__[0] + "/feature_extraction/features.json"
131
+
132
+ if tag not in ["audio", "eeg", "ecg", None]:
133
+ raise SystemExit(
134
+ "Tag not valid. Please choose between: audio, eeg, ecg or None"
135
+ )
136
+ features_tag = {}
137
+ dict_features = load_json(json_path)
138
+ if tag is None:
139
+ return dict_features
140
+ else:
141
+ for domain in dict_features:
142
+ features_tag[domain] = {}
143
+ for feat in dict_features[domain]:
144
+ if dict_features[domain][feat]["use"] == "no":
145
+ continue
146
+ # Check if tag is defined
147
+ try:
148
+ js_tag = dict_features[domain][feat]["tag"]
149
+ if isinstance(js_tag, list):
150
+ if any([tag in js_t for js_t in js_tag]):
151
+ features_tag[domain].update(
152
+ {feat: dict_features[domain][feat]}
153
+ )
154
+ elif js_tag == tag:
155
+ features_tag[domain].update({feat: dict_features[domain][feat]})
156
+ except KeyError:
157
+ continue
158
+ # To remove empty dicts
159
+ return dict(
160
+ [
161
+ [d, features_tag[d]]
162
+ for d in list(features_tag.keys())
163
+ if bool(features_tag[d])
164
+ ]
165
+ )
166
+
167
+
168
+ def add_feature(
169
+ cfg,
170
+ domain,
171
+ name,
172
+ function: str = None,
173
+ features_path: Union[str, types.ModuleType] = None, # str or module
174
+ parameters={},
175
+ tag=None,
176
+ description="",
177
+ ):
178
+ """
179
+ Add a feature to the cfg dictionary
180
+
181
+ Parameters
182
+ ----------
183
+ cfg : dictionary
184
+ Dictionary of features
185
+ domain : string
186
+ Domain of the feature
187
+ name : string
188
+ Name of the feature
189
+ function : function
190
+ Function to compute the feature
191
+ parameters : dictionary
192
+ Parameters of the feature
193
+ tag : string
194
+ Tag of the feature
195
+ description : string
196
+ Description of the feature
197
+
198
+ Returns
199
+ -------
200
+ cfg : dictionary
201
+ Updated dictionary of features
202
+ """
203
+ if isinstance(features_path, str):
204
+ features_path = __import__(features_path)
205
+ _path = features_path.__file__
206
+
207
+ # _path = getattr(feature_path, name)
208
+
209
+ if function is None:
210
+ function = name
211
+
212
+ if domain not in cfg:
213
+ cfg[domain] = {}
214
+
215
+ cfg[domain][name] = {}
216
+ cfg[domain][name]["parameters"] = parameters
217
+ cfg[domain][name]["tag"] = tag
218
+ cfg[domain][name]["description"] = description
219
+ cfg[domain][name]["use"] = "yes"
220
+ cfg[domain][name]["function"] = function
221
+ cfg["features_path"] = _path
222
+ # function.__module__ + "." + function.__name__
223
+
224
+ return cfg
225
+
226
+
227
+ def add_features_from_json(json_path, features_path, fea_dict={}):
228
+ """
229
+ add features from json file to cfg
230
+
231
+ Parameters
232
+ ----------
233
+ cfg : dictionary
234
+ Dictionary of features, if empty, a new dictionary is created
235
+ json_path : string
236
+ Path to json file
237
+ """
238
+
239
+ #! TODO: if fea_dict is not empty, check if the feature is already in the dict
240
+ #! check also for conflicts in the parameters, and function
241
+
242
+ if json_path is None:
243
+ json_path = vbi.__path__[0] + "/feature_extraction/features.json"
244
+
245
+ dict_features = load_json(json_path)
246
+
247
+ for domain in dict_features:
248
+ for feat in dict_features[domain]:
249
+ use = (
250
+ dict_features[domain][feat]["use"]
251
+ if "use" in dict_features[domain][feat]
252
+ else "yes"
253
+ )
254
+ tag = (
255
+ dict_features[domain][feat]["tag"]
256
+ if "tag" in dict_features[domain][feat]
257
+ else "all"
258
+ )
259
+ description = (
260
+ dict_features[domain][feat]["description"]
261
+ if "description" in dict_features[domain][feat]["description"]
262
+ else ""
263
+ )
264
+ if use == "no":
265
+ continue
266
+ fea_dict = add_feature(
267
+ fea_dict,
268
+ domain=domain,
269
+ name=feat,
270
+ features_path=features_path,
271
+ parameters=dict_features[domain][feat]["parameters"],
272
+ tag=tag,
273
+ description=description,
274
+ )
275
+
276
+ return fea_dict
277
+
278
+
279
+ class Data_F(object):
280
+ def __init__(self, values=None, labels=None, info=None):
281
+ self.values = values
282
+ self.labels = labels
283
+ self.info = info
284
+
285
+ def __repr__(self):
286
+ return f"Data_F(values={self.values}, labels={self.labels}, info={self.info})"
287
+
288
+ def __str__(self):
289
+ return f"Data_F(values={self.values}, labels={self.labels}, info={self.info})"
290
+
291
+
292
+ def update_cfg(cfg: dict, name: str, parameters: dict):
293
+ """
294
+ Set parameters of a feature
295
+
296
+ Parameters
297
+ ----------
298
+ cfg : dictionary
299
+ Dictionary of features
300
+ domain : string
301
+ Domain of the feature
302
+ name : string
303
+ Name of the feature
304
+ parameters : dictionary
305
+ Parameters of the feature
306
+
307
+ Returns
308
+ -------
309
+ cfg : dictionary
310
+ Updated dictionary of features
311
+ """
312
+ # find domain of giving feature
313
+ domain = None
314
+ for d in cfg:
315
+ if name in cfg[d]:
316
+ domain = d
317
+ break
318
+ if domain is None:
319
+ raise SystemExit(f"Feature {name} not found in the dictionary")
320
+ _params = cfg[domain][name]["parameters"]
321
+
322
+ for p in parameters:
323
+ # check if parameter is valid
324
+ if p not in _params:
325
+ raise SystemExit(f"Parameter {p} not valid for feature {name}")
326
+ _params[p] = parameters[p]
327
+
328
+ return cfg
329
+
330
+
331
+ # not used in the code
332
+ def select_features_by_domain(module_name, domain):
333
+ selected_functions = []
334
+ module = importlib.import_module(module_name)
335
+ functions = inspect.getmembers(module, inspect.isfunction)
336
+ for name, f in functions:
337
+ if hasattr(f, "domain"):
338
+ domains = getattr(f, "domain")
339
+ if domain in domains:
340
+ selected_functions.append(f)
341
+
342
+ return selected_functions
343
+
344
+
345
+ # not used in the code
346
+ def select_functions_by_tag(module_name, tag):
347
+
348
+ selected_functions = []
349
+ module = importlib.import_module(module_name)
350
+ functions = inspect.getmembers(module, inspect.isfunction)
351
+ for name, f in functions:
352
+ if hasattr(f, "tag"):
353
+ tags = getattr(f, "tag")
354
+ if tag in tags:
355
+ selected_functions.append(f)
356
+
357
+ return selected_functions
358
+
359
+
360
+ # not used in the code
361
+ def select_functions_by_domain_and_tag(module_name, domain=None, tag=None):
362
+ selected_functions = []
363
+
364
+ module = importlib.import_module(module_name)
365
+ functions = inspect.getmembers(module, inspect.isfunction)
366
+
367
+ for name, func in functions:
368
+ if hasattr(func, "domain") and hasattr(func, "tag"):
369
+ domains = getattr(func, "domain")
370
+ tags = getattr(func, "tag")
371
+ if (domain in domains) and (tag in tags):
372
+ selected_functions.append(func)
373
+
374
+ return selected_functions