Docsity

Exploring the Diderot programming language and its ..., Lecture notes of Programming Languages

Toggle sidebar
bg1
Project Report:
Exploring the Diderot programming language and its
applications to the visualization of neural models
ELEN E6001
Daniel Clark
djc2184
December 26, 2013
Overview
This objective of this report is to explain the functionality of a domain-specific programming language
called Diderot and discuss how it can be utilized in the realm of computational neuroscience. The report will
give a thorough explanation of the idea behind Diderot, some examples of its applications, and its potential
use for implementing high-level brain operators on continuous neural fields. A particular high-level operator,
optical flow, will be discussed as well as some approaches for calculating it, as initial experiments into Diderot
involved coding some of these approaches. Further detail will be given into the experiments performed with
the software, a summary of what was learned from it, and its advantages and shortcomings with regard to
the implementation of neural information processing algorithms.
An aspect of image visualization which Diderot excels at, line integral convolution or LIC, will be ex-
plained in detail - as this method was used to visualize the phase portraits of various neuron spiking models.
This report will break down the idea behind LIC, its mathematical formulation, computational methods,
and its applications. It will also discuss the basics of each neuron model, the behavior of the phase plane,
and bifurcation theory.
Finally, a summary of experiments performed with visualizing the phase portraits via LIC in Diderot
will be given. A breakdown of the Diderot code, MATLAB code, and miscellaneous importing/exporting
utilities developed will be delivered. In addition, the appendix has a README file showing how the code
pieces come together and how the files are organized so further experiments can be done.
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b

Partial preview of the text

Download Exploring the Diderot programming language and its ... and more Lecture notes Programming Languages in PDF only on Docsity!

Project Report:

Exploring the Diderot programming language and its

applications to the visualization of neural models

ELEN E

Daniel Clark

djc

December 26, 2013

Overview

This objective of this report is to explain the functionality of a domain-specific programming language called Diderot and discuss how it can be utilized in the realm of computational neuroscience. The report will give a thorough explanation of the idea behind Diderot, some examples of its applications, and its potential use for implementing high-level brain operators on continuous neural fields. A particular high-level operator, optical flow, will be discussed as well as some approaches for calculating it, as initial experiments into Diderot involved coding some of these approaches. Further detail will be given into the experiments performed with the software, a summary of what was learned from it, and its advantages and shortcomings with regard to the implementation of neural information processing algorithms.

An aspect of image visualization which Diderot excels at, line integral convolution or LIC, will be ex- plained in detail - as this method was used to visualize the phase portraits of various neuron spiking models. This report will break down the idea behind LIC, its mathematical formulation, computational methods, and its applications. It will also discuss the basics of each neuron model, the behavior of the phase plane, and bifurcation theory.

Finally, a summary of experiments performed with visualizing the phase portraits via LIC in Diderot will be given. A breakdown of the Diderot code, MATLAB code, and miscellaneous importing/exporting utilities developed will be delivered. In addition, the appendix has a README file showing how the code pieces come together and how the files are organized so further experiments can be done.

Contents

  • The Diderot Language
    • Background
    • Language design and implementation
    • Examples
  • High-level brain operators
    • Continuous neural fields
    • Optical flow
    • Initial Diderot experimentation
  • Visualizing the phase plane
    • Neuron dynamics and bifurcation
    • Line integral convolution
    • Experiments visualizing phase portraits
  • Summary and further direction
  • Acknowledgements
  • References
  • Appendix: README code descriptions

Synonms are implemented for commonly used tensors, such as vec3 for 3D vectors or real for scalars. Three abstract data types are implemented to assist with the language’s high-level format:

image(d)[σ] − (input) image data of d dimension with σ-shaped tensor values kernel#k − convolution kernel that is k times differentiable field#k(d)[σ] − continuous tensor field that is k times differentiable, of dimension d and having σ-order tensor values

