Mx parser for multiple groups

neale's picture
Category:feature request

The Mx script attached works ok. The parser generates a lot of errors. It is possible that my installation of the parser is the problem, as it has never yet worked for me.

Michael-Neales-Macbook-Pro-2% ~/mx/openmx/OpenMx/trunk/inst/tools/ < ~/mx/openmxscripts/testalgebraparser.txt > ~/mx/openmxscripts/testalgebraparser.out
Traceback (most recent call last):
File "/Users/neale/mx/openmx/OpenMx/trunk/inst/tools/", line 149, in
File "build/bdist.macosx-10.3-i386/egg/ply/", line 265, in parse
File "build/bdist.macosx-10.3-i386/egg/ply/", line 921, in parseopt_notrack
File "build/bdist.macosx-10.3-i386/egg/ply/", line 384, in token
File "/Users/neale/mx/openmx/OpenMx/trunk/inst/tools/", line 42, in t_error
raise Exception("Illegal character " + str(t.value[0]))
Exception: Illegal character #
Michael-Neales-Macbook-Pro-2% cat ~/mx/openmxscripts/testalgebraparser.out

testalgebraparser.txt156 bytes


mspiegel's picture


So ./ is the tool you want to use to parse entire Mx scripts. I ran it on your input and it works. ./ only works on the right-hand side of a algebra expression (and no semicolon). The algebra parser will freak out if you give it a whole model. So you can feed ./ the following input:

A+C+E       |       A+C _
                        A+C             |       A+C+E 

neale's picture


Doh! Well it had to be something simple... and omfg it actually works! Kinda sorta.

makeLabels <- function(x) { sapply(x, function(y) { paste('var', y, sep = '') })}
matrixA <- mxMatrix(type = "full", nrow = 1, ncol = 1, free = FALSE, byrow = TRUE, name = "A")
matrixC <- mxMatrix(type = "full", nrow = 1, ncol = 1, free = FALSE, byrow = TRUE, name = "C")
matrixE <- mxMatrix(type = "full", nrow = 1, ncol = 1, free = FALSE, byrow = TRUE, name = "E")
algebraB <- mxAlgebra(cbind(rbind(cbind(A + C + E, A) + C, A) + C, A) + C + E, name = "B")

model <- mxModel(name = "")
model <- mxModel(model, matrixA, matrixC, matrixE)
model <- mxModel(model, algebraB)

Two issues remain:

1. I encounter errors running mxRun(model) in OpenMx
2. The Algebra is not correct, apologies to Muhammad ibn Mūsā al-Khwārizmī, as I suspect that the operators | and _ have not been given sufficiently low priority (they come below + and - in precedence).

neale's picture


Oh and another thing, the attached script generates errors thusly:

Michael-Neales-Macbook-Pro-2% ~/mx/openmx/OpenMx/trunk/inst/tools/ < ~/mx/openmx/Mx\ 1.0\ Scripts/ > ~/mx/openmx/Mx\ 1.0\ Scriptsutneloc.o
Traceback (most recent call last):
File "/Users/neale/mx/openmx/OpenMx/trunk/inst/tools/", line 254, in
File "/Users/neale/mx/openmx/OpenMx/trunk/inst/tools/", line 235, in parseModel
mxInput = tryDirectives(mxInput)
File "/Users/neale/mx/openmx/OpenMx/trunk/inst/tools/", line 220, in tryDirectives
subtract = mxDirectives[directive](mxInput)
File "/Users/neale/mx/openmx/OpenMx/trunk/inst/tools/", line 63, in parseMatrices
declareLines ='\n')
AttributeError: 'NoneType' object has no attribute 'group'

AttachmentSize 721 bytes
mspiegel's picture


OK I got this script to work. It turns out that "_" has the lowest precedence, and then "|" has a higher precedence, and then followed by "+" and "-" and the rest of the operators. Also the Mx 1.0 parser is case insensitive and will recognize the matrix type "full". But it doesn't convert the label to "Full" and so R currently throws an error. This is an error in the parser, I'll get around to fixing it. But for now just label the matrices "Full" and it will work.

mspiegel's picture


Yeah sorry I can't parse more than one group at present.

mspiegel's picture


Title:Mx parser Python thingie doesn't work» Mx parser for multiple groups
Status:active» postponed

The Mx parser supports only one group at the present time.

AdminNeale's picture


Version:Unknown» <none>
Category:bug report» feature request
Status:postponed» closed

I don't think we will be pursuing this potentially nice addition. One group at a time if you have to...