Skip to content

Commit

Permalink
Merge pull request #18 from PKU-NIP-Lab/develop
Browse files Browse the repository at this point in the history
Update phase-plane-analysis and bifurcation-analysis
  • Loading branch information
chaoming0625 committed Nov 29, 2020
2 parents 5327b71 + 72c5d87 commit d8ce6cd
Show file tree
Hide file tree
Showing 28 changed files with 3,029 additions and 1,192 deletions.
25 changes: 14 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ Neurodynamics simulation
</table>


Network examples please see `networks <https://github.com/PKU-NIP-Lab/BrainPy/tree/master/examples/networks>`_.

More neuron examples please see `neurons <https://github.com/PKU-NIP-Lab/BrainPy/tree/master/examples/neurons>`_.

More synapse examples please see `synapses <https://github.com/PKU-NIP-Lab/BrainPy/tree/master/examples/synapses>`_.

More network examples please see `networks <https://github.com/PKU-NIP-Lab/BrainPy/tree/master/examples/networks>`_.


Neurodynamics analysis
======================
Expand All @@ -172,35 +172,38 @@ Neurodynamics analysis
<table border="0">
<tr>
<td border="0" width="30%">
<a href="examples/dynamics_analysis/phase_portrait.py">
<a href="examples/dynamics_analysis/phase_portrait_of_NaK_model.py">
<img src="docs/images/phase_plane_analysis.png">
</a>
</td>
<td border="0" valign="top">
<h3><a href="examples/dynamics_analysis/phase_portrait.py">Phase Plane Analysis</a></h3>
<p>Phase plane analysis of a two-dimensional system model.</p>
<h3><a href="examples/dynamics_analysis/phase_portrait_of_NaK_model.py">Phase Plane Analysis</a></h3>
<p>Phase plane analysis of a two-dimensional system model:
the I<sub>Na,p+</sub>-I<sub>K</sub> model.</p>
</td>
</tr>
<tr>
<td border="0" width="30%">
<a href="examples/dynamics_analysis/bifurcation_codim-1.py">
<a href="examples/dynamics_analysis/1D_system_bifur_codim1.py">
<img src="docs/images/codimension1.png">
</a>
</td>
<td border="0" valign="top">
<h3><a href="examples/dynamics_analysis/bifurcation_codim-1.py">Codimension 1 Bifurcation Analysis</a></h3>
<p>An example of codimension 1 bifurcation analysis.</p>
<h3><a href="examples/dynamics_analysis/1D_system_bifur_codim1.py">Codimension 1 Bifurcation Analysis</a></h3>
<p>Codimension 1 bifurcation analysis of a one-dimensional system.</p>
</td>
</tr>
<tr>
<td border="0" width="30%">
<a href="examples/dynamics_analysis/bifurcation_codim-2.py">
<a href="examples/dynamics_analysis/2D_system_bifur_codim2.py">
<img src="docs/images/codimension2.png">
</a>
</td>
<td border="0" valign="top">
<h3><a href="examples/dynamics_analysis/bifurcation_codim-2.py">Codimension 2 Bifurcation Analysis</a></h3>
<p>An example of codimension 2 bifurcation analysis.</p>
<h3><a href="examples/dynamics_analysis/2D_system_bifur_codim2.py">
Codimension 2 Bifurcation Analysis</a></h3>
<p>Codimension 2 bifurcation analysis of a two-variable neuron model:
the I<sub>Na,p+</sub>-I<sub>K</sub> model.</p>
</td>
</tr>
</table>
Expand Down
9 changes: 7 additions & 2 deletions brainpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

__version__ = "0.2.4"
__version__ = "0.2.5"

# "profile" module
from . import profile
Expand All @@ -19,12 +19,17 @@
from .core_system.network import *
from .core_system import types

# "dynamics" module
# "integration" module
from . import integration
from .integration import integrate
from .integration import DiffEquation
from .integration.integrator import *

# "dynamics" module
from . import dynamics
from .dynamics import PhasePortraitAnalyzer
from .dynamics import BifurcationAnalyzer

# "tools" module
from . import tools

