As of revision 784, literal constant substitution is implemented in the repository. This only works for literal expressions that evaluate to constants, such as "1" or "1.0" or "8675903". There is a trivial example in models/passing/ConstantSubstitution.R replicated here in its entirety:
require(OpenMx) foo <- mxAlgebra(1 + 2 + 3, 'foo') model <- mxModel('model', foo) modelOut <- mxRun(model) omxCheckEquals(6, mxEval(foo, modelOut))
The next step will be to implement free parameter and fixed parameter substitution (this week), and then I can finish with global variable substitution in algebra expressions (either this week or next week).
Awesome! To be clear, numeric constants are treated as 1x1 matrices, so that they can be used with, e.g., Kronecker product or other matrix operators? And second, can exponential or double precision format constants be used, 1.234E+56 or 1.234D+56?
Yup, numeric constants are treated as 1x1 matrices, so that they can be used with, e.g., Kronecker product or other matrix operator. Oops, you need to svn update to revision 785 to write 1.234E+56 or 1.234e+56. I'm not supporting 1.234D+56 because R doesn't recognize that expression.
Indeed awesome! Must be watching Entourage: likes E
Doesn't like D
Kronecker happy
Global variable substitution has been checked into the repository. Any global variable that evaluates to a numeric type (scalar, vector, or matrix) and whose name does not match a free parameter, fixed parameter, or named entity, can be used in an mxAlgebra statement. A simple example is the following:
nice!
modelOut= mxRun(mxModel('model', mxMatrix("Full", 2,2,values=0:3, name="A"), mxAlgebra(pi%x%A, name = 'foo') ) )
Running model
> mxEval(foo, modelOut)
[,1] [,2]
[1,] 0.000000 6.283185
[2,] 3.141593 9.424778