File rule_list.hpp

Functions

std::unique_ptr<IRuleList> createRuleList(bool defaultRuleTakesPrecedence)

Creates and returns a new instance of the type IRuleList.

Parameters:

defaultRuleTakesPrecedence – True, if the default rule should take precedence over the remaining rules, false otherwise

Returns:

An unique pointer to an object of type IRuleList that has been created

class IRuleList : public IRuleModel
#include <rule_list.hpp>

Defines an interface for all rule-based models that store several rules in an ordered list. Optionally, the model may also contain a default rule that either takes precedence over the remaining rules or not.

Subclassed by RuleList

Public Functions

inline virtual ~IRuleList() override
virtual void addDefaultRule(std::unique_ptr<IHead> headPtr) = 0

Creates a new default rule from a given head and adds it to the model.

Parameters:

headPtr – An unique pointer to an object of type IHead that should be used as the head of the rule

virtual void addRule(std::unique_ptr<IBody> bodyPtr, std::unique_ptr<IHead> headPtr) = 0

Creates a new rule from a given body and head and adds it to the end of the model.

Parameters:
  • bodyPtr – An unique pointer to an object of type IBody that should be used as the body of the rule

  • headPtr – An unique pointer to an object of type IHead that should be used as the head of the rule

virtual bool containsDefaultRule() const = 0

Returns whether the model contains a default rule or not.

Returns:

True, if the model contains a default rule, false otherwise

virtual bool isDefaultRuleTakingPrecedence() const = 0

Returns whether the default rule takes precedence over the remaining rules or not.

Returns:

True, if the default rule takes precedence over the remaining rules, false otherwise

virtual void visit(IBody::EmptyBodyVisitor emptyBodyVisitor, IBody::ConjunctiveBodyVisitor conjunctiveBodyVisitor, IHead::CompleteHeadVisitor completeHeadVisitor, IHead::PartialHeadVisitor partialHeadVisitor) const = 0

Invokes some of the given visitor functions, depending on which ones are able to handle the bodies and heads of all rules that are contained in this model, including the default rule, if available.

Parameters:
  • emptyBodyVisitor – The visitor function for handling objects of the type EmptyBody

  • conjunctiveBodyVisitor – The visitor function for handling objects of the type ConjunctiveBody

  • completeHeadVisitor – The visitor function for handling objects of the type CompleteHead

  • partialHeadVisitor – The visitor function for handling objects of the type PartialHead

virtual void visitUsed(IBody::EmptyBodyVisitor emptyBodyVisitor, IBody::ConjunctiveBodyVisitor conjunctiveBodyVisitor, IHead::CompleteHeadVisitor completeHeadVisitor, IHead::PartialHeadVisitor partialHeadVisitor) const = 0

Invokes some of the given visitor functions, depending on which ones are able to handle the bodies and heads of all used rules that are contained in this model, including the default rule, if available.

Parameters:
  • emptyBodyVisitor – The visitor function for handling objects of the type EmptyBody

  • conjunctiveBodyVisitor – The visitor function for handling objects of the type ConjunctiveBody

  • completeHeadVisitor – The visitor function for handling objects of the type CompleteHead

  • partialHeadVisitor – The visitor function for handling objects of the type PartialHead

class RuleList : public IRuleList
#include <rule_list.hpp>

An implementation of the type IRuleList that stores several rules in the order of their induction. Optionally, the model may also contain a default rule that either takes precedence over the remaining rules or not.

Public Types

typedef ConstIterator const_iterator

An iterator that provides read-only access to rules.

Public Functions

RuleList(bool defaultRuleTakesPrecedence)
Parameters:

defaultRuleTakesPrecedence – True, if the default rule should take precedence over the remaining rules, false otherwise

const_iterator cbegin(uint32 maxRules = 0) const

Returns a const_iterator to the beginning of all rules, including the default rule, if available.

Parameters:

maxRules – The maximum number of rules to consider or 0, if all rules should be considered

Returns:

A const_iterator to the beginning

const_iterator cend(uint32 maxRules = 0) const

Returns a const_iterator to the end of all rules, including the default rule, if available.

Parameters:

maxRules – The maximum number of rules to consider or 0, if all rules should be considered

Returns:

A const_iterator to the end

