0

I have 50 (large) decision trees that are currently serialized (in pre-order) as individual, long strings. All of the strings are directly stored in a .cpp declaration file in order to avoid having to read them from a file at run-time. So, at run-time, a function is called that deserializes each string and constructs its corresponding decision tree using a standard recursive process. Subsequently, a set of features (vector of doubles) is dropped down each decision tree and a class prediction is output. A la Random Forest, a majority vote is taken and final class is taken.

I've tried optimizing the code and have discovered that the re-construction of these large trees takes up the majority (~98%) of my run-time. Thus, I wanted to ask if there were some way to hardcode the entire tree object into the .cpp declaration file. So, instead of having to re-construct the trees at run-time, the tree objects are already available to be traversed at run-time.

slaw
  • 6,591
  • 16
  • 56
  • 109
  • I would be happy to edit my post and provide more code upon request but the code itself has become rather complex and may be beyond the scope of my question. – slaw Jan 19 '14 at 17:36
  • Have you considered Cap'n proto - http://kentonv.github.io/capnproto/ – tumdum Jan 19 '14 at 17:49
  • @TomaszKłak: Unfortunately, my boss wants a solution that is completely standalone. Thanks for the suggestion. I'll keep it in mind for other projects! – slaw Jan 19 '14 at 17:53

1 Answers1

0

I you have access to C++11, I think constexpr functions are your solution.

You could write functions to generate the data of the trees at compile-time, storing that data in arrays at compile time.

See this thread for a working usage example.

Community
  • 1
  • 1
Manu343726
  • 13,969
  • 4
  • 40
  • 75