TobyPDE / libforest

C++ Random Forest Library
7 stars 4 forks source link

Template RandomForest Classifier #14

Closed TobyPDE closed 9 years ago

TobyPDE commented 9 years ago

Learning random forests should be done independent of the tree type (normal, kernel, dag, etc.).


TobyPDE commented 9 years ago

I am addressing this issue right now and I think I found a good solution using the CRTP pattern. Not only can we reduce virtually all code redundancy and unify Random Forests/AdaBoost and all the other stuff. But we also get rid of multiple inheritance.


Original comment by: Tobias Pohlen

TobyPDE commented 9 years ago

This is the new preliminary API:

#!c++
RandomForestLearner<DecisionTree, DecisionTreeLearner> learner;
auto forest = learner.learn(storage);

Obviously, the first template parameter is redundant. If you use DecisionTreeLearner, then it's clear that it outputs a DecisionTree. I will fix this tomorrow using decltype. The final API will be:

#!c++
RandomForestLearner<DecisionTreeLearner> learner;
auto forest = learner.learn(storage);

I only did it for the offline learning algorithms. I don't want to mess with your code too much right now as you need it for your project.


Original comment by: Tobias Pohlen

TobyPDE commented 9 years ago

Online random forests are now also template based. The API is very simple and works as follows:

#!c++

OnlineRandomForestLearner<OnlineDecisionTreeLearner> onlineForestLearner;
auto onlineForest = onlineForestLearner.learn(storage);

Original comment by: Tobias Pohlen