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 * ThreadPoolHandle
 opaque handle types
 

Public Member Functions

 Predictor (int num_worker_thread=-1)
 
void Load (const char *libpath)
 load the prediction function from dynamic shared library. More...
 
void Free ()
 unload the prediction function
 
size_t PredictBatch (const DMatrix *dmat, int verbose, bool pred_margin, PredictorOutputHandle out_result) const
 Make predictions on a batch of data rows (synchronously). This function internally divides the workload among all worker threads. More...
 
size_t QueryResultSize (const DMatrix *dmat) 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 DMatrix *dmat, 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 QueryNumClass () const
 Get the number of classes in the loaded model The number is 1 for most tasks; it is greater than 1 for multiclass classification. More...
 
size_t QueryNumFeature () const
 Get the width (number of features) of each instance used to train the loaded model. More...
 
std::string QueryPredTransform () const
 Get name of post prediction transformation used to train the loaded model. More...
 
float QuerySigmoidAlpha () const
 Get alpha value in sigmoid transformation used to train the loaded model. More...
 
float QueryRatioC () const
 Get c value in exponential standard ratio used to train the loaded model. More...
 
float QueryGlobalBias () const
 Get global bias which adjusting predicted margin scores. More...
 
TypeInfo QueryThresholdType () const
 Get the type of the split thresholds. More...
 
TypeInfo QueryLeafOutputType () const
 Get the type of the leaf outputs. More...
 
PredictorOutputHandle CreateOutputVector (const DMatrix *dmat) const
 Create an output vector suitable to hold prediction result for a given data matrix. More...
 
void DeleteOutputVector (PredictorOutputHandle output_vector) const
 Free an output vector from memory. More...
 

Detailed Description

predictor class: wrapper for optimized prediction code

Definition at line 128 of file predictor.h.

Member Function Documentation

◆ CreateOutputVector()

PredictorOutputHandle CreateOutputVector ( const DMatrix dmat) const

Create an output vector suitable to hold prediction result for a given data matrix.

Parameters
dmata data matrix
Returns
Opaque handle to the allocated output vector

Definition at line 470 of file predictor.cc.

◆ DeleteOutputVector()

void DeleteOutputVector ( PredictorOutputHandle  output_vector) const

Free an output vector from memory.

Parameters
output_vectorOpaque handle to the output vector

Definition at line 476 of file predictor.cc.

◆ Load()

void Load ( const char *  libpath)

load the prediction function from dynamic shared library.

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

Definition at line 304 of file predictor.cc.

◆ PredictBatch()

size_t PredictBatch ( const DMatrix dmat,
int  verbose,
bool  pred_margin,
PredictorOutputHandle  out_result 
) const

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

Parameters
dmata batch of rows
verbosewhether to produce extra messages
pred_marginwhether to produce raw margin scores instead of transformed probabilities
out_resultResulting output vector. This pointer must point to an array of length QueryResultSize() and of type QueryLeafOutputType().
Returns
length of the output vector, which is guaranteed to be less than or equal to QueryResultSize()

Definition at line 422 of file predictor.cc.

◆ QueryGlobalBias()

float QueryGlobalBias ( ) const
inline

Get global bias which adjusting predicted margin scores.

Returns
global bias

Definition at line 223 of file predictor.h.

◆ QueryLeafOutputType()

TypeInfo QueryLeafOutputType ( ) const
inline

Get the type of the leaf outputs.

Returns
type of the leaf outputs

Definition at line 237 of file predictor.h.

◆ QueryNumClass()

size_t QueryNumClass ( ) const
inline

Get the number of classes in the loaded model The number is 1 for most tasks; it is greater than 1 for multiclass classification.

Returns
length of prediction array

Definition at line 187 of file predictor.h.

◆ QueryNumFeature()

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 195 of file predictor.h.

◆ QueryPredTransform()

std::string QueryPredTransform ( ) const
inline

Get name of post prediction transformation used to train the loaded model.

Returns
name of prediction transformation

Definition at line 202 of file predictor.h.

◆ QueryRatioC()

float QueryRatioC ( ) const
inline

Get c value in exponential standard ratio used to train the loaded model.

Returns
c value in exponential standard ratio transformation

Definition at line 216 of file predictor.h.

◆ QueryResultSize() [1/2]

size_t QueryResultSize ( const DMatrix dmat) const
inline

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

Parameters
dmata batch of rows
Returns
length of prediction array

Definition at line 164 of file predictor.h.

◆ QueryResultSize() [2/2]

size_t QueryResultSize ( const DMatrix dmat,
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
dmata batch of rows
rbeginbeginning of range of rows
rendend of range of rows
Returns
length of prediction array

Definition at line 176 of file predictor.h.

◆ QuerySigmoidAlpha()

float QuerySigmoidAlpha ( ) const
inline

Get alpha value in sigmoid transformation used to train the loaded model.

Returns
alpha value in sigmoid transformation

Definition at line 209 of file predictor.h.

◆ QueryThresholdType()

TypeInfo QueryThresholdType ( ) const
inline

Get the type of the split thresholds.

Returns
type of the split thresholds

Definition at line 230 of file predictor.h.


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