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,352 @@
1
+ #ifndef JANSENRIT_HPP
2
+ #define JANSENRIT_HPP
3
+
4
+ #include <cmath>
5
+ #include <vector>
6
+ #include <string>
7
+ #include <random>
8
+ #include <fstream>
9
+ #include <assert.h>
10
+ #include <iostream>
11
+ #include "utility.hpp"
12
+
13
+ using std::string;
14
+ using std::vector;
15
+
16
+ typedef std::vector<double> dim1;
17
+ typedef std::vector<dim1> dim2;
18
+ typedef std::vector<float> dim1f;
19
+ typedef std::vector<dim1f> dim2f;
20
+
21
+ class JR_sdde
22
+ {
23
+
24
+ private:
25
+ int N;
26
+ dim1 y0;
27
+ double dt;
28
+ int dimension;
29
+ int num_nodes;
30
+ double maxdelay;
31
+ size_t fix_seed;
32
+ double coupling;
33
+ double par_vmax;
34
+ dim2 states;
35
+
36
+ dim1 C0;
37
+ dim1 C1;
38
+ dim1 C2;
39
+ dim1 C3;
40
+
41
+ double noise_sigma;
42
+ double noise_mu;
43
+ double par_A;
44
+ double par_a;
45
+ double par_B;
46
+ double par_b;
47
+ double par_r;
48
+ double par_v0;
49
+
50
+ dim1 sti_amp;
51
+ double sti_ti;
52
+ double sti_duration;
53
+ double sti_gain = 0.0;
54
+ double _sti_gain = 0.0;
55
+
56
+ double t_final;
57
+ double t_transition;
58
+ size_t index_transition;
59
+ long unsigned num_iteration;
60
+
61
+ vector<vector<unsigned>> adjlist;
62
+ vector<vector<unsigned>> D;
63
+ // vector<vector<unsigned>> plag;
64
+
65
+ dim1 t_ar;
66
+ dim1 t_arr;
67
+ dim2 y;
68
+ dim2 adj;
69
+ dim2 delays;
70
+
71
+ public:
72
+ int nstart;
73
+ dim1 sti_vector;
74
+
75
+ JR_sdde(double dt,
76
+ dim1 y0,
77
+ dim2 adj,
78
+ dim2 delays,
79
+ double coupling,
80
+ int dimension,
81
+ double A,
82
+ double B,
83
+ double a,
84
+ double b,
85
+ double r,
86
+ double v0,
87
+ double vmax,
88
+ dim1 C0,
89
+ dim1 C1,
90
+ dim1 C2,
91
+ dim1 C3,
92
+ dim1 sti_amp,
93
+ double sti_gain,
94
+ double sti_ti,
95
+ double sti_duration,
96
+ double noise_mu,
97
+ double noise_sigma,
98
+ double t_transition = 1.0,
99
+ double t_final = 10.0,
100
+ size_t noise_seed = 0)
101
+ {
102
+ N = num_nodes = adj.size();
103
+ this->dimension = dimension;
104
+
105
+ assert(t_final > t_transition);
106
+
107
+ this->noise_mu = noise_mu;
108
+ this->noise_sigma = noise_sigma;
109
+
110
+ par_A = A;
111
+ par_a = a;
112
+ par_B = B;
113
+ par_b = b;
114
+ par_r = r;
115
+ par_v0 = v0;
116
+ par_vmax = vmax;
117
+
118
+ this->dt = dt;
119
+ this->adj = adj;
120
+ this->delays = delays;
121
+ this->t_final = t_final;
122
+ this->fix_seed = noise_seed;
123
+ this->coupling = coupling;
124
+ this->t_transition = t_transition;
125
+ this->C0 = C0;
126
+ this->C1 = C1;
127
+ this->C2 = C2;
128
+ this->C3 = C3;
129
+
130
+ assert(y0.size() == (dimension * N));
131
+ prepare_sti(sti_amp, sti_gain, sti_ti, sti_duration);
132
+
133
+ {
134
+ maxdelay = 0.0;
135
+ dim1 tmp(N);
136
+ for (size_t i = 0; i < N; ++i)
137
+ tmp[i] = *std::max_element(delays[i].begin(), delays[i].end());
138
+ maxdelay = *std::max_element(tmp.begin(), tmp.end());
139
+ }
140
+ nstart = (std::abs(maxdelay) > dt) ? int(ceil(maxdelay / dt)) : 50;
141
+ num_iteration = int(ceil(t_final / dt)) + nstart;
142
+ index_transition = int(round(t_transition / dt));
143
+
144
+ assert((index_transition) < num_iteration); // make sure the simulation is long enough
145
+
146
+ // memory allocations -------------------------------------------------
147
+ D.resize(N);
148
+ states.resize(N);
149
+ y.resize(dimension * N);
150
+ t_ar.resize(num_iteration);
151
+
152
+ for (size_t i = 0; i < N; ++i)
153
+ {
154
+ D[i].resize(N);
155
+ states[i].resize(num_iteration - index_transition);
156
+ }
157
+ for (int i = 0; i < dimension * N; ++i)
158
+ y[i].resize(num_iteration);
159
+
160
+ for (int i = 0; i < N; ++i)
161
+ for (int j = 0; j < N; ++j)
162
+ D[i][j] = int(round(delays[i][j] / dt)); // delay indices
163
+ // --------------------------------------------------------------------
164
+ adjlist = adjmat_to_adjlist(adj);
165
+
166
+ set_history(y0);
167
+ }
168
+
169
+ void set_history(const dim1 &hist)
170
+ {
171
+ for (int i = 0; i < num_iteration; ++i)
172
+ t_ar[i] = i * dt;
173
+
174
+ // p_x_ar: N x nstart
175
+ for (int i = 0; i < (dimension * N); ++i)
176
+ for (int j = 0; j < nstart + 1; ++j)
177
+ y[i][j] = hist[i];
178
+ }
179
+
180
+ void prepare_sti(const dim1 sti_amp, double sti_gain, double sti_ti, double sti_duration)
181
+ {
182
+ if ((sti_amp.size() != N) && (std::abs(sti_gain) > 0.0))
183
+ {
184
+ std::cout << "Stimulation amplitude vector size is not equal to the number of nodes" << std::endl;
185
+ exit(1);
186
+ }
187
+ else if (std::abs(sti_gain) > 1e-10)
188
+ {
189
+ this->sti_amp = sti_amp;
190
+ this->sti_gain = sti_gain;
191
+ this->sti_ti = sti_ti;
192
+ this->sti_duration = sti_duration;
193
+ // assert((sti_ti + sti_duration) <= t_final); // make sure the stimulation duration is not longer than the simulation duration
194
+ assert(sti_ti >= t_transition); // make sure the stimulation starts after the transition period
195
+ }
196
+ else // no stimulation
197
+ {
198
+ this->sti_amp.resize(N);
199
+ this->sti_gain = 0.0;
200
+ this->sti_ti = 0.0;
201
+ this->sti_duration = 0.0;
202
+ }
203
+ }
204
+
205
+ // ------------------------------------------------------------------------
206
+ double _sigma(const double v)
207
+ {
208
+ return par_vmax / (1 + exp(par_r * (par_v0 - v)));
209
+ }
210
+
211
+ dim1 f_sys(const double t,
212
+ const unsigned n)
213
+ {
214
+ dim1 dxdt(dimension * N);
215
+
216
+ double a2 = par_a * par_a;
217
+ double b2 = par_b * par_b;
218
+ double Aa = par_A * par_a;
219
+ double Bb = par_B * par_b;
220
+
221
+ int N2 = 2 * N;
222
+ int N3 = 3 * N;
223
+ int N4 = 4 * N;
224
+ int N5 = 5 * N;
225
+
226
+ for (size_t i = 0; i < N; ++i)
227
+ {
228
+ double coupling_term = 0.0;
229
+
230
+ for (size_t j = 0; j < adjlist[i].size(); ++j)
231
+ {
232
+ int k = adjlist[i][j];
233
+ coupling_term += adj[i][k] * _sigma(y[k + N][n - D[i][k]] - y[k + N2][n - D[i][k]]);
234
+ }
235
+
236
+ dxdt[i] = y[i + N3][n];
237
+ dxdt[i + N] = y[i + N4][n];
238
+ dxdt[i + N2] = y[i + N5][n];
239
+ dxdt[i + N3] = Aa * _sigma(y[i + N][n] - y[i + N2][n]) - 2 * par_a * y[i + N3][n] - a2 * y[i][n];
240
+ dxdt[i + N4] = Aa * (noise_mu + _sti_gain * sti_amp[i] + C1[i] * _sigma(C0[i] * y[i][n]) + coupling * coupling_term) - 2 * par_a * y[i + N4][n] - a2 * y[i + N][n];
241
+ dxdt[i + N5] = Bb * C3[i] * _sigma(C2[i] * y[i][n]) - 2 * par_b * y[i + N5][n] - b2 * y[i + N2][n];
242
+ }
243
+
244
+ return dxdt;
245
+ }
246
+ // ------------------------------------------------------------------------
247
+
248
+ void euler(const double t, const unsigned n)
249
+ {
250
+ std::normal_distribution<> normal(0, 1);
251
+ size_t nc = dimension * num_nodes;
252
+ dim1 dy(nc);
253
+
254
+ double coeff = sqrt(dt) * noise_sigma;
255
+
256
+ dy = f_sys(t, n);
257
+ for (int i = 0; i < (N * dimension); ++i)
258
+ {
259
+ if ((i >= 4 * N) && (i < 5 * N))
260
+ y[i][n + 1] = y[i][n] + dt * dy[i] + coeff * normal(rng(fix_seed));
261
+ else
262
+ y[i][n + 1] = y[i][n] + dt * dy[i];
263
+ }
264
+ }
265
+ // ------------------------------------------------------------------------
266
+
267
+ void heun(const double t, const unsigned n)
268
+ {
269
+ std::normal_distribution<> normal(0, 1);
270
+ size_t nc = dimension * num_nodes;
271
+ dim1 k1(nc);
272
+ dim1 k2(nc);
273
+
274
+ double coeff = sqrt(dt) * noise_sigma;
275
+ double half_dt = 0.5 * dt;
276
+
277
+ k1 = f_sys(t, n);
278
+ for (int i = 0; i < (N * dimension); ++i)
279
+ {
280
+ if ((i >= 4 * N) && (i < 5 * N))
281
+ y[i][n + 1] = y[i][n] + dt * k1[i] + coeff * normal(rng(fix_seed));
282
+ else
283
+ y[i][n + 1] = y[i][n] + dt * k1[i];
284
+ }
285
+
286
+ k2 = f_sys(t + dt, n + 1);
287
+ for (int i = 0; i < (N * dimension); ++i)
288
+ {
289
+ if ((i >= 4 * N) && (i < 5 * N))
290
+ y[i][n + 1] = y[i][n] + half_dt * (k1[i] + k2[i]) + coeff * normal(rng(fix_seed));
291
+ else
292
+ y[i][n + 1] = y[i][n] + half_dt * (k1[i] + k2[i]);
293
+ }
294
+ }
295
+ // ------------------------------------------------------------------------
296
+
297
+ void integrate(const std::string method)
298
+ {
299
+ std::normal_distribution<> normal(0, 1);
300
+ size_t nc = dimension * num_nodes;
301
+ unsigned counter = 0;
302
+ unsigned N2 = 2 * N;
303
+ t_arr.resize(num_iteration - index_transition);
304
+ sti_vector.resize(t_arr.size());
305
+
306
+ for (unsigned it = nstart; it < num_iteration - 1; ++it)
307
+ {
308
+ double t = (it - nstart + 1) * dt;
309
+
310
+ // stimulation
311
+ if ((t >= sti_ti) && (t <= (sti_ti + sti_duration)))
312
+ _sti_gain = sti_gain;
313
+ else
314
+ _sti_gain = 0.0;
315
+
316
+ if (method == "euler")
317
+ euler(t, it);
318
+ else if (method == "heun")
319
+ heun(t, it);
320
+ else
321
+ {
322
+ throw std::invalid_argument("Invalid integration method");
323
+ exit(1);
324
+ }
325
+
326
+ if (it >= (index_transition))
327
+ {
328
+ t_arr[counter] = t;
329
+ sti_vector[counter] = _sti_gain;
330
+ for (int j = 0; j < N; ++j)
331
+ states[j][counter] = y[j + N][it + 1] - y[j + N2][it + 1];
332
+ counter++;
333
+ }
334
+ }
335
+ }
336
+
337
+ dim1 get_t()
338
+ {
339
+ return t_arr;
340
+ }
341
+
342
+ dim2 get_y()
343
+ {
344
+ return states;
345
+ }
346
+ dim1 get_sti_vector()
347
+ {
348
+ return sti_vector;
349
+ }
350
+ };
351
+
352
+ #endif
@@ -0,0 +1,19 @@
1
+
2
+ %module jr_sdde
3
+
4
+ %{
5
+ #include "jr_sdde.hpp"
6
+ %}
7
+
8
+ %include stl.i
9
+ %include "std_string.i"
10
+ /* instantiate the required template specializations */
11
+ namespace std {
12
+ %template(IntVector) vector<int>;
13
+ %template(DoubleVector) vector<double>;
14
+ %template(DoubleVector2) vector<vector<double> >;
15
+ %template(SingleVector) vector<float>;
16
+ %template(SingleVector2) vector<vector<float> >;
17
+ }
18
+
19
+ %include "jr_sdde.hpp"