Monday, July 28, 2014

Weekly Log: July 21 - July 27

The flattening routine should in theory work for all SBML core constructs. I have been testing the flattening function this past week. I integrated the flattening routine in a tool called iBioSim, which is a tool being developed at the University of Utah that can be used for the modeling and analysis of SBML models. Within iBioSim, I was able to construct an arrayed model thanks to one of my lab colleagues, Scott Glass, who is responsible for the GUI support for the Arrays package.

Here is a model in iBioSim. In this model, there are two parameters of size n and one rule of size n, where n is a constant parameter of value 10. This parameter is not shown here, because constant parameters are kept in the constants tab. These objects are enclosed by a compartment Cell, but this is irrelevant to this model. iBioSim adds a compartment by default.

I give a initial assignment to Y as shown below.

Y is given a vector as initial assignment. This can be translated as
Y[0] = 0
Y[1] = 1 and so on

Finally, I specify the attributes for the rule:



rule0 is an assignment rule, where X is the LHS and Y is the RHS. This is actually saying that:
X[9-d0] = Y[d0] where d0 is the dimension id for a Dimension object of the assignment rule with array dimension 0. Since the dimension has size 10, d0 can take any value from 0 to 9. When this is simulated, I get the following:

Values of Y

Values of X

You can see that X has the values of Y in reverse order, just like we specified in the assignment rule.

One of the requirements for a package to be fully accepted to the standard is to have at least two tools implement the package. iBioSim has started the implementation, though it is not yet finalized. Hopefully, there will be other tools using the arrays package because I believe it can be very helpful from a modeling standpoint.

Tuesday, July 22, 2014

Weekly Log: July 14 - July 20

I am posting one day late this week so I apologize. I have been working on the flattening routine for the arrays package. I implemented the algorithm and the routine is completed in two passes:

1. Flatten dimension and index objects

Essentially, what I am doing to flatten SBase objects with dimension objects is making n copies of the arrayed sbase, where n is the product of each dimension size. For instance, imagine you have this SBML model. For the sake of simplicity, I would write this in a Java-base syntax:

Parameter size = 2;
Parameter X = new Parameter[size][size];

Essentially, I would turn this into:

Parameter size = 2;
Parameter X_0_0;
Parameter X_0_1;
Parameter X_1_0;
Parameter X_1_1;

If an SBase you are flattening has math associated with it and in the math there is a dimension id, then I replace the dimension id for the actual index value. When there is an assignment, I update the id of the SBaseRef. For example:

Parameter size = 2;
Parameter X = new Parameter[size][size];
Parameter Y = new Parameter[size][size];

for (int i  = 0; i < 2; ++i) 
  for (int i  = 0; i < 2; ++i) 
    X[i][j] = Y[j][i];

The above example would be turned into:

Parameter size = 2;
Parameter X_0_0, X_0_1, X_1_0, X_1_1;
Parameter Y_0_0, Y_0_1, Y_1_0, Y_1_1;
X_0_0 = {{Y_0_0, Y_0_1}, {Y_1_0, Y_1_1}}[0][0];
X_0_1 = {{Y_0_0, Y_0_1}, {Y_1_0, Y_1_1}}[1][0];
X_1_0 = {{Y_0_0, Y_0_1}, {Y_1_0, Y_1_1}}[0][1];
X_1_1 = {{Y_0_0, Y_0_1}, {Y_1_0, Y_1_1}}[1][1];

Last, I update the Metaid of each SBase.


2. Flatten vector and selector math

After I flatten dimension and index objects, I evaluate vector and selector MathML objects to be just a scalar value. In the above example, the assignments would be turned into:

X_0_0 = Y_0_0;
X_0_1 = Y_1_0;
X_1_0 = Y_0_1;
X_1_1 = Y_1_1;

Vectors are also evaluated and at the end you end up with scalars only.

Here is an example in SBML:

