Code: Select all

```
/* NOTE1: Here I approximated a roughly uniform distribution over the cell, meaning
that synapses are generated regardless of the length of each segment. So long and
short dendrites have equal probability of receiving synapses.
```

Here is a simple, efficient, and mathematically sound algorithm for attaching a predetermined number of synapses.

Code: Select all

```
to_be_done = nsyn
func onepass() { local p, num
for each section to which a new synapse might be attached {
for (x,0) {
if (to_be_done>0) {
determine the likelihood p that this segment will get a new synapse
pick a number num from the uniform distribution over the interval 0...1, excluding 0 and 1
if num <= p {
attach a new synapse to this location
decrease to_be_done by 1
}
}
}
}
}
// there is no guarantee that all synapses will be placed
// in a single pass
while (to_be_done>0) onepass()
```

Implementation comments

1. "for each section to which a new synapse might be attached"

In advance, create a SectionList called innervated.

Append to it all sections that might be innervated.

Then

forsec innervated

is the statement that iterates over these sections.

2. "pick a number num from the uniform distribution over the interval 0...1, excluding 0 and 1"

Locations 0 and 1 are not associated with length or surface area, so the probability of attaching a synapse to either one of them is 0.

So instead of just picking a value for num, do this

Code: Select all

```
repeat
num = value from the interval [0,1]
until ((num>0) && (num<1))
```

3. "the likelihood p that a segment will get a new synapse"

If you want to specify synaptic density in terms of synapses per micron length, in advance calculate the total length of all sections in innervated.

total_length = 0

forsec innervated total_length+=L

Then synaptic density is nsyn/total_length, and the probability that any particular segment will be innervated is

p = (L/nseg)*(nsyn/total_length)

If you prefer to specify synaptic density in terms of synapses per square micron surface area, in advance calculate the total area of all sections in innervated

total_area = 0

forsec innervated for (x,0) total_area+=area(x)

Then synaptic density is nsyn/total_area, and the probability that any particular segment will be innervated is

p = area(x)*nsyn/total_area