-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #779 from mrapp-ke/ordinal-feature-vector
Neue Klasse OrdinalFeatureVector
- Loading branch information
Showing
5 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
cpp/subprojects/common/include/mlrl/common/input/feature_vector_ordinal.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* @author Michael Rapp ([email protected]) | ||
*/ | ||
#pragma once | ||
|
||
#include "mlrl/common/input/feature_vector_nominal.hpp" | ||
|
||
/** | ||
* A feature vector that stores the indices of the examples that are associated with each value, except for the majority | ||
* value, i.e., the most frequent value, of an ordinal feature. | ||
*/ | ||
class OrdinalFeatureVector : public NominalFeatureVector { | ||
private: | ||
|
||
uint32* order_; | ||
|
||
public: | ||
|
||
/** | ||
* @param numValues The number of distinct values of the ordinal feature, excluding the majority value | ||
* @param numElements The number of elements in the vector, i.e., the number of examples not associated with | ||
* the majority value | ||
* @param majorityValue The majority value, i.e., the most frequent value, of the ordinal feature | ||
*/ | ||
OrdinalFeatureVector(uint32 numValues, uint32 numElements, int32 majorityValue); | ||
|
||
~OrdinalFeatureVector() override; | ||
|
||
/** | ||
* Returns an `index_iterator` to the beginning of the ordered indices of the values of the ordinal feature. | ||
* | ||
* @param index The index of the value | ||
* @return An `index_iterator` to the beginning | ||
*/ | ||
index_iterator order_begin(uint32 index); | ||
|
||
/** | ||
* Returns an `index_iterator` to the end of the ordered indices of the values of the ordinal feature. | ||
* | ||
* @param index The index of the value | ||
* @return An `index_iterator` to the end | ||
*/ | ||
index_iterator order_end(uint32 index); | ||
|
||
/** | ||
* Returns an `index_const_iterator` to the beginning of the ordered indices of the values of the ordinal | ||
* feature. | ||
* | ||
* @param index The index of the value | ||
* @return An `index_const_iterator` to the beginning | ||
*/ | ||
index_const_iterator order_cbegin(uint32 index) const; | ||
|
||
/** | ||
* Returns an `index_const_iterator` to the end of the ordered indices of the values of the ordinal feature. | ||
* | ||
* @param index The index of the value | ||
* @return An `index_const_iterator` to the end | ||
*/ | ||
index_const_iterator order_cend(uint32 index) const; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
cpp/subprojects/common/src/mlrl/common/input/feature_vector_ordinal.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "mlrl/common/input/feature_vector_ordinal.hpp" | ||
|
||
OrdinalFeatureVector::OrdinalFeatureVector(uint32 numValues, uint32 numElements, int32 majorityValue) | ||
: NominalFeatureVector(numValues, numElements, majorityValue), order_(new uint32[numValues]) {} | ||
|
||
OrdinalFeatureVector::~OrdinalFeatureVector() { | ||
delete[] order_; | ||
} | ||
|
||
OrdinalFeatureVector::index_iterator OrdinalFeatureVector::order_begin(uint32 index) { | ||
return order_; | ||
} | ||
|
||
OrdinalFeatureVector::index_iterator OrdinalFeatureVector::order_end(uint32 index) { | ||
return &order_[numValues_]; | ||
} | ||
|
||
OrdinalFeatureVector::index_const_iterator OrdinalFeatureVector::order_cbegin(uint32 index) const { | ||
return order_; | ||
} | ||
|
||
OrdinalFeatureVector::index_const_iterator OrdinalFeatureVector::order_cend(uint32 index) const { | ||
return &order_[numValues_]; | ||
} |