Mx parser for multiple groups

neale's picture
Project:OpenMx
Component:Code
Category:bug report
Priority:normal
Assigned:mspiegel
Status:postponed
Description

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/mxAlgebraParser.py < ~/mx/openmxscripts/testalgebraparser.txt > ~/mx/openmxscripts/testalgebraparser.out
Traceback (most recent call last):
File "/Users/neale/mx/openmx/OpenMx/trunk/inst/tools/mxAlgebraParser.py", line 149, in
print(parser.parse(input))
File "build/bdist.macosx-10.3-i386/egg/ply/yacc.py", line 265, in parse
File "build/bdist.macosx-10.3-i386/egg/ply/yacc.py", line 921, in parseopt_notrack
File "build/bdist.macosx-10.3-i386/egg/ply/lex.py", line 384, in token
File "/Users/neale/mx/openmx/OpenMx/trunk/inst/tools/mxAlgebraParser.py", 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

AttachmentSize
testalgebraparser.txt156 bytes

Comments

mspiegel's picture

#1

So ./mxParser.py is the tool you want to use to parse entire Mx scripts. I ran it on your input and it works. ./mxAlgebraParser.py 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 ./mxAlgebraParser.py the following input:

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

neale's picture

#2

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

#3

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

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

AttachmentSize
oneloc.mx 721 bytes
mspiegel's picture

#4

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

#5

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

mspiegel's picture

#6

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.