-
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.
- Loading branch information
1 parent
5578af0
commit 9450cad
Showing
3 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
cpp/subprojects/common/include/mlrl/common/input/feature_vector_numerical.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,86 @@ | ||
/* | ||
* @author Michael Rapp ([email protected]) | ||
*/ | ||
#pragma once | ||
|
||
#include "mlrl/common/data/vector_sparse_array.hpp" | ||
#include "mlrl/common/input/feature_vector_common.hpp" | ||
|
||
/** | ||
* A feature vector that stores the values of training examples for a certain numerical feature. | ||
*/ | ||
class NumericalFeatureVector final : public AbstractFeatureVector { | ||
private: | ||
|
||
SparseArrayVector<float32> vector_; | ||
|
||
const float32 sparseValue_; | ||
|
||
public: | ||
|
||
/** | ||
* @param numElements The number of elements in the vector | ||
* @param sparseValue The value of sparse elements not explicitly stored in the vector | ||
*/ | ||
NumericalFeatureVector(uint32 numElements, float32 sparseValue); | ||
|
||
/** | ||
* An iterator that provides access to the feature values in the vector and allows to modify them. | ||
*/ | ||
typedef SparseArrayVector<float32>::iterator iterator; | ||
|
||
/** | ||
* An iterator that provides read-only access to the feature values in the vector. | ||
*/ | ||
typedef SparseArrayVector<float32>::const_iterator const_iterator; | ||
|
||
/** | ||
* Returns an `iterator` to the beginning of the vector. | ||
* | ||
* @return An `iterator` to the beginning | ||
*/ | ||
iterator begin(); | ||
|
||
/** | ||
* Returns an `iterator` to the end of the vector. | ||
* | ||
* @return An `iterator` to the end | ||
*/ | ||
iterator end(); | ||
|
||
/** | ||
* Returns a `const_iterator` to the beginning of the vector. | ||
* | ||
* @return A `const_iterator` to the beginning | ||
*/ | ||
const_iterator cbegin() const; | ||
|
||
/** | ||
* Returns a `const_iterator` to the end of the vector. | ||
* | ||
* @return A `const_iterator` to the end | ||
*/ | ||
const_iterator cend() const; | ||
|
||
/** | ||
* Returns the value of sparse elements not explicitly stored in the vector. | ||
* | ||
* @return The value of sparse elements | ||
*/ | ||
float32 getSparseValue() const; | ||
|
||
/** | ||
* Sorts the elements in the vector in ascending order based on their values. | ||
*/ | ||
void sortByValues(); | ||
|
||
/** | ||
* Sets the number of elements in the vector. | ||
* | ||
* @param numElements The number of elements to be set | ||
* @param freeMemory True, if unused memory should be freed, if possible, false otherwise | ||
*/ | ||
void setNumElements(uint32 numElements, bool freeMemory); | ||
|
||
uint32 getNumElements() const override; | ||
}; |
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
28 changes: 28 additions & 0 deletions
28
cpp/subprojects/common/src/mlrl/common/input/feature_vector_numerical.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,28 @@ | ||
#include "mlrl/common/input/feature_vector_numerical.hpp" | ||
|
||
NumericalFeatureVector::NumericalFeatureVector(uint32 numElements, float32 sparseValue) | ||
: vector_(SparseArrayVector<float32>(numElements)), sparseValue_(sparseValue) {} | ||
|
||
NumericalFeatureVector::iterator NumericalFeatureVector::begin() { | ||
return vector_.begin(); | ||
} | ||
|
||
NumericalFeatureVector::iterator NumericalFeatureVector::end() { | ||
return vector_.end(); | ||
} | ||
|
||
NumericalFeatureVector::const_iterator NumericalFeatureVector::cbegin() const { | ||
return vector_.cbegin(); | ||
} | ||
|
||
NumericalFeatureVector::const_iterator NumericalFeatureVector::cend() const { | ||
return vector_.cend(); | ||
} | ||
|
||
void NumericalFeatureVector::setNumElements(uint32 numElements, bool freeMemory) { | ||
return vector_.setNumElements(numElements, freeMemory); | ||
} | ||
|
||
uint32 NumericalFeatureVector::getNumElements() const { | ||
return vector_.getNumElements(); | ||
} |