epfl-lcn / neuronaldynamics-exercises Goto Github PK
View Code? Open in Web Editor NEWPython exercises accompanying the book "Neuronal Dynamics"
License: GNU General Public License v2.0
Python exercises accompanying the book "Neuronal Dynamics"
License: GNU General Public License v2.0
When trying to create a noisy 'A' pattern I get the following error (skipping extra info):
pattern_tools.get_noisy_copy(abc_dictionary['A'], noise_level=0.2)
...../neurodynex/hopfield_network/pattern_tools.py in get_noisy_copy
237 linear_template[idx_reassignment] = rand_values
ValueError: shape mismatch: value array of shape (100,) could not be broadcast to indexing result of shape (20,)
This is fixed on the github version, however the pypi version is not updated and still has this bug
To solve it, change the line
rand_values = np.random.binomial(1, 0.5, n)
to
rand_values = np.random.binomial(1, 0.5, nr_mutations)
If you follow the "classroom" instructions, we recommend the installation of Jupyter notebook and the creation of a conda environment. This has led to some problems, depending on what people already had installed on their computers.
Solution:
Do NOT install Jupyter notebook before creating an the environment (called bmnn in the instructions)
Instead: create the environment, activate it, and then install Jupyter within that environment.
Todo: update install instructions accordingly
Where can we Download the required files (such as HH.py, etc)?
I reverted the brian2 version back to 2.0b4.
Testing locally shows that brian2.0rc1
seems to fix the build errors, but somehow travis still installed brian2rc
.
@flinz Looks good!
Ok to add this to OSB?
it is a little unclearly formulated how to change variables in the exp_if
http://neuronaldynamics-exercises.readthedocs.io/en/latest/exercises/exponential-integrate-and-fire.html
setting e.g. exp_IF. RHEOBASE_THRESHOLD_v_rh = 0 mV
will not affect the function call.
In ex 3.11 this is asked.
it should be used as
state_monitor, spike_monitor = exp_IF.simulate_exponential_IF_neuron( I_stim=input_current, simulation_time=200*b2.ms, *v_rheobase=VALUE*)
Hi,
Are there solutions available for the exercises (mathematical and code based) in this book ?
Thanks
The module loaded with * can't be reloaded.
In executing the create_checkerboard function and a couple others, you'd get an error like the one below rather than having the expected pattern returned. This is due to removal of a previously deprecated attribute .int
from numpy. Replacing it with builtin int
as suggested resolves the issue.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[1], line 11
9 factory = pattern_tools.PatternFactory(pattern_size, pattern_size)
10 # create a checkerboard pattern and add it to the pattern list
---> 11 checkerboard = factory.create_checkerboard()
12 pattern_list = [checkerboard]
14 # add random patterns to the list
File ~/work/neuronal-dynamics/bmnn/lib/python3.11/site-packages/neurodynex3/hopfield_network/pattern_tools.py:116, in PatternFactory.create_checkerboard(self)
110 def create_checkerboard(self):
111 """
112 creates a checkerboard pattern of size (pattern_length x pattern_width)
113 Returns:
114 checkerboard pattern
115 """
--> 116 pw = np.ones(self.pattern_length, np.int)
117 # set every second value to -1
118 pw[1::2] = -1
File ~/work/neuronal-dynamics/bmnn/lib/python3.11/site-packages/numpy/__init__.py:313, in __getattr__(attr)
308 warnings.warn(
309 f"In the future `np.{attr}` will be defined as the "
310 "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
312 if attr in __former_attrs__:
--> 313 raise AttributeError(__former_attrs__[attr])
315 if attr == 'testing':
316 import numpy.testing as testing
AttributeError: module 'numpy' has no attribute 'int'.
`np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
While running the introductory code for exercises 5:
import brian2 as b2 import matplotlib.pyplot as plt from neurodynex3.cable_equation import passive_cable from neurodynex3.tools import input_factory import numpy as np %matplotlib inline passive_cable.getting_started()
I get the following error trace:
_cython_magic_15f462c2d8ad86b6857db74f110ed9a8.cpp
C:\Users\dgcxb\anaconda3\envs\bmnn\lib\site-packages\numpy\core\include\numpy\npy_1_7_deprecated_api.h(14) : Warning Msg: Using deprecated NumPy API, disable it with #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
Creating library C:\Users\dgcxb.cython\brian_extensions\Users\dgcxb.cython\brian_extensions_cython_magic_15f462c2d8ad86b6857db74f110ed9a8.cp38-win_amd64.lib and object C:\Users\dgcxb.cython\brian_extensions\Users\dgcxb.cython\brian_extensions_cython_magic_15f462c2d8ad86b6857db74f110ed9a8.cp38-win_amd64.exp
Generating code
Finished generating code
_cython_magic_963f4ad1402bd5c688206467215aef7b.cpp
C:\Users\dgcxb\anaconda3\envs\bmnn\lib\site-packages\numpy\core\include\numpy\npy_1_7_deprecated_api.h(14) : Warning Msg: Using deprecated NumPy API, disable it with #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
Creating library C:\Users\dgcxb.cython\brian_extensions\Users\dgcxb.cython\brian_extensions_cython_magic_963f4ad1402bd5c688206467215aef7b.cp38-win_amd64.lib and object C:\Users\dgcxb.cython\brian_extensions\Users\dgcxb.cython\brian_extensions_cython_magic_963f4ad1402bd5c688206467215aef7b.cp38-win_amd64.exp
Generating code
Finished generating code
_cython_magic_7208c94ddee8df5b2361722452059636.cpp
C:\Users\dgcxb\anaconda3\envs\bmnn\lib\site-packages\numpy\core\include\numpy\npy_1_7_deprecated_api.h(14) : Warning Msg: Using deprecated NumPy API, disable it with #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
Creating library C:\Users\dgcxb.cython\brian_extensions\Users\dgcxb.cython\brian_extensions_cython_magic_7208c94ddee8df5b2361722452059636.cp38-win_amd64.lib and object C:\Users\dgcxb.cython\brian_extensions\Users\dgcxb.cython\brian_extensions_cython_magic_7208c94ddee8df5b2361722452059636.cp38-win_amd64.exp
Generating code
Finished generating code
ZeroDivisionError Traceback (most recent call last)
~\anaconda3\envs\bmnn\lib\site-packages\brian2\codegen\runtime\cython_rt\cython_rt.py in run_block(self, block)
159 try:
--> 160 return compiled_code.main(self.namespace)
161 except Exception as exc:
_cython_magic_a4e948818012e0811dae587a5d0fef77.pyx in _cython_magic_a4e948818012e0811dae587a5d0fef77.main()
ZeroDivisionError: float division
The above exception was the direct cause of the following exception:
BrianObjectException Traceback (most recent call last)
in
----> 1 passive_cable.getting_started()
~\anaconda3\envs\bmnn\lib\site-packages\neurodynex3\cable_equation\passive_cable.py in getting_started()
106 """
107 current = input_factory.get_step_current(500, 510, unit_time=b2.us, amplitude=3. * b2.namp)
--> 108 voltage_monitor, cable_model = simulate_passive_cable(
109 length=0.5 * b2.mm, current_injection_location=[0.1 * b2.mm], input_current=current,
110 nr_compartments=100, simulation_time=2 * b2.ms)
~\anaconda3\envs\bmnn\lib\site-packages\neurodynex3\cable_equation\passive_cable.py in simulate_passive_cable(current_injection_location, input_current, length, diameter, r_longitudinal, r_transversal, e_leak, initial_voltage, capacitance, nr_compartments, simulation_time)
98 # set initial values and run for 1 ms
99 cable_model.v = initial_voltage
--> 100 b2.run(simulation_time)
101 return monitor_v, cable_model
102
~\anaconda3\envs\bmnn\lib\site-packages\brian2\units\fundamentalunits.py in new_f(*args, **kwds)
2383 get_dimensions(newkeyset[k]))
2384
-> 2385 result = f(*args, **kwds)
2386 if 'result' in au:
2387 if au['result'] == bool:
~\anaconda3\envs\bmnn\lib\site-packages\brian2\core\magic.py in run(duration, report, report_period, namespace, profile, level)
371 intended use. See MagicNetwork
for more details.
372 '''
--> 373 return magic_network.run(duration, report=report, report_period=report_period,
374 namespace=namespace, profile=profile, level=2+level)
375 run.module = name
~\anaconda3\envs\bmnn\lib\site-packages\brian2\core\magic.py in run(self, duration, report, report_period, namespace, profile, level)
229 namespace=None, profile=False, level=0):
230 self._update_magic_objects(level=level+1)
--> 231 Network.run(self, duration, report=report, report_period=report_period,
232 namespace=namespace, profile=profile, level=level+1)
233
~\anaconda3\envs\bmnn\lib\site-packages\brian2\core\base.py in device_override_decorated_function(*args, **kwds)
276 return getattr(curdev, name)(*args, **kwds)
277 else:
--> 278 return func(*args, **kwds)
279
280 device_override_decorated_function.doc = func.doc
~\anaconda3\envs\bmnn\lib\site-packages\brian2\units\fundamentalunits.py in new_f(*args, **kwds)
2383 get_dimensions(newkeyset[k]))
2384
-> 2385 result = f(*args, **kwds)
2386 if 'result' in au:
2387 if au['result'] == bool:
~\anaconda3\envs\bmnn\lib\site-packages\brian2\core\network.py in run(self, duration, report, report_period, namespace, profile, level)
1074 else:
1075 for obj in active_objects:
-> 1076 obj.run()
1077
1078 timestep[0] += 1
~\anaconda3\envs\bmnn\lib\site-packages\brian2\core\base.py in run(self)
179 def run(self):
180 for codeobj in self._code_objects:
--> 181 codeobj()
182
183 contained_objects = property(fget=lambda self:self._contained_objects,
~\anaconda3\envs\bmnn\lib\site-packages\brian2\codegen\codeobject.py in call(self, **kwds)
105 self.namespace.update(**kwds)
106
--> 107 return self.run()
108
109 def run_block(self, block):
~\anaconda3\envs\bmnn\lib\site-packages\brian2\codegen\codeobject.py in run(self)
133 defined during the call of CodeGenerator.code_object
.
134 '''
--> 135 return self.run_block('run')
136
137 def after_run(self):
~\anaconda3\envs\bmnn\lib\site-packages\brian2\codegen\runtime\cython_rt\cython_rt.py in run_block(self, block)
162 message = ('An exception occured during the execution of the {} '
163 'block of code object {}.\n').format(block, self.name)
--> 164 raise BrianObjectException(message, self.owner) from exc
165
166 def _insert_func_namespace(self, func):
BrianObjectException: Error encountered with object named "spatialneuron_1".
Object was created here (most recent call only, full details in debug log):
File "C:\Users\dgcxb\anaconda3\envs\bmnn\lib\site-packages\neurodynex3\cable_equation\passive_cable.py", line 85, in simulate_passive_cable
cable_model = b2.SpatialNeuron(morphology=cable_morphology, model=eqs, Cm=capacitance, Ri=r_longitudinal)
An exception occured during the execution of the run block of code object spatialneuron_1_spatialstateupdater_codeobject.
(See above for original error message and traceback.)
neurodynex.hopfield_network.plot_tools.plot_pattern_list() crashes if a pattern list of length 1 is passed.
Hi,
i'd like to take this course but would like to know if solutions to the exercises like the ones in this page are available - https://neuronaldynamics-exercises.readthedocs.io/en/latest/exercises/leaky-integrate-and-fire.html
Thanks
How do I resolve this issue.
finalVirtual.zip
After the recent update, pip is no longer supported and pip install directly from Github fails with req
not found. Do you think we can add pip support back instead of requiring everyone to use miniconda :D
Units in questions 2.2.1 and 2.2.2 in page http://neuronaldynamics-exercises.readthedocs.org/en/latest/exercises/leaky-integrate-and-fire.html should be kHz.
When I copied the code of exercise 1,like this,
%matplotlib inline
import brian2 as b2
import matplotlib.pyplot as plt
import numpy as np
from neurodynex3.leaky_integrate_and_fire import LIF
from neurodynex3.tools import input_factory, plot_tools
LIF.getting_started()
LIF.print_default_parameters()
python reminded me,like this,
AttributeError: module 'brian2' has no attribute 'units'
Add input parameter: figure_size or figure object
Return figure and axis
document accordingly
give call example
'''
Traceback (most recent call last):
File "C:\Users\mvres\miniconda2\envs\bmnn\Scripts\pip-script.py", line 5, in
from pip._internal.cli.main import main
File "C:\Users\mvres\miniconda2\envs\bmnn\lib\site-packages\pip_internal\cli\main.py", line 10, in
from pip._internal.cli.autocompletion import autocomplete
File "C:\Users\mvres\miniconda2\envs\bmnn\lib\site-packages\pip_internal\cli\autocompletion.py", line 9, in
from pip._internal.cli.main_parser import create_main_parser
File "C:\Users\mvres\miniconda2\envs\bmnn\lib\site-packages\pip_internal\cli\main_parser.py", line 7, in
from pip._internal.cli import cmdoptions
File "C:\Users\mvres\miniconda2\envs\bmnn\lib\site-packages\pip_internal\cli\cmdoptions.py", line 24, in
from pip._internal.cli.progress_bars import BAR_TYPES
File "C:\Users\mvres\miniconda2\envs\bmnn\lib\site-packages\pip_internal\cli\progress_bars.py", line 55, in
_BaseBar = _select_progress_class(IncrementalBar, Bar) # type: Any
File "C:\Users\mvres\miniconda2\envs\bmnn\lib\site-packages\pip_internal\cli\progress_bars.py", line 48, in _select_progress_class
six.text_type().join(characters).encode(encoding)
LookupError: unknown encoding: cp65001
(bmnn) C:\Users\mvres>conda activate bmnn
(bmnn) C:\Users\mvres>conda install -c conda-forge jupyterlab
Traceback (most recent call last):
File "C:\Users\mvres\miniconda2\lib\site-packages\conda\gateways\logging.py", line 134, in emit
stream.write(ufs % msg)
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 41, in write
self.__convertor.write(text)
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 162, in write
self.write_and_convert(text)
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 190, in write_and_convert
self.write_plain_text(text, cursor, len(text))
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 195, in write_plain_text
self.wrapped.write(text[start:end])
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 41, in write
self.__convertor.write(text)
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 162, in write
self.write_and_convert(text)
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 190, in write_and_convert
self.write_plain_text(text, cursor, len(text))
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 195, in write_plain_text
self.wrapped.write(text[start:end])
LookupError: unknown encoding: cp65001
Logged from file exceptions.py, line 1088
Traceback (most recent call last):
File "C:\Users\mvres\miniconda2\lib\site-packages\conda\gateways\logging.py", line 134, in emit
stream.write(ufs % msg)
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 41, in write
self.__convertor.write(text)
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 162, in write
self.write_and_convert(text)
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 190, in write_and_convert
self.write_plain_text(text, cursor, len(text))
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 195, in write_plain_text
self.wrapped.write(text[start:end])
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 41, in write
self.__convertor.write(text)
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 162, in write
self.write_and_convert(text)
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 190, in write_and_convert
self.write_plain_text(text, cursor, len(text))
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 195, in write_plain_text
self.wrapped.write(text[start:end])
LookupError: unknown encoding: cp65001
Logged from file exceptions.py, line 1088
Traceback (most recent call last):
File "C:\Users\mvres\miniconda2\lib\site-packages\conda\gateways\logging.py", line 134, in emit
stream.write(ufs % msg)
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 41, in write
self.__convertor.write(text)
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 162, in write
self.write_and_convert(text)
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 190, in write_and_convert
self.write_plain_text(text, cursor, len(text))
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 195, in write_plain_text
self.wrapped.write(text[start:end])
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 41, in write
self.__convertor.write(text)
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 162, in write
self.write_and_convert(text)
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 190, in write_and_convert
self.write_plain_text(text, cursor, len(text))
File "C:\Users\mvres\AppData\Roaming\Python\Python27\site-packages\colorama\ansitowin32.py", line 195, in write_plain_text
self.wrapped.write(text[start:end])
LookupError: unknown encoding: cp65001
Logged from file exceptions.py, line 1088
'''
I'm getting the above error when I'm trying to run conda install jupyter. Is it because I'm trying to install it in a conda env, in a folder where I already have Jupyter installed for Anaconda3?
Now it points to the github page.
It looks like these python codes import brian modules instead of installed brian2 ones , if this might be easily fixed, i don't know how to solve for brian.library.ionic_currents import
Any advice?
@flinz @MarcoLehmann
My apologies, didn't know where else to get help so raised an issue.
I was wondering if it was possible to chain HH model with a passive model and observe the voltage output at the end?
Thanks in advance!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.