|
From: <cc...@us...> - 2014-11-25 17:24:14
|
Revision: 21756
http://sourceforge.net/p/sbml/code/21756
Author: ccmyers
Date: 2014-11-25 17:24:06 +0000 (Tue, 25 Nov 2014)
Log Message:
-----------
Update validation and flatten algorithm
Modified Paths:
--------------
trunk/specifications/sbml-level-3/version-1/arrays/spec/apdx-validation.tex
trunk/specifications/sbml-level-3/version-1/arrays/spec/examples.tex
trunk/specifications/sbml-level-3/version-1/arrays/spec/syntax.tex
Modified: trunk/specifications/sbml-level-3/version-1/arrays/spec/apdx-validation.tex
===================================================================
--- trunk/specifications/sbml-level-3/version-1/arrays/spec/apdx-validation.tex 2014-11-24 21:40:20 UTC (rev 21755)
+++ trunk/specifications/sbml-level-3/version-1/arrays/spec/apdx-validation.tex 2014-11-25 17:24:06 UTC (rev 21756)
@@ -106,8 +106,8 @@
(Reference: SBML Level~3 Package Specification for Arrays,
Version~1, \sec{math-formulas}.) }
-\printValid{{\color{red} Deprecate?}The arguments of a MathML \token{vector} must all have the same number of dimensions and agree in their size. (Reference: SBML Level~3 Package Specification for Arrays,
- Version~1, \sec{math-formulas}.)}
+% \printValid{{\color{red} Deprecate?}The arguments of a MathML \token{vector} must all have the same number of dimensions and agree in their size. (Reference: SBML Level~3 Package Specification for Arrays,
+% Version~1, \sec{math-formulas}.)}
\printValid{The first argument of a MathML \token{selector} must be a MathML \token{vector} object or a valid identifier to an \SBase object extended with a list of \Dimension objects. (Reference: SBML Level~3 Package Specification for Arrays,
Version~1, \sec{math-formulas}.)}
@@ -126,8 +126,7 @@
\printValid{For each possible value of each \Dimension \primtype{id} (i.e., 0 to size-1 of the \Dimension referred to) that appears in the second and later arguments of the \token{selector}, there should be no array out-of-bounds problems. Namely, it must evaluate to a non-negative integer that is less than the size of the corresponding \Dimension for the object being indexed where the last argument refers to dimension 0, next to last to dimension 1, etc. (Reference: SBML Level~3 Package Specification for Arrays, Version~1, \sec{math-formulas}.)}
-\printModeling{It is strongly advised to perform mathematical
- operations on scalar values rather than vectors. (Reference: SBML Level~3 Package Specification for Arrays, Version~1, \sec{math-formulas}.)}
+\printValid{All mathematical operations must be performed on scalar values rather than vectors. (Reference: SBML Level~3 Package Specification for Arrays, Version~1, \sec{math-formulas}.)}
%% QUESTION: Is this a validation rule?
% \printValid{For MathML unary operations involving a MathML \token{vector} or an \SBase object with a list of \Dimension objects, the operator is performed element-wise on each entry of the array.}
@@ -321,31 +320,29 @@
The algorithms below provide a method for interpreting the Arrays
constructs and creating a ``flattened'' SBML Level~3 Version~1 Core
document. Algorithm~\ref{flattenArrays} considers each \SBase object
-in a \Model. If this object has dimensions, then it calls
+in a SBMLDocument. First, it removes the \SBase object from the
+document. Then, it calls
Algorithm~\ref{expandDimension} recursively to expand each dimension.
-Algorithm~\ref{expandDimension} creates a clone of the object for each
+If the \emph{currentDimension} is greater than or equal to 0, Algorithm~\ref{expandDimension} creates a clone of the object for each
member of the array within the current dimension in which the id is
given a unique value based on its position in that array dimension.
It also replaces the current dimension id with this value, as
-well. The metaid of the SBase is also updated and given a unique value. Finally, it recursively calls Algorithm~\ref{expandDimension} to expand the next dimension. Once all dimensions have been expanded, this algorithm evaluates the indices. It considers each attribute being indexed in turn. For each index dimension in reverse order, it updates the id being referenced by that attribute. Finally, it adds the final flattened object to the document. Once Algorithm~\ref{expandDimension} completes, the original object is removed from the document. Finally, once all arrayed objects are flattened, Algorithm~\ref{flattenArrays} evaluates all selectors and replaces them with the corresponding flattened ids.
+well. The metaid of the SBase is also updated and given a unique value. Finally, it recursively calls Algorithm~\ref{expandDimension} to expand the next dimension. Once all dimensions have been expanded, this algorithm evaluates the indices. It considers each attribute being indexed in turn. For each index dimension in reverse order, it updates the id being referenced by that attribute. After expanding the indices, it adds the final flattened object to the document. Finally, once all arrayed objects are flattened, Algorithm~\ref{flattenArrays} evaluates all selectors and replaces them with the corresponding flattened ids.
\begin{algorithm}[ht]
\label{flattenArrays}
\caption{flattenArrays(SBMLDocument document)}
-\ForEach{sBase in Model(document)}
+\ForEach{sBase in document}
{
- \If{dimensionCount(sBase)>0}
- {
- expandDimension(document, sBase, dimensionCount(sBase) - 1)\;
- remove(document, sBase)\;
- }
+ remove(document, sBase)\;
+ expandDimensions(document, sBase, dimensionCount(sBase) - 1)\;
}
Evaluate all selectors and replace with new ids\;
\end{algorithm}
\begin{algorithm}[ht]
\label{expandDimension}
- \caption{expandDimension(SBMLDocument document, SBase sBase, int currentDimension)}
+ \caption{expandDimensions(SBMLDocument document, SBase sBase, int currentDimension)}
%\ForEach{SBase sbase}
%{
\If{currentDimension $\geq 0$}
@@ -354,16 +351,16 @@
{
sBase':=clone(sBase)\;
id(sBase', id(sBase) + ``\_'' + i)\;
+ replace(sBase', dimensionId(currentDimension), i)\;
metaid(sBase', metaid(sBase) + ``\_'' + i)\;
- replace(sBase', dimensionId(currentDimension), i)\;
- expandDimension(document,sBase',currentDimension-1)\;
+ expandDimensions(document,sBase',currentDimension-1)\;
}
}
\Else
{
\ForEach{attribute with an index for sBase}
{
- \For{$i := indexCount(sBase,attribute)-1; i>=0; i--$}
+ \For{$i :=$ indexCount(sBase,attribute)$-1; i>=0; i--$}
{
attribute(sBase) := attribute(sBase) + ``\_'' + evaluate(indexMath(sBase,attribute,i))\;
}
@@ -375,7 +372,10 @@
After performing the steps of the flattening algorithm, the result should be evaluated for validity according to the normal rules of SBML Level~3 Version~1 Core and (if applicable) the rules defined by any other Level~3 packages used in the model. However, it is our belief that a valid SBML document with arrays will always flatten into an valid SBML document without arrays.
+It should be noted that the algorithm above assumes for simplicity that the new id's generated are unique. If there are id's already that end with ``\_'' and a number, this may not be the case. In that situation, the algorithm will need to add additional underscores until it finds a unique id. It should also be noted that the algorithm above is further complicated when objects with dimensions have children which can also have dimensions. In SBML Level 3 Version 1 Core, the two types of objects that need special consideration are \Event and \Reaction. For an \Event, it is necessary to expand its dimensions before expanding the dimensions of the \EventAssignment objects that are its children. For a \Reaction, it is necessary to expand its dimensions before expanding the dimensions of the \SpeciesReference objects that are its children. Furthermore, since the \SpeciesReference ids are in the global namespace, they must be given unique ids as the \Reaction dimensions are expanded.
+TODO: SpeciesReferences in the global name space really complicate flatten. Is this really necessary?
+
%\begin{figure}[thb]
% \renewcommand{\arraystretch}{0.85}
% \newcounter{rownum}
Modified: trunk/specifications/sbml-level-3/version-1/arrays/spec/examples.tex
===================================================================
--- trunk/specifications/sbml-level-3/version-1/arrays/spec/examples.tex 2014-11-24 21:40:20 UTC (rev 21755)
+++ trunk/specifications/sbml-level-3/version-1/arrays/spec/examples.tex 2014-11-25 17:24:06 UTC (rev 21756)
@@ -714,8 +714,6 @@
% </listOfRules>
% \end{example}
-<<<<<<< .mine
-=======
% Here is an example to assign a single value.
% \begin{example}
@@ -750,129 +748,129 @@
% </listOfInitialAssignments>
% \end{example}
-\subsection{Examples for array referencing}
+% \subsection{Examples for array referencing}
-Here is an example array reference using {\tt selector}.
-\begin{displaymath}
-0.1 * S[x]
-\end{displaymath}
-\begin{example}
-<math xmlns="http://www.w3.org/1998/Math/MathML">
- <apply>
- <times/>
- <apply>
- <selector/>
- <ci> S </ci>
- <ci> x </ci>
- </apply>
- <cn> 0.1 </cn>
- </apply>
-</math>
+% Here is an example array reference using {\tt selector}.
+% \begin{displaymath}
+% 0.1 * S[x]
+% \end{displaymath}
+% \begin{example}
+% <math xmlns="http://www.w3.org/1998/Math/MathML">
+% <apply>
+% <times/>
+% <apply>
+% <selector/>
+% <ci> S </ci>
+% <ci> x </ci>
+% </apply>
+% <cn> 0.1 </cn>
+% </apply>
+% </math>
-\end{example}
+% \end{example}
-Here is a more complicated example of array referencing.
-\begin{displaymath}
-W[d0]= A[d0][0]V[0]+ A[d0][1]V[1]+ A[d0][2]V[2]
-\end{displaymath}
+% Here is a more complicated example of array referencing.
+% \begin{displaymath}
+% W[d0]= A[d0][0]V[0]+ A[d0][1]V[1]+ A[d0][2]V[2]
+% \end{displaymath}
-\begin{example}
+% \begin{example}
-<listOfParameters>
- <!-- Create size variable n=3 -->
- <parameter id="n" constant="true" value="3"/>
- <!-- Create 2-dimensional array A of size n by n -->
- <parameter id="A" constant="false" value="0">
- <arrays:listOfDimensions
- xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1">
- <arrays:dimension arrays:id="d0" arrays:size="n" arrays:arrayDimension="0"/>
- <arrays:dimension arrays:id="d1" arrays:size="n" arrays:arrayDimension="1"/>
- </arrays:listOfDimensions>
- </parameter>
- <!-- Create an array W of size n -->
- <parameter id="W" constant="false" value="0">
- <arrays:listOfDimensions
- xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1">
- <arrays:dimension arrays:id="d0" arrays:size="n" arrays:arrayDimension="0"/>
- </arrays:listOfDimensions>
- </parameter>
- <!-- Create an array V of size n -->
- <parameter id="V" constant="false" value="0">
- <arrays:listOfDimensions
- xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1">
- <arrays:dimension arrays:id="d0" arrays:size="n" arrays:arrayDimension="0"/>
- </arrays:listOfDimensions>
- </parameter>
-</listOfParameters>
-<listOfRules>
- <!-- W[d0] = A[d0][0]V[0] + A[d0][1]V[1] + A[d0][2]V[2] -->
- <assignmentRule metaid="rule" variable="W">
- <math xmlns="http://www.w3.org/1998/Math/MathML">
- <apply>
- <plus/>
- <apply>
- <plus/>
- <apply>
- <times/>
- <apply>
- <selector/>
- <ci> A </ci>
- <ci> d0 </ci>
- <cn type="integer"> 0 </cn>
- </apply>
- <apply>
- <selector/>
- <ci> V </ci>
- <cn type="integer"> 1 </cn>
- </apply>
- </apply>
- <apply>
- <times/>
- <apply>
- <selector/>
- <ci> A </ci>
- <ci> d0 </ci>
- <cn type="integer"> 1 </cn>
- </apply>
- <apply>
- <selector/>
- <ci> V </ci>
- <cn type="integer"> 1 </cn>
- </apply>
- </apply>
- </apply>
- <apply>
- <times/>
- <apply>
- <selector/>
- <ci> A </ci>
- <ci> d0 </ci>
- <cn type="integer"> 2 </cn>
- </apply>
- <apply>
- <selector/>
- <ci> V </ci>
- <cn type="integer"> 2 </cn>
- </apply>
- </apply>
- </apply>
- </math>
- <arrays:listOfDimensions
- xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1">
- <arrays:dimension arrays:id="d0" 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">
- <ci> d0 </ci>
- </math>
- </arrays:index>
- </arrays:listOfIndices>
- </assignmentRule>
-</listOfRules>
-\end{example}
+% <listOfParameters>
+% <!-- Create size variable n=3 -->
+% <parameter id="n" constant="true" value="3"/>
+% <!-- Create 2-dimensional array A of size n by n -->
+% <parameter id="A" constant="false" value="0">
+% <arrays:listOfDimensions
+% xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1">
+% <arrays:dimension arrays:id="d0" arrays:size="n" arrays:arrayDimension="0"/>
+% <arrays:dimension arrays:id="d1" arrays:size="n" arrays:arrayDimension="1"/>
+% </arrays:listOfDimensions>
+% </parameter>
+% <!-- Create an array W of size n -->
+% <parameter id="W" constant="false" value="0">
+% <arrays:listOfDimensions
+% xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1">
+% <arrays:dimension arrays:id="d0" arrays:size="n" arrays:arrayDimension="0"/>
+% </arrays:listOfDimensions>
+% </parameter>
+% <!-- Create an array V of size n -->
+% <parameter id="V" constant="false" value="0">
+% <arrays:listOfDimensions
+% xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1">
+% <arrays:dimension arrays:id="d0" arrays:size="n" arrays:arrayDimension="0"/>
+% </arrays:listOfDimensions>
+% </parameter>
+% </listOfParameters>
+% <listOfRules>
+% <!-- W[d0] = A[d0][0]V[0] + A[d0][1]V[1] + A[d0][2]V[2] -->
+% <assignmentRule metaid="rule" variable="W">
+% <math xmlns="http://www.w3.org/1998/Math/MathML">
+% <apply>
+% <plus/>
+% <apply>
+% <plus/>
+% <apply>
+% <times/>
+% <apply>
+% <selector/>
+% <ci> A </ci>
+% <ci> d0 </ci>
+% <cn type="integer"> 0 </cn>
+% </apply>
+% <apply>
+% <selector/>
+% <ci> V </ci>
+% <cn type="integer"> 1 </cn>
+% </apply>
+% </apply>
+% <apply>
+% <times/>
+% <apply>
+% <selector/>
+% <ci> A </ci>
+% <ci> d0 </ci>
+% <cn type="integer"> 1 </cn>
+% </apply>
+% <apply>
+% <selector/>
+% <ci> V </ci>
+% <cn type="integer"> 1 </cn>
+% </apply>
+% </apply>
+% </apply>
+% <apply>
+% <times/>
+% <apply>
+% <selector/>
+% <ci> A </ci>
+% <ci> d0 </ci>
+% <cn type="integer"> 2 </cn>
+% </apply>
+% <apply>
+% <selector/>
+% <ci> V </ci>
+% <cn type="integer"> 2 </cn>
+% </apply>
+% </apply>
+% </apply>
+% </math>
+% <arrays:listOfDimensions
+% xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1">
+% <arrays:dimension arrays:id="d0" 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">
+% <ci> d0 </ci>
+% </math>
+% </arrays:index>
+% </arrays:listOfIndices>
+% </assignmentRule>
+% </listOfRules>
+% \end{example}
% This could also be done with {\tt scalarproduct} as follows:
Modified: trunk/specifications/sbml-level-3/version-1/arrays/spec/syntax.tex
===================================================================
--- trunk/specifications/sbml-level-3/version-1/arrays/spec/syntax.tex 2014-11-24 21:40:20 UTC (rev 21755)
+++ trunk/specifications/sbml-level-3/version-1/arrays/spec/syntax.tex 2014-11-25 17:24:06 UTC (rev 21756)
@@ -287,9 +287,9 @@
%% Use condition to set range
% \item \emph{quantifier operators:} \token{forall}, \token{exists}
% \item \emph{statistics operators:} \token{mean}, \token{sdev}, \token{variance}, \token{median}, \token{mode}, \token{moment}, \token{momentabout}
-The arguments of a MathML \token{vector} must all have the same number
-of dimensions and agree on their size.
-{\color{red} (SHOULD WE ALLOW VECTOR MATH? IF NOT, THIS RULE WILL BECOME DEPRECATED.)}
+% The arguments of a MathML \token{vector} must all have the same number
+% of dimensions and agree on their size.
+% {\color{red} (SHOULD WE ALLOW VECTOR MATH? IF NOT, THIS RULE WILL BECOME DEPRECATED.)}
% For example, the following use of \token{vector} is invalid, but it would be valid if $m=2$ instead.
% \begin{example}[showstringspaces=false]
% <listOfParameters>
@@ -396,4 +396,4 @@
</initialAssignment>
</listOfInitialAssignments>
\end{example}
-Note that it is invalid for any SBase object to have a value of type \token{vector}. Every mathematical operation must result in a scalar value. Although operations on \token{vector} nodes are allowed, they are not needed since \token{vector} objects must be reduced to scalars. In fact, it is more efficient to work with operations on scalars rather than vectors. For instance, $(\{\{1,2\},\{4,5\}\}+\{\{5,6\},\{7,8\}\})[0][1]$ is equivalent to $\{\{1,2\},\{4,5\}\}[0][1] + \{\{5,6\},\{7,8\}\}[0][1]$.
+Note that it is invalid for any SBase object to have a value of type \token{vector}. Every mathematical operation must result in a scalar value. Although operations on \token{vector} nodes could be allowed, they are not needed since \token{vector} objects must be reduced to scalars. In fact, it is more efficient to work with operations on scalars rather than vectors. For instance, $(\{\{1,2\},\{4,5\}\}+\{\{5,6\},\{7,8\}\})[0][1]$ is equivalent to $\{\{1,2\},\{4,5\}\}[0][1] + \{\{5,6\},\{7,8\}\}[0][1]$, so only the later one without vector math is considered to be valid.
|