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.

Community
  • 1
  • 1
JeromeLaurent
  • 327
  • 3
  • 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? – user1808924 May 27 '15 at 09:34
  • 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. – JeromeLaurent May 27 '15 at 09:51
  • 1
    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. – user1808924 May 27 '15 at 10:32
  • 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. – user1808924 May 27 '15 at 10:36
  • 1
    Thank you for these tips. Havinge never used Java before, I guess I'm going to try to translate the trees in C++. – JeromeLaurent May 27 '15 at 10:43
  • 1
    Did you find a way to do it in C++? Please add an answer if possible, I'm looking for the same. – AbdealiLoKo Nov 18 '16 at 04:19
  • 2
    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 ? – JeromeLaurent Nov 21 '16 at 14:55
  • @JeromeLaurent how did you do this? You read in the file with all the trees and generated one for each in cpp? – Carlos Apr 01 '18 at 20:49
  • @Carlos Yes, I'll try to post an answer if I can find my file. – JeromeLaurent Apr 03 '18 at 12:22
  • @JeromeLaurent did you just read the xml and generate a cpp file with a load of if-else? – Carlos Apr 03 '18 at 14:58

0 Answers0