const_iterator used_cbegin(uint32 maxRules = 0) const

Returns a const_iterator to the beginning of all used rules, including the default rule, if available.

Parameters:

maxRules – The maximum number of rules to consider or 0, if all rules should be considered

Returns:

A const_iterator to the beginning

const_iterator used_cend(uint32 maxRules = 0) const

Returns a const_iterator to the end of all used rules, including the default rule, if available.

Parameters:

maxRules – The maximum number of rules to consider or 0, if all used rules should be considered

Returns:

A const_iterator to the end

virtual uint32 getNumRules() const override

Returns the total number of rules in the model, including the default rule, if available.

Returns:

The number of rules

virtual uint32 getNumUsedRules() const override

Returns the number of used rules, including the default rule, if available.

Returns:

The number of used rules

virtual void setNumUsedRules(uint32 numUsedRules) override

Sets the number of used rules, including the default rule, if available.

Parameters:

numUsedRules – The number of used rules to be set or 0, if all rules should be used

virtual void addDefaultRule(std::unique_ptr<IHead> headPtr) override

Creates a new default rule from a given head and adds it to the model.

Parameters:

headPtr – An unique pointer to an object of type IHead that should be used as the head of the rule

virtual void addRule(std::unique_ptr<IBody> bodyPtr, std::unique_ptr<IHead> headPtr) override

Creates a new rule from a given body and head and adds it to the end of the model.

Parameters:
  • bodyPtr – An unique pointer to an object of type IBody that should be used as the body of the rule

  • headPtr – An unique pointer to an object of type IHead that should be used as the head of the rule

virtual bool containsDefaultRule() const override

Returns whether the model contains a default rule or not.

Returns:

True, if the model contains a default rule, false otherwise

virtual bool isDefaultRuleTakingPrecedence() const override

Returns whether the default rule takes precedence over the remaining rules or not.

Returns:

True, if the default rule takes precedence over the remaining rules, false otherwise

virtual void visit(IBody::EmptyBodyVisitor emptyBodyVisitor, IBody::ConjunctiveBodyVisitor conjunctiveBodyVisitor, IHead::CompleteHeadVisitor completeHeadVisitor, IHead::PartialHeadVisitor partialHeadVisitor) const override

Invokes some of the given visitor functions, depending on which ones are able to handle the bodies and heads of all rules that are contained in this model, including the default rule, if available.

Parameters:
  • emptyBodyVisitor – The visitor function for handling objects of the type EmptyBody

  • conjunctiveBodyVisitor – The visitor function for handling objects of the type ConjunctiveBody

  • completeHeadVisitor – The visitor function for handling objects of the type CompleteHead

  • partialHeadVisitor – The visitor function for handling objects of the type PartialHead

virtual void visitUsed(IBody::EmptyBodyVisitor emptyBodyVisitor, IBody::ConjunctiveBodyVisitor conjunctiveBodyVisitor, IHead::CompleteHeadVisitor completeHeadVisitor, IHead::PartialHeadVisitor partialHeadVisitor) const override

Invokes some of the given visitor functions, depending on which ones are able to handle the bodies and heads of all used rules that are contained in this model, including the default rule, if available.

Parameters:
  • emptyBodyVisitor – The visitor function for handling objects of the type EmptyBody

  • conjunctiveBodyVisitor – The visitor function for handling objects of the type ConjunctiveBody

  • completeHeadVisitor – The visitor function for handling objects of the type CompleteHead

  • partialHeadVisitor – The visitor function for handling objects of the type PartialHead

virtual std::unique_ptr<IBinaryPredictor> createBinaryPredictor(const IBinaryPredictorFactory &factory, const CContiguousView<const float32> &featureMatrix, const ILabelSpaceInfo &labelSpaceInfo, const IMarginalProbabilityCalibrationModel &marginalProbabilityCalibrationModel, const IJointProbabilityCalibrationModel &jointProbabilityCalibrationModel, uint32 numLabels) const override

Creates and returns a new instance of the class IBinaryPredictor, based on the type of this rule-based model.