The image type stores the input to the Diderot program, such that Diderot is aware of how many dimensions the image is, and what type of tensor data it holds. image can be used to store a standard 2D frame of scalar values, or something more sophisticated, like a 3D image of 3×1 velocity vectors, or a time-evolving 3D image (4D data) of 2×2 Hessian matrices. The kernel type instantiates an underlying “continuous” kernel used to perform interpolation of input data, as well as to implicitly calculate higher-order operations on continuous fields (i.e. gradient). There are a number of built-in kernels for use, including tent for non-differntiable, linear interpolated data, ctmr for once-differentiable Catmull-Rom spline interpolation, and bspln3 for the twice-differentiable uniform cubic B-spline basis function. The use of these various kernels are up to the discretion of the researcher to utilize the appropriate basis for the formation of the continuous data domain. The amount of differentiability that a kernel allows for is important, as it limits the amount of gradient operations that can be performed on the resulting field. If a field F 1 is defined to be k = 1 times differentiable, and a gradient ∇ operator is performed on it, then the resulting field F 2 will be k = 0 times differentiable, and using the ∇ operator on F 2 will yield a compile-time error. By convolving a kernel with an image (directly in code via the ~ character), one creates a continuous field of their input data. This field object is compatible with high-level operators like ∇ (for fields of scalar values) and ∇⊗ (for fields of vector and matrix values). Then when one wants to access the modified field values, they can probe the field at a location pos, via something like: fieldVal = F(pos) and store the values of interest. Additionally, Diderot also supports adding and subtracting, as well as scaling of entire fields at once. As Diderot is optimized for parallel programming, its code structure reflects an independent, multithread approach. A Diderot program is broken into three primary sections: global definitions, strand updates, and initialization. The global definitions section is where the user declares immutable variables to use as constants through- out the program. This is also the section where an input image is typically loaded in and its continuous field is created. This can be seen in the “Global defs” section in the sample code shown on the next page. Along with various constants, the user can specify the granularity of how many samples they’d like to extract from the continuous field (regardless of the resolution of the input). The strand updates section is analogous to a kernel function in CUDA or OpenCL as this part of the code does all of the central math of the program. The strand in code on the following page is called DEMO and it iterates via indexing parameters xi and yi. In this case, these parameters are used to probe the field at different positions. An output variable is declared, sum, which serves as the data that is written to the disk when the program is ran. The update method within the strand updates sum until a condition is met where the stabilize method is called. Once stabilize is invoked, the output strand finishes running on that particular index of xi and yi and the program outputs the results to a text file. Strands can also be terminated via the die keyword, in which case, no output is written to disk. Notice the gradient operator on field V. We create V as a continuous scalar (0-order tensor) field. However, when we probe the gradient of V, the output is a 2-dimensional vector (as there are two space dimensions of the input image from which to compute the derivative with respect to). Also in this process, the differentiability of ∇V goes down by one count (from 1 to 0), which would prevent any more gradient operations from operating on that field (as it is no longer continuously differentiable). The initialization section is pretty straightforward as it declares what strand is to be run and how the strand will be iterated through. The code below shows the initially method calling our strand name with parameters xi and yi, which will iterate over the range 0..imgSizeX-1 and 0..imgSizeY-1, respectfully, with xi as the inner loop and yi as the outer. It should be noted here that the loop order follows a

bulk-synchronous parallelism model [3], where, program execution happens in super-steps. The super-step here is the update method being called once over every strand dictated by the loop range so that every parallel strand is updated synchronously; update is then invoked again and again, over all strands, until the stabilize or die methods are called. This model allows for optimal performance and portability to parallel processing implementations. In the case of a serial execution, the super-step acts as an inner-loop (first strand DEMO runs per xi, yi once) and the update method as the outer loop (now update each strand one-by-one another time...etc).

// ----- Global defs ----- int imgSizeX = 300; // how many x pts user wants from field int imgSizeY = 200; // how many y pts user wants from field int stepNum = 25; // step limit before writing to output image (2)[] img = load ("../ data / einstein. nrrd "); // import image field #1(2)[] F = img ctmr ; // convolve img with kernel = field

