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.
- vbi/__init__.py +37 -0
- vbi/_version.py +17 -0
- vbi/dataset/__init__.py +0 -0
- vbi/dataset/connectivity_84/centers.txt +84 -0
- vbi/dataset/connectivity_84/centres.txt +84 -0
- vbi/dataset/connectivity_84/cortical.txt +84 -0
- vbi/dataset/connectivity_84/tract_lengths.txt +84 -0
- vbi/dataset/connectivity_84/weights.txt +84 -0
- vbi/dataset/connectivity_88/Aud_88.txt +88 -0
- vbi/dataset/connectivity_88/Bold.npz +0 -0
- vbi/dataset/connectivity_88/Labels.txt +17 -0
- vbi/dataset/connectivity_88/Region_labels.txt +88 -0
- vbi/dataset/connectivity_88/tract_lengths.txt +88 -0
- vbi/dataset/connectivity_88/weights.txt +88 -0
- vbi/feature_extraction/__init__.py +1 -0
- vbi/feature_extraction/calc_features.py +293 -0
- vbi/feature_extraction/features.json +535 -0
- vbi/feature_extraction/features.py +2124 -0
- vbi/feature_extraction/features_settings.py +374 -0
- vbi/feature_extraction/features_utils.py +1357 -0
- vbi/feature_extraction/infodynamics.jar +0 -0
- vbi/feature_extraction/utility.py +507 -0
- vbi/inference.py +98 -0
- vbi/models/__init__.py +0 -0
- vbi/models/cpp/__init__.py +0 -0
- vbi/models/cpp/_src/__init__.py +0 -0
- vbi/models/cpp/_src/__pycache__/mpr_sde.cpython-310.pyc +0 -0
- vbi/models/cpp/_src/_do.cpython-310-x86_64-linux-gnu.so +0 -0
- vbi/models/cpp/_src/_jr_sdde.cpython-310-x86_64-linux-gnu.so +0 -0
- vbi/models/cpp/_src/_jr_sde.cpython-310-x86_64-linux-gnu.so +0 -0
- vbi/models/cpp/_src/_km_sde.cpython-310-x86_64-linux-gnu.so +0 -0
- vbi/models/cpp/_src/_mpr_sde.cpython-310-x86_64-linux-gnu.so +0 -0
- vbi/models/cpp/_src/_vep.cpython-310-x86_64-linux-gnu.so +0 -0
- vbi/models/cpp/_src/_wc_ode.cpython-310-x86_64-linux-gnu.so +0 -0
- vbi/models/cpp/_src/bold.hpp +303 -0
- vbi/models/cpp/_src/do.hpp +167 -0
- vbi/models/cpp/_src/do.i +17 -0
- vbi/models/cpp/_src/do.py +467 -0
- vbi/models/cpp/_src/do_wrap.cxx +12811 -0
- vbi/models/cpp/_src/jr_sdde.hpp +352 -0
- vbi/models/cpp/_src/jr_sdde.i +19 -0
- vbi/models/cpp/_src/jr_sdde.py +688 -0
- vbi/models/cpp/_src/jr_sdde_wrap.cxx +18718 -0
- vbi/models/cpp/_src/jr_sde.hpp +264 -0
- vbi/models/cpp/_src/jr_sde.i +17 -0
- vbi/models/cpp/_src/jr_sde.py +470 -0
- vbi/models/cpp/_src/jr_sde_wrap.cxx +13406 -0
- vbi/models/cpp/_src/km_sde.hpp +158 -0
- vbi/models/cpp/_src/km_sde.i +19 -0
- vbi/models/cpp/_src/km_sde.py +671 -0
- vbi/models/cpp/_src/km_sde_wrap.cxx +17367 -0
- vbi/models/cpp/_src/makefile +52 -0
- vbi/models/cpp/_src/mpr_sde.hpp +327 -0
- vbi/models/cpp/_src/mpr_sde.i +19 -0
- vbi/models/cpp/_src/mpr_sde.py +711 -0
- vbi/models/cpp/_src/mpr_sde_wrap.cxx +18618 -0
- vbi/models/cpp/_src/utility.hpp +307 -0
- vbi/models/cpp/_src/vep.hpp +171 -0
- vbi/models/cpp/_src/vep.i +16 -0
- vbi/models/cpp/_src/vep.py +464 -0
- vbi/models/cpp/_src/vep_wrap.cxx +12968 -0
- vbi/models/cpp/_src/wc_ode.hpp +294 -0
- vbi/models/cpp/_src/wc_ode.i +19 -0
- vbi/models/cpp/_src/wc_ode.py +686 -0
- vbi/models/cpp/_src/wc_ode_wrap.cxx +24263 -0
- vbi/models/cpp/damp_oscillator.py +143 -0
- vbi/models/cpp/jansen_rit.py +543 -0
- vbi/models/cpp/km.py +187 -0
- vbi/models/cpp/mpr.py +289 -0
- vbi/models/cpp/vep.py +150 -0
- vbi/models/cpp/wc.py +216 -0
- vbi/models/cupy/__init__.py +0 -0
- vbi/models/cupy/bold.py +111 -0
- vbi/models/cupy/ghb.py +284 -0
- vbi/models/cupy/jansen_rit.py +473 -0
- vbi/models/cupy/km.py +224 -0
- vbi/models/cupy/mpr.py +475 -0
- vbi/models/cupy/mpr_modified_bold.py +12 -0
- vbi/models/cupy/utils.py +184 -0
- vbi/models/numba/__init__.py +0 -0
- vbi/models/numba/_ww_EI.py +444 -0
- vbi/models/numba/damp_oscillator.py +162 -0
- vbi/models/numba/ghb.py +208 -0
- vbi/models/numba/mpr.py +383 -0
- vbi/models/pytorch/__init__.py +0 -0
- vbi/models/pytorch/data/default_parameters.npz +0 -0
- vbi/models/pytorch/data/input/ROI_sim.mat +0 -0
- vbi/models/pytorch/data/input/fc_test.csv +68 -0
- vbi/models/pytorch/data/input/fc_train.csv +68 -0
- vbi/models/pytorch/data/input/fc_vali.csv +68 -0
- vbi/models/pytorch/data/input/fcd_test.mat +0 -0
- vbi/models/pytorch/data/input/fcd_test_high_window.mat +0 -0
- vbi/models/pytorch/data/input/fcd_test_low_window.mat +0 -0
- vbi/models/pytorch/data/input/fcd_train.mat +0 -0
- vbi/models/pytorch/data/input/fcd_vali.mat +0 -0
- vbi/models/pytorch/data/input/myelin.csv +68 -0
- vbi/models/pytorch/data/input/rsfc_gradient.csv +68 -0
- vbi/models/pytorch/data/input/run_label_testset.mat +0 -0
- vbi/models/pytorch/data/input/sc_test.csv +68 -0
- vbi/models/pytorch/data/input/sc_train.csv +68 -0
- vbi/models/pytorch/data/input/sc_vali.csv +68 -0
- vbi/models/pytorch/data/obs_kong0.npz +0 -0
- vbi/models/pytorch/ww_sde_kong.py +570 -0
- vbi/models/tvbk/__init__.py +9 -0
- vbi/models/tvbk/tvbk_wrapper.py +166 -0
- vbi/models/tvbk/utils.py +72 -0
- vbi/papers/__init__.py +0 -0
- vbi/papers/pavlides_pcb_2015/pavlides.py +211 -0
- vbi/tests/__init__.py +0 -0
- vbi/tests/_test_mpr_nb.py +36 -0
- vbi/tests/test_features.py +355 -0
- vbi/tests/test_ghb_cupy.py +90 -0
- vbi/tests/test_mpr_cupy.py +49 -0
- vbi/tests/test_mpr_numba.py +84 -0
- vbi/tests/test_suite.py +19 -0
- vbi/utils.py +402 -0
- vbi-0.1.3.dist-info/METADATA +166 -0
- vbi-0.1.3.dist-info/RECORD +121 -0
- vbi-0.1.3.dist-info/WHEEL +5 -0
- vbi-0.1.3.dist-info/licenses/LICENSE +201 -0
- vbi-0.1.3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,307 @@
|
|
1
|
+
#ifndef UTILITY_HPP
|
2
|
+
#define UTILITY_HPP
|
3
|
+
|
4
|
+
#include <vector>
|
5
|
+
#include <string>
|
6
|
+
#include <random>
|
7
|
+
#include <assert.h>
|
8
|
+
#include <iostream>
|
9
|
+
#include <algorithm>
|
10
|
+
#include <sys/stat.h>
|
11
|
+
#include <unistd.h>
|
12
|
+
#include <sys/time.h>
|
13
|
+
#include <sys/resource.h>
|
14
|
+
// #include <Eigen/Dense>
|
15
|
+
|
16
|
+
using std::string;
|
17
|
+
using std::vector;
|
18
|
+
|
19
|
+
typedef std::vector<double> dim1;
|
20
|
+
typedef std::vector<unsigned> dim1I;
|
21
|
+
typedef std::vector<std::vector<double>> dim2;
|
22
|
+
typedef std::vector<std::vector<unsigned>> dim2I;
|
23
|
+
|
24
|
+
bool fileExists(const std::string &filename)
|
25
|
+
{
|
26
|
+
struct stat buf;
|
27
|
+
if (stat(filename.c_str(), &buf) != -1)
|
28
|
+
{
|
29
|
+
return true;
|
30
|
+
}
|
31
|
+
return false;
|
32
|
+
}
|
33
|
+
|
34
|
+
bool folderExists(const std::string &path)
|
35
|
+
{
|
36
|
+
struct stat st;
|
37
|
+
if (stat(path.c_str(), &st) == 0)
|
38
|
+
{
|
39
|
+
if (st.st_mode & S_IFDIR != 0)
|
40
|
+
return true;
|
41
|
+
else
|
42
|
+
return false;
|
43
|
+
}
|
44
|
+
else
|
45
|
+
return false;
|
46
|
+
}
|
47
|
+
|
48
|
+
std::vector<std::vector<unsigned>> adjmat_to_adjlist(const dim2 &A)
|
49
|
+
{
|
50
|
+
size_t n = A.size();
|
51
|
+
|
52
|
+
std::vector<std::vector<unsigned>> adjlist;
|
53
|
+
adjlist.resize(n);
|
54
|
+
|
55
|
+
for (int i = 0; i < n; ++i)
|
56
|
+
{
|
57
|
+
for (int j = 0; j < n; ++j)
|
58
|
+
{
|
59
|
+
if (std::abs(A[i][j]) > 1e-8)
|
60
|
+
adjlist[i].push_back(j);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
return adjlist;
|
65
|
+
}
|
66
|
+
|
67
|
+
// std::vector<std::vector<size_t>> adjmat_to_adjlist(const dim2 &A)
|
68
|
+
// {
|
69
|
+
// size_t n = A.size();
|
70
|
+
|
71
|
+
// std::vector<std::vector<size_t>> adjlist;
|
72
|
+
// adjlist.resize(n);
|
73
|
+
|
74
|
+
// for (int i = 0; i < n; ++i)
|
75
|
+
// {
|
76
|
+
// for (int j = 0; j < n; ++j)
|
77
|
+
// {
|
78
|
+
// if (std::abs(A[j][i]) > 1e-8)
|
79
|
+
// adjlist[i].push_back(j);
|
80
|
+
// }
|
81
|
+
// }
|
82
|
+
|
83
|
+
// return adjlist;
|
84
|
+
// }
|
85
|
+
|
86
|
+
dim1 moving_average(const dim1 &vec, const size_t window)
|
87
|
+
{
|
88
|
+
size_t size = vec.size();
|
89
|
+
size_t ind = 0;
|
90
|
+
size_t buffer_size = int(size / window);
|
91
|
+
dim1 vec_out(buffer_size);
|
92
|
+
|
93
|
+
for (size_t itr = 0; itr < (size - window); ++itr)
|
94
|
+
{
|
95
|
+
double sum = 0.0;
|
96
|
+
for (int j = itr; j < itr + window; ++j)
|
97
|
+
sum += vec[j];
|
98
|
+
vec_out[ind] = sum / double(window);
|
99
|
+
ind++;
|
100
|
+
}
|
101
|
+
|
102
|
+
return vec_out;
|
103
|
+
}
|
104
|
+
|
105
|
+
// adding vectors
|
106
|
+
void add(const vector<double> &a, const vector<double> &b, vector<double> &c)
|
107
|
+
{
|
108
|
+
// c need to be allocated memory.
|
109
|
+
transform(a.begin(), a.end(), b.begin(), c.begin(),
|
110
|
+
[](double a, double b)
|
111
|
+
{ return a + b; });
|
112
|
+
}
|
113
|
+
|
114
|
+
void add(const vector<float> &a, const vector<double> &b, vector<float> &c)
|
115
|
+
{
|
116
|
+
assert(a.size() == b.size());
|
117
|
+
assert(b.size() == c.size());
|
118
|
+
|
119
|
+
for (size_t i = 0; i < a.size(); ++i)
|
120
|
+
c[i] = a[i] + b[i];
|
121
|
+
}
|
122
|
+
|
123
|
+
double average(std::vector<double> const &numbers)
|
124
|
+
{
|
125
|
+
if (numbers.empty())
|
126
|
+
{
|
127
|
+
return 0;
|
128
|
+
}
|
129
|
+
double sum = 0;
|
130
|
+
size_t arrayLength = numbers.size();
|
131
|
+
for (size_t i = 0; i < arrayLength; i++)
|
132
|
+
sum += numbers[i];
|
133
|
+
return sum / arrayLength;
|
134
|
+
|
135
|
+
// return std::reduce(v.begin(), v.end()) / count;
|
136
|
+
}
|
137
|
+
|
138
|
+
dim1 average(dim2 &V)
|
139
|
+
{
|
140
|
+
// size_t num_nodes = (axis == "COL") ? V.size() : V[0].size();
|
141
|
+
size_t n = V[0].size();
|
142
|
+
size_t nt = V.size();
|
143
|
+
dim1 out(n);
|
144
|
+
|
145
|
+
for (size_t i = 0; i < n; ++i)
|
146
|
+
{
|
147
|
+
for (size_t j = 0; j < nt; ++j)
|
148
|
+
out[i] += V[j][i];
|
149
|
+
}
|
150
|
+
return out;
|
151
|
+
}
|
152
|
+
|
153
|
+
long get_mem_usage()
|
154
|
+
{
|
155
|
+
// measure memory usage
|
156
|
+
|
157
|
+
struct rusage myusage;
|
158
|
+
|
159
|
+
getrusage(RUSAGE_SELF, &myusage);
|
160
|
+
return myusage.ru_maxrss;
|
161
|
+
}
|
162
|
+
|
163
|
+
void display_timing(double wtime, double cptime)
|
164
|
+
{
|
165
|
+
int wh; //, ch;
|
166
|
+
int wmin; //, cpmin;
|
167
|
+
double wsec; //, csec;
|
168
|
+
wh = (int)wtime / 3600;
|
169
|
+
// ch = (int)cptime / 3600;
|
170
|
+
wmin = ((int)wtime % 3600) / 60;
|
171
|
+
// cpmin = ((int)cptime % 3600) / 60;
|
172
|
+
wsec = wtime - (3600. * wh + 60. * wmin);
|
173
|
+
// csec = cptime - (3600. * ch + 60. * cpmin);
|
174
|
+
printf("Wall Time : %d hours and %d minutes and %.4f seconds.\n", wh, wmin, wsec);
|
175
|
+
// printf ("CPU Time : %d hours and %d minutes and %.4f seconds.\n",ch,cpmin,csec);
|
176
|
+
}
|
177
|
+
|
178
|
+
template <typename T>
|
179
|
+
inline std::vector<std::vector<T>> load_matrix(
|
180
|
+
const std::string filename,
|
181
|
+
const size_t row,
|
182
|
+
const size_t col)
|
183
|
+
{
|
184
|
+
/*!
|
185
|
+
* Read matrix into vector of vector
|
186
|
+
*
|
187
|
+
* \param filename [string] name of text file to read
|
188
|
+
* \param row [int] number of rows
|
189
|
+
* \param col [int] number of columns
|
190
|
+
|
191
|
+
* \return vector of vector of specified type
|
192
|
+
*
|
193
|
+
* **example**
|
194
|
+
* std::vector<std::vector<int>> A = Neuro::read_matrix<int>(
|
195
|
+
* "data/matrix_integer.txt", 4, 3);
|
196
|
+
*/
|
197
|
+
|
198
|
+
std::ifstream ifile(filename);
|
199
|
+
|
200
|
+
/*to check if input file exists*/
|
201
|
+
if (fileExists(filename))
|
202
|
+
{
|
203
|
+
std::vector<std::vector<T>> Cij(row, std::vector<T>(col));
|
204
|
+
|
205
|
+
for (size_t i = 0; i < row; i++)
|
206
|
+
{
|
207
|
+
for (size_t j = 0; j < col; j++)
|
208
|
+
{
|
209
|
+
ifile >> Cij[i][j];
|
210
|
+
}
|
211
|
+
}
|
212
|
+
ifile.close();
|
213
|
+
return Cij;
|
214
|
+
}
|
215
|
+
else
|
216
|
+
{
|
217
|
+
std::cerr << "\n file : " << filename << " not found \n";
|
218
|
+
exit(2);
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
double get_wall_time()
|
223
|
+
{
|
224
|
+
/*!
|
225
|
+
measure real passed time
|
226
|
+
\return wall time in second
|
227
|
+
*/
|
228
|
+
|
229
|
+
struct timeval time;
|
230
|
+
if (gettimeofday(&time, NULL))
|
231
|
+
{
|
232
|
+
// Handle error
|
233
|
+
return 0;
|
234
|
+
}
|
235
|
+
return (double)time.tv_sec + (double)time.tv_usec * .000001;
|
236
|
+
}
|
237
|
+
|
238
|
+
std::mt19937 &rng(const bool fix_seed)
|
239
|
+
{
|
240
|
+
if (fix_seed)
|
241
|
+
{
|
242
|
+
static std::mt19937 instance{2};
|
243
|
+
return instance;
|
244
|
+
}
|
245
|
+
else
|
246
|
+
{
|
247
|
+
static std::mt19937 instance{std::random_device{}()};
|
248
|
+
return instance;
|
249
|
+
}
|
250
|
+
}
|
251
|
+
|
252
|
+
void fill_vector(dim1 &v, const vector<int> indices, const double value)
|
253
|
+
{
|
254
|
+
for (size_t i = 0; i < indices.size(); ++i)
|
255
|
+
v[indices[i]] = value;
|
256
|
+
}
|
257
|
+
|
258
|
+
int find_nan(const dim1 &vec)
|
259
|
+
{
|
260
|
+
int ind = vec.size() - 1;
|
261
|
+
if (std::isnan(vec[ind]))
|
262
|
+
{
|
263
|
+
std::cout << "nan found!" << std::endl;
|
264
|
+
return -1;
|
265
|
+
}
|
266
|
+
return 0;
|
267
|
+
}
|
268
|
+
|
269
|
+
dim1 matvec(const dim2 &mat, const dim1 &x, const int offset = 0)
|
270
|
+
{
|
271
|
+
int N = mat.size();
|
272
|
+
dim1 y(N);
|
273
|
+
|
274
|
+
// # pragma omp simd
|
275
|
+
for (int i = 0; i < N; ++i)
|
276
|
+
{
|
277
|
+
y[i] = 0.0;
|
278
|
+
for (int j = 0; j < N; ++j)
|
279
|
+
y[i] += mat[i][j] * x[j + offset];
|
280
|
+
}
|
281
|
+
return y;
|
282
|
+
}
|
283
|
+
|
284
|
+
dim1 matvec_s(const dim2 &mat, const dim2I &a, const dim1 &x, const int offset = 0)
|
285
|
+
{
|
286
|
+
int n = mat.size();
|
287
|
+
dim1 y(n);
|
288
|
+
|
289
|
+
# pragma omp simd
|
290
|
+
for (int i=0; i<n; ++i)
|
291
|
+
{
|
292
|
+
for(int j:a[i])
|
293
|
+
{
|
294
|
+
y[i] += mat[i][j] * x[j + offset];
|
295
|
+
}
|
296
|
+
}
|
297
|
+
return y;
|
298
|
+
}
|
299
|
+
|
300
|
+
// dim1 matmul_e(const Eigen::MatrixXd &A, const Eigen::VectorXd &x)
|
301
|
+
// {
|
302
|
+
// Eigen::VectorXd y = A * x;
|
303
|
+
// dim1 y_vec(y.data(), y.data() + y.size());
|
304
|
+
// return y_vec;
|
305
|
+
// }
|
306
|
+
|
307
|
+
#endif
|
@@ -0,0 +1,171 @@
|
|
1
|
+
#ifndef bvep_HPP
|
2
|
+
#define bvep_HPP
|
3
|
+
|
4
|
+
#include <cmath>
|
5
|
+
#include <fenv.h>
|
6
|
+
#include <vector>
|
7
|
+
#include <random>
|
8
|
+
#include <string>
|
9
|
+
#include <assert.h>
|
10
|
+
#include <iostream>
|
11
|
+
#include <fstream>
|
12
|
+
#include "utility.hpp"
|
13
|
+
|
14
|
+
using std::string;
|
15
|
+
using std::vector;
|
16
|
+
|
17
|
+
typedef std::vector<double> dim1;
|
18
|
+
typedef std::vector<dim1> dim2;
|
19
|
+
|
20
|
+
class VEP
|
21
|
+
{
|
22
|
+
private:
|
23
|
+
int nn;
|
24
|
+
dim1 x;
|
25
|
+
dim1 eta;
|
26
|
+
double G;
|
27
|
+
dim1 iext;
|
28
|
+
double dt;
|
29
|
+
dim1 times;
|
30
|
+
double tcut;
|
31
|
+
double tend;
|
32
|
+
dim2 states;
|
33
|
+
int fix_seed;
|
34
|
+
dim2 weights;
|
35
|
+
string method;
|
36
|
+
double inv_tau;
|
37
|
+
unsigned num_steps;
|
38
|
+
double noise_sigma;
|
39
|
+
dim1 initial_state;
|
40
|
+
vector<vector<unsigned>> adjlist;
|
41
|
+
|
42
|
+
public:
|
43
|
+
VEP(
|
44
|
+
double G,
|
45
|
+
dim1 iext,
|
46
|
+
dim1 eta,
|
47
|
+
double dt,
|
48
|
+
double tcut,
|
49
|
+
double tend,
|
50
|
+
double tau,
|
51
|
+
double noise_sigma,
|
52
|
+
dim1 initial_state,
|
53
|
+
dim2 weights,
|
54
|
+
int fix_seed,
|
55
|
+
string method)
|
56
|
+
{
|
57
|
+
this->G = G;
|
58
|
+
this->dt = dt;
|
59
|
+
this->nn = weights.size();
|
60
|
+
this->iext = iext;
|
61
|
+
this->eta = eta;
|
62
|
+
this->tcut = tcut;
|
63
|
+
this->tend = tend;
|
64
|
+
this->method = method;
|
65
|
+
this->fix_seed = fix_seed;
|
66
|
+
this->weights = weights;
|
67
|
+
this->inv_tau = 1.0 / tau;
|
68
|
+
this->noise_sigma = noise_sigma;
|
69
|
+
this->initial_state = initial_state;
|
70
|
+
adjlist = adjmat_to_adjlist(weights);
|
71
|
+
|
72
|
+
unsigned idx_cut = (int)(tcut / dt);
|
73
|
+
num_steps = (int)(tend / dt);
|
74
|
+
unsigned bufsize = num_steps - idx_cut;
|
75
|
+
|
76
|
+
states.resize(bufsize);
|
77
|
+
for (int i = 0; i < bufsize; i++)
|
78
|
+
{
|
79
|
+
states[i].resize(nn);
|
80
|
+
}
|
81
|
+
times.resize(bufsize);
|
82
|
+
};
|
83
|
+
|
84
|
+
void rhs(const vector<double> &x, vector<double> &dxdt, const double t)
|
85
|
+
{
|
86
|
+
for (int i = 0; i < nn; i++)
|
87
|
+
{
|
88
|
+
double gx = 0.0;
|
89
|
+
for (size_t j = 0; j < adjlist[i].size(); ++j)
|
90
|
+
{
|
91
|
+
int k = adjlist[i][j];
|
92
|
+
gx += weights[i][k] * (x[k] - x[i]);
|
93
|
+
}
|
94
|
+
dxdt[i] = 1.0 - x[i] * x[i] * x[i] - 2.0 * x[i] * x[i] - x[i + nn] + iext[i];
|
95
|
+
dxdt[i + nn] = inv_tau * (4.0 * (x[i] - eta[i]) - x[i + nn] - G * gx);
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
void euler_step(vector<double> &x, const double t)
|
100
|
+
{
|
101
|
+
std::normal_distribution<> normal(0, 1);
|
102
|
+
vector<double> dxdt(nn * 2);
|
103
|
+
|
104
|
+
rhs(x, dxdt, t);
|
105
|
+
for (int i = 0; i < nn * 2; i++)
|
106
|
+
{
|
107
|
+
x[i] += dt * dxdt[i] + sqrt(dt) * noise_sigma * normal(rng(fix_seed));
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
void heun_step(vector<double> &x, const double t)
|
112
|
+
{
|
113
|
+
std::normal_distribution<> normal(0, 1);
|
114
|
+
vector<double> dxdt(nn * 2);
|
115
|
+
vector<double> xtemp(nn * 2);
|
116
|
+
|
117
|
+
rhs(x, dxdt, t);
|
118
|
+
for (int i = 0; i < nn * 2; i++)
|
119
|
+
{
|
120
|
+
xtemp[i] = x[i] + dt * dxdt[i] + sqrt(dt) * noise_sigma * normal(rng(fix_seed));
|
121
|
+
}
|
122
|
+
|
123
|
+
vector<double> dxdt_temp(nn * 2);
|
124
|
+
rhs(xtemp, dxdt_temp, t + dt);
|
125
|
+
for (int i = 0; i < nn * 2; i++)
|
126
|
+
{
|
127
|
+
x[i] += 0.5 * dt * (dxdt[i] + dxdt_temp[i]) + sqrt(dt) * noise_sigma * normal(rng(fix_seed));
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
void integrate()
|
132
|
+
{
|
133
|
+
dim1 x = initial_state;
|
134
|
+
int idxtcut = (int)(tcut / dt);
|
135
|
+
double t = 0.0;
|
136
|
+
int counter = 0;
|
137
|
+
|
138
|
+
for (int it = 0; it < num_steps; it++)
|
139
|
+
{
|
140
|
+
if (it >= idxtcut)
|
141
|
+
{
|
142
|
+
for (int i = 0; i < nn; i++)
|
143
|
+
{
|
144
|
+
states[counter][i] = x[i];
|
145
|
+
}
|
146
|
+
times[counter] = t;
|
147
|
+
counter++;
|
148
|
+
}
|
149
|
+
|
150
|
+
t += dt;
|
151
|
+
if (method == "euler")
|
152
|
+
euler_step(x, t);
|
153
|
+
else if (method == "heun")
|
154
|
+
heun_step(x, t);
|
155
|
+
else
|
156
|
+
throw std::invalid_argument("Invalid method");
|
157
|
+
}
|
158
|
+
}
|
159
|
+
|
160
|
+
dim2 get_states()
|
161
|
+
{
|
162
|
+
return states;
|
163
|
+
}
|
164
|
+
|
165
|
+
dim1 get_times()
|
166
|
+
{
|
167
|
+
return times;
|
168
|
+
}
|
169
|
+
};
|
170
|
+
|
171
|
+
#endif
|
@@ -0,0 +1,16 @@
|
|
1
|
+
%module vep
|
2
|
+
|
3
|
+
%{
|
4
|
+
#include "vep.hpp"
|
5
|
+
%}
|
6
|
+
|
7
|
+
%include stl.i
|
8
|
+
%include "std_string.i"
|
9
|
+
/* instantiate the required template specializations */
|
10
|
+
namespace std {
|
11
|
+
%template(IntVector) vector<int>;
|
12
|
+
%template(DoubleVector) vector<double>;
|
13
|
+
%template(DoubleVector2) vector<vector<double> >;
|
14
|
+
}
|
15
|
+
|
16
|
+
%include "vep.hpp"
|