Regimes in behavior definitions
This example introduces the Regime, Transition and OnEntry elements within a behavior block. Rather than having a single state instance, the entity can be on one of the defined regimes at any given time. The Transition element occurring inside a condition block serves to move it from one regime to another. The OnEntry block inside a regime can contain initialization directives that apply each time the entity enters that regime.
example8.xml
(xml)
<Lems>
<DefaultRun component="sim1" />
<Include file="ex2dims.xml" />
<Include file="spikegenerators.xml" />
<Include file="misciaf.xml" />
<Type name="refractiaf">
<Parameter name="threshold" dimension="voltage" />
<Parameter name="refractoryPeriod" dimension="time" />
<Parameter name="capacitance" dimension="capacitance" />
<Parameter name="vleak" dimension="voltage" />
<Parameter name="gleak" dimension="conductance" />
<Parameter name="current" dimension="current" />
<Parameter name="vreset" dimension="voltage" />
<Parameter name="deltaV" dimension="voltage" />
<Parameter name="v0" dimension="voltage" />
<EventPort name="out" direction="out" />
<EventPort name="in" direction="in" />
<Behavior>
<StateVariable name="v" dimension="voltage" />
<OnStart>
<StateAssignment variable="v" value="v0" />
</OnStart>
<Regime name="refr">
<StateVariable name="tin" dimension="time" />
<OnEntry>
<StateAssignment variable="tin" value="t" />
<StateAssignment variable="v" value="vreset" />
</OnEntry>
<OnCondition test="t .gt. tin + refractoryPeriod">
<Transition regime="int" />
</OnCondition>
</Regime>
<Regime name="int" initial="true">
<TimeDerivative variable="v" value="(current + gleak * (vleak - v)) / capacitance" />
<OnCondition test="v .gt. threshold">
<EventOut port="out" />
<Transition regime="refr" />
</OnCondition>
<OnEvent port="in">
<StateAssignment variable="v" value="v + deltaV" />
</OnEvent>
</Regime>
</Behavior>
</Type>
<Component id="gen1" type="spikeGenerator" period="7ms" />
<Component id="multiregime" type="refractiaf" threshold="-50mV" v0="-80mV" refractoryPeriod="20ms" capacitance="1pF" vreset="-80mV" vleak="-90mV" gleak="5pS" current="0.00001nA" deltaV="5mV" />
<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="1" />
<Population id="p3" component="multiregime" size="2" />
<EventConnectivity id="p1-p3" source="p1" target="p3">
<Connections type="AllAll" />
</EventConnectivity>
</Network>
<Simulation id="sim1" length="200ms" step="0.05ms" target="net1">
<Display timeScale="1ms">
<Line id="gen_vmr" quantity="p3[0]/v" scale="1ms" color="#00c000" />
</Display>
</Simulation>
</Lems>
<DefaultRun component="sim1" />
<Include file="ex2dims.xml" />
<Include file="spikegenerators.xml" />
<Include file="misciaf.xml" />
<Type name="refractiaf">
<Parameter name="threshold" dimension="voltage" />
<Parameter name="refractoryPeriod" dimension="time" />
<Parameter name="capacitance" dimension="capacitance" />
<Parameter name="vleak" dimension="voltage" />
<Parameter name="gleak" dimension="conductance" />
<Parameter name="current" dimension="current" />
<Parameter name="vreset" dimension="voltage" />
<Parameter name="deltaV" dimension="voltage" />
<Parameter name="v0" dimension="voltage" />
<EventPort name="out" direction="out" />
<EventPort name="in" direction="in" />
<Behavior>
<StateVariable name="v" dimension="voltage" />
<OnStart>
<StateAssignment variable="v" value="v0" />
</OnStart>
<Regime name="refr">
<StateVariable name="tin" dimension="time" />
<OnEntry>
<StateAssignment variable="tin" value="t" />
<StateAssignment variable="v" value="vreset" />
</OnEntry>
<OnCondition test="t .gt. tin + refractoryPeriod">
<Transition regime="int" />
</OnCondition>
</Regime>
<Regime name="int" initial="true">
<TimeDerivative variable="v" value="(current + gleak * (vleak - v)) / capacitance" />
<OnCondition test="v .gt. threshold">
<EventOut port="out" />
<Transition regime="refr" />
</OnCondition>
<OnEvent port="in">
<StateAssignment variable="v" value="v + deltaV" />
</OnEvent>
</Regime>
</Behavior>
</Type>
<Component id="gen1" type="spikeGenerator" period="7ms" />
<Component id="multiregime" type="refractiaf" threshold="-50mV" v0="-80mV" refractoryPeriod="20ms" capacitance="1pF" vreset="-80mV" vleak="-90mV" gleak="5pS" current="0.00001nA" deltaV="5mV" />
<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="1" />
<Population id="p3" component="multiregime" size="2" />
<EventConnectivity id="p1-p3" source="p1" target="p3">
<Connections type="AllAll" />
</EventConnectivity>
</Network>
<Simulation id="sim1" length="200ms" step="0.05ms" target="net1">
<Display timeScale="1ms">
<Line id="gen_vmr" quantity="p3[0]/v" scale="1ms" color="#00c000" />
</Display>
</Simulation>
</Lems>