// ----- Strand section ----- strand DEMO ( int xi , int yi ) { real xx = lerp (0.0 , 3.0 , -0.5 , real ( xi ) , real ( imgSizeX ) -0.5); real yy = lerp (0.0 , 2.0 , -0.5 , real ( yi ) , real ( imgSizeY ) -0.5); vec2 pos0 = [ xx , yy ]; output real sum = F ( pos0 ); int step = 0; // --- Update thread with math under condtions --- update { // Do some fancy math vec2 grad = F ( pos ); // take gradient of field and probe it sum = grad [0]+ grad [1]; step += 1; if ( step == stepNum ) { stabilize ; // write " sum " to output } } }

// ----- Initialization section ----- initially [ DEMO ( xi , yi ) | yi in 0..( imgSizeY -1) , xi in 0..( imgSizeX -1) ]; It is important to get a sense of how Diderot manages the “continuous” fields under the hood. The fields are abstract data types, so the entire “continuous” field is not necessarily known or calculated when a field operation is performed (i.e. convolution, gradient). In fact, the underlying values are only computed when the field is probed at a particular location. This is best understood by looking at an example equation which shows the underlying calculations for computing the gradient of a field at point x = [x, y]>.

∇F (x) = (V ⊗ ∇h)(x)

=

V ⊗

[ ∂

∂x ∂ h ∂y h

] )

[∑s i=1−s

∑s j=1−s V^ [n^ +^ 〈i, j〉]^ h ′(fx − i)h(fy − j) ∑s i=1−s

∑s j=1−s V^ [n^ +^ 〈i, j〉]^ h(fx^ −^ i)h

′(f y −^ j)

]

where V is a discrete (scalar-valued) input, h is a (separable) continuous kernel, x is the field position index, M −^1 is the space mapping matrix, n = bM −^1 xc is the discrete-mapped point, f = M −^1 x − n is the continuous point shifted by the discrete-mapped point. It can be seen here that the field gradient is computed only around a single point in the field space x. The equation above implements differentiation

Equation : Code : H = ∇F ⊗ ∇F tensor[3,3] H = ∇ ⊗ ∇F(pos); n = ||∇F || vec3 norm = normalize(∇F); P = I − n ⊗ n>^ tensor[3,3] P = identity[3] - norm ⊗ norm;

G = −

P HP

|∇F |

tensor[3,3] G = -(P•H•P)/|∇F|;

d =

2 |G|^2 − tr(G)^2 real d = sqrt(2.0*|G|^2-trace(G)^2);

kx = tr(G) + d 2

real kx = (trace(G) + d)/2.0;

ky =

tr(G) − d 2 real ky = (trace(G) - d)/2.0;

The equations behind curvature calculations and the program that calculates this on real images look almost identical, with a line-for-line match. This concept is used to produce the colored surfaces shown in Fig. 2b. This sample code served as a nice starting template for the experiments that were carried out in later sections. It should be noted that any Diderot program, including the examples, can be run serially or in parallel. The backend of the compiler can be told to compile code for: sequential C code, parallel C code, and OpenCL. Plans for a CUDA backend are in the works, however this functionality has yet to be seen. The expectation is that, especially for very large datasets, that parallel hardware support (such as a GPU cluster) will accelerate runtime results dramatically.

(a) Isocontour analysis

(b) Curvature color-mapping visu- alization

Figure 2: Diderot analysis and visualization examples

High-level brain operators

The primary utility of Diderot is that it abstracts away the tedious computations needed to perform math on continuous tensor fields. It allows for a manipulation of lots of data from a high-level, including the ability to use continuous derivatives as entire entities in programmable equations. With regard to computational neuroscience, it is advantageous to take the same approach with regard to neural circuits. If we can implement biologically-plausible algorithms on the neuron level, interconnect these entities as neural circuits, and achieve some benefit with regard to neural information processing (i.e. encoding of relative motion in a visual stimulus), then there should be a way to abstract away all of the low-level engineering and define a high-level “brain operator.” In other words, is it possible to define an operator, call it β, that performs sophisticated encoding on a neural circuit in the way that a gradient operator, like ∇ used in Diderot, performs a transformation of data on a continuous tensor field? What kinds of operators are

