How to use a PMML model in C++?
Asked Answered
R

0

8

I have converted a R model into PMML, using r2pmml.

I am now supposed to use this model in the C++ calculation module of machine but I'm a bit lost (I have never used C++ before). I can't use Java PMML evaluation engines (as proposed in this answer) so I guess I have to find a "C++ based PMML evaluation engine".

PMMLlib seems to be used to create PMML files from C++, not to read them. I have found numerous XML parsers (pugixml, tinyxml2, XmlLite) for C++ but I don't know if any of these can be used to read PMML.

And if they can and I understood correctly the way the work, they will create a Document Object Model which will contain my model and I will be able to use this object with XPath ?
Otherwise, I would like to know how to parse a PMML file in C++ and how to use the resulting object.

Recluse answered 27/5, 2015 at 8:30 Comment(10)
What type of R model is that? Can't you simply access that R library from within your C++ application, completely avoiding the PMML step?Sanfordsanfourd
It is a random forest model built with caret. And I'd rather want to avoid recreating the model in C++. But I guess "application" was the wrong word to use. The model is supposed to be used in the calculation module of a machine working with C++ code. So I can't install external stuff like Java or R.Recluse
You should be able to parse PMML with any XML library - there is nothing specific about PMML as an XML dialect. R's randomForest algorithm generates rather simple trees. I would attempt to translate them to C++ source code, compile and run them natively. I think it will be difficult to achieve decent performance with XPath.Sanfordsanfourd
If you're comfortable with Java, then I would recommend to do PMML to C++ source code translation using JPMML libraries. It's much-much more convenient than working with low-level DOM APIs. Ideally, you could extend the r2pmml package with your own Java classes that implement a function r2cpp or something like it.Sanfordsanfourd
Thank you for these tips. Havinge never used Java before, I guess I'm going to try to translate the trees in C++.Recluse
Did you find a way to do it in C++? Please add an answer if possible, I'm looking for the same.Candleberry
I didn't find a way to use PMML in C++ ; I directly translated the RF in C++. Is it what you're interested in ?Recluse
@Recluse how did you do this? You read in the file with all the trees and generated one for each in cpp?Bovill
@Bovill Yes, I'll try to post an answer if I can find my file.Recluse
@Recluse did you just read the xml and generate a cpp file with a load of if-else?Bovill

© 2022 - 2024 — McMap. All rights reserved.