pyNIBS 0.2024.8__py3-none-any.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.
- pyNIBS-0.2024.8.dist-info/LICENSE +623 -0
- pyNIBS-0.2024.8.dist-info/METADATA +723 -0
- pyNIBS-0.2024.8.dist-info/RECORD +107 -0
- pyNIBS-0.2024.8.dist-info/WHEEL +5 -0
- pyNIBS-0.2024.8.dist-info/top_level.txt +1 -0
- pynibs/__init__.py +34 -0
- pynibs/coil.py +1367 -0
- pynibs/congruence/__init__.py +15 -0
- pynibs/congruence/congruence.py +1108 -0
- pynibs/congruence/ext_metrics.py +257 -0
- pynibs/congruence/stimulation_threshold.py +318 -0
- pynibs/data/configuration_exp0.yaml +59 -0
- pynibs/data/configuration_linear_MEP.yaml +61 -0
- pynibs/data/configuration_linear_RT.yaml +61 -0
- pynibs/data/configuration_sigmoid4.yaml +68 -0
- pynibs/data/network mapping configuration/configuration guide.md +238 -0
- pynibs/data/network mapping configuration/configuration_TEMPLATE.yaml +42 -0
- pynibs/data/network mapping configuration/configuration_for_testing.yaml +43 -0
- pynibs/data/network mapping configuration/configuration_modelTMS.yaml +43 -0
- pynibs/data/network mapping configuration/configuration_reg_isi_05.yaml +43 -0
- pynibs/data/network mapping configuration/output_documentation.md +185 -0
- pynibs/data/network mapping configuration/recommendations_for_accuracy_threshold.md +77 -0
- pynibs/data/neuron/models/L23_PC_cADpyr_biphasic_v1.csv +1281 -0
- pynibs/data/neuron/models/L23_PC_cADpyr_monophasic_v1.csv +1281 -0
- pynibs/data/neuron/models/L4_LBC_biphasic_v1.csv +1281 -0
- pynibs/data/neuron/models/L4_LBC_monophasic_v1.csv +1281 -0
- pynibs/data/neuron/models/L4_NBC_biphasic_v1.csv +1281 -0
- pynibs/data/neuron/models/L4_NBC_monophasic_v1.csv +1281 -0
- pynibs/data/neuron/models/L4_SBC_biphasic_v1.csv +1281 -0
- pynibs/data/neuron/models/L4_SBC_monophasic_v1.csv +1281 -0
- pynibs/data/neuron/models/L5_TTPC2_cADpyr_biphasic_v1.csv +1281 -0
- pynibs/data/neuron/models/L5_TTPC2_cADpyr_monophasic_v1.csv +1281 -0
- pynibs/expio/Mep.py +1518 -0
- pynibs/expio/__init__.py +8 -0
- pynibs/expio/brainsight.py +979 -0
- pynibs/expio/brainvis.py +71 -0
- pynibs/expio/cobot.py +239 -0
- pynibs/expio/exp.py +1876 -0
- pynibs/expio/fit_funs.py +287 -0
- pynibs/expio/localite.py +1987 -0
- pynibs/expio/signal_ced.py +51 -0
- pynibs/expio/visor.py +624 -0
- pynibs/freesurfer.py +502 -0
- pynibs/hdf5_io/__init__.py +10 -0
- pynibs/hdf5_io/hdf5_io.py +1857 -0
- pynibs/hdf5_io/xdmf.py +1542 -0
- pynibs/mesh/__init__.py +3 -0
- pynibs/mesh/mesh_struct.py +1394 -0
- pynibs/mesh/transformations.py +866 -0
- pynibs/mesh/utils.py +1103 -0
- pynibs/models/_TMS.py +211 -0
- pynibs/models/__init__.py +0 -0
- pynibs/muap.py +392 -0
- pynibs/neuron/__init__.py +2 -0
- pynibs/neuron/neuron_regression.py +284 -0
- pynibs/neuron/util.py +58 -0
- pynibs/optimization/__init__.py +5 -0
- pynibs/optimization/multichannel.py +278 -0
- pynibs/optimization/opt_mep.py +152 -0
- pynibs/optimization/optimization.py +1445 -0
- pynibs/optimization/workhorses.py +698 -0
- pynibs/pckg/__init__.py +0 -0
- pynibs/pckg/biosig/biosig4c++-1.9.5.src_fixed.tar.gz +0 -0
- pynibs/pckg/libeep/__init__.py +0 -0
- pynibs/pckg/libeep/pyeep.so +0 -0
- pynibs/regression/__init__.py +11 -0
- pynibs/regression/dual_node_detection.py +2375 -0
- pynibs/regression/regression.py +2984 -0
- pynibs/regression/score_types.py +0 -0
- pynibs/roi/__init__.py +2 -0
- pynibs/roi/roi.py +895 -0
- pynibs/roi/roi_structs.py +1233 -0
- pynibs/subject.py +1009 -0
- pynibs/tensor_scaling.py +144 -0
- pynibs/tests/data/InstrumentMarker20200225163611937.xml +19 -0
- pynibs/tests/data/TriggerMarkers_Coil0_20200225163443682.xml +14 -0
- pynibs/tests/data/TriggerMarkers_Coil1_20200225170337572.xml +6373 -0
- pynibs/tests/data/Xdmf.dtd +89 -0
- pynibs/tests/data/brainsight_niiImage_nifticoord.txt +145 -0
- pynibs/tests/data/brainsight_niiImage_nifticoord_largefile.txt +1434 -0
- pynibs/tests/data/brainsight_niiImage_niifticoord_mixedtargets.txt +47 -0
- pynibs/tests/data/create_subject_testsub.py +332 -0
- pynibs/tests/data/data.hdf5 +0 -0
- pynibs/tests/data/geo.hdf5 +0 -0
- pynibs/tests/test_coil.py +474 -0
- pynibs/tests/test_elements2nodes.py +100 -0
- pynibs/tests/test_hdf5_io/test_xdmf.py +61 -0
- pynibs/tests/test_mesh_transformations.py +123 -0
- pynibs/tests/test_mesh_utils.py +143 -0
- pynibs/tests/test_nnav_imports.py +101 -0
- pynibs/tests/test_quality_measures.py +117 -0
- pynibs/tests/test_regressdata.py +289 -0
- pynibs/tests/test_roi.py +17 -0
- pynibs/tests/test_rotations.py +86 -0
- pynibs/tests/test_subject.py +71 -0
- pynibs/tests/test_util.py +24 -0
- pynibs/tms_pulse.py +34 -0
- pynibs/util/__init__.py +4 -0
- pynibs/util/dosing.py +233 -0
- pynibs/util/quality_measures.py +562 -0
- pynibs/util/rotations.py +340 -0
- pynibs/util/simnibs.py +763 -0
- pynibs/util/util.py +727 -0
- pynibs/visualization/__init__.py +2 -0
- pynibs/visualization/para.py +4372 -0
- pynibs/visualization/plot_2D.py +137 -0
- pynibs/visualization/render_3D.py +347 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Functions to select optimal stimulation conditions based on the estimated y (i.e., MEPs in MEP studies).
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def get_fim_sample(fun, x, p):
|
|
9
|
+
"""
|
|
10
|
+
Get Fisher Information Matrix of one single sample.
|
|
11
|
+
|
|
12
|
+
Parameters
|
|
13
|
+
----------
|
|
14
|
+
fun : callable
|
|
15
|
+
Callable the fisher information matrix is calculated for. The sample is passed as the first argument.
|
|
16
|
+
x : float
|
|
17
|
+
Sample passed to function.
|
|
18
|
+
p : dict
|
|
19
|
+
Dictionary containing the parameter estimates. The keys are the parameter names of fun.
|
|
20
|
+
|
|
21
|
+
Returns
|
|
22
|
+
-------
|
|
23
|
+
fim_matrix : np.ndarray of float
|
|
24
|
+
(n_params, n_params) Fisher information matrix.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
# read function arguments
|
|
28
|
+
params = p.keys()
|
|
29
|
+
|
|
30
|
+
# determine gradient of function w.r.t. parameters using forward approximation
|
|
31
|
+
dfdp = np.zeros(len(params))
|
|
32
|
+
|
|
33
|
+
for i, para in enumerate(params):
|
|
34
|
+
# copy original params dict
|
|
35
|
+
p_dp = dict()
|
|
36
|
+
|
|
37
|
+
for pa in params:
|
|
38
|
+
p_dp[pa] = p[pa]
|
|
39
|
+
|
|
40
|
+
# perturb parameter
|
|
41
|
+
dp = p[para] / 1000
|
|
42
|
+
p_dp[para] = p[para] + dp
|
|
43
|
+
|
|
44
|
+
# determine gradient with forward approximation
|
|
45
|
+
dfdp[i] = (fun(x, **p_dp) - fun(x, **p)) / dp
|
|
46
|
+
|
|
47
|
+
fim_matrix = np.outer(dfdp, dfdp)
|
|
48
|
+
|
|
49
|
+
return fim_matrix
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def get_det_fim(x, fun, p, fim_matrix):
|
|
53
|
+
"""
|
|
54
|
+
Updates the Fisher Information Matrix and returns the negative determinant based on the sample x.
|
|
55
|
+
It is a score how much information the additional sample yields.
|
|
56
|
+
|
|
57
|
+
Parameters
|
|
58
|
+
----------
|
|
59
|
+
fun : callable
|
|
60
|
+
Callable defined in interval [0, 1].
|
|
61
|
+
x : float
|
|
62
|
+
Single sample location (interval [0, 1]).
|
|
63
|
+
p : dict
|
|
64
|
+
Dictionary containing the parameter estimates. The keys are the parameter names of fun.
|
|
65
|
+
fim_matrix : np.ndarray of float
|
|
66
|
+
(n_params, n_params) Fisher Information Matrix.
|
|
67
|
+
|
|
68
|
+
Returns
|
|
69
|
+
-------
|
|
70
|
+
det : float
|
|
71
|
+
Determinant of the Fisher Information Matrix after adding sample x.
|
|
72
|
+
"""
|
|
73
|
+
fim_matrix_sample = fim_matrix + get_fim_sample(fun=fun, x=x, p=p)
|
|
74
|
+
sign, logdet = np.linalg.slogdet(fim_matrix_sample)
|
|
75
|
+
|
|
76
|
+
return -sign * np.exp(logdet)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def init_fim_matrix(fun, x, p):
|
|
80
|
+
"""
|
|
81
|
+
Initializes the Fisher Information Matrix based on the samples given in x.
|
|
82
|
+
|
|
83
|
+
Parameters
|
|
84
|
+
----------
|
|
85
|
+
fun : callable
|
|
86
|
+
Callable defined in interval [0, 1].
|
|
87
|
+
x : np.ndarray of float
|
|
88
|
+
Initial sample locations (interval [0, 1]).
|
|
89
|
+
p : dict
|
|
90
|
+
Dictionary containing the parameter estimates. The keys are the parameter names of fun.
|
|
91
|
+
|
|
92
|
+
Returns
|
|
93
|
+
-------
|
|
94
|
+
fim_matrix : np.ndarray of float [n_params x n_params]
|
|
95
|
+
Fisher Information Matrix.
|
|
96
|
+
"""
|
|
97
|
+
fim_matrix = np.zeros((len(p), len(p)))
|
|
98
|
+
|
|
99
|
+
for x_i in x:
|
|
100
|
+
fim_matrix += get_fim_sample(fun=fun, x=x_i, p=p)
|
|
101
|
+
|
|
102
|
+
return fim_matrix
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def get_optimal_sample_fim(fun, p, x=None):
|
|
106
|
+
"""
|
|
107
|
+
Determines optimal location of next sample by maximizing the determinant of the Fisher Information Matrix.
|
|
108
|
+
|
|
109
|
+
Parameters
|
|
110
|
+
----------
|
|
111
|
+
fun : callable
|
|
112
|
+
Callable (interval [0, 1]).
|
|
113
|
+
x : np.ndarray of float, optional
|
|
114
|
+
Previous sample locations (interval [0, 1]).
|
|
115
|
+
p : dict
|
|
116
|
+
Dictionary containing the parameter estimates. The keys are the parameter names of fun.
|
|
117
|
+
|
|
118
|
+
Returns
|
|
119
|
+
-------
|
|
120
|
+
x_opt : float
|
|
121
|
+
Optimal location of next sample (interval [0, 1]).
|
|
122
|
+
"""
|
|
123
|
+
# initialize fim matrix with initial samples
|
|
124
|
+
if x is None:
|
|
125
|
+
fim_matrix = np.zeros((len(p), len(p)))
|
|
126
|
+
else:
|
|
127
|
+
fim_matrix = init_fim_matrix(fun=fun, x=x, p=p)
|
|
128
|
+
|
|
129
|
+
# run optimization
|
|
130
|
+
# res = minimize(fun=get_det_fim,
|
|
131
|
+
# method="trust-constr",
|
|
132
|
+
# bounds=((0, 1),),
|
|
133
|
+
# x0=np.array([0.5]),
|
|
134
|
+
# args=(fun, p, fim_matrix),
|
|
135
|
+
# options={"finite_diff_rel_step": 0.05, "xtol": 0.01})
|
|
136
|
+
|
|
137
|
+
# res = minimize(fun=get_det_fim,
|
|
138
|
+
# method="SLSQP",
|
|
139
|
+
# x0=np.array([0.5]),
|
|
140
|
+
# bounds=((0, 1),),
|
|
141
|
+
# args=(fun, p, fim_matrix),
|
|
142
|
+
# options={'disp': None, "eps": 0.001, "ftol": 1e-12}) #,
|
|
143
|
+
# return res.x[0]
|
|
144
|
+
|
|
145
|
+
x_bf = np.linspace(0, 1, 200)
|
|
146
|
+
det = np.zeros(len(x_bf))
|
|
147
|
+
for i in range(len(x_bf)):
|
|
148
|
+
det[i] = get_det_fim(x=x_bf[i], fun=fun, p=p, fim_matrix=fim_matrix)
|
|
149
|
+
|
|
150
|
+
x_opt = x_bf[np.argmin(det)]
|
|
151
|
+
|
|
152
|
+
return x_opt
|