XML specification

XML specification — Specification of the XML format used to describe a cpg network

Sections

A basic, empty XML file looks like this:

<cpg>
  <network>
  </network>
</cpg>

Thus, the root element is cpg which contains the network root element network. The network itself consists of four distinct sections:

Globals

The globals section of the network is an optional section containing property definitions which can be used in any expression in the network. As such, they are similar to global variables. The following is an example of defining a global property x.

Example 3. 

<cpg>
  <network>
    <globals>
      <property name="x">2 * PI</property>
    </globals>
  </network>
</cpg>



Templates

The network specification can make use of a simple templating system. This means that you can write generic state, link and relay objects which can serve as templates to base the actual objects in the network on. You could for instance define a template for a state which defines some properties that apply to all the states in your network, and override some specific properties in each instance of the template. Templating is also very useful for link objects. For instance, defining a phase coupling link as a template and instantiating that template for specific states will greatly reduce the size of the network representation. Templates definitions can themselves also be based on another template, making the templates a simple, yet powerful mechanism. The following example shows a network with a template for a basic oscillator and integration link:

Example 4. Demonstration of templates

<cpg>
  <network>
    <templates>
      <state id="oscillator">
        <property name="x" integrated="true">rand()</property>
        <property name="y" integrated="true">rand()</property>
        <property name="amplitude">1</property>
      </state>
      <link id="integrate">
        <action target="x">y</action>
        <action target="y">x</action>
      </link>
    </templates>
    <state id="osc1" ref="oscillator">
      <!-- Override amplitude property -->
      <property name="amplitude">2</property>
    </state>
    <state id="osc2" ref="oscillator">
      <!-- Override amplitude property -->
      <property name="amplitude">3</property>
    </state>

    <link id="integrate1" ref="integrate" from="osc1" to="osc1"/>
    <link id="integrate2" ref="integrate" from="osc2" to="osc2"/>
  </network>
</cpg>



Objects

The example in the Templates section already showed how objects can be defined in a network. Any state, link or relay can be defined in the network. Each of these objects requires an unique id by which the object can be referenced in the network. Optionally, you can specify a ref attribute which bases the object on a template defined in the templates section.

Each object can then define a list of property elements specifying the state variables of the object. A property tag MUST have a name attribute. The content of the tag is a mathematical expression defining the initial value of the property:

<property name="x">2 * PI</property>

A property can reference other properties with the following precendence:

  1. Properties from the object itself
  2. Previously defined global properties

To indicate that a property should be integrated when acted upon by a link, the tag integrated can be specified on the property.

A link tag has two additional required attributes, from and to. These define respectively the source and the destination objects of the link. In addition to properties, a link has one ore more action tags. An action defines information to be transfered to a target property in the destination object, using a mathematical expression. The expression can reference properties with the following precedence:

  1. Properties from the link itself
  2. Properties from the source object
  3. Previously defined global properties

In addition, properties from the source and destination objects can be referenced explicitly by using the format from.<prop> and to.<prop> respectively.


Functions

A special section in the network specifies user defined functions which you can then use in any expression in the network. This can be very convenient if you have subexpressions which need to be evaluated at many places.

<functions>
  <function name="f1">
    <expression>x * x</expression>
    <argument optional="yes" default="1">x</argument>
  </function>
</functions>

The small example shows a custom user function f1 with one optional argument (with a default value of 1) named x. The specified expression is the same kind of mathematical expression you can specify in other parts of the network. You can use global constants and other user functions in this expression.

There is one more specialized user function which allows you to easily define and evaluate piecewise polynomial functions.

<functions>
  <polynomial name="f1">
    <piece begin="-0.25" end="0.25">-4, 6, 0, -1</piece>
    <piece begin="0.25" end="0.75">4, -6, 0, 1</piece>
    <piece begin="0.75" end="1.25">-4, 6, 0, -1</piece>
  </function>
</functions>

The example above defines a piecewise 4th order, periodic polynomial resembling a sine wave. You can evaluate this function with f1(t) where t is the point at which to evaluate the piecewise polynomial function. Additionally, an optional second argument specifies with order derivative of the function to evaluate. Thus f1(t, 1) evaluates the first order derivative of the function.

DTD specification

The specification of the XML format used to represent a network can be precisely described with the following DTD:

<!ELEMENT cpg (network)>
<!ELEMENT network (globals?, templates?, functions?, state*, link*, relay*)>
<!ELEMENT globals (property*)>
<!ELEMENT templates (state*, link*, relay*)>
<!ELEMENT functions (function*, polynomial*)>
<!ELEMENT function (expression, argument*)>
<!ELEMENT polynomial (piece*)>
<!ELEMENT argument (#PCDATA)>
<!ELEMENT expression (#PCDATA)>
<!ELEMENT piece (#PCDATA)>

<!ELEMENT state (property*)>
<!ATTLIST state
	id CDATA #REQUIRED
	ref CDATA
>

<!ELEMENT link (property*, action*)>
<!ATTLIST link
	id CDATA #REQUIRED
	from CDATA
	to CDATA
	ref CDATA
>

<!ELEMENT relay (property*)>
<!ATTLIST relay
	id CDATA #REQUIRED
	ref CDATA
>

<!ELEMENT action (#PCDATA)>
<!ATTLIST action
	target CDATA #REQUIRED
>

<!ELEMENT property (#PCDATA)>
<!ATTLIST property
	name CDATA #REQUIRED
	integrated CDATA
	in CDATA
	out CDATA
>

<!ATTLIST argument
	optional CDATA
	default CDATA
>

<!ATTLIST function
	name CDATA #REQUIRED
>

<!ATTLIST polynomial
	name CDATA #REQUIRED
>

<!ATTLIST piece
	begin CDATA #REQUIRED
	end CDATA #REQUIRED
>