Parameters:
  • factory – A reference to an object of type IBinaryPredictorFactory that should be used to create the instance

  • featureMatrix – A reference to an object of type CContiguousView that provides row-wise access to the features of the query examples

  • labelSpaceInfo – A reference to an object of type ILabelSpaceInfo that provides information about the label space that may be used as a basis for making predictions

  • marginalProbabilityCalibrationModel – A reference to an object of type IMarginalProbabilityCalibrationModel that may be used for the calibration of marginal probabilities

  • jointProbabilityCalibrationModel – A reference to an object of type IJointProbabilityCalibrationModel that may be used for the calibration of joint probabilities

  • numLabels – The number of labels to predict for

Returns:

An unique pointer to an object of type IBinaryPredictor that has been created

virtual std::unique_ptr<IBinaryPredictor> createBinaryPredictor(const IBinaryPredictorFactory &factory, const CsrView<const float32> &featureMatrix, const ILabelSpaceInfo &labelSpaceInfo, const IMarginalProbabilityCalibrationModel &marginalProbabilityCalibrationModel, const IJointProbabilityCalibrationModel &jointProbabilityCalibrationModel, uint32 numLabels) const override

Creates and returns a new instance of the class IBinaryPredictor, based on the type of this rule-based model.

Parameters:
  • factory – A reference to an object of type IBinaryPredictorFactory that should be used to create the instance

  • featureMatrix – A reference to an object of type CsrView that provides row-wise access to the features of the query examples

  • labelSpaceInfo – A reference to an object of type ILabelSpaceInfo that provides information about the label space that may be used as a basis for making predictions

  • marginalProbabilityCalibrationModel – A reference to an object of type IMarginalProbabilityCalibrationModel that may be used for the calibration of marginal probabilities

  • jointProbabilityCalibrationModel – A reference to an object of type IJointProbabilityCalibrationModel that may be used for the calibration of joint probabilities

  • numLabels – The number of labels to predict for

Returns:

An unique pointer to an object of type IBinaryPredictor that has been created

virtual std::unique_ptr<ISparseBinaryPredictor> createSparseBinaryPredictor(const ISparseBinaryPredictorFactory &factory, const CContiguousView<const float32> &featureMatrix, const ILabelSpaceInfo &labelSpaceInfo, const IMarginalProbabilityCalibrationModel &marginalProbabilityCalibrationModel, const IJointProbabilityCalibrationModel &jointProbabilityCalibrationModel, uint32 numLabels) const override

Creates and returns a new instance of the class ISparseBinaryPredictor, based on the type of this rule-based model.

Parameters:
  • factory – A reference to an object of type IBinaryPredictorFactory that should be used to create the instance

  • featureMatrix – A reference to an object of type CContiguousView that provides row-wise access to the features of the query examples

  • labelSpaceInfo – A reference to an object of type ILabelSpaceInfo that provides information about the label space that may be used as a basis for making predictions

  • marginalProbabilityCalibrationModel – A reference to an object of type IMarginalProbabilityCalibrationModel that may be used for the calibration of marginal probabilities

  • jointProbabilityCalibrationModel – A reference to an object of type IJointProbabilityCalibrationModel that may be used for the calibration of joint probabilities

  • numLabels – The number of labels to predict for

Returns:

An unique pointer to an object of type ISparseBinaryPredictor that has been created

virtual std::unique_ptr<ISparseBinaryPredictor> createSparseBinaryPredictor(const ISparseBinaryPredictorFactory &factory, const CsrView<const float32> &featureMatrix, const ILabelSpaceInfo &labelSpaceInfo, const IMarginalProbabilityCalibrationModel &marginalProbabilityCalibrationModel, const IJointProbabilityCalibrationModel &jointProbabilityCalibrationModel, uint32 numLabels) const override

Creates and returns a new instance of the class ISparseBinaryPredictor, based on the type of this rule-based model.

Parameters:
  • factory – A reference to an object of type IBinaryPredictorFactory that should be used to create the instance

  • featureMatrix – A reference to an object of type CsrView that provides row-wise access to the features of the query examples

  • labelSpaceInfo – A reference to an object of type ILabelSpaceInfo that provides information about the label space that may be used as a basis for making predictions

  • marginalProbabilityCalibrationModel – A reference to an object of type IMarginalProbabilityCalibrationModel that may be used for the calibration of marginal probabilities

  • jointProbabilityCalibrationModel – A reference to an object of type IJointProbabilityCalibrationModel that may be used for the calibration of joint probabilities

  • numLabels – The number of labels to predict for

