MLpp
ml::Features Namespace Reference

Utilities and types for working with features. More...

Typedefs

typedef std::pair< Eigen::Index, double > IndexedFeatureValue
 Used to sort feature vectors.
 
template<typename T >
using VectorRange = std::pair< typename std::vector< T >::iterator, typename std::vector< T >::iterator >
 Pair of vector iterators.
 

Functions

template<typename T >
VectorRange< T > from_vector (std::vector< T > &v)
 
void set_to_nth (Eigen::Ref< const Eigen::MatrixXd > X, Eigen::Index n, VectorRange< IndexedFeatureValue > features)
 Copies the n-th coordinate to features. More...
 
void swap_columns (Eigen::Ref< Eigen::MatrixXd > X, Eigen::Index i1, Eigen::Index i2)
 Swaps two columns in feature matrix. More...
 
Eigen::Index partition (Eigen::Ref< Eigen::MatrixXd > X, Eigen::Index pivot_idx, Eigen::Index k)
 Partitions features (in columns) so that those with x[k] < pivot[k] are before the pivot, and those with x[k] > pivot[k] are after it. More...
 
Eigen::Index partition (Eigen::Ref< Eigen::MatrixXd > X, Eigen::Ref< Eigen::VectorXd > y, Eigen::Index pivot_idx, Eigen::Index k)
 Partitions features (in columns) and labels so that those with x[k] < pivot[k] are before the pivot, and those with x[k] > pivot[k] are after it. More...
 

Detailed Description

Utilities and types for working with features.

Function Documentation

◆ from_vector()

template<typename T >
VectorRange<T> ml::Features::from_vector ( std::vector< T > &  v)

Creates an iterator pair containing begin() and end().

◆ set_to_nth()

void ml::Features::set_to_nth ( Eigen::Ref< const Eigen::MatrixXd >  X,
Eigen::Index  n,
VectorRange< IndexedFeatureValue features 
)

Copies the n-th coordinate to features.

Parameters
[in]XFeatures matrix, with data points in columns.
[in]nCoordinate index.
[out]featuresIterator range for indexed feature values.
Exceptions
std::invalid_argumentIf size of the iterator range is different from the number of data points, or n is too large.

◆ swap_columns()

void ml::Features::swap_columns ( Eigen::Ref< Eigen::MatrixXd >  X,
Eigen::Index  i1,
Eigen::Index  i2 
)

Swaps two columns in feature matrix.

Parameters
XFeature matrix.
i1Index of the 1st column.
i2Index of the 2nd column.
Exceptions
std::out_of_rangeIf i1 >= X.cols() or i2 >= X.cols().

◆ partition() [1/2]

Eigen::Index ml::Features::partition ( Eigen::Ref< Eigen::MatrixXd >  X,
Eigen::Index  pivot_idx,
Eigen::Index  k 
)

Partitions features (in columns) so that those with x[k] < pivot[k] are before the pivot, and those with x[k] > pivot[k] are after it.

pivot = X.col(pivot_idx).

Parameters
XFeatures with data points in columns.
pivot_idxPivot index.
kDimension used for comparison.
Returns
Position of the pivot feature after partitioning.
Exceptions
std::out_of_rangeIf pivot_idx >= X.cols() or k >= X.rows().

◆ partition() [2/2]

Eigen::Index ml::Features::partition ( Eigen::Ref< Eigen::MatrixXd >  X,
Eigen::Ref< Eigen::VectorXd >  y,
Eigen::Index  pivot_idx,
Eigen::Index  k 
)

Partitions features (in columns) and labels so that those with x[k] < pivot[k] are before the pivot, and those with x[k] > pivot[k] are after it.

pivot = X.col(pivot_idx).

Parameters
XFeatures with data points in columns.
yVector of labels.
pivot_idxPivot index.
kDimension used for comparison.
Returns
Position of the pivot feature after partitioning.
Exceptions
std::out_of_rangeIf pivot_idx >= X.cols() or k >= X.rows().
std::invalid_argumentIf X.cols() != y.size().