Arrayed model:
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<sbml xmlns="http://www.sbml.org/sbml/level3/version1/core" level="3" arrays:required="true" xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1" version="1">
  <model>
    <listOfParameters>
      <parameter id="n" value="10"/>
      <parameter id="X" value="1">
        <arrays:listOfDimensions xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1">
          <arrays:dimension arrays:id="i" arrays:size="n" arrays:arrayDimension="0"/>
        </arrays:listOfDimensions>
      </parameter>
      <parameter id="Y" value="2">
        <arrays:listOfDimensions xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1">
          <arrays:dimension arrays:id="i" arrays:size="n" arrays:arrayDimension="0"/>
        </arrays:listOfDimensions>
      </parameter>
    </listOfParameters>
    <listOfInitialAssignments>
      <initialAssignment symbol="X">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <vector>
            <cn type="integer"> 1 </cn>
            <cn type="integer"> 2 </cn>
            <cn type="integer"> 3 </cn>
            <cn type="integer"> 4 </cn>
            <cn type="integer"> 5 </cn>
            <cn type="integer"> 6 </cn>
            <cn type="integer"> 7 </cn>
            <cn type="integer"> 8 </cn>
            <cn type="integer"> 9 </cn>
            <cn type="integer"> 10 </cn>
          </vector>
        </math>
              <arrays:listOfDimensions xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1">
          <arrays:dimension arrays:id="i" arrays:size="n" arrays:arrayDimension="0"/>
        </arrays:listOfDimensions>
      </initialAssignment>
    </listOfInitialAssignments>
    <listOfRules>
      <assignmentRule variable="Y">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <apply>
            <selector/>
            <ci> X </ci>
            <ci> i </ci>
          </apply>
        </math>
              <arrays:listOfDimensions xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1">
          <arrays:dimension arrays:id="i" arrays:size="n" arrays:arrayDimension="0"/>
        </arrays:listOfDimensions>
        <arrays:listOfIndices xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1">
          <arrays:index arrays:referencedAttribute="variable" arrays:arrayDimension="0">
            <math xmlns="http://www.w3.org/1998/Math/MathML">            
              <apply>
                <minus/>
                <cn type="integer"> 9 </cn>
                <ci> i </ci>
              </apply>
            </math>
                    </arrays:index>
        </arrays:listOfIndices>
      </assignmentRule>
    </listOfRules>
  </model>

</sbml>

Flatten model:
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<sbml xmlns="http://www.sbml.org/sbml/level3/version1/core" level="3" arrays:required="true" xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1" version="1">
  <model>
    <listOfParameters>
      <parameter id="n" value="10"/>
      <parameter id="X_0" value="1"/>
      <parameter id="X_1" value="1"/>
      <parameter id="X_2" value="1"/>
      <parameter id="X_3" value="1"/>
      <parameter id="X_4" value="1"/>
      <parameter id="X_5" value="1"/>
      <parameter id="X_6" value="1"/>
      <parameter id="X_7" value="1"/>
      <parameter id="X_8" value="1"/>
      <parameter id="X_9" value="1"/>
      <parameter id="Y_0" value="2"/>
      <parameter id="Y_1" value="2"/>
      <parameter id="Y_2" value="2"/>
      <parameter id="Y_3" value="2"/>
      <parameter id="Y_4" value="2"/>
      <parameter id="Y_5" value="2"/>
      <parameter id="Y_6" value="2"/>
      <parameter id="Y_7" value="2"/>
      <parameter id="Y_8" value="2"/>
      <parameter id="Y_9" value="2"/>
    </listOfParameters>
    <listOfInitialAssignments>
      <initialAssignment symbol="X_0">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <cn type="integer"> 1 </cn>
        </math>
            </initialAssignment>
      <initialAssignment symbol="X_1">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <cn type="integer"> 2 </cn>
        </math>
            </initialAssignment>
      <initialAssignment symbol="X_2">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <cn type="integer"> 3 </cn>
        </math>
            </initialAssignment>
      <initialAssignment symbol="X_3">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <cn type="integer"> 4 </cn>
        </math>
            </initialAssignment>
      <initialAssignment symbol="X_4">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <cn type="integer"> 5 </cn>
        </math>
            </initialAssignment>
      <initialAssignment symbol="X_5">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <cn type="integer"> 6 </cn>
        </math>
            </initialAssignment>
      <initialAssignment symbol="X_6">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <cn type="integer"> 7 </cn>
        </math>
            </initialAssignment>
      <initialAssignment symbol="X_7">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <cn type="integer"> 8 </cn>
        </math>
            </initialAssignment>
      <initialAssignment symbol="X_8">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <cn type="integer"> 9 </cn>
        </math>
            </initialAssignment>
      <initialAssignment symbol="X_9">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <cn type="integer"> 10 </cn>
        </math>
            </initialAssignment>
    </listOfInitialAssignments>
    <listOfRules>
      <assignmentRule variable="Y_9">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <ci> X_0 </ci>
        </math>
            </assignmentRule>
      <assignmentRule variable="Y_8">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <ci> X_1 </ci>
        </math>
            </assignmentRule>
      <assignmentRule variable="Y_7">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <ci> X_2 </ci>
        </math>
            </assignmentRule>
      <assignmentRule variable="Y_6">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <ci> X_3 </ci>
        </math>
            </assignmentRule>
      <assignmentRule variable="Y_5">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <ci> X_4 </ci>
        </math>
            </assignmentRule>
      <assignmentRule variable="Y_4">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <ci> X_5 </ci>
        </math>
            </assignmentRule>
      <assignmentRule variable="Y_3">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <ci> X_6 </ci>
        </math>
            </assignmentRule>
      <assignmentRule variable="Y_2">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <ci> X_7 </ci>
        </math>
            </assignmentRule>
      <assignmentRule variable="Y_1">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <ci> X_8 </ci>
        </math>
            </assignmentRule>
      <assignmentRule variable="Y_0">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <ci> X_9 </ci>
        </math>
            </assignmentRule>
    </listOfRules>
  </model>

