brainmass 0.0.5__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.
- brainmass/__init__.py +187 -0
- brainmass/_xy_model.py +96 -0
- brainmass/coupling.py +499 -0
- brainmass/coupling_test.py +214 -0
- brainmass/fhn.py +239 -0
- brainmass/fhn_test.py +142 -0
- brainmass/forward_model.py +487 -0
- brainmass/forward_model_test.py +176 -0
- brainmass/hopf.py +167 -0
- brainmass/hopf_test.py +158 -0
- brainmass/horn.py +804 -0
- brainmass/jansen_rit.py +1027 -0
- brainmass/jansen_rit_test.py +470 -0
- brainmass/kuramoto.py +269 -0
- brainmass/leadfield.py +81 -0
- brainmass/linear.py +186 -0
- brainmass/linear_test.py +141 -0
- brainmass/noise.py +254 -0
- brainmass/noise_test.py +307 -0
- brainmass/qif.py +265 -0
- brainmass/qif_test.py +139 -0
- brainmass/sl.py +168 -0
- brainmass/sl_test.py +121 -0
- brainmass/typing.py +33 -0
- brainmass/utils.py +182 -0
- brainmass/vdp.py +220 -0
- brainmass/vdp_test.py +129 -0
- brainmass/wilson_cowan.py +2683 -0
- brainmass/wilson_cowan_test.py +910 -0
- brainmass/wong_wang.py +292 -0
- brainmass/wong_wang_test.py +414 -0
- brainmass-0.0.5.dist-info/METADATA +132 -0
- brainmass-0.0.5.dist-info/RECORD +36 -0
- brainmass-0.0.5.dist-info/WHEEL +5 -0
- brainmass-0.0.5.dist-info/licenses/LICENSE +202 -0
- brainmass-0.0.5.dist-info/top_level.txt +1 -0
brainmass/__init__.py
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# Copyright 2024 BrainX Ecosystem Limited. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# ==============================================================================
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
__version__ = "0.0.5"
|
|
18
|
+
__version_info__ = tuple(map(int, __version__.split(".")))
|
|
19
|
+
|
|
20
|
+
from ._xy_model import (
|
|
21
|
+
XY_Oscillator,
|
|
22
|
+
)
|
|
23
|
+
# Coupling mechanisms
|
|
24
|
+
from .coupling import (
|
|
25
|
+
DiffusiveCoupling,
|
|
26
|
+
AdditiveCoupling,
|
|
27
|
+
diffusive_coupling,
|
|
28
|
+
additive_coupling,
|
|
29
|
+
laplacian_connectivity,
|
|
30
|
+
LaplacianConnParam,
|
|
31
|
+
)
|
|
32
|
+
# Neural mass models
|
|
33
|
+
from .fhn import FitzHughNagumoStep
|
|
34
|
+
# Forward models and lead field
|
|
35
|
+
from .forward_model import (
|
|
36
|
+
BOLDSignal,
|
|
37
|
+
LeadFieldModel,
|
|
38
|
+
EEGLeadFieldModel,
|
|
39
|
+
MEGLeadFieldModel,
|
|
40
|
+
)
|
|
41
|
+
from .hopf import HopfStep
|
|
42
|
+
# HORN models
|
|
43
|
+
from .horn import (
|
|
44
|
+
HORNStep,
|
|
45
|
+
HORNSeqLayer,
|
|
46
|
+
HORNSeqNetwork,
|
|
47
|
+
)
|
|
48
|
+
from .jansen_rit import (
|
|
49
|
+
JansenRitStep,
|
|
50
|
+
JansenRitTR,
|
|
51
|
+
)
|
|
52
|
+
from .kuramoto import KuramotoNetwork
|
|
53
|
+
from .leadfield import LeadfieldReadout
|
|
54
|
+
from .linear import ThresholdLinearStep
|
|
55
|
+
# Noise processes
|
|
56
|
+
from .noise import (
|
|
57
|
+
Noise,
|
|
58
|
+
OUProcess,
|
|
59
|
+
GaussianNoise,
|
|
60
|
+
WhiteNoise,
|
|
61
|
+
ColoredNoise,
|
|
62
|
+
BrownianNoise,
|
|
63
|
+
PinkNoise,
|
|
64
|
+
BlueNoise,
|
|
65
|
+
VioletNoise,
|
|
66
|
+
)
|
|
67
|
+
from .qif import MontbrioPazoRoxinStep
|
|
68
|
+
from .sl import StuartLandauStep
|
|
69
|
+
# Type aliases
|
|
70
|
+
from .typing import (
|
|
71
|
+
Initializer,
|
|
72
|
+
Array,
|
|
73
|
+
Parameter,
|
|
74
|
+
)
|
|
75
|
+
# Common utilities
|
|
76
|
+
from .utils import (
|
|
77
|
+
sys2nd,
|
|
78
|
+
sigmoid,
|
|
79
|
+
bounded_input,
|
|
80
|
+
process_sequence,
|
|
81
|
+
delay_index,
|
|
82
|
+
)
|
|
83
|
+
from .vdp import VanDerPolStep
|
|
84
|
+
from .wilson_cowan import (
|
|
85
|
+
WilsonCowanStep,
|
|
86
|
+
WilsonCowanNoSaturationStep,
|
|
87
|
+
WilsonCowanSymmetricStep,
|
|
88
|
+
WilsonCowanSimplifiedStep,
|
|
89
|
+
WilsonCowanLinearStep,
|
|
90
|
+
WilsonCowanDivisiveStep,
|
|
91
|
+
WilsonCowanDivisiveInputStep,
|
|
92
|
+
WilsonCowanDelayedStep,
|
|
93
|
+
WilsonCowanAdaptiveStep,
|
|
94
|
+
WilsonCowanThreePopBase,
|
|
95
|
+
WilsonCowanThreePopulationStep,
|
|
96
|
+
)
|
|
97
|
+
from .wong_wang import WongWangStep
|
|
98
|
+
|
|
99
|
+
__all__ = [
|
|
100
|
+
# Version
|
|
101
|
+
'__version__',
|
|
102
|
+
'__version_info__',
|
|
103
|
+
|
|
104
|
+
# Common utilities
|
|
105
|
+
'XY_Oscillator',
|
|
106
|
+
'sys2nd',
|
|
107
|
+
'sigmoid',
|
|
108
|
+
'bounded_input',
|
|
109
|
+
'process_sequence',
|
|
110
|
+
'delay_index',
|
|
111
|
+
|
|
112
|
+
# Type aliases
|
|
113
|
+
'Initializer',
|
|
114
|
+
'Array',
|
|
115
|
+
'Parameter',
|
|
116
|
+
|
|
117
|
+
# Noise processes
|
|
118
|
+
'Noise',
|
|
119
|
+
'OUProcess',
|
|
120
|
+
'GaussianNoise',
|
|
121
|
+
'WhiteNoise',
|
|
122
|
+
'ColoredNoise',
|
|
123
|
+
'BrownianNoise',
|
|
124
|
+
'PinkNoise',
|
|
125
|
+
'BlueNoise',
|
|
126
|
+
'VioletNoise',
|
|
127
|
+
|
|
128
|
+
# Neural mass models
|
|
129
|
+
'FitzHughNagumoStep',
|
|
130
|
+
'HopfStep',
|
|
131
|
+
'WilsonCowanStep',
|
|
132
|
+
'WilsonCowanNoSaturationStep',
|
|
133
|
+
'WilsonCowanSymmetricStep',
|
|
134
|
+
'WilsonCowanSimplifiedStep',
|
|
135
|
+
'WilsonCowanLinearStep',
|
|
136
|
+
'WilsonCowanDivisiveStep',
|
|
137
|
+
'WilsonCowanDivisiveInputStep',
|
|
138
|
+
'WilsonCowanDelayedStep',
|
|
139
|
+
'WilsonCowanAdaptiveStep',
|
|
140
|
+
'WilsonCowanThreePopBase',
|
|
141
|
+
'WilsonCowanThreePopulationStep',
|
|
142
|
+
'WongWangStep',
|
|
143
|
+
'VanDerPolStep',
|
|
144
|
+
'MontbrioPazoRoxinStep',
|
|
145
|
+
'ThresholdLinearStep',
|
|
146
|
+
'LeadfieldReadout',
|
|
147
|
+
'KuramotoNetwork',
|
|
148
|
+
'StuartLandauStep',
|
|
149
|
+
|
|
150
|
+
# Jansen-Rit model
|
|
151
|
+
'JansenRitStep',
|
|
152
|
+
'JansenRitTR',
|
|
153
|
+
|
|
154
|
+
# Forward models and lead field
|
|
155
|
+
'BOLDSignal',
|
|
156
|
+
'LeadFieldModel',
|
|
157
|
+
'EEGLeadFieldModel',
|
|
158
|
+
'MEGLeadFieldModel',
|
|
159
|
+
|
|
160
|
+
# Coupling mechanisms
|
|
161
|
+
'DiffusiveCoupling',
|
|
162
|
+
'AdditiveCoupling',
|
|
163
|
+
'diffusive_coupling',
|
|
164
|
+
'additive_coupling',
|
|
165
|
+
'laplacian_connectivity',
|
|
166
|
+
'LaplacianConnParam',
|
|
167
|
+
|
|
168
|
+
# HORN models
|
|
169
|
+
'HORNStep',
|
|
170
|
+
'HORNSeqLayer',
|
|
171
|
+
'HORNSeqNetwork',
|
|
172
|
+
]
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def __getattr__(old_name):
|
|
176
|
+
name = old_name.replace('Model', 'Step')
|
|
177
|
+
if name in __all__:
|
|
178
|
+
import warnings
|
|
179
|
+
from . import __name__ as module_name
|
|
180
|
+
module = __import__(module_name, fromlist=[name])
|
|
181
|
+
warnings.warn(
|
|
182
|
+
f"{module_name}.{name} is deprecated, use {module_name}.{old_name} instead.",
|
|
183
|
+
DeprecationWarning
|
|
184
|
+
)
|
|
185
|
+
return getattr(module, name)
|
|
186
|
+
else:
|
|
187
|
+
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
|
brainmass/_xy_model.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Copyright 2026 BrainX Ecosystem Limited. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# ==============================================================================
|
|
15
|
+
|
|
16
|
+
from typing import Callable
|
|
17
|
+
|
|
18
|
+
import braintools
|
|
19
|
+
import brainunit as u
|
|
20
|
+
|
|
21
|
+
import brainstate
|
|
22
|
+
from .noise import Noise
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
'XY_Oscillator',
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class XY_Oscillator(brainstate.nn.Dynamics):
|
|
30
|
+
def __init__(
|
|
31
|
+
self,
|
|
32
|
+
in_size: brainstate.typing.Size,
|
|
33
|
+
|
|
34
|
+
# noise parameters
|
|
35
|
+
noise_x: Noise = None,
|
|
36
|
+
noise_y: Noise = None,
|
|
37
|
+
|
|
38
|
+
# other parameters
|
|
39
|
+
init_x: Callable = braintools.init.Uniform(0, 0.05),
|
|
40
|
+
init_y: Callable = braintools.init.Uniform(0, 0.05),
|
|
41
|
+
method: str = 'exp_euler',
|
|
42
|
+
):
|
|
43
|
+
super().__init__(in_size)
|
|
44
|
+
|
|
45
|
+
# initializers
|
|
46
|
+
assert isinstance(noise_x, Noise) or noise_x is None, "noise_x must be a Noise instance or None."
|
|
47
|
+
assert isinstance(noise_y, Noise) or noise_y is None, "noise_y must be a Noise instance or None."
|
|
48
|
+
assert callable(init_x), "init_x must be a callable."
|
|
49
|
+
assert callable(init_y), "init_y must be a callable."
|
|
50
|
+
self.init_x = init_x
|
|
51
|
+
self.init_y = init_y
|
|
52
|
+
self.noise_x = noise_x
|
|
53
|
+
self.noise_y = noise_y
|
|
54
|
+
self.method = method
|
|
55
|
+
|
|
56
|
+
def init_state(self, batch_size=None, **kwargs):
|
|
57
|
+
"""Initialize model states ``x`` and ``y``.
|
|
58
|
+
|
|
59
|
+
Parameters
|
|
60
|
+
----------
|
|
61
|
+
batch_size : int or None, optional
|
|
62
|
+
Optional leading batch dimension. If ``None``, no batch dimension is
|
|
63
|
+
used. Default is ``None``.
|
|
64
|
+
"""
|
|
65
|
+
self.x = brainstate.HiddenState.init(self.init_x, self.varshape, batch_size)
|
|
66
|
+
self.y = brainstate.HiddenState.init(self.init_y, self.varshape, batch_size)
|
|
67
|
+
|
|
68
|
+
def dx(self, x, y, x_ext):
|
|
69
|
+
raise NotImplementedError
|
|
70
|
+
|
|
71
|
+
def dy(self, y, x, y_ext):
|
|
72
|
+
raise NotImplementedError
|
|
73
|
+
|
|
74
|
+
def derivative(self, state, t, x_ext, y_ext):
|
|
75
|
+
x, y = state
|
|
76
|
+
dxdt = self.dx(x, y, x_ext)
|
|
77
|
+
dydt = self.dy(y, x, y_ext)
|
|
78
|
+
return dxdt, dydt
|
|
79
|
+
|
|
80
|
+
def update(self, x_inp=None, y_inp=None):
|
|
81
|
+
x_inp = 0. if x_inp is None else x_inp
|
|
82
|
+
y_inp = 0. if y_inp is None else y_inp
|
|
83
|
+
if self.noise_x is not None:
|
|
84
|
+
x_inp = x_inp + self.noise_x()
|
|
85
|
+
if self.noise_y is not None:
|
|
86
|
+
y_inp = y_inp + self.noise_y()
|
|
87
|
+
if self.method == 'exp_euler':
|
|
88
|
+
x = brainstate.nn.exp_euler_step(self.dx, self.x.value, self.y.value, x_inp)
|
|
89
|
+
y = brainstate.nn.exp_euler_step(self.dy, self.y.value, self.x.value, y_inp)
|
|
90
|
+
else:
|
|
91
|
+
method = getattr(braintools.quad, f'ode_{self.method}_step')
|
|
92
|
+
t = brainstate.environ.get('t', 0 * u.ms)
|
|
93
|
+
x, y = method(self.derivative, (self.x.value, self.y.value), t, x_inp, y_inp)
|
|
94
|
+
self.x.value = x
|
|
95
|
+
self.y.value = y
|
|
96
|
+
return x, y
|