File predictor_binary_common.hpp

namespace boosting
template<typename FeatureMatrix, typename Model>
class BinaryPredictor : public IBinaryPredictor
#include <predictor_binary_common.hpp>

An implementation of the type IBinaryPredictor that allows to predict binary labels for given query examples by summing up the scores that are predicted by individual rules in a rule-based model and transforming the aggregated scores into binary predictions in {0, 1} according to an IBinaryTransformation.

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 BinaryPredictor(const FeatureMatrix &featureMatrix, const Model &model, uint32 numLabels, uint32 numThreads, std::unique_ptr<IBinaryTransformation> binaryTransformationPtr)
Parameters:
  • featureMatrix – A reference to an object of template type FeatureMatrix that provides row-wise access to the feature values of the query examples

  • model – A reference to an object of template type Model that should be used to obtain predictions

  • numLabels – The number of labels to predict for

  • numThreads – The number of CPU threads to be used to make predictions for different query examples in parallel. Must be at least 1

  • binaryTransformationPtr – An unique pointer to an object of type IBinaryTransformation that should be used to transform aggregated scores into binary predictions or a null pointer, if all labels should be predicted as irrelevant

inline std::unique_ptr<DensePredictionMatrix<uint8>> predict(uint32 maxRules) const override

See also

IPredictor::predict

inline bool canPredictIncrementally() const override

See also

IPredictor::canPredictIncrementally

inline std::unique_ptr<IIncrementalPredictor<DensePredictionMatrix<uint8>>> createIncrementalPredictor(uint32 maxRules) const override

See also

IPredictor::createIncrementalPredictor

Private Members

const FeatureMatrix &featureMatrix_
const Model &model_
const uint32 numLabels_
const uint32 numThreads_
const std::shared_ptr<IBinaryTransformation> binaryTransformationPtr_
class IncrementalPredictor : public AbstractIncrementalPredictor<FeatureMatrix, Model, DensePredictionMatrix<uint8>>

Public Functions

inline IncrementalPredictor(const BinaryPredictor &predictor, uint32 maxRules, std::shared_ptr<IBinaryTransformation> binaryTransformationPtr)

Protected Functions

inline DensePredictionMatrix<uint8> &applyNext(const FeatureMatrix &featureMatrix, uint32 numThreads, typename Model::const_iterator rulesBegin, typename Model::const_iterator rulesEnd) override

Private Members

const std::shared_ptr<IBinaryTransformation> binaryTransformationPtr_
DensePredictionMatrix<float64> realMatrix_
DensePredictionMatrix<uint8> predictionMatrix_
class IncrementalPredictionDelegate : public PredictionDispatcher::IPredictionDelegate

Public Functions

inline IncrementalPredictionDelegate(CContiguousView<float64> &realMatrix, CContiguousView<uint8> &predictionMatrix, const IBinaryTransformation &binaryTransformation)
inline void predictForExample(const FeatureMatrix &featureMatrix, typename Model::const_iterator rulesBegin, typename Model::const_iterator rulesEnd, uint32 threadIndex, uint32 exampleIndex, uint32 predictionIndex) const override

Private Members

CContiguousView<float64> &realMatrix_
CContiguousView<uint8> &predictionMatrix_
const IBinaryTransformation &binaryTransformation_
class PredictionDelegate : public PredictionDispatcher::IPredictionDelegate

Public Functions

inline PredictionDelegate(CContiguousView<float64> &realMatrix, CContiguousView<uint8> &predictionMatrix, const IBinaryTransformation &binaryTransformation)
inline void predictForExample(const FeatureMatrix &featureMatrix, typename Model::const_iterator rulesBegin, typename Model::const_iterator rulesEnd, uint32 threadIndex, uint32 exampleIndex, uint32 predictionIndex) const override

Private Members

CContiguousView<float64> &realMatrix_
CContiguousView<uint8> &predictionMatrix_
const IBinaryTransformation &binaryTransformation_
template<typename FeatureMatrix, typename Model>
class SparseBinaryPredictor : public ISparseBinaryPredictor
#include <predictor_binary_common.hpp>

