Skip to content

Instantly share code, notes, and snippets.

View mstimberg's full-sized avatar
💾

Marcel Stimberg mstimberg

💾
View GitHub Profile
@mstimberg
mstimberg / imshow.svg
Created June 6, 2012 18:29
Example outptu for matplotlib issue #925
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mstimberg
mstimberg / theano_scalar_vector.py
Created December 5, 2013 13:52
Theano example: vector vs. scalar
import time
import numpy as np
import theano
import theano.tensor as tt
# constants
N = 1000000
freq = 1000.
tau = 20*0.001
dt = 0.1*0.001
@mstimberg
mstimberg / delayed_variable_buffer.py
Last active January 18, 2022 16:13
Example of implementing a buffer for a delayed variable in Brian2
# Tested with Brian 2.1.3.1
from brian2 import *
G = NeuronGroup(2, '''drate/dt = amplitude*sin(2*pi*100*Hz*t)/(10*ms) : Hz
rate_delayed : Hz
amplitude : Hz
buffer_pointer : integer (shared)
delay_steps : integer''', method='euler')
G.amplitude = [50, 100] * Hz
@mstimberg
mstimberg / backward_euler.ipynb
Created June 10, 2015 14:26
Explicitly solved backward Euler step
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mstimberg
mstimberg / print_unit_errors.py
Last active August 29, 2015 14:26
Print Brian2 unit error messages
from brian2 import *
# A little script to get an overview over the new error messages for unit
# errors in Brian 2 (in the form of a table that can be pasted into github)
if __name__ == '__main__':
@check_units(x=volt, y=1, result=amp)
def myfunc(x, y):
if y == 0:
@mstimberg
mstimberg / emergency_stop.py
Created November 10, 2015 16:59
Stop a Brian2 simulation if the network firing rate is too high
from brian2 import *
from brian2.devices.cpp_standalone import CPPStandaloneCodeObject
# The following code works only for numpy runtime or C++ standalone
set_device('cpp_standalone')
prefs.codegen.cpp.headers += ['"run.h"'] # This is necessary to use brian_end()
#prefs.codegen.target = 'numpy'
# Simple model, the neurons will increasingly spike
@mstimberg
mstimberg / monitor_spikes.py
Created February 8, 2016 10:10
Record spikes at a synapse with Brian 2
'''
Record the spikes at a synapse with Brian 2. Note that you cannot use
SpikeMonitor for this task, as it is only meant to record from a NeuronGroup
(or another SpikeSource such as PoissonGroup).
'''
from brian2 import *
# The record_spikes function only works with the numpy target
prefs.codegen.target = 'numpy'
synapse_spikes = []
def print_schedule(network=None):
if network is None:
network = magic_network
network._update_magic_objects(level=1)
network._sort_objects()
print('Available slots (also "before_..." and "after_..."):\n%s\n' % network.schedule)
print('Slot Order Name')
prev_slot = None
@mstimberg
mstimberg / brian_bluepyopt.ipynb
Last active June 13, 2016 13:21
Optimize a Brian 2 model with BluePyOpt
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mstimberg
mstimberg / brian2_max_mon.py
Last active November 14, 2016 17:04
Recording the maximum of a state variable with Brian 2
from brian2 import *
# Does also work in standalone mode, enable with:
# set_device('cpp_standalone')
N = 10
G = NeuronGroup(N,
'''
dv/dt = -v / (10*ms) + 1*mV*ms**-0.5*xi : volt
v_max : volt
''')