16 #include <unordered_map>
41 std::weak_ptr< DMatrix >
ref;
56 std::unordered_map<DMatrix *, PredictionCacheEntry> container_;
57 void ClearExpiredEntries();
117 virtual void Configure(
const std::vector<std::pair<std::string, std::string>>&);
127 const gbm::GBTreeModel& model)
const;
140 const gbm::GBTreeModel& model, uint32_t tree_begin,
141 uint32_t tree_end = 0)
const = 0;
156 virtual bool InplacePredict(std::shared_ptr<DMatrix> p_fmat,
const gbm::GBTreeModel& model,
158 uint32_t tree_begin = 0, uint32_t tree_end = 0)
const = 0;
172 std::vector<bst_float>* out_preds,
173 const gbm::GBTreeModel& model,
174 unsigned tree_end = 0)
const = 0;
187 const gbm::GBTreeModel& model,
188 unsigned tree_end = 0)
const = 0;
207 const gbm::GBTreeModel &model,
unsigned tree_end = 0,
208 std::vector<bst_float>
const *tree_weights =
nullptr,
209 bool approximate =
false,
int condition = 0,
210 unsigned condition_feature = 0)
const = 0;
214 const gbm::GBTreeModel &model,
unsigned tree_end = 0,
215 std::vector<bst_float>
const *tree_weights =
nullptr,
216 bool approximate =
false)
const = 0;
232 :
public dmlc::FunctionRegEntryBase<
233 PredictorReg, std::function<Predictor*(GenericParameter const*)>> {};
235 #define XGBOOST_REGISTER_PREDICTOR(UniqueId, Name) \
236 static DMLC_ATTRIBUTE_UNUSED ::xgboost::PredictorReg& \
237 __make_##PredictorReg##_##UniqueId##__ = \
238 ::dmlc::Registry<::xgboost::PredictorReg>::Get()->__REGISTER__(Name)
defines configuration macros of xgboost.
Internal data structured used by XGBoost during training.
Definition: data.h:490
Definition: predictor.h:55
PredictionContainer()=default
PredictionCacheEntry & Entry(DMatrix *m)
PredictionCacheEntry & Cache(std::shared_ptr< DMatrix > m, int32_t device)
decltype(container_) const & Container()
Performs prediction on individual training instances or batches of instances for GBTree....
Definition: predictor.h:103
virtual void PredictInteractionContributions(DMatrix *dmat, HostDeviceVector< bst_float > *out_contribs, const gbm::GBTreeModel &model, unsigned tree_end=0, std::vector< bst_float > const *tree_weights=nullptr, bool approximate=false) const =0
static Predictor * Create(std::string const &name, GenericParameter const *generic_param)
Creates a new Predictor*.
void InitOutPredictions(const MetaInfo &info, HostDeviceVector< bst_float > *out_predt, const gbm::GBTreeModel &model) const
Initialize output prediction.
virtual void PredictContribution(DMatrix *dmat, HostDeviceVector< bst_float > *out_contribs, const gbm::GBTreeModel &model, unsigned tree_end=0, std::vector< bst_float > const *tree_weights=nullptr, bool approximate=false, int condition=0, unsigned condition_feature=0) const =0
feature contributions to individual predictions; the output will be a vector of length (nfeats + 1) *...
virtual void Configure(const std::vector< std::pair< std::string, std::string >> &)
Configure and register input matrices in prediction cache.
Predictor(Context const *ctx)
Definition: predictor.h:108
virtual void PredictLeaf(DMatrix *dmat, HostDeviceVector< bst_float > *out_preds, const gbm::GBTreeModel &model, unsigned tree_end=0) const =0
predict the leaf index of each tree, the output will be nsample * ntree vector this is only valid in ...
Context const * ctx_
Definition: predictor.h:105
virtual void PredictInstance(const SparsePage::Inst &inst, std::vector< bst_float > *out_preds, const gbm::GBTreeModel &model, unsigned tree_end=0) const =0
online prediction function, predict score for one instance at a time NOTE: use the batch prediction i...
virtual ~Predictor()=default
virtual bool InplacePredict(std::shared_ptr< DMatrix > p_fmat, const gbm::GBTreeModel &model, float missing, PredictionCacheEntry *out_preds, uint32_t tree_begin=0, uint32_t tree_end=0) const =0
Inplace prediction.
virtual void PredictBatch(DMatrix *dmat, PredictionCacheEntry *out_preds, const gbm::GBTreeModel &model, uint32_t tree_begin, uint32_t tree_end=0) const =0
Generate batch predictions for a given feature matrix. May use cached predictions if available instea...
span class implementation, based on ISO++20 span<T>. The interface should be the same.
Definition: span.h:423
The input data structure of xgboost.
A device-and-host vector abstraction layer.
namespace of xgboost
Definition: base.h:110
Definition: generic_parameters.h:15
Contains pointer to input matrix and associated cached predictions.
Definition: predictor.h:35
uint32_t version
Definition: predictor.h:39
HostDeviceVector< bst_float > predictions
Definition: predictor.h:37
void Update(uint32_t v)
Definition: predictor.h:48
std::weak_ptr< DMatrix > ref
Definition: predictor.h:41
PredictionCacheEntry()=default
Registry entry for predictor.
Definition: predictor.h:233