Here, we suggest possible modifications to the four-classes algorithm of Cao and Abbott [21] as well as introduce novel alternative algorithms for the sum-over-trips formalism.
3.1 Formal Language Theory Approach
The four-classes algorithm generates duplicate trips [21], which must then be removed by a binary search through the list of existing trips for every new trip generated, which takes time overall, where k is the number of trips constructed. There are two different mechanisms by which duplicate trips are generated, and both mechanisms can be eliminated by applying simple restrictions to the choice of excursions applicable to a trip. As an example of the first, for the tree in Fig. 1, it is possible to generate the trip in two different ways from the shortest Class 1 trip, :
Due to the fact that the excursion may be added at any step in the trip (at the first or second B), the same trip may be generated multiple times. If we insist that excursions cannot be added at any step that precedes the excursion most recently added to the trip, this can be prevented. In the theory of context-free grammars, this is equivalent to requiring a leftmost derivation. We can represent this using a symbol to separate the mutable and immutable parts of the trip:
The second mechanism by which duplicate trips are produced is the addition of excursions along the same branch, starting from either end. In the structure in Fig. 1, we have both and . Hence, in spite of the leftmost derivation rule, we can generate in two different ways (brackets added for clarity):
This problem can be avoided by assigning each branch a direction. If the branch AB is given the direction , then the excursion is disallowed. The choice of direction for each branch is unambiguous on acyclic structures: apart from the branch on which x is found, each branch must be directed away from x. The branch upon which x resides is directed away from y. This ensures that each node has a sequence of excursions that allow the algorithm to generate trips including it. The allocation of direction to each branch can be performed before the process of generating trips and may coincide with finding the four main classes of trips. These modifications require that the graph be acyclic, since “away from a point” is not generally definable on a graph with cycles. There do exist cyclic graphs for which an unambiguous grammar can generate the language of trips, but these are not relevant to the study of single dendritic trees.
The two presented modifications of the four-classes algorithm are sufficient to prevent the generation of any duplicate trips, without any trips being missed. Together, they provide an unambiguous context-free grammar generating the language of trips.
3.2 Length-Priority Method
Since the coefficients decay at most with (although the number of trips increases with ), the dominating term in the Green’s function (5) is the exponential decay in . The four-classes algorithm [21] does not generate trips in monotonic order in length, since trips are constructed by adding the same excursion to all four classes of trips. If, for example, a Class 2 trip is significantly longer than its Class 1 counterpart, due to x being along a long edge but close to a node, then a longer Class 2 trip will be generated before a potentially shorter Class 1 trip having an additional excursion on a shorter branch. In general, trips are likely to be disordered in length if the branches upon which x or y reside are substantially longer than at least one other branch on the tree, or if x or y are much closer to one of their adjacent nodes than to the other.
Here, we propose to realise the sum-over-trips framework by a length-priority method. In this implementation, trips are generated and the corresponding terms are added to the infinite series solution (5) in monotonic order in length . This is achieved by incorporating Eppstein’s algorithm [23] for finding the k shortest trips on a graph in time, with n being the number of nodes and m the number of edges on the branching structure.
Both the four-classes algorithm and the improvements described in the language-theoretic approach rely on storing trips explicitly as sequences of nodes. This consumes space and time for k trips with n nodes but allows on-the-fly calculation of coefficients . This is contrary to Eppstein’s algorithm [23], which stores trips using an implicit representation and allows us to find the k shortest trips implicitly using only space and time for each trip. The current implementation, based on Eppstein’s algorithm, requires time to calculate coefficients despite the savings on space due to the implicit trip representation. However, Eppstein provides a method for computing any property that can be described by a monoid in time per trip. Such a description of coefficient calculation exists, and its use would supplement the current to decrease in space requirements with an analogous decrease in time complexity. The savings in space already allow the length-priority method to scale better than the four-classes algorithm.
3.3 Monte-Carlo Method
The path integral formulation of the solution to the cable equation introduced by Abbott et al. [20] is derived via consideration of a Feynman–Kac representation of the solution in terms of random walkers on the dendritic geometry. Hence, it is natural to consider Monte-Carlo approaches to evaluating this path integral. Instead of a length-ordered series solution as provided by the length-priority approach, the Green’s function (5) can be constructed using a stochastic algorithm. The aim of this approach is to sample from trips in such a way that the probabilistically more likely samples coincide with the trips that contribute most to the series solution (5).
To motivate this Monte-Carlo approach, let us consider a linear diffusion equation along an infinite one-dimensional cable,
(11)
satisfying the initial condition . Analogously, a diffusion process for the state variable can be defined by the stochastic equation
with the Wiener process and the initial condition . It is well known that Eq. (11) is the Kolmogorov equation of the diffusion process (12), that is, the time evolution equation of the probability density for the state of the diffusion (12). On the one hand, solution of (11) via classical numerical or analytical methodology informs the probability density of ; on the other hand, repeated sampling from (12) converges upon the solution of (11). This method of sampling from random walks can also be applied for arbitrary geometries by setting the appropriate boundary conditions at the branching nodes and terminals. Knowing on a branching structure, we can easily find a solution of the cable equation on this geometry using the relation
Because the path integral form of the solution is equivalent to the expectation of a function on random walks upon the branching points of the dendritic tree, reduction of the random walk problem from the complete continuous space geometry of the neuron to the discrete topology of the branching points of the neuron gives a considerable efficiency saving to a Monte-Carlo solver. We introduce a parameter , the maximum number of discrete hops on nodes for which we wish to calculate the expectation. The maximum number is based upon the effective maximum range of diffusion during the interval . Then, we generate a realisation of a random walk on the nodes,
(13)
where each is a label identifying a particular node. For trips we select such that it is either of the two nodes adjacent to the branch containing x, with equal probability. By indexing a branch between two nodes, and , as the k th branch, subsequent steps are performed with the transition probability
(14)
where is given by (7). This connects the Monte-Carlo method to the earlier discussed path enumeration methods. Here, we introduce two auxiliary functions, ϕ and , of subwalks of ω. The first is a function indicating whether a subwalk of k steps on a realisation ω is a valid trip, and is defined by
where k is the number of hops on nodes in the subwalk and is the length of the subwalk. The other auxiliary function is defined as
The relevant function on paths can be defined as a composite of the auxiliary functions described above:
The expectation of with respect to the random walk (14) is equivalent to solving for the path integral, up to some value of at time t:
where is the probability of the realisation ω, and denotes the expectation operator. Therefore, the Monte-Carlo strategy is to sample, sequentially or in parallel, the random function in order to construct this expectation.
3.4 Matrix Method
An alternative method of constructing the sum-over-trips series solution is by grouping trips by their lengths:
where the sum over l is over all possible trip lengths . On a dendritic tree, discretised as in compartmental models [10] or in a manner similar to the discretisation of the tree into segments in NEURON [26], grouping trips according to their lengths allows us to count the number of trips of a given length l without having to explicitly construct them.
This method uses a modified directed edge adjacency matrix of the discretised tree in order to compute the sum of coefficients of trips of a given length. It requires all compartments to have the same fixed length Δx, although this restriction can be relaxed in a generalisation presented at the end of this section. The extremities of compartments define the position of nodes; there is a directed edge in both directions between adjacent nodes.
We begin by defining as the set of nodes and ℰ as the set of directed edges in the discretised tree. Edges are ordered pairs of nodes: is a directed edge from u to v, with . For any edge , we denote the reverse edge by . Trips are taken to begin from a point x along a starting edge and end at a point y along a goal edge for . We say that or if x resides along edge . Based on the locations of and , the orientations of s and g are defined such that the shortest trip satisfies . Therefore, the shortest trip always starts on edge s, that is, in the direction, and approaches y along the edge g, in the direction. This is equivalent to a Class 1 trip; Class 2 trips leave x along the edge, arrive at ; Class 3 trips go from to ; Class 4 trips, finally, go from to . The locations of the points and along their respective edges are given as a fraction of the branch length such that denotes the distance from x to and is the distance between node and point y. We distinguish between k, the number of edges travelled in a particular trip, from the length of the trip . Because x and y reside along their respective edges, the total length of a trip that travels along k edges is less than if the full distance along k edges had been travelled. That is, for any combination of x, y and for all k.
The aim of the matrix method is to group all trips starting on a given edge and finishing on a target edge by their lengths, , and calculate the sum of the coefficients of those trips for each particular group instead of calculating coefficients individually for each trip. The sums of coefficients are computed simultaneously for trips ending on all edges, starting at a point , allowing us to compute for all j, for all x on edge i and for all y on any edge, in a single run of the calculation. We define the coefficients function , , as the sum of all coefficients which begin at point and travel over k edges, finishing on a given edge g:
Because the set of edges ℰ is both ordered and finite, then can be thought of as a vector, where for . The i th element of the vector corresponds to the sum of coefficients for all trips originating at x on s and ending along the i th edge , having travelled over k edges. The vector consists mostly of zeros, with a one only in the entry corresponding to the edge s, as the coefficient of moving in this direction remains 1, while all other moves are invalid by travelling over only one edge, and hence have coefficient 0.
We can now define a matrix such that
Q is a modified form of the edge-adjacency matrix, where instead of containing ones to denote edge adjacency and zero otherwise, it contains the coefficient taken in moving from one edge to another. The entries of Q can be computed based on the morphology of the graph. If the j th entry corresponds to edge and the i th entry to edge , then the entry is the coefficient taken when moving from branch to . In the general case, these numerical values must be determined for each entry. However, in the simplified case where the radii on all branches are equal and all nodes have degree or , the matrix Q can be constructed according to
(16)
Note that the above rules apply to the transpose of .
Thus, knowing the matrix Q from the dendritic geometry and the vector from the starting edge s, it is possible to construct the sum of terms, for all , equal to the sum of coefficients for all trips travelling up to edges, from to . However, by considering trips moving from x in one direction only and arriving at y from only one direction, we have calculated the coefficients of just Class 1 trips. In order to find coefficients for the remaining three classes, we must also compute , and . These can be found in the same way as above. Using (15), the Green’s function in (5) can therefore be written as
(17)
where is the g th element of the matrix-vector product of Q and . Lengths are the lengths of Class 1 to Class 4 trips, respectively, and are defined as
By selecting a small Δx, branches may be approximated by a discretisation using an integer number of edges of length Δx. As in compartmental models, this allows the full morphology of the dendritic tree to be approximated, in a trade-off between high speed (large Δx) and accuracy (small Δx). As , however, this approach tends to the computational complexity of naively integrating the cable equation using numerical methods. As in numerical simulations, where reducing Δx in order to increase accuracy brings about a necessary and associated change in Δt, the same is true of the matrix method: selecting a small Δx and hence increasing , implies that must be increased.
This algorithm can be generalised to accept several discrete edge lengths , at an exponential cost in the number of different lengths n, allowing “caricature” neurons to be constructed from a small number of different edge lengths. Our description of this method is focused on the case where x and y are located on different branches. For computations where x and y are required to exist on the same edge, the edges can be discretised such that x and y appear on different segments. In all cases with bounded node degree, Q is a sparse matrix with only a few entries per row, and entries altogether, making the complexity for the calculation of all coefficients by using highly-efficient sparse linear algebra algorithms.
3.4.1 Example calculation
Here, we demonstrate an example realisation of the matrix method for a dendritic structure of three branches of equal length Δx, shown in Fig. 2. In this symmetrical case, the matrix Q is very small and can be constructed by hand. We place the point of measurement x along edge and the point of current injection y along .
We begin by ordering the edge pairs as follows: , , , , , . Based on this ordered set, we can obtain two coefficients vectors , one for trips that begin at x and move towards B, denoted , and another for trips moving from x towards node A, denoted . Using the rules described in (16), we can construct the matrix Q for our dendritic structure as follows:
Note that all rows and columns sum to 1. Knowing this matrix Q and breaking the trips into four main classes, it is straightforward to find the complete Green’s function:
(18)