Skip to content

Commit

Permalink
Merge pull request #779 from mrapp-ke/ordinal-feature-vector
Browse files Browse the repository at this point in the history
Neue Klasse OrdinalFeatureVector
  • Loading branch information
michael-rapp authored Sep 25, 2023
2 parents 2ea7547 + 02f6493 commit 17c2854
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ class NominalFeatureVector : public AbstractFeatureVector {

uint32* indptr_;

const uint32 numValues_;

const int32 majorityValue_;

protected:

/**
* The number of distinct values of the nominal feature, excluding the majority value.
*/
const uint32 numValues_;

public:

/**
Expand Down
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;
};
1 change: 1 addition & 0 deletions cpp/subprojects/common/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ source_files = [
'src/mlrl/common/input/feature_vector_equal.cpp',
'src/mlrl/common/input/feature_vector_nominal.cpp',
'src/mlrl/common/input/feature_vector_numerical.cpp',
'src/mlrl/common/input/feature_vector_ordinal.cpp',
'src/mlrl/common/input/label_matrix_c_contiguous.cpp',
'src/mlrl/common/input/label_matrix_csc.cpp',
'src/mlrl/common/input/label_matrix_csr.cpp',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

NominalFeatureVector::NominalFeatureVector(uint32 numValues, uint32 numElements, int32 majorityValue)
: values_(new int32[numValues]), indices_(new uint32[numElements]), indptr_(new uint32[numValues + 1]),
numValues_(numValues), majorityValue_(majorityValue) {
majorityValue_(majorityValue), numValues_(numValues) {
indptr_[numValues] = numElements;
}

Expand Down
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_];
}

0 comments on commit 17c2854

Please sign in to comment.