Returns:

An unique pointer to an object of type ISparseBinaryPredictor that has been created

virtual std::unique_ptr<IScorePredictor> createScorePredictor(const IScorePredictorFactory &factory, const CContiguousView<const float32> &featureMatrix, const ILabelSpaceInfo &labelSpaceInfo, uint32 numLabels) const override

Creates and returns a new instance of the class IScorePredictor, based on the type of this rule-based model.

Parameters:
  • factory – A reference to an object of type IScorePredictorFactory that should be used to create the instance

  • featureMatrix – A reference to an object of type CContiguousView that provides row-wise access to the features of the query examples

  • labelSpaceInfo – A reference to an object of type ILabelSpaceInfo that provides information about the label space that may be used as a basis for making predictions

  • numLabels – The number of labels to predict for

Returns:

An unique pointer to an object of type IScorePredictor that has been created

virtual std::unique_ptr<IScorePredictor> createScorePredictor(const IScorePredictorFactory &factory, const CsrView<const float32> &featureMatrix, const ILabelSpaceInfo &labelSpaceInfo, uint32 numLabels) const override

Creates and returns a new instance of the class IScorePredictor, based on the type of this rule-based model.

Parameters:
  • factory – A reference to an object of type IScorePredictorFactory that should be used to create the instance

  • featureMatrix – A reference to an object of type CsrView that provides row-wise access to the features of the query examples

  • labelSpaceInfo – A reference to an object of type ILabelSpaceInfo that provides information about the label space that may be used as a basis for making predictions

  • numLabels – The number of labels to predict for

Returns:

An unique pointer to an object of type IScorePredictor that has been created

virtual std::unique_ptr<IProbabilityPredictor> createProbabilityPredictor(const IProbabilityPredictorFactory &factory, const CContiguousView<const float32> &featureMatrix, const ILabelSpaceInfo &labelSpaceInfo, const IMarginalProbabilityCalibrationModel &marginalProbabilityCalibrationModel, const IJointProbabilityCalibrationModel &jointProbabilityCalibrationModel, uint32 numLabels) const override

Creates and returns a new instance of the class IProbabilityPredictor, based on the type of this rule-based model.

Parameters:
  • factory – A reference to an object of type IProbabilityPredictorFactory that should be used to create the instance

  • featureMatrix – A reference to an object of type CContiguousView that provides row-wise access to the features of the query examples

  • labelSpaceInfo – A reference to an object of type ILabelSpaceInfo that provides information about the label space that may be used as a basis for making predictions

  • marginalProbabilityCalibrationModel – A reference to an object of type IMarginalProbabilityCalibrationModel that may be used for the calibration of marginal probabilities

  • jointProbabilityCalibrationModel – A reference to an object of type IJointProbabilityCalibrationModel that may be used for the calibration of joint probabilities

  • numLabels – The number of labels to predict for

Returns:

An unique pointer to an object of type IProbabilityPredictor that has been created

virtual std::unique_ptr<IProbabilityPredictor> createProbabilityPredictor(const IProbabilityPredictorFactory &factory, const CsrView<const float32> &featureMatrix, const ILabelSpaceInfo &labelSpaceInfo, const IMarginalProbabilityCalibrationModel &marginalProbabilityCalibrationModel, const IJointProbabilityCalibrationModel &jointProbabilityCalibrationModel, uint32 numLabels) const override

Creates and returns a new instance of the class IProbabilityPredictor, based on the type of this rule-based model.

Parameters:
  • factory – A reference to an object of type IProbabilityPredictorFactory that should be used to create the instance

  • featureMatrix – A reference to an object of type CsrView that provides row-wise access to the features of the query examples

  • labelSpaceInfo – A reference to an object of type ILabelSpaceInfo that provides information about the label space that may be used as a basis for making predictions

  • marginalProbabilityCalibrationModel – A reference to an object of type IMarginalProbabilityCalibrationModel that may be used for the calibration of marginal probabilities

  • jointProbabilityCalibrationModel – A reference to an object of type IJointProbabilityCalibrationModel that may be used for the calibration of joint probabilities

  • numLabels – The number of labels to predict for

Returns:

An unique pointer to an object of type IProbabilityPredictor that has been created

Private Members

