About
Introduction
Elements
Interpreter
Example 1
Example 2
Example 3
Example 4
Example 5
Example 6
Example 7
Regimes example
Example n
Canonical form
Discussion

User defined types for networks and populations

As with the hard-coded constructs for display and simulation in the previous example, all the examples so far have used the temporary hard-coded constructs XNetwork, XPopulation etc for networks. These are undesirable because they unduly prioritize particular parameterizations.

Replacing these with user-defined constructs involves two stages. Defining types to contain the same parameters is trivial. For example, the following definitions do the same as the previously hard-coded ones in terms of specification:


<Type name="Network">     
   <Children name="populations" type="Population" />     
   <Children name="connectivities" type="EventConnectivity" />
</Type>

<Type name="Population">     
   <ComponentRef name="component" type="Component" />     
   <Parameter name="size" dimension="none" />  
</Type>

<Type name="EventConnectivity">     
   <Link name="source" type="Population" />     
   <Link name="target" type="Population" />     
   <Child name="Connections" type="ConnectionPattern" />
</Type>

The harder part is to provide elements in the Behavior blocks to express what should be done with components based on these types. The Network element doesn't pose any problems because the default behavior on instantiation will do the right thing: it will instantiate each of the child populations and EventConnectivity elements.

But the population element needs to say that its instantiation involves making 'size' instances of the component referred to by the 'component' reference, where 'size' is the value supplied for the size parameter in a component specification. This can be done by including a Build element inside the Behavior block:


<Type name="Population">     
   <ComponentRef name="component" type="Component" />     
   <Parameter name="size" dimension="none" />     
   <Behavior>         
      <Build>             
         <MultiInstantiate number="size" component="component" />         
      </Build>     
   </Behavior>
</Type>

The MultiInstantiate specification says that there should be 'size' instances of the component referred to in the 'component' parameter created when the model is built. This overrides the default behavior. [TODO: what is the Build element content corresponding to the default behavior?].

This serves to create some rather simple populations. More complex specifications, such as putting one instance at each point of a grid satisfying a particular constraint could be handled via first declaring elements to form the grid, and then using selectors that pick the points in the population element to actually put the cells at [its not clear to me how much more would be required to make this work, other than implementing proper xpath-like selectors].

The following three types define a general connectivity structure with an abstract ConnectionPattern type, and a specific instance for All-All connectivity.


<Type name="EventConnectivity">     
   <Link name="source" type="Population" />     
   <Link name="target" type="Population" />     
   <Child name="Connections" type="ConnectionPattern" />
</Type>

<Type name="ConnectionPattern">
</Type>

<Type name="AllAll" extends="ConnectionPattern">     
   <Behavior>         
      <Build>             
         <ForEach instances="../source" as="a">                  
            <ForEach instances="../target" as="b">                       
               <EventConnection from="a" to="b" />                  
            </ForEach>             
         </ForEach>             
      </Build>     
   </Behavior>
</Type>

The Build element in the AllAll pattern uses a new ForEach construct and the EventConnectin element from before. The ForEach element operates selects each instance matching its 'instances' attribute, and applies the enclosing directives, much in the same way as for-each in XSL. The proof of concept interpreter also has Choose, When and Otherwise elements that operate much like their XSL equivalents, although these are not used in this example.

With these definitions in place, a network simulation can be defined with the following:


<Network id="net1">     
   <Population id="p1" component="gen1" size="2" />     
   <Population id="p3" component="iaf3cpt" size="3" />           
   <EventConnectivity id="p1-p3" source="p1" target="p3">         
      <Connections type="AllAll" />     
   </EventConnectivity>
</Network>

<Simulation id="sim1" length="80ms" step="0.05ms" target="net1">     
   <Display timeScale="1ms">         
      <Line id="gen_v" quantity="p3[0]/v" scale="1mV" color="#0000f0" />         
      <Line id="gen_tsince" quantity="p1[0]/tsince" scale="1ms" color="#00c000" />     
   </Display>
</Simulation>

The output when the model is run is shown below, followed by the full listing.

example7.xml (xml)
<Lems>  
   <DefaultRun component="sim1" />       
   <Include file="ex2dims.xml" />
   <Include file="spikegenerators.xml" />
   <Include file="misciaf.xml" />      

   <Component id="gen1" type="spikeGenerator" period="30ms" />

   <Component id="gen2" type="spikeGenerator2" period="32ms" />

   <Component id="iaf3cpt" type="iaf3" leakReversal="-50mV" deltaV="50mV" threshold="-30mV" leakConductance="50pS" refractoryPeriod="4ms" capacitance="1pF" />

   <Type name="Display">     
      <Parameter name="timeScale" Dimension="time" />     
      <Children name="lines" type="Line" />     
      <Behavior>          
         <Show src="lines" scale="timeScale" />     
      </Behavior>
   </Type>

   <Type name="Line">     
      <Parameter name="scale" Dimension="*" />     
      <Text name="color" />     
      <Path name="quantity" />     
      <Behavior>         
         <Record quantity="quantity" scale="scale" color="color" />     
      </Behavior>
   </Type>

   <Type name="Simulation">     
      <Parameter name="length" dimension="time" />     
      <Parameter name="step" dimension="time" />     
      <ComponentRef name="target" type="Network" />     
      <Children name="displays" type="Display" />     
      <Behavior>         
         <StateVariable name="t" dimension="time" />         
         <Run component="target" variable="t" increment="step" total="length" />         
         <Show src="displays" />     
      </Behavior>
   </Type>

   <Type name="Network">     
      <Children name="populations" type="Population" />     
      <Children name="connectivities" type="EventConnectivity" />
   </Type>

   <Type name="Population">     
      <ComponentRef name="component" type="Component" />     
      <Parameter name="size" dimension="none" />     
      <Behavior>         
         <Build>             
            <MultiInstantiate number="size" component="component" />         
         </Build>     
      </Behavior>
   </Type>

   <Type name="EventConnectivity">     
      <Link name="source" type="Population" />     
      <Link name="target" type="Population" />     
      <Child name="Connections" type="ConnectionPattern" />
   </Type>

   <Type name="ConnectionPattern">
   </Type>

   <Type name="AllAll" extends="ConnectionPattern">     
      <Behavior>         
         <Build>             
            <ForEach instances="../source" as="a">                  
               <ForEach instances="../target" as="b">                       
                  <EventConnection from="a" to="b" />                  
               </ForEach>             
            </ForEach>             
         </Build>     
      </Behavior>
   </Type>

   <Network id="net1">     
      <Population id="p1" component="gen1" size="2" />     
      <Population id="p3" component="iaf3cpt" size="3" />           
      <EventConnectivity id="p1-p3" source="p1" target="p3">         
         <Connections type="AllAll" />     
      </EventConnectivity>
   </Network>

   <Simulation id="sim1" length="80ms" step="0.05ms" target="net1">     
      <Display timeScale="1ms">         
         <Line id="gen_v" quantity="p3[0]/v" scale="1mV" color="#0000f0" />         
         <Line id="gen_tsince" quantity="p1[0]/tsince" scale="1ms" color="#00c000" />     
      </Display>
   </Simulation>
</Lems>