Expand Down
30 changes: 24 additions & 6 deletions brainpy/connectivity/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,24 @@ def __init__(self, include_self=False):
self.include_self = include_self

def __call__(self, pre_indices, post_indices=None):
assert np.ndim(pre_indices) == 2
if post_indices is not None:
assert np.shape(pre_indices) == np.shape(post_indices)
try:
assert np.shape(pre_indices) == np.shape(post_indices)
except AssertionError:
raise ModelUseError(f'The shape of pre-synaptic group should be the same with the post group. '
f'But we got {np.shape(pre_indices)} != {np.shape(post_indices)}.')

global _grid_four
if nb is not None:
if not isinstance(_grid_four, Dispatcher):
_grid_four = nb.njit(_grid_four)

height, width = pre_indices.shape
if len(pre_indices.shape) == 1:
height, width = pre_indices.shape[0], 1
elif len(pre_indices.shape) == 2:
height, width = pre_indices.shape
else:
raise ModelUseError('Currently only support two-dimensional geometry.')
conn_i = []
conn_j = []
for row in range(height):
Expand All @@ -149,6 +157,7 @@ def __call__(self, pre_indices, post_indices=None):
if self.num_post is None:
self.num_post = post_indices.max()


grid_four = GridFour()


Expand Down Expand Up @@ -195,16 +204,25 @@ def __init__(self, n=1, include_self=False):
self.include_self = include_self

def __call__(self, pre_indices, post_indices=None):
assert np.ndim(pre_indices) == 2
if post_indices is not None:
assert np.shape(pre_indices) == np.shape(post_indices)
try:
assert np.shape(pre_indices) == np.shape(post_indices)
except AssertionError:
raise ModelUseError(f'The shape of pre-synaptic group should be the same with the post group. '
f'But we got {np.shape(pre_indices)} != {np.shape(post_indices)}.')

global _grid_n
if nb is not None:
if not isinstance(_grid_n, Dispatcher):
_grid_n = nb.njit(_grid_n)

height, width = pre_indices.shape
if len(pre_indices.shape) == 1:
height, width = pre_indices.shape[0], 1
elif len(pre_indices.shape) == 2:
height, width = pre_indices.shape
else:
raise ModelUseError('Currently only support two-dimensional geometry.')

conn_i = []
conn_j = []
for row in range(height):
Expand Down
2 changes: 1 addition & 1 deletion brainpy/core_system/neurons.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class NeuGroup(BaseEnsemble):
def __init__(
self,
model: NeuType,
geometry: typing.Union[typing.Tuple[int], typing.List[int], int],
geometry: typing.Union[typing.Tuple, typing.List, int],
pars_update: typing.Dict = None,
monitors: typing.Union[typing.List, typing.Tuple] = None,
name: str = None
Expand Down
13 changes: 8 additions & 5 deletions brainpy/core_system/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,11 +1087,11 @@ def __init__(self, ensemble, target_vars, fixed_vars=None):
fixed_vars = dict()
except AssertionError:
raise ModelUseError('"fixed_vars" must be a dict.')
for var in fixed_vars.keys():
try:
assert var in self._model.variables
except AssertionError:
raise ModelUseError(f'"{var}" in "fixed_vars" is not defined in model "{self._model.name}".')
# for var in fixed_vars.keys():
# try:
# assert var in self._model.variables
# except AssertionError:
# raise ModelUseError(f'"{var}" in "fixed_vars" is not defined in model "{self._model.name}".')
self.fixed_vars = dict()
for integrator in self._model.integrators:
var_name = integrator.diff_eq.var_name
Expand All @@ -1100,6 +1100,9 @@ def __init__(self, ensemble, target_vars, fixed_vars=None):
self.fixed_vars[var_name] = fixed_vars.get(var_name)
else:
self.fixed_vars[var_name] = self._model.variables.get(var_name)
for var in fixed_vars.keys():
if var not in self.fixed_vars:
self.fixed_vars[var] = fixed_vars.get(var)

def step_mode_np_vector(self):
results = dict()
Expand Down

0 comments on commit d8ce6cd

Please sign in to comment.