std::unique_ptr<Rule> defaultRulePtr_
std::vector<Rule> ruleList_
uint32 numUsedRules_
bool defaultRuleTakesPrecedence_
class ConstIterator

A forward iterator that provides access to the rules in a model, including the default rule, if available.

Public Types

typedef int difference_type

The type that is used to represent the difference between two iterators.

typedef const Rule value_type

The type of the elements, the iterator provides access to.

typedef const Rule *pointer

The type of a pointer to an element, the iterator provides access to.

typedef const Rule &reference

The type of a reference to an element, the iterator provides access to.

typedef std::forward_iterator_tag iterator_category

The tag that specifies the capabilities of the iterator.

Public Functions

ConstIterator(bool defaultRuleTakesPrecedence, const Rule *defaultRule, const std::vector<Rule>::const_iterator iterator, uint32 start, uint32 end)
Parameters:
  • defaultRuleTakesPrecedence – True, if the default rule takes precedence over the remaining rules, false otherwise

  • defaultRule – A pointer to an object of type Rule that stores the default rule or a null pointer, if no default rule is available

  • iterator – An iterator to the beginning of the remaining rules

  • start – The index of the rule to start at

  • end – The index of the rule to end at (exclusive)

reference operator*() const

Returns the element, the iterator currently refers to.

Returns:

The element, the iterator currently refers to

ConstIterator &operator++()

Returns an iterator to the next element.

Returns:

A reference to an iterator that refers to the next element

ConstIterator &operator++(int n)

Returns an iterator to the next element.

Returns:

A reference to an iterator that refers to the next element

ConstIterator operator+(const uint32 difference) const

Returns an iterator to one of the subsequent elements.

Parameters:

difference – The number of elements to increment the iterator by

Returns:

A copy of this iterator that refers to the specified element

ConstIterator &operator+=(const uint32 difference)

Returns an iterator to one of the subsequent elements.

Parameters:

difference – The number of elements to increment the iterator by

Returns:

A reference to an iterator that refers to the specified element

bool operator!=(const ConstIterator &rhs) const

Returns whether this iterator and another one refer to the same element.

Parameters:

rhs – A reference to another iterator

Returns:

True, if the iterators do not refer to the same element, false otherwise

bool operator==(const ConstIterator &rhs) const

Returns whether this iterator and another one refer to the same element.

Parameters:

rhs – A reference to another iterator

Returns:

True, if the iterators refer to the same element, false otherwise

difference_type operator-(const ConstIterator &rhs) const

Returns the difference between this iterator and another one.

Parameters:

rhs – A reference to another iterator

Returns:

The difference between the iterators

Private Members

const Rule *defaultRule_
std::vector<Rule>::const_iterator iterator_
uint32 offset_
uint32 defaultRuleIndex_
uint32 index_
class Rule
#include <rule_list.hpp>

An implementation of the type IRule that stores unique pointers to the body and head of a rule.

Public Functions

Rule(std::unique_ptr<IBody> bodyPtr, std::unique_ptr<IHead> headPtr)
Parameters:
  • bodyPtr – An unique pointer to an object of type IBody that represents the body of the rule

  • headPtr – An unique pointer to an object of type IHead that represents the head of the rule

const IBody &getBody() const

Returns the body of the rule.

Returns:

A reference to an object of type IBody that represents the body of the rule

const IHead &getHead() const

Returns the head of the rule.

Returns:

A reference to an object of type IHead that represents the head of the rule

void visit(IBody::EmptyBodyVisitor emptyBodyVisitor, IBody::ConjunctiveBodyVisitor conjunctiveBodyVisitor, IHead::CompleteHeadVisitor completeHeadVisitor, IHead::PartialHeadVisitor partialHeadVisitor) const

Invokes some of the given visitor functions, depending on which ones are able to handle the rule’s particular type of body and head.

Parameters:
  • emptyBodyVisitor – The visitor function for handling objects of type EmptyBody

  • conjunctiveBodyVisitor – The visitor function for handling objects of type ConjunctiveBody

  • completeHeadVisitor – The visitor function for handling objects of type CompleteHead

  • partialHeadVisitor – The visitor function for handling objects of type PartialHead

Private Members

std::unique_ptr<IBody> bodyPtr_
std::unique_ptr<IHead> headPtr_