treelite
Public Types | Public Member Functions | List of all members
Predictor Class Reference

predictor class: wrapper for optimized prediction code More...

#include <predictor.h>

Public Types

typedef void * QueryFuncHandle
 opaque handle types
 
typedef void * PredFuncHandle
 
typedef void * LibraryHandle
 
typedef void * ThreadPoolHandle
 

Public Member Functions

 Predictor (int num_worker_thread=-1, bool include_master_thread=false)
 
void Load (const char *name)
 load the prediction function from dynamic shared library. More...
 
void Free ()
 unload the prediction function
 
size_t PredictBatch (const CSRBatch *batch, int verbose, bool pred_margin, float *out_result)
 Make predictions on a batch of data rows (synchronously). This function internally divides the workload among all worker threads. More...
 
size_t PredictBatch (const DenseBatch *batch, int verbose, bool pred_margin, float *out_result)
 
size_t PredictInst (TreelitePredictorEntry *inst, bool pred_margin, float *out_result)
 Make predictions on a single data row (synchronously). The work will be scheduled to the calling thread. More...
 
size_t QueryResultSize (const CSRBatch *batch) const
 Given a batch of data rows, query the necessary size of array to hold predictions for all data points. More...
 
size_t QueryResultSize (const DenseBatch *batch) const
 Given a batch of data rows, query the necessary size of array to hold predictions for all data points. More...
 
size_t QueryResultSize (const CSRBatch *batch, size_t rbegin, size_t rend) const
 Given a batch of data rows, query the necessary size of array to hold predictions for all data points. More...
 
size_t QueryResultSize (const DenseBatch *batch, size_t rbegin, size_t rend) const
 Given a batch of data rows, query the necessary size of array to hold predictions for all data points. More...
 
size_t QueryResultSizeSingleInst () const
 Query the necessary size of array to hold the prediction for a single data row. More...
 
size_t QueryNumOutputGroup () const
 Get the number of output groups in the loaded model The number is 1 for most tasks; it is greater than 1 for multiclass classifcation. More...
 
size_t QueryNumFeature () const
 Get the width (number of features) of each instance used to train the loaded model. More...
 

Detailed Description

predictor class: wrapper for optimized prediction code

Definition at line 49 of file predictor.h.

Member Function Documentation

void Load ( const char *  name)

load the prediction function from dynamic shared library.

Parameters
namename of dynamic shared library (.so/.dll/.dylib).

Definition at line 237 of file predictor.cc.

size_t PredictBatch ( const CSRBatch batch,
int  verbose,
bool  pred_margin,
float *  out_result 
)

Make predictions on a batch of data rows (synchronously). This function internally divides the workload among all worker threads.

Parameters
batcha batch of rows
verbosewhether to produce extra messages
pred_marginwhether to produce raw margin scores instead of transformed probabilities
out_resultresulting output vector; use QueryResultSize() to allocate sufficient space
Returns
length of the output vector, which is guaranteed to be less than or equal to QueryResultSize()

Definition at line 446 of file predictor.cc.

size_t PredictInst ( TreelitePredictorEntry inst,
bool  pred_margin,
float *  out_result 
)

Make predictions on a single data row (synchronously). The work will be scheduled to the calling thread.

Parameters
instsingle data row
pred_marginwhether to produce raw margin scores instead of transformed probabilities
out_resultresulting output vector; use QueryResultSizeSingleInst() to allocate sufficient space
Returns
length of the output vector, which is guaranteed to be less than or equal to QueryResultSizeSingleInst()

Definition at line 458 of file predictor.cc.

size_t QueryNumFeature ( ) const
inline

Get the width (number of features) of each instance used to train the loaded model.

Returns
number of features

Definition at line 177 of file predictor.h.

size_t QueryNumOutputGroup ( ) const
inline

Get the number of output groups in the loaded model The number is 1 for most tasks; it is greater than 1 for multiclass classifcation.

Returns
length of prediction array

Definition at line 168 of file predictor.h.

size_t QueryResultSize ( const CSRBatch batch) const
inline

Given a batch of data rows, query the necessary size of array to hold predictions for all data points.

Parameters
batcha batch of rows
Returns
length of prediction array

Definition at line 106 of file predictor.h.

size_t QueryResultSize ( const DenseBatch batch) const
inline

Given a batch of data rows, query the necessary size of array to hold predictions for all data points.

Parameters
batcha batch of rows
Returns
length of prediction array

Definition at line 117 of file predictor.h.

size_t QueryResultSize ( const CSRBatch batch,
size_t  rbegin,
size_t  rend 
) const
inline

Given a batch of data rows, query the necessary size of array to hold predictions for all data points.

Parameters
batcha batch of rows
rbeginbeginning of range of rows
rendend of range of rows
Returns
length of prediction array

Definition at line 130 of file predictor.h.

size_t QueryResultSize ( const DenseBatch batch,
size_t  rbegin,
size_t  rend 
) const
inline

Given a batch of data rows, query the necessary size of array to hold predictions for all data points.

Parameters
batcha batch of rows
rbeginbeginning of range of rows
rendend of range of rows
Returns
length of prediction array

Definition at line 145 of file predictor.h.

size_t QueryResultSizeSingleInst ( ) const
inline

Query the necessary size of array to hold the prediction for a single data row.

Returns
length of prediction array

Definition at line 157 of file predictor.h.


The documentation for this class was generated from the following files: