Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ordinale Conditions separat speichern #768

Merged
merged 22 commits into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4338515
Rename arguments, class members, etc. that refer to conditions.
michael-rapp Aug 8, 2023
0aded8c
Rename values of the enum Comparator.
michael-rapp Aug 8, 2023
0bbfd67
Merge branch 'development' into store-ordinal-conditions-separately
michael-rapp Aug 8, 2023
ebc6256
Merge branch 'development' into store-ordinal-conditions-separately
michael-rapp Aug 13, 2023
a069b91
The class CompleteHead now uses a DenseVector.
michael-rapp Aug 13, 2023
e4b9b22
Export class SparseArrayVector.
michael-rapp Aug 13, 2023
0d89a5e
Do not export class SparseArrayVector.
michael-rapp Aug 13, 2023
8015c7e
The class PartialHead now uses DenseVectors.
michael-rapp Aug 13, 2023
989b4de
Add class SparseArraysVector.
michael-rapp Aug 13, 2023
01aac76
The class PartialHead now uses a SparseArraysVector.
michael-rapp Aug 13, 2023
31a21e9
Rename class member.
michael-rapp Aug 13, 2023
4ecabc4
Export class SparseArraysVector.
michael-rapp Aug 13, 2023
9d72ab3
Edit comment.
michael-rapp Aug 13, 2023
7eb66d6
The class SparseArraysVector is not final anymore.
michael-rapp Aug 13, 2023
c9f171b
Add class IConditional.
michael-rapp Aug 13, 2023
42d0e94
The class ConjunctiveBody now uses SparseArraysVectors.
michael-rapp Aug 13, 2023
0e10c4d
The class ConjunctiveBody now stores ordinal conditions separately.
michael-rapp Aug 13, 2023
7ae02fa
Consider ordinal conditions for the output of models or model charact…
michael-rapp Aug 13, 2023
c7f6e12
Add function "isOrdinal" to class IFeatureType.
michael-rapp Aug 13, 2023
2e0b505
Format code.
michael-rapp Aug 13, 2023
daa6752
Format code.
michael-rapp Aug 13, 2023
5429468
Use appropriate conditions if a feature is nominal.
michael-rapp Aug 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

/**
* An one-dimensional sparse vector that stores a fixed number of elements, consisting of an index and a value, in a
* C-contiguous array.
* C-contiguous array. Such a vector is similar to a `SparseArraysVector`, but uses a single array for storing the
* indices and values.
*
* @tparam T The type of the data that is stored in the vector
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* @author Michael Rapp ([email protected])
*/
#pragma once

#include "mlrl/common/data/vector_dense.hpp"

/**
* An one-dimensional sparse vector that stores a fixed number of elements, consisting of an index and a value, in
* C-contiguous arrays. Such a vector is similar to a `SparseArrayVector`, but uses separate arrays for storing the
* indices and values.
*
* @tparam T The type of the data that is stored in the vector
*/
template<typename T>
class MLRLCOMMON_API SparseArraysVector : public IOneDimensionalView {
private:

DenseVector<uint32> indices_;

DenseVector<T> values_;

public:

/**
* @param numElements The number of elements in the vector
*/
SparseArraysVector(uint32 numElements);

virtual ~SparseArraysVector() override {};

/**
* An iterator that provides access to the indices in the vector and allows to modify them.
*/
typedef DenseVector<uint32>::iterator index_iterator;

/**
* An iterator that provides read-only access to the indices in the vector.
*/
typedef DenseVector<uint32>::const_iterator index_const_iterator;

/**
* An iterator that provides access to the values in the vector and allows to modify them.
*/
typedef typename DenseVector<T>::iterator value_iterator;

/**
* An iterator that provides read-only access to the values in the vector.
*/
typedef typename DenseVector<T>::const_iterator value_const_iterator;

/**
* Returns an `index_iterator` to the beginning of the indices in the vector.
*
* @return An `index_iterator` to the beginning
*/
index_iterator indices_begin();

/**
* Returns an `index_iterator` to the end of the indices in the vector.
*
* @return An `index_iterator` to the end
*/
index_iterator indices_end();

/**
* Returns an `index_const_iterator` to the beginning of the indices in the vector.
*
* @return An `index_const_iterator` to the beginning
*/
index_const_iterator indices_cbegin() const;

/**
* Returns an `index_const_iterator` to the end of the indices in the vector.
*
* @return An `index_const_iterator` to the end
*/
index_const_iterator indices_cend() const;

/**
* Returns a `value_iterator` to the beginning of the values in the vector.
*
* @return A `value_iterator` to the beginning
*/
value_iterator values_begin();

/**
* Returns a `value_iterator` to the end of the values in the vector.
*
* @return A `value_iterator` to the end
*/
value_iterator values_end();

/**
* Returns a `value_const_iterator` to the beginning of the values in the vector.
*
* @return A `value_const_iterator` to the beginning
*/
value_const_iterator values_cbegin() const;

/**
* Returns a `value_const_iterator` to the end of the values in the vector.
*
* @return A `value_const_iterator` to the end
*/
value_const_iterator values_cend() const;

uint32 getNumElements() const override;
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ class IFeatureType {

virtual ~IFeatureType() {};

/**
* Returns whether the feature is ordinal or not.
*
* @return True, if the feature is ordinal, false otherwise
*/
virtual bool isOrdinal() const = 0;

/**
* Returns whether the feature is nominal or not.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
class NominalFeatureType final : public IFeatureType {
public:

bool isOrdinal() const override;

bool isNominal() const override;
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
class NumericalFeatureType final : public IFeatureType {
public:

bool isOrdinal() const override;

bool isNominal() const override;
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
class OrdinalFeatureType final : public IFeatureType {
public:

bool isOrdinal() const override;

bool isNominal() const override;
};
40 changes: 24 additions & 16 deletions cpp/subprojects/common/include/mlrl/common/model/body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,15 @@ class EmptyBody;
class ConjunctiveBody;

/**
* Defines an interface for all classes that represent the body of a rule.
* Defines an interface for all classes that allow to check whether an example is covered or not.
*/
class MLRLCOMMON_API IBody {
class MLRLCOMMON_API IConditional {
public:

virtual ~IBody() {};

/**
* A visitor function for handling objects of the type `EmptyBody`.
*/
typedef std::function<void(const EmptyBody&)> EmptyBodyVisitor;

/**
* A visitor function for handling objects of the type `ConjunctiveBody`.
*/
typedef std::function<void(const ConjunctiveBody&)> ConjunctiveBodyVisitor;
virtual ~IConditional() {};

/**
* Returns whether an individual example, which is stored in a C-contiguous matrix, is covered by the body or
* not.
* Returns whether an individual example, which is stored in a C-contiguous matrix, is covered or not.
*
* @param begin A `VectorConstView::const_iterator` to the beginning of the example's feature values
* @param end A `VectorConstView::const_iterator` to the end of the example's feature values
Expand All @@ -43,7 +32,7 @@ class MLRLCOMMON_API IBody {
VectorConstView<const float32>::const_iterator end) const = 0;

/**
* Returns whether an individual example, which is stored in a CSR sparse matrix, is covered by the body or not.
* Returns whether an individual example, which is stored in a CSR sparse matrix, is covered or not.
*
* @param indicesBegin An iterator to the beginning of the example's feature values
* @param indicesEnd An iterator to the end of the example's feature values
Expand All @@ -64,6 +53,25 @@ class MLRLCOMMON_API IBody {
CsrConstView<const float32>::value_const_iterator valuesBegin,
CsrConstView<const float32>::value_const_iterator valuesEnd, float32* tmpArray1,
uint32* tmpArray2, uint32 n) const = 0;
};

/**
* Defines an interface for all classes that represent the body of a rule.
*/
class MLRLCOMMON_API IBody : public IConditional {
public:

virtual ~IBody() override {};

/**
* A visitor function for handling objects of the type `EmptyBody`.
*/
typedef std::function<void(const EmptyBody&)> EmptyBodyVisitor;

/**
* A visitor function for handling objects of the type `ConjunctiveBody`.
*/
typedef std::function<void(const ConjunctiveBody&)> ConjunctiveBodyVisitor;

/**
* Invokes one of the given visitor functions, depending on which one is able to handle this particular type of
Expand Down
Loading