possible and how can neural circuitry be represented in the form of a continuous tensor field? The following sections will address these questions and analyze our initial experiments with Diderot.

Continuous neural fields

The amount of connections and synapses between neurons in any particular area of the brain is gigantic. Therefore, there is a need to represent the dynamics of significant layers of neurons in a convenient way, on a macro level. One way to do this is to use the already maturely-developed area of continuous dynamical sys- tems to approximate the behavior of neural networks. This implies that continuous mathematical equations are able to model neural activity as quantities in a continuous field, with functional relationships to sources and sinks of that field [4]. This allows for an explicit form for the activity at any particular point in the field as a weighted (non-linear) function of neighboring points. The basic idea comes from the assumption that the average activity of a neuron (i.e. average firing rate) in the field at point x at time t can be represented by

Zi(x, t) = fi

ui(x, t)

where Zi(x, t) is the activity of neuron at point x, at time t, in layer i of some neural network. ui(x, t) is the average membrane potential and fi is a non-linear activation function assumed to be monotonically non-decreasing [5]. In addition, this model assumes a time-varying, two-dimensional weighting function wij (x, y; t) (shown in Fig. 3) to quantify the conduction time, synaptic delay, and inter-neuron connection strength; in other words, the amount of influence activity from neuron at point y in layer j has on neuron at point x in layer i, t time units after firing initiates from neuron y. A majority of the literature models this weighting function to be of a lateral-inhibition type - where any neuron has strong, excitatory connections local to its proximity, and dominantly inhibitory influence on neurons farther away - and this model has been shown to yield realistic, biologically-inspired topographic maps of stimulus encoders in the visual system [6] [7]. In addition to this weighting function, the field model must also incorporate any intensity change due to an external stimulus, si input as well as the steady-state resting membrane potential, ri, such that

si(x, t) = ¯si + ∆si(x, t) (6) ri = ¯si − hi, (7)

where ¯si is the average stimulus intensity in layer i, ∆si(x, t) is the change in stimulus at point x, t and hi is the difference between the contribution of potential due to the stimulus ¯si and the resting potential ri in layer i. hi can also be thought of as where ui will converge (given no stimulus fluctuations) after a certain duration of time, τi. These values can be generalized at the layer-level as the same type of neurons are arranged on their respective layer, as seen in Fig. 3 [5].

I(x, t) = I(x − vt, 0), (9) where x = [x, y]>^ and v = [u, v]>^ represent two-dimensional quantities for position and velocity, respec- tively, in each coordinate axes. The reasonable assumption is made that intensities are conserved, in other words, the image intensity along its direction of spatiotemporal motion has no change from one time instant to the next. Formally,

dI(x, t) dt = 0 ⇒ ∇xI(x, t) · v +

∂I(x, t) ∂t

Eq. (10) is known as the gradient constraint equation, where

∇xI(x, t) =

[ (^) ∂I(x,t) ∂x ∂I(x,t) ∂y

]

Horn and Schunck approached detecting optical flow utilizing this method and posing it as an optimization problem [9]. They solved for their algorithm form by minimizing Eq. (10) with an additional smoothness term to ensure a certain level of continuity of flow, where ∫

Ω

(∇I · v +

∂I

∂t

)^2 + λ^2 (||∇u||^22 + ||∇v||^22 )dx (12)

is performed over an image domain of Ω, and λ is a tuneable parameter, which controls the influence of the smoothness constraint on the output. An iterative solution was arrived at, which enables numerical algorithms to compute for

uk+1^ = ¯uk^ −

Ix

Ix ¯uk^ + Iy ¯vk^ + It

α^2 + I^2 x + I y^2

vk+1^ = ¯vk^ −

Iy

Ix u¯k^ + Iy ¯vk^ + It

α^2 + I x^2 + I y^2

