File predictor_common.hpp¶
-
template<typename T, typename FeatureMatrix, typename Model>
class PredictionDispatcher¶ - #include <predictor_common.hpp>
Allows to obtain predictions for multiple query examples by delegating the prediction for individual examples to another class.
- Template Parameters:
T – The type of the predictions
FeatureMatrix – The type of the feature matrix that provides row-wise access to the feature values of the query examples
Model – The type of the rule-based model that is used to obtain predictions
Public Functions
-
inline void predict(const IPredictionDelegate &delegate, const FeatureMatrix &featureMatrix, typename Model::const_iterator rulesBegin, typename Model::const_iterator rulesEnd, uint32 numThreads) const¶
Obtains predictions for multiple query examples by delegating the prediction for individual examples to a given
PredictionDelegate
.- Parameters:
delegate – A reference to an object of type
IPredictionDelegate
, the prediction for individual examples should be delegated tofeatureMatrix – A reference to an object of template type
FeatureMatrix
that provides row-wise access to the feature values of the query examplesrulesBegin – An iterator of type
Model::const_iterator
to the first rule that should be used for predictionrulesEnd – An iterator of type
Model::const_iterator
to the last rule (exclusive) that should be used for predictionnumThreads – The number of CPU threads to be used to make predictions for different query examples in parallel. Must be at least 1
-
class IPredictionDelegate¶
- #include <predictor_common.hpp>
Defines an interface for all classes, the prediction for individual examples can be delegated to by a
PredictionDispatcher
.Public Functions
-
inline virtual ~IPredictionDelegate()¶
-
virtual void predictForExample(const FeatureMatrix &featureMatrix, typename Model::const_iterator rulesBegin, typename Model::const_iterator rulesEnd, uint32 threadIndex, uint32 exampleIndex, uint32 predictionIndex) const = 0¶
Obtains predictions for a single query example.
- Parameters:
featureMatrix – A reference to an object of template type
FeatureMatrix
that provides row-wise access to the feature values of the query examplesrulesBegin – An iterator of type
Model::const_iterator
to the first rule that should be used for predictionrulesEnd – An iterator of type
Model::const_iterator
to the last rule (exclusive) that should be used for predictionthreadIndex – The index of the thread used for prediction
exampleIndex – The index of the query example to predict for
predictionIndex – The index of the row in the prediction matrix, where the predictions should be stored
-
inline virtual ~IPredictionDelegate()¶
-
template<typename FeatureMatrix, typename Model>
class BinarySparsePredictionDispatcher¶ - #include <predictor_common.hpp>
Allows to obtain sparse binary predictions for multiple query examples by delegating the prediction for individual examples to another class.
- Template Parameters:
FeatureMatrix – The type of the feature matrix that provides row-wise access to the feature values of the query examples
Model – The type of the rule-based model that is used to obtain predictions
Public Functions
-
inline uint32 predict(const IPredictionDelegate &delegate, const FeatureMatrix &featureMatrix, typename Model::const_iterator rulesBegin, typename Model::const_iterator rulesEnd, uint32 numThreads) const¶
Obtains predictions for multiple query examples by delegating the prediction for individual examples to a given
IPredictionDelegate
.- Parameters:
delegate – A reference to an object of type
IPredictionDelegate
, the prediction for individual examples should be delegated tofeatureMatrix – A reference to an object of template type
FeatureMatrix
that provides row-wise access to the feature values of the query examplesrulesBegin – An iterator of type
Model::const_iterator
to the first rule that should be used for predictionrulesEnd – An iterator of type
Model::const_iterator
to the last rule (exclusive) that should be used for predictionnumThreads – The number of CPU threads to be used to make predictions for different query examples in parallel. Must be at least 1
- Returns:
The total number of non-zero predictions
-
class IPredictionDelegate¶
- #include <predictor_common.hpp>
Defines an interface for all classes, the prediction for individual examples can be delegated to by a
BinarySparsePredictionDispatcher
.Public Functions
-
inline virtual ~IPredictionDelegate()¶
-
virtual uint32 predictForExample(const FeatureMatrix &featureMatrix, typename Model::const_iterator rulesBegin, typename Model::const_iterator rulesEnd, uint32 threadIndex, uint32 exampleIndex, uint32 predictionIndex) const = 0¶
Obtains predictions for a single query example.
- Parameters:
featureMatrix – A reference to an object of template type
FeatureMatrix
that provides row-wise access to the feature values of the query examplesrulesBegin – An iterator of type
Model::const_iterator
to the first rule that should be used for predictionrulesEnd – An iterator of type
Model::const_iterator
to the last rule (exclusive) that should be used for predictionthreadIndex – The index of the thread used for prediction
exampleIndex – The index of the query example to predict for
predictionIndex – The index of the row in the prediction matrix, where the predictions should be stored
- Returns:
The number of non-zero predictions
-
inline virtual ~IPredictionDelegate()¶
-
template<typename FeatureMatrix, typename Model, typename PredictionMatrix>
class AbstractIncrementalPredictor : public IIncrementalPredictor<PredictionMatrix>¶ - #include <predictor_common.hpp>
An abstract base class for all implementations of the class
IIncrementalPredictor
.- Template Parameters:
FeatureMatrix – The type of the feature matrix that provides row-wise access to the feature values of the query examples
Model – The type of the rule-based model that is used to obtain predictions
PredictionMatrix – The type of the matrix that is used to store the predictions
Public Functions
-
inline AbstractIncrementalPredictor(const FeatureMatrix &featureMatrix, const Model &model, uint32 numThreads, uint32 maxRules)¶
- Parameters:
featureMatrix – A reference to an object of template type
FeatureMatrix
that provides row-wise access to the feature values of the query examplesmodel – A reference to an object of template type
Model
that should be used for predictionnumThreads – The number of CPU threads to be used to make predictions for different query examples in parallel. Must be at least 1
maxRules – The maximum number of rules to be used for prediction. Must be at least 1 or 0, if the number of rules should not be restricted
-
inline virtual ~AbstractIncrementalPredictor() override¶
-
inline virtual uint32 getNumNext() const final override¶
Returns the number of remaining ensemble members that have not been used yet.
- Returns:
The number of remaining ensemble members
-
inline virtual PredictionMatrix &applyNext(uint32 stepSize) final override¶
Updates the current predictions by considering several of the remaining ensemble members. If not enough ensemble members are remaining, only the available ones will be used for updating the current predictions.
- Parameters:
stepSize – The number of additional ensemble members to be considered for prediction
- Returns:
A reference to an object of template type
PredictionMatrix
that stores the updated predictions
Protected Functions
-
virtual PredictionMatrix &applyNext(const FeatureMatrix &featureMatrix, uint32 numThreads, typename Model::const_iterator rulesBegin, typename Model::const_iterator rulesEnd) = 0¶
Must be implemented by subclasses in order to obtain predictions.
- Parameters:
featureMatrix – A reference to an object of template type
FeatureMatrix
that provides row-wise access to the feature values of the query examplesnumThreads – The number of CPU threads to be used to make predictions for different query examples in parallel. Must be at least 1
rulesBegin – An iterator of type
Model::const_iterator
to the first rule that should be used for predictionrulesEnd – An iterator of type
Model::const_iterator
to the last rule (exclusive) that should be used for prediction
- Returns:
A reference to an object of template type
PredictionMatrix
that stores the predictions