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, MultiThreadingSettings multiThreadingSettings) 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
FeatureMatrixthat provides row-wise access to the feature values of the query examplesrulesBegin – An iterator of type
Model::const_iteratorto the first rule that should be used for predictionrulesEnd – An iterator of type
Model::const_iteratorto the last rule (exclusive) that should be used for predictionmultiThreadingSettings – An object of type
MultiThreadingSettingsthat stores the settings to be used for making predictions for different query examples in parallel
-
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
FeatureMatrixthat provides row-wise access to the feature values of the query examplesrulesBegin – An iterator of type
Model::const_iteratorto the first rule that should be used for predictionrulesEnd – An iterator of type
Model::const_iteratorto 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, MultiThreadingSettings multiThreadingSettings) 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
FeatureMatrixthat provides row-wise access to the feature values of the query examplesrulesBegin – An iterator of type
Model::const_iteratorto the first rule that should be used for predictionrulesEnd – An iterator of type
Model::const_iteratorto the last rule (exclusive) that should be used for predictionmultiThreadingSettings – An object of type
MultiThreadingSettingsthat stores the settings to be used for making predictions for different query examples in parallel
- Returns:
The total number of dense predictions explicitly stored in the affected row of the prediction matrix
-
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
FeatureMatrixthat provides row-wise access to the feature values of the query examplesrulesBegin – An iterator of type
Model::const_iteratorto the first rule that should be used for predictionrulesEnd – An iterator of type
Model::const_iteratorto 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 dense elements explicitly stored in the affected row of the prediction matrix
-
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, MultiThreadingSettings multiThreadingSettings, uint32 maxRules)¶
- Parameters:
featureMatrix – A reference to an object of template type
FeatureMatrixthat provides row-wise access to the feature values of the query examplesmodel – A reference to an object of template type
Modelthat should be used for predictionmultiThreadingSettings – An object of type
MultiThreadingSettingsthat stores the settings to be used for making predictions for different query examples in parallelmaxRules – 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
PredictionMatrixthat stores the updated predictions
Protected Functions
-
virtual PredictionMatrix &applyNext(const FeatureMatrix &featureMatrix, MultiThreadingSettings multiThreadingSettings, 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
FeatureMatrixthat provides row-wise access to the feature values of the query examplesmultiThreadingSettings – An object of type
MultiThreadingSettingsthat stores the settings to be used for making predictions for different query examples in parallelrulesBegin – An iterator of type
Model::const_iteratorto the first rule that should be used for predictionrulesEnd – An iterator of type
Model::const_iteratorto the last rule (exclusive) that should be used for prediction
- Returns:
A reference to an object of template type
PredictionMatrixthat stores the predictions
Private Members
-
const FeatureMatrix &featureMatrix_¶
-
const MultiThreadingSettings multiThreadingSettings_¶