where the partial derivatives of I(x, t) with respect to x, y, t are represented as Ix, Iy , It, respectively, and ¯uk, ¯vk^ are the locally-averaged values for the optical flow at iteration k (computed via spatial filtering

  • e.g. Gaussian kernel smoothing). It is natural to think of the spatiotemporal gradient of our intensity function dI( dtx ,t)as a single entity over the entire image with 3 × Nx × Ny × Nt discrete 4-dimensional grid, where N represents the number of points at which the gradient is analyzed. In general, the gradient entity is actually continuous in all dimensions, and can be best represented as a continuous tensor field - a convenient formulation for a Diderot implementation. A more biologically-inspired model represents flow velocity gradients (the v in Horn-Schunk) as likeli- hood values corresponding to membrane potential of neurons [10]. Specifically, the model assumes a neural network composed of three cascading stages, inspired by the structure found in the visual cortex, with feed- forward, feedback, and lateral connectivity between neural units. The first stage of the cascade approximates an activation function of the spatially-integrated input signals - akin to the linear-nonlinear (LN) neuron encoding model. The literature expresses this in the form of an ordinary differential equation, where

x˙(1)^ = −x(1)^ + fsample

[xF F^ ]α^ ∗ Λspace

∗ Λvel. (15)

The change in likelihood is a function of the previous likelihood value and a sampled (nonlinear) function of the spatial convolution of a kernel Λspace with a quadratically-transformed (by α) input signal, which is smoothed in the temporal domain (to omit discontinuous sharp velocity changes) by Λvel. An isotropic kernel, like a Gaussian, is a good model for the smoothing kernels in this model as it has been shown that the early stages of the visual system have these types of receptive fields [11]. The second stage in this model incorporates feedback connectivity to enhance and characterize the likelihood values encoded on the

first. This is analogous to the connections between V1 and area MT in the higher stages of the cortex. Mathematically, this is represented as the ODE

x˙(2)^ = −x(2)^ + x(1)(1 + βxF B^ ). (16) This equation demonstrates the positive effect of feedback connectivity, but notice, only in the case where activity is present on that unit. If x(1)^ is very small, the feedback influence will be negligible. Finally, the third stage incorporates lateral connectivity, specifically, lateral inhibition - which provides for a divisive normalization of likelihood values. Not only does this mathematically bound the quantities calculated, it replicates a normalization phenomena seen in vivo through visual devices such as gain control [12]. The third and final stage for velocity gradient encoding is shown by the ODE

x˙(3)^ = −γx(3)^ + x(2)^ ∗ Λ+^ − x(3)

x(2)^ ∗ Λ−

where the convolution with kernels Λ+, Λ−^ yield the traditional center-surround receptive fields of the simple cells in lower layers of V1. This sophisticated structure serves as the feature extraction stage described in the beginning of the optical flow section. The weighting and integration of these velocity gradient features is implemented via a similar three-stage cascade with more complicated kernel functions (i.e. asymmetric difference of Gaussians) performing integration of the gradients in a more abstract, higher space - see Fig. 4. For the sake of brevity, the equations will not be elaborated any more here, but can be found in detail in the literature [10]. We will focus on just the feature extraction (V1) stage of the bio-inspired model as the higher stages (MT, MST) that perform the integration and flow vectors are of a similar structure.

Figure 4: Process pathways in the bio-inspired optical flow model [10]

In this model the likelihood values x exist, not only for each spatial location (i.e. topographic map of neurons), but also for every motion direction and motion speed that we care to resolve. From a higher level, this can be represented as a single entity (or neural circuit) of Nx × Ny × Nd × Nv elements, where N corresponds to the number of x, y spatial elements, d directional resolution, and v velocity resolution. Though of a different form than the Horn-Schunk intensity-based gradient entity, it also can be generalized and conveniently represented as a continuous tensor field.

Initial Diderot experimentation and limitations

With the above sections in consideration, we can begin to approach using Diderot for implementing continuous tensor fields to represent neural circuits. The neural field ui(x, t) given in Eq. (8) is analogous

Figure 6: First and second image overlay

