xml interface for I/O of ADMB types
To create an xml interface for ADMB that permits storing all data, model structure, control flags, estimation phases, and parameter bounds in a single file. The intent is for the xml tree to contain complete documentation for every parameter estimation run using an ADMB application.
Advantages of using xml:
-
Order of named variable nodes in file is unimportant as long as the integrity of the tree structure is respected.
-
Easily viewed in browser using a xsl style sheet.
-
Speed. The xml tree is only read from the file once. Data elements can be extracted (or updated) in any order as needed without reading the file again.
-
Xml trees can be extended to accomodate whatever is needed (the 'x' in xml).
Disadvantages of using xml:
-
Xml files can be tedious to edit, but is unusual to need to edit a large object such as an array.
-
Creating an initial xml file can be problematical (but see example tpl).
This example tpl is Arni Magnusson's Pella example with the alb data. One FUNCTION has been added to write data and parameters into an xml tree.
FUNCTION saveXMLFile
ADMB_XMLDoc xml;
int ret = 0;
if (fabs(neglogL) <= 0.0)
xml.allocate("FIT","pella-xml","Starting Values", "pella-xml.x00");
else
{
xml.allocate("FIT","pella-xml","Final Estimates", "pella-xml.x01");
ret = xml.createXMLcomment("fit statistics");
ret = xml.createXMLelement(neglogL);
}
ret = xml.createXMLelement(nc,"Catch Data Years");
ret = xml.createXMLelement(Cdata,"Catch Data");
ret = xml.createXMLelement(ni,"Survey Data Years");
ret = xml.createXMLelement(Idata,"Survey Data");
ret = xml.createXMLelement(logr,"log growth rate");
ret = xml.createXMLelement(logk,"log carrying capacity");
ret = xml.createXMLelement(loga,"log a");
ret = xml.createXMLelement(logp,"log p");
ret = xml.createXMLelement(logq,"log q");
ret = xml.createXMLelement(logsigma,"log sigma");
ret = xml.write();
This function is called twice: once at the end of PRELIMINARY_CALCS section to record the data and starting values of the parameters, and once in the REPORT_SECTION to record the statistics about the fit, parameter estimates and the data. The ADMB_XMLDoc::createXMLelement(...)
member function is overloaded for many of the data types generated by tpl2cpp
(there are few that I missed).
The two output files pella-xml.x00
and pella-xml.x01
can be viewed either with a text editor or with a bowser (Firefox works fine) using the supplied xml stylesheet ADMB.xsl
.
The machinery required to create ADMB objects from xml nodes needs to be written. Recent insights from Dave Fournier and Arni Magunsson offer some directions. The lex code needs to be modified and allocate(ADMB_XMLDoc& node) need to be written.