Skip to content

Commit

Permalink
Merge ffd4891 into 495f5ed
Browse files Browse the repository at this point in the history
  • Loading branch information
apdavison committed Dec 17, 2020
2 parents 495f5ed + ffd4891 commit e758926
Show file tree
Hide file tree
Showing 44 changed files with 2,159 additions and 119 deletions.
5 changes: 5 additions & 0 deletions ci/install_brian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ if [ "$TRAVIS_PYTHON_VERSION" == "2.7" ]; then
pip install sympy;
pip install brian;
fi
if [ "$TRAVIS_PYTHON_VERSION" == "3.7" ]; then
echo -e "\n========== Installing Brian 2 ==========\n"
pip install cython;
pip install brian2;
fi
2 changes: 0 additions & 2 deletions examples/cell_type_demonstration.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from pyNN.utility import get_simulator, init_logging, normalized_filename


# === Configure the simulator ================================================

sim, options = get_simulator(("--plot-figure", "Plot the simulation results to a file.", {"action": "store_true"}),
Expand All @@ -28,7 +27,6 @@


# === Build and instrument the network =======================================

cuba_exp = sim.Population(1, sim.IF_curr_exp(i_offset=1.0), label="IF_curr_exp")
hh = sim.Population(1, sim.HH_cond_exp(i_offset=0.2), label="HH_cond_exp")
adexp = sim.Population(1, sim.EIF_cond_exp_isfa_ista(i_offset=1.0), label="EIF_cond_exp_isfa_ista")
Expand Down
55 changes: 26 additions & 29 deletions examples/iaf_sfa_relref/iaf_sfa_network_INH_GAMMA.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
"""
A PyNN version of the network architecture described in:
Muller, E., Meier, K., & Schemmel, J. (2004). Methods for simulating
high-conductance states in neural microcircuits. Proc. of BICS2004.
high-conductance states in neural microcircuits. Proc. of BICS2004.
http://neuralensemble.org/people/eilifmuller/Publications/bics2004_mueller.pdf
Script written by Lucas Sinclair & Eilif Muller.
LCN, EPFL - October 2009
"""

## Debugger ##
#import pdb
# pdb.set_trace()

## Import modules ##
import numpy, pylab, time
Expand All @@ -33,28 +30,28 @@ class LatticeConnector(connectors.Connector):
For every connection that is made the delay is set proportional to
the distance that separates the two neurons plus some random noise
coming from a gamma distribution.
N cannot be drawn from a random distribution.
Self connections are always enabled.
"""

def __init__(self, weights=0.0, dist_factor=1.0, noise_factor=0.01, n=1.0):
"""
Create a new connector.
`weights` -- The weights of all the connections made.
`dist_factor` -- A factor to control the delay (conversion of
distance to milliseconds of delay).
`noise_factor` -- A factor to control the noise (scale of gamma
`noise_factor` -- A factor to control the noise (scale of gamma
distribution).
`n` -- Number of connections to make for each neuron.
"""
connectors.Connector.__init__(self, weights, dt)
self.dist_factor = dist_factor
self.noise_factor = noise_factor
self.n = n

def connect(self, projection):
"""Connect-up a Projection."""
# Timers
Expand All @@ -64,42 +61,42 @@ def connect(self, projection):
timer2 = 0.0
timer3 = 0.0
timer4 = 0.0

# Recuperate variables #
n = self.n
dist_factor = self.dist_factor
noise_factor = self.noise_factor

# Do some checking #
assert dist_factor >= 0
assert noise_factor >= 0
if isinstance(n, int):
assert n >= 0
else:
raise Exception("n must be an integer.")

# Get posts and pres #
listPostIDs = projection.post.local_cells
listPreIDs = projection.pre.all_cells
countPost = len(listPostIDs)
countPre = len(listPreIDs)
countPre = len(listPreIDs)
listPreIndexes = numpy.arange(countPre)
listPostIndexes = map(projection.post.id_to_index, listPostIDs)

# Prepare all distances #
allDistances = self.space.distances(projection.post.positions, projection.pre.positions)
allDistances = self.space.distances(projection.post.positions, projection.pre.positions)

# Get weights #
weights = numpy.empty(n)
weights[:] = self.weights
is_conductance = common.is_conductance(projection.post[listPostIndexes[0]])
weights = common.check_weight(weights, projection.synapse_type, is_conductance)

for i in xrange(len(listPostIDs)):
currentPostIndex = listPostIndexes[i]
currentPostID = listPostIDs[i]
#currentPostIDAsList = [currentPostID]

# Pick n neurons at random in pre population
myTimer = time.time()
chosenPresIndexes = list(numpy.random.permutation(numpy.arange(countPre))[0:n])
Expand All @@ -108,22 +105,22 @@ def connect(self, projection):
# print(chosenPresIDs)
#chosenPresIDs = chosenPresIDs.tolist()
timer0 += time.time() - myTimer

# Get distances
myTimer = time.time()
#distances = allDistances[currentPostIndex,chosenPresIndexes]
distances = allDistances[currentPostIndex, chosenPresIndexes]
timer1 += time.time() - myTimer

# Generate gamme noise
noise = numpy.random.gamma(1.0, noise_factor, n)

# Create delays with distance and noise
myTimer = time.time()
delays = dist_factor * distances * (1.0 + noise)
timer2 += time.time() - myTimer
#delays[:] = 1.0

# Check for small and big delays
myTimer = time.time()
delaysClipped = numpy.clip(delays, common.get_min_delay(), common.get_max_delay())
Expand All @@ -132,12 +129,12 @@ def connect(self, projection):
print("Warning: %d of %d delays were cliped because they were either bigger than the max delay or lower than the min delay." % (howManyClipped, n))
delaysClipped = delaysClipped.tolist()
timer3 += time.time() - myTimer

# Connect everything up
yTimer = time.time()
projection._convergent_connect(chosenPresIDs, currentPostID, weights, delaysClipped)
timer4 += time.time() - myTimer

# Print timings
if rank == 0:
print("\033[2;46m" + ("Timer 0: %5.4f seconds" % timer0).ljust(60) + "\033[m")
Expand Down Expand Up @@ -434,7 +431,7 @@ def printMessage(message):
highestIndexE = numpy.max(spikesE[:, 0])
listNeuronsE = list(spikesE[:, 0])
listTimesE = list(spikesE[:, 1])
listNeuronsI = list(spikesI[:, 0] + highestIndexE)
listNeuronsI = list(spikesI[:, 0] + highestIndexE)
listTimesI = list(spikesI[:, 1])

## Kill the bad dir ##
Expand All @@ -446,28 +443,28 @@ def printMessage(message):
#m = re.search('\nf(\w+)\n', theText)
#theFD = m.group(1)
#os.close(int(theFD))

## Close the simulation ##
sim.end()


###################### PLOTTING ###########################
if rank == 0:

## Graph Burst ##
pylab.figure()
allSpikes = listTimesE + listTimesI
allNeurons = listNeuronsE + listNeuronsI
pylab.plot(allSpikes, allNeurons, 'r.', markersize=1, label='Action potentials')

pylab.xlabel("Time [milliseconds]")
pylab.ylabel("Neuron (first E, then I)")
pylab.title(("$C_{E\\rightarrow E}=%.2f$, $C_{E\\rightarrow I}=%.2f$," +
"$C_{I\\rightarrow E}=%.2f$, $C_{I\\rightarrow I}=%.2f$,") %
(ICFactorE_E, ICFactorE_I, ICFactorI_E, ICFactorI_I))
pylab.suptitle("Layer 4 model with Connection Factors:")
#pylab.legend()

axisHeight = pylab.axis()[3]
pylab.vlines(tinit, 0.0, axisHeight / 8, linewidth="4", color='k', linestyles='solid')

Expand Down
Loading

0 comments on commit e758926

Please sign in to comment.