To verify that Diderot can compute the gradient with respect to each axis correctly, we first convolved our input with a ctmr kernel to form the continuous tensor field F. Since Diderot represents this as a continuous entity, the spatial and temporal granularity can be determined by the user, despite the resolution of the input. Instead of taking the gradient of a two-image sequence, we sampled 10 slices from the underlying continuous field, and calculated the gradient using the del operator from Diderot on each slice (with respect to each dimension x, y, t). The output of the result was ported to MATLAB. Fig. 7 shows the 7th time slice gradients calculated by Diderot.

Figure 7: Display of x, y, t gradients calculated from Diderot

This verified that Diderot can accurately transform the discrete input into a continuous field, and produce reliable gradient information. The next step was to perform iterative local averaging on the continuous tensor field to implement the Horn-Schunk algorithm of Eq. (13) - in other words calculate ¯uk, v¯k. However, it quickly became apparent that this is a problem at this stage of development for Diderot. To implmement the aglorithm, the local average of the gradients needed to be calculated. The gradient operator in Diderot was able to generate another field from which we could probe at specific locations to extract the gradient tensor, however, there was no way to conveniently access neighboring points on the field and store an average of them to use for the next iteration - which is the computational core of the Horn-Schunk method. The problem with the current state of Diderot is that it does not support global mutable memory [1] [14]. This is a great limitation in performing the feature extraction and integration stages for the optical flow methods discussed above, as well as the canonical neural field model from Eq. (8). All of these methods

require inter-strand communication to enable the neural network to perform proper encoding; the three- stage cascade with feedforward and feedback connections of the bio-inspired model and the neural field weighting function all require the ability to communicate and update a common variable. Since Diderot does not have this feature enabled at this time, we must explore other ways to use the software to its strong points; primarily, as a visualization tool - which can be quite powerful for developing an intuition for certain phenomena discussed in computational neuroscience.

Visualizing the phase plane

When considering other potential uses for Diderot, it was important to keep in mind the novelties of the software: the flexibility and convenience in dealing with continuous tensor fields at a high level, and the portable parallel framework optimized for image analysis and visualization. With this in mind, we explored various topics in computational neuroscience that could benefit from this model. A great way to understand the dynamics of various conductance-based neuron models is by visualizing its response in the phase plane. This section will discuss several basic neuron models and how they operate from the point of view of their phase portraits. A novel visualization technique called line integral convolution (LIC) will also be introduced. Finally, the results of using Diderot to visualize phase portraits using LIC will be discussed along with the code developed and relevant figures.

Neuron dynamics and bifurcation

Three neuron models were explored: Hodgkin-Huxley, Morris-Lecar, and Fitzhugh-Nagumo. The Hodgkin- Huxley model is implemented via evaluating KCL across the neuron membrane with the assumption that the cross-membrane currents are attributed to four (activation) voltage-gated potassium ion (K+) channels, three (activation) and one (inactivation) voltage-gated sodium ion (Na+) channels and an ohmic leak current attributed to chloride ions (Cl−) [15]. The dynamics of the gates are represented as probabilities via gating variables n, m, h for K+^ activation, Na+^ activation, and Na+^ inactivation, respectively. The result is the following set of the nonlinear differential equations which form the Hodgkin-Huxley neuron model:

C V˙ = I −

IK ︷ ︸︸ ︷ ¯gK n^4 (V − EK ) −

IN a ︷ ︸︸ ︷ ¯gN am^3 h(V − EN a) −

IL ︷ ︸︸ ︷ gL(V − EL) n˙ = αn(V )(1 − n) − βn(V )n m ˙ = αm(V )(1 − m) − βm(V )m h^ ˙ = αh(V )(1 − h) − βh(V )h.

The phase plane for neuron models is generally defined to be a plot over one of the gating variables vs. voltage response V - though it can be generalized to be three or four-dimensional when more than one gating variable is plotted. In the Hodgkin-Huxley case, the gating variable n can be plotted against V to observe how the neuron is expected to behave when injected with an input current I. This plot can give an idea of where the dynamical system has stability or instability. An example of this is shown in Fig. ??.

C V˙ = I − gL(V − EL) − gCam∞(V )(V − ECa) − gK n(V − EK ) n˙ = (n∞(V ) − n)/τn(V )

