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
IRuleListthat 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
IHeadthat 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.
-
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<uint8> completeBinaryHeadVisitor, IHead::CompleteHeadVisitor<float32> complete32BitHeadVisitor, IHead::CompleteHeadVisitor<float64> complete64BitHeadVisitor, IHead::PartialHeadVisitor<uint8> partialBinaryHeadVisitor, IHead::PartialHeadVisitor<float32> partial32BitHeadVisitor, IHead::PartialHeadVisitor<float64> partial64BitHeadVisitor) 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 – A visitor function for handling objects of the type
EmptyBodyconjunctiveBodyVisitor – A visitor function for handling objects of the type
ConjunctiveBodycompleteBinaryHeadVisitor – A visitor function for handling objects of the type
CompleteHead<uint8>complete32BitHeadVisitor – A visitor function for handling objects of the type
CompleteHead<float32>complete64BitHeadVisitor – A visitor function for handling objects of the type
CompleteHead<float64>partialBinaryHeadVisitor – A visitor function for handling objects of the type
PartialHead<uint8>partial32BitHeadVisitor – A visitor function for handling objects of the type
PartialHead<float32>partial64BitHeadVisitor – A visitor function for handling objects of the type
PartialHead<float64>
-
virtual void visitUsed(IBody::EmptyBodyVisitor emptyBodyVisitor, IBody::ConjunctiveBodyVisitor conjunctiveBodyVisitor, IHead::CompleteHeadVisitor<uint8> completeBinaryHeadVisitor, IHead::CompleteHeadVisitor<float32> complete32BitHeadVisitor, IHead::CompleteHeadVisitor<float64> complete64BitHeadVisitor, IHead::PartialHeadVisitor<uint8> partialBinaryHeadVisitor, IHead::PartialHeadVisitor<float32> partial32BitHeadVisitor, IHead::PartialHeadVisitor<float64> partial64BitHeadVisitor) 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 – A visitor function for handling objects of the type
EmptyBodyconjunctiveBodyVisitor – A visitor function for handling objects of the type
ConjunctiveBodycompleteBinaryHeadVisitor – A visitor function for handling objects of the type
CompleteHead<uint8>complete32BitHeadVisitor – A visitor function for handling objects of the type
CompleteHead<float32>complete64BitHeadVisitor – A visitor function for handling objects of the type
CompleteHead<float64>partialBinaryHeadVisitor – A visitor function for handling objects of the type
PartialHead<uint8>partial32BitHeadVisitor – A visitor function for handling objects of the type
PartialHead<float32>partial64BitHeadVisitor – A visitor function for handling objects of the type
PartialHead<float64>
-
inline virtual ~IRuleList() override¶
-
class RuleList : public IRuleList¶
- #include <rule_list.hpp>
An implementation of the type
IRuleListthat 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
-
using const_iterator = ConstIterator¶
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_iteratorto 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_iteratorto the beginning
-
const_iterator cend(uint32 maxRules = 0) const¶
Returns a
const_iteratorto 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_iteratorto the end
-
const_iterator used_cbegin(uint32 maxRules = 0) const¶
Returns a
const_iteratorto 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_iteratorto the beginning
-
const_iterator used_cend(uint32 maxRules = 0) const¶
Returns a
const_iteratorto 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_iteratorto 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
IHeadthat 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.
-
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<uint8> completeBinaryHeadVisitor, IHead::CompleteHeadVisitor<float32> complete32BitHeadVisitor, IHead::CompleteHeadVisitor<float64> complete64BitHeadVisitor, IHead::PartialHeadVisitor<uint8> partialBinaryHeadVisitor, IHead::PartialHeadVisitor<float32> partial32BitHeadVisitor, IHead::PartialHeadVisitor<float64> partial64BitHeadVisitor) 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 – A visitor function for handling objects of the type
EmptyBodyconjunctiveBodyVisitor – A visitor function for handling objects of the type
ConjunctiveBodycompleteBinaryHeadVisitor – A visitor function for handling objects of the type
CompleteHead<uint8>complete32BitHeadVisitor – A visitor function for handling objects of the type
CompleteHead<float32>complete64BitHeadVisitor – A visitor function for handling objects of the type
CompleteHead<float64>partialBinaryHeadVisitor – A visitor function for handling objects of the type
PartialHead<uint8>partial32BitHeadVisitor – A visitor function for handling objects of the type
PartialHead<float32>partial64BitHeadVisitor – A visitor function for handling objects of the type
PartialHead<float64>
-
virtual void visitUsed(IBody::EmptyBodyVisitor emptyBodyVisitor, IBody::ConjunctiveBodyVisitor conjunctiveBodyVisitor, IHead::CompleteHeadVisitor<uint8> completeBinaryHeadVisitor, IHead::CompleteHeadVisitor<float32> complete32BitHeadVisitor, IHead::CompleteHeadVisitor<float64> complete64BitHeadVisitor, IHead::PartialHeadVisitor<uint8> partialBinaryHeadVisitor, IHead::PartialHeadVisitor<float32> partial32BitHeadVisitor, IHead::PartialHeadVisitor<float64> partial64BitHeadVisitor) 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 – A visitor function for handling objects of the type
EmptyBodyconjunctiveBodyVisitor – A visitor function for handling objects of the type
ConjunctiveBodycompleteBinaryHeadVisitor – A visitor function for handling objects of the type
CompleteHead<uint8>complete32BitHeadVisitor – A visitor function for handling objects of the type
CompleteHead<float32>complete64BitHeadVisitor – A visitor function for handling objects of the type
CompleteHead<float64>partialBinaryHeadVisitor – A visitor function for handling objects of the type
PartialHead<uint8>partial32BitHeadVisitor – A visitor function for handling objects of the type
PartialHead<float32>partial64BitHeadVisitor – A visitor function for handling objects of the type
PartialHead<float64>
-
virtual std::unique_ptr<IBinaryPredictor> createBinaryPredictor(const IBinaryPredictorFactory &factory, const CContiguousView<const float32> &featureMatrix, const IOutputSpaceInfo &outputSpaceInfo, 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
IBinaryPredictorFactorythat should be used to create the instancefeatureMatrix – A reference to an object of type
CContiguousViewthat provides row-wise access to the features of the query examplesoutputSpaceInfo – A reference to an object of type
IOutputSpaceInfothat provides information about the output space that may be used as a basis for making predictionsmarginalProbabilityCalibrationModel – A reference to an object of type
IMarginalProbabilityCalibrationModelthat may be used for the calibration of marginal probabilitiesjointProbabilityCalibrationModel – A reference to an object of type
IJointProbabilityCalibrationModelthat may be used for the calibration of joint probabilitiesnumLabels – The number of labels to predict for
- Returns:
An unique pointer to an object of type
IBinaryPredictorthat has been created
-
virtual std::unique_ptr<IBinaryPredictor> createBinaryPredictor(const IBinaryPredictorFactory &factory, const CsrView<const float32> &featureMatrix, const IOutputSpaceInfo &outputSpaceInfo, 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
IBinaryPredictorFactorythat should be used to create the instancefeatureMatrix – A reference to an object of type
CsrViewthat provides row-wise access to the features of the query examplesoutputSpaceInfo – A reference to an object of type
IOutputSpaceInfothat provides information about the output space that may be used as a basis for making predictionsmarginalProbabilityCalibrationModel – A reference to an object of type
IMarginalProbabilityCalibrationModelthat may be used for the calibration of marginal probabilitiesjointProbabilityCalibrationModel – A reference to an object of type
IJointProbabilityCalibrationModelthat may be used for the calibration of joint probabilitiesnumLabels – The number of labels to predict for
- Returns:
An unique pointer to an object of type
IBinaryPredictorthat has been created
-
virtual std::unique_ptr<ISparseBinaryPredictor> createSparseBinaryPredictor(const ISparseBinaryPredictorFactory &factory, const CContiguousView<const float32> &featureMatrix, const IOutputSpaceInfo &outputSpaceInfo, 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
IBinaryPredictorFactorythat should be used to create the instancefeatureMatrix – A reference to an object of type
CContiguousViewthat provides row-wise access to the features of the query examplesoutputSpaceInfo – A reference to an object of type
IOutputSpaceInfothat provides information about the output space that may be used as a basis for making predictionsmarginalProbabilityCalibrationModel – A reference to an object of type
IMarginalProbabilityCalibrationModelthat may be used for the calibration of marginal probabilitiesjointProbabilityCalibrationModel – A reference to an object of type
IJointProbabilityCalibrationModelthat may be used for the calibration of joint probabilitiesnumLabels – The number of labels to predict for
- Returns:
An unique pointer to an object of type
ISparseBinaryPredictorthat has been created
-
virtual std::unique_ptr<ISparseBinaryPredictor> createSparseBinaryPredictor(const ISparseBinaryPredictorFactory &factory, const CsrView<const float32> &featureMatrix, const IOutputSpaceInfo &outputSpaceInfo, 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
IBinaryPredictorFactorythat should be used to create the instancefeatureMatrix – A reference to an object of type
CsrViewthat provides row-wise access to the features of the query examplesoutputSpaceInfo – A reference to an object of type
IOutputSpaceInfothat provides information about the output space that may be used as a basis for making predictionsmarginalProbabilityCalibrationModel – A reference to an object of type
IMarginalProbabilityCalibrationModelthat may be used for the calibration of marginal probabilitiesjointProbabilityCalibrationModel – A reference to an object of type
IJointProbabilityCalibrationModelthat may be used for the calibration of joint probabilitiesnumLabels – The number of labels to predict for
- Returns:
An unique pointer to an object of type
ISparseBinaryPredictorthat has been created
-
virtual std::unique_ptr<IScorePredictor> createScorePredictor(const IScorePredictorFactory &factory, const CContiguousView<const float32> &featureMatrix, const IOutputSpaceInfo &outputSpaceInfo, uint32 numOutputs) 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
IScorePredictorFactorythat should be used to create the instancefeatureMatrix – A reference to an object of type
CContiguousViewthat provides row-wise access to the features of the query examplesoutputSpaceInfo – A reference to an object of type
IOutputSpaceInfothat provides information about the output space that may be used as a basis for making predictionsnumOutputs – The number of outputs to predict for
- Returns:
An unique pointer to an object of type
IScorePredictorthat has been created
-
virtual std::unique_ptr<IScorePredictor> createScorePredictor(const IScorePredictorFactory &factory, const CsrView<const float32> &featureMatrix, const IOutputSpaceInfo &outputSpaceInfo, uint32 numOutputs) 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
IScorePredictorFactorythat should be used to create the instancefeatureMatrix – A reference to an object of type
CsrViewthat provides row-wise access to the features of the query examplesoutputSpaceInfo – A reference to an object of type
IOutputSpaceInfothat provides information about the output space that may be used as a basis for making predictionsnumOutputs – The number of outputs to predict for
- Returns:
An unique pointer to an object of type
IScorePredictorthat has been created
-
virtual std::unique_ptr<IProbabilityPredictor> createProbabilityPredictor(const IProbabilityPredictorFactory &factory, const CContiguousView<const float32> &featureMatrix, const IOutputSpaceInfo &outputSpaceInfo, 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
IProbabilityPredictorFactorythat should be used to create the instancefeatureMatrix – A reference to an object of type
CContiguousViewthat provides row-wise access to the features of the query examplesoutputSpaceInfo – A reference to an object of type
IOutputSpaceInfothat provides information about the output space that may be used as a basis for making predictionsmarginalProbabilityCalibrationModel – A reference to an object of type
IMarginalProbabilityCalibrationModelthat may be used for the calibration of marginal probabilitiesjointProbabilityCalibrationModel – A reference to an object of type
IJointProbabilityCalibrationModelthat may be used for the calibration of joint probabilitiesnumLabels – The number of labels to predict for
- Returns:
An unique pointer to an object of type
IProbabilityPredictorthat has been created
-
virtual std::unique_ptr<IProbabilityPredictor> createProbabilityPredictor(const IProbabilityPredictorFactory &factory, const CsrView<const float32> &featureMatrix, const IOutputSpaceInfo &outputSpaceInfo, 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
IProbabilityPredictorFactorythat should be used to create the instancefeatureMatrix – A reference to an object of type
CsrViewthat provides row-wise access to the features of the query examplesoutputSpaceInfo – A reference to an object of type
IOutputSpaceInfothat provides information about the output space that may be used as a basis for making predictionsmarginalProbabilityCalibrationModel – A reference to an object of type
IMarginalProbabilityCalibrationModelthat may be used for the calibration of marginal probabilitiesjointProbabilityCalibrationModel – A reference to an object of type
IJointProbabilityCalibrationModelthat may be used for the calibration of joint probabilitiesnumLabels – The number of labels to predict for
- Returns:
An unique pointer to an object of type
IProbabilityPredictorthat has been created
Private Members
-
bool defaultRuleTakesPrecedence_¶
-
class Rule¶
- #include <rule_list.hpp>
An implementation of the type
IRulethat stores unique pointers to the body and head of a rule.Public Functions
-
const IBody &getBody() const¶
Returns the body of the rule.
- Returns:
A reference to an object of type
IBodythat represents the body of the rule
-
const IHead &getHead() const¶
Returns the head of the rule.
- Returns:
A reference to an object of type
IHeadthat represents the head of the rule
-
void visit(IBody::EmptyBodyVisitor emptyBodyVisitor, IBody::ConjunctiveBodyVisitor conjunctiveBodyVisitor, IHead::CompleteHeadVisitor<uint8> completeBinaryHeadVisitor, IHead::CompleteHeadVisitor<float32> complete32BitHeadVisitor, IHead::CompleteHeadVisitor<float64> complete64BitHeadVisitor, IHead::PartialHeadVisitor<uint8> partialBinaryHeadVisitor, IHead::PartialHeadVisitor<float32> partial32BitHeadVisitor, IHead::PartialHeadVisitor<float64> partial64BitHeadVisitor) 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 – A visitor function for handling objects of type
EmptyBodyconjunctiveBodyVisitor – A visitor function for handling objects of type
ConjunctiveBodycompleteBinaryHeadVisitor – A visitor function for handling objects of the type
CompleteHead<uint8>complete32BitHeadVisitor – A visitor function for handling objects of type
CompleteHead<float32>complete64BitHeadVisitor – A visitor function for handling objects of type
CompleteHead<float64>partialBinaryHeadVisitor – A visitor function for handling objects of the type
PartialHead<uint8>partial32BitHeadVisitor – A visitor function for handling objects of type
PartialHead<float32>partial64BitHeadVisitor – A visitor function for handling objects of type
PartialHead<float64>
-
const IBody &getBody() const¶
-
class ConstIterator¶
A forward iterator that provides access to the rules in a model, including the default rule, if available.
Public Types
-
using difference_type = int¶
The type that is used to represent the difference between two iterators.
-
using reference = const Rule&¶
The type of a reference to an element, the iterator provides access to.
-
using iterator_category = std::forward_iterator_tag¶
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
Rulethat stores the default rule or a null pointer, if no default rule is availableiterator – 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
-
using difference_type = int¶
-
using const_iterator = ConstIterator¶