This commit is contained in:
tqchen 2014-03-03 22:20:45 -08:00 committed by tqchen
parent 9da9861377
commit cba130c40c
2 changed files with 17 additions and 17 deletions

View File

@ -6,6 +6,12 @@
* \author Tianqi Chen: tianqi.tchen@gmail.com * \author Tianqi Chen: tianqi.tchen@gmail.com
*/ */
// implementation of boosters go to here // implementation of boosters go to here
// A good design should have minimum functions defined interface, user should only operate on interface
// I break it a bit, by using template and let user 'see' the implementation
// The user should pretend that they only can use the interface, and we are all cool
// I find this is the only way so far I can think of to make boosters invariant of data structure,
// while keep everything fast
#include "xgboost.h" #include "xgboost.h"
#include "../utils/xgboost_utils.h" #include "../utils/xgboost_utils.h"
#include "tree/xgboost_tree.hpp" #include "tree/xgboost_tree.hpp"
@ -13,21 +19,21 @@
namespace xgboost{ namespace xgboost{
namespace booster{ namespace booster{
/*! /*!
* \brief create a gradient booster, given type of booster * \brief create a gradient booster, given type of booster
* \param booster_type type of gradient booster, can be used to specify implements * \param booster_type type of gradient booster, can be used to specify implements
* \tparam FMatrix input data type for booster * \tparam FMatrix input data type for booster
* \return the pointer to the gradient booster created * \return the pointer to the gradient booster created
*/ */
template<typename FMatrix> template<typename FMatrix>
inline InterfaceBooster<FMatrix> *CreateBooster( int booster_type ){ inline InterfaceBooster<FMatrix> *CreateBooster( int booster_type ){
switch( booster_type ){ switch( booster_type ){
case 0: return new RegTreeTrainer<FMatrix>(); case 0: return new RegTreeTrainer<FMatrix>();
case 1: return new LinearBooster<FMatrix>(); case 1: return new LinearBooster<FMatrix>();
default: utils::Error("unknown booster_type"); return NULL; default: utils::Error("unknown booster_type"); return NULL;
} }
} }
}; }; // namespace booster
}; }; // namespace xgboost
#endif // XGBOOST_INL_HPP #endif // XGBOOST_INL_HPP

View File

@ -150,12 +150,6 @@ namespace xgboost{
}; };
}; };
// A good design should have minimum functions defined interface, user should only operate on interface
// I break it a bit, by using template and let user 'see' the implementation
// The user should pretend that they only can use the interface, and we are all cool
// I find this is the only way so far I can think of to make boosters invariant of data structure,
// while keep everything fast
// this file includes the template implementations of all boosters // this file includes the template implementations of all boosters
// the cost of using template is that the user can 'see' all the implementations, which is OK // the cost of using template is that the user can 'see' all the implementations, which is OK
// ignore implementations and focus on the interface:) // ignore implementations and focus on the interface:)