m∞(V ) =

1 + tanh(

V − V 1

V 2

n∞(V ) =

1 + tanh(

V − V 3

V 4

τn(V ) = φ cosh

( V − V 3

2 V 4

where V 1 , V 2 , V 3 , V 4 are tuning parameters. Finally, the Fitzhugh-Nagumo model can also be analyzed. This model is a reduced Hodgkin-Huxley-type model which guarantees a cubic V -nullcline with w acting as the recovery activation variable. Fitzhugh-Nagumo has tuning parameters a, b, c and is defined by the differential equations [16]:

V˙ = V (a − V )(V − 1) − w + I w ˙ = bV − cw.

Accurately depicting the bifurcation of neuron states is vital to replicating how neurons encode infor- mation in vivo. It is helpful comparing the different neuron models in the phase plane, as it is easier to analyze then something like spike trains from each model. However, the gradients display of Fig. 8 can be an eyesore, making it hard to compare between various models (e.g. Hodgkin-Huxley vs. Morris-Lecar). Additionally, the vector field usually has to be distorted to illustrate the model’s dynamics. It would be helpful to visualize the phase plane via another medium, which is discussed in the following section.

Line integral convolution

The vector field from the phase plane of Fig. 8 is convenient for visualizing the general flow of the states, but it would be nicer to have an image displaying the vector field as a continuous surface. Line integral convolution is a visualization technique that is specifically designed to transform a vector field into a solid image that better shows how the vector field looks continuously. The technique requires two inputs, the vector field grid V and a texture image F. The local behavior of the vector field is approximated by a local stream line that starts at the center of each pixel in the field and moves outward in “forward” and “backward” directions. The position vector is incremented by 0.5 in both x and y, where an entire pixel corresponds to a 1 × 1 unit, to ensure the stream line starts exactly in the center of the field vector pixel. The coordinates of the stream line are then calculated as

P 0 = (x + 0. 5 , y + 0.5) (22)

P (^) fk = P (^) fk −^1 +

V

bP (^) fk −^1 c

||V

bP (^) fk −^1 c

∆sk f −^1 (23)

P (^) bk = P (^) bk −^1 −

V

bP (^) bk −^1 c

||V

bP (^) bk −^1 c

∆sk b −^1 , (24)

where P (^) fk , P (^) bk correspond to the stream line position indices of forward and backward directions at the

kth iteration, V

bP k−^1 c

is the gradient field value at the floored index of V , ∆sk f −^1 , ∆sk b −^1 are the (always positive) step sizes in the forward and backward directions, respectively [19]. In general, a convolution kernel function k(w) is computed and used as a weight in the LIC over the image, where

hk^ =

∫ (^) sk^ +∆sk

sk

k(w)dw. (25)

The result of Eq. (25) is then used to weigh the underlying image texture at each stream line index i; this result is then summed over the length of the streamline lf , lb and normalized by the sum of the weights, where

LIC(x, y) =

∑lf k=0 F^

bP (^) fk c

hkf +

∑lb k=0 F^

bP (^) bk c

hkb ∑lf k=0 h k f +^

∑lb k=0 h k b

The algorithm is well understood by studying Fig. 9

(a) Integration process (b) Stream line formation across vector field

Figure 9: LIC algorithm visualization [19]

In most cases, the underlying image texture is a white noise image; this way no local areas of the vector field yield heavier LIC lines than any others. Additionally, a box filter for k(w) can be used over the underlying texture image, so the inclusion of hk^ in the summation terms can be taken out and used as a single scaling value (akin to step size) across the entire stream line to be summed over. LIC is a great application for a Diderot program as not only are the calculations done on an independent pixel-by-pixel basis, but the flexibility of having a user-defined granularity to the input data allows for a very detailed LIC plot, despite a low-resolution vector field. Since the continuous tensor field object in Diderot can interpolate coarse input data, the midpoint method step can be relaxed to a simpler, forward/backward Euler integration. Additionally, the box filter can be used, so the kernel function k(w) doesn’t have to be calculated for each pixel. This simplifies the equation, algorithmically, to

P 0 = (x, y) P (^) fk = P (^) fk −^1 + ∆sV (P (^) fk −^1 ) P (^) bk = P (^) bk −^1 − ∆sV (P (^) bk −^1 )

⇒ LIC(x, y) =

∑ 2 l k=0 F^ (P^ k f ) +^ F^ (P^ k b ) 2 l + 1

where the step size ∆s and stream line length l are the same for forward and backward. The Diderot implementation of LIC implements Eq. (27) with the exception that it adds an additional |V (P 0 )| bias term to the numerator of LIC(x, y) for each pixel. Diderot’s LIC demo yields the results from Fig. 10.

Figure 11: Un-normalized phase portraits for each neuron model

The normalization technique we used involved taking a range of the input potentials and dividing dV by a factor η times the range, or

dVnorm = dV /η

max(V ) − min(V )

Utilizing Eq. (31) and overlaying the multi-path limit cycle runs yielded an accurate representation for the phase portraits, as seen in Fig. 12. The current values for each plot were I = 30μA/cm^2 , I = 80μA/cm^2 , I = 0 μA/cm^2 for the Hodgkin-Huxley, Morris-Lecar, and Fitzhugh-Nagumo models, respectively.

Figure 12: Normalized phase portraits for each neuron model

With the shape of the phase portraits verified in this manner, we then wanted to test Diderot’s ability to import and perform LIC over the inputs. Each phase portrait gradient vector field was exported from MATLAB as a 2 × 33 × 21 .h5 file. This file was then conerted to a .nrrd file via the h5 to nrrd.py Python script. This supplied the world-space coordinates in much the same way as img 2 nrrd.py. These .nrrd files served as inputs to licp.diderot - LIC visualization code that specifically handled the phase portrait data files. The code used a tent kernel to convolve the gradient field into a continuous tensor field and we probed it at 600 × 500 points to perform the LIC. The step-size was best found to be ∆s = 0.0005, with l = 200. A white-noise image was used as the underlying texture for convolution and was also imported to a continuous tensor field with a tent kernel. The results of the LIC can be seen in Fig. 13.

(a) Hodgkin-Huxley LIC (b) Morris-Lecar LIC

(c) Fitzhugh-Nagumo LIC

Figure 13: LIC results from Diderot program licp.diderot

The LIC does a nice job of helping to visualize a “continuous” behavior of the models in the phase plane. The transition states are more obvious and the V and n nullclines appear inherently in the flow of the images. The next step forward was to remove MATLAB’s role in generating any of the data. We realized that interpolating the gradient vectors in to Diderot through a kernel was a technical distortion of the phase portrait, even if that kernel was linear. We set out to implement the neuron models directly in Diderot, calculate the phase portraits, perform the LIC of the calculations, and finally generate the correct output. The input data to Diderot would then be the range of V and n that we wanted to calculate the phase portraits over (calculated via vnirange.m). Interpolating the range into a continuous tensor would not be an issue, as it is merely an input to the model, not an output from nonlinear equations. Despite Diderot’s limitations with not being able to define function handles, or share mutable memory, the models were successfully implemented and the LIC was calculated from the output of the models in the same way as with licp.diderot

  • all within one Diderot file. The outputs of the figures were not quite on par with the licp.diderot results, however. Generating a smooth-looking LIC portrait requires many iterations per strand and a larger step size to sample from the underlying white noise texture. These parameters are limited for a few reasons. The amount of calculations that the code performs with the addition of the neuron model is far greater than in just calculating LIC from input vectors. As a result, the programs were more sensitive to bus errors and segmentation faults. This is due to limitations of the software package, hardware that is not optimized for the program, and boundary conditions that are not checked for in the Diderot code file itself. There was much experimentation done with the checking of boundary conditions (to ensure the field was being probed where expected and not running out of the program somewhere), however, a universal solution to the problem was not found. Regardless, the phase portrait/LIC generating code for each neuron model does yield reliable results, as shown in Fig. 14.