</sbml>


Monday, July 14, 2014

Weekly Log: July 7 - July 13

This week I continued working on the compiler that evaluates vectors. I implemented a few of the functions that were missing and I think I am somewhat close to finishing up everything on the compiler.

After the last meeting with my mentor, Nico Rodriguez, we decided to put the validation aside for a little bit and start the implementation of the flattening routine.  Arrays is just syntactic sugar for the modeling language; you can construct models that would behave exactly the same using other constructs. For this reason,  flattening makes a lot of sense in the context of the arrays package. Note that the flattening routine is important for the arrays package because it would allow many tools to simulate arrayed models without much effort.

In a previous meeting, we discussed an algorithm for the arrays package. Chris Myers, one of my mentors, helped me solidify the algorithm. I started the implementation, and I am testing the code. I will post details and the results in the next blog post.

Monday, July 7, 2014

Weekly Log: June 30 - July 6

This week I worked on a compiler that evaluates vectors. For instance, the compiler
  • accepts {{1},{2},{3}} + {{4},{5},{6}} and outputs {{5},{7},{9}}
  • accepts {{1},{2},{3}} + 2 and outputs {{3},{4},{5}}
  • accepts sin({pi, pi/2, -pi}) and outputs {0, 1, 0}
  • and so on.
For every binary or nary operations, the vector dimension of the input nodes should match in size unless it is a scalar. As shown in the example, if you have a vector plus a scalar, then each entry will be incremented by the scalar value. For instance, the compiler
  • rejects {{1},{2},{3}} + {{4}}
  • rejects {1, 2, 3} + {{1},{2},{3}}
  • and so on.
When there is an SIdRef object type, I check if the object has dimensions and, if so, I convert it to a vector. Otherwise, I convert it to a scalar.

Ultimately, the compiler needs to do absolute value, trigonometric operations, logical operations, arithmetic operations, floor, ceiling, fraction, inequalities, lambda function, piecewise function, logarithm operations, power, square root, selector... 

I haven't implemented all of them, but I got a lot of them done. This compiler will be used in the remaining validation rule that specifies that states the vector dimensions should match unless it is a scalar. 

In addition to the compiler, I updated the arrays specification to include a flattening algorithm. I discussed the algorithm with my mentors, Chris and Nico. There are a couple of things that needs to be fixed but the algorithm seem to be in the right track. Perhaps after polishing it a little bit, the algorithm will be good to go and I can start the implementation. The vector compiler can potentially be used in the flattening routine as well.