An implementation of the type ISparseBinaryPredictor that allows to predict sparse binary labels for given query examples by summing up the scores that are predicted by individual rules in a rule-based model and transforming the aggregated scores into binary predictions in {0, 1} according to an IBinaryTransformation.

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 SparseBinaryPredictor(const FeatureMatrix &featureMatrix, const Model &model, uint32 numLabels, uint32 numThreads, std::unique_ptr<IBinaryTransformation> binaryTransformationPtr)
Parameters:
  • featureMatrix – A reference to an object of template type FeatureMatrix that provides row-wise access to the feature values of the query examples

  • model – A reference to an object of template type Model that should be used to obtain predictions

  • numLabels – The number of labels to predict for

  • numThreads – The number of CPU threads to be used to make predictions for different query examples in parallel. Must be at least 1

  • binaryTransformationPtr – An unique pointer to an object of type IBinaryTransformation that should be used to transform real-valued predictions into binary predictions or a null pointer, if no such object is available

inline std::unique_ptr<BinarySparsePredictionMatrix> predict(uint32 maxRules) const override

See also

IPredictor::predict

inline bool canPredictIncrementally() const override

See also

IPredictor::canPredictIncrementally

inline std::unique_ptr<IIncrementalPredictor<BinarySparsePredictionMatrix>> createIncrementalPredictor(uint32 maxRules) const override

See also

IPredictor::createIncrementalPredictor

Private Members

const FeatureMatrix &featureMatrix_
const Model &model_
const uint32 numLabels_
const uint32 numThreads_
const std::shared_ptr<IBinaryTransformation> binaryTransformationPtr_
class IncrementalPredictor : public AbstractIncrementalPredictor<FeatureMatrix, Model, BinarySparsePredictionMatrix>

Public Functions

inline IncrementalPredictor(const SparseBinaryPredictor &predictor, uint32 maxRules, std::shared_ptr<IBinaryTransformation> binaryTransformationPtr)

Protected Functions

inline BinarySparsePredictionMatrix &applyNext(const FeatureMatrix &featureMatrix, uint32 numThreads, typename Model::const_iterator rulesBegin, typename Model::const_iterator rulesEnd) override

Private Members

const std::shared_ptr<IBinaryTransformation> binaryTransformationPtr_
DensePredictionMatrix<float64> realMatrix_
BinaryLilMatrix predictionMatrix_
std::unique_ptr<BinarySparsePredictionMatrix> predictionMatrixPtr_
class IncrementalPredictionDelegate : public BinarySparsePredictionDispatcher::IPredictionDelegate

Public Functions

inline IncrementalPredictionDelegate(CContiguousView<float64> &realMatrix, BinaryLilMatrix &predictionMatrix, const IBinaryTransformation &binaryTransformation)
inline uint32 predictForExample(const FeatureMatrix &featureMatrix, typename Model::const_iterator rulesBegin, typename Model::const_iterator rulesEnd, uint32 threadIndex, uint32 exampleIndex, uint32 predictionIndex) const override

Private Members

CContiguousView<float64> &realMatrix_
BinaryLilMatrix &predictionMatrix_
const IBinaryTransformation &binaryTransformation_
class PredictionDelegate : public BinarySparsePredictionDispatcher::IPredictionDelegate

Public Functions

inline PredictionDelegate(CContiguousView<float64> &realMatrix, BinaryLilMatrix &predictionMatrix, const IBinaryTransformation &binaryTransformation)
inline uint32 predictForExample(const FeatureMatrix &featureMatrix, typename Model::const_iterator rulesBegin, typename Model::const_iterator rulesEnd, uint32 threadIndex, uint32 exampleIndex, uint32 predictionIndex) const override

Private Members

CContiguousView<float64> &realMatrix_
BinaryLilMatrix &predictionMatrix_
const IBinaryTransformation &binaryTransformation_