Manages data partitioning for cross-validation.
More...
#include <folds.h>
|
| | Folds () |
| | Default constructor.
|
| |
| | Folds (int n_samples, int n_folds, int n_repeats=1, uint64_t seed=42) |
| | Constructor for generating random folds with optional repetitions.
|
| |
| | Folds (const std::vector< std::vector< int > > &user_folds) |
| | Constructor for user-provided folds.
|
| |
| | Folds (const std::vector< std::vector< std::vector< int > > > &user_folds) |
| | Constructor for user-provided repeated folds.
|
| |
| const std::vector< int > & | getTestIndices (size_t fold_idx, size_t rep_idx=0) const |
| | Get test indices for a specific fold and repetition.
|
| |
| std::vector< int > | getTrainingIndices (size_t fold_idx, size_t rep_idx=0) const |
| | Get training indices for a specific fold and repetition.
|
| |
| template<typename T > |
| auto | split (Eigen::EigenBase< T > &x, const Eigen::MatrixXd &y, size_t fold_idx, size_t rep_idx=0) const |
| | Split data into training and test sets for a specific fold and repetition.
|
| |
| size_t | numFolds () const |
| | Get the number of folds.
|
| |
| size_t | numRepetitions () const |
| | Get the number of repetitions.
|
| |
| size_t | numEvals () const |
| | Get the total number of folds (repetitions * folds)
|
| |
|
| std::vector< std::vector< std::vector< int > > > | folds |
| | Indices for each fold in each repetition.
|
| |
| std::size_t | n_folds |
| | Number of folds.
|
| |
| std::size_t | n_repeats |
| | Number of repetitions.
|
| |
Manages data partitioning for cross-validation.
This class handles the creation and access of training/test splits for k-fold cross-validation. It can generate random folds or use user-provided custom fold definitions.
Definition at line 25 of file folds.h.
◆ Folds() [1/4]
Default constructor.
Creates an empty Folds object that can be assigned to later.
Definition at line 33 of file folds.h.
◆ Folds() [2/4]
| slope::Folds::Folds |
( |
int |
n_samples, |
|
|
int |
n_folds, |
|
|
int |
n_repeats = 1, |
|
|
uint64_t |
seed = 42 |
|
) |
| |
|
inline |
Constructor for generating random folds with optional repetitions.
- Parameters
-
| n_samples | Total number of samples in the dataset |
| n_folds | Number of folds to create |
| n_repeats | Number of repetitions (default: 1) |
| seed | Random seed for reproducibility |
Creates k-fold partitions by randomly assigning samples to folds. When n_repeats > 1, multiple sets of folds are created with different random seeds.
Definition at line 51 of file folds.h.
◆ Folds() [3/4]
| slope::Folds::Folds |
( |
const std::vector< std::vector< int > > & |
user_folds | ) |
|
|
inlineexplicit |
Constructor for user-provided folds.
- Parameters
-
| user_folds | Vector of vectors containing indices for each fold |
Uses the provided fold assignments instead of creating random folds.
Definition at line 70 of file folds.h.
◆ Folds() [4/4]
| slope::Folds::Folds |
( |
const std::vector< std::vector< std::vector< int > > > & |
user_folds | ) |
|
|
inlineexplicit |
Constructor for user-provided repeated folds.
- Parameters
-
| user_folds | Vector of fold sets for multiple repetitions |
Definition at line 82 of file folds.h.
◆ getTestIndices()
| const std::vector< int > & slope::Folds::getTestIndices |
( |
size_t |
fold_idx, |
|
|
size_t |
rep_idx = 0 |
|
) |
| const |
Get test indices for a specific fold and repetition.
- Parameters
-
| fold_idx | Index of the fold to use as test set |
| rep_idx | Index of the repetition (default: 0) |
- Returns
- const std::vector<int>& Reference to the vector of test indices
◆ getTrainingIndices()
| std::vector< int > slope::Folds::getTrainingIndices |
( |
size_t |
fold_idx, |
|
|
size_t |
rep_idx = 0 |
|
) |
| const |
Get training indices for a specific fold and repetition.
- Parameters
-
| fold_idx | Index of the fold to exclude from training |
| rep_idx | Index of the repetition (default: 0) |
- Returns
- std::vector<int> Vector containing all indices except those in the specified fold
◆ numEvals()
| size_t slope::Folds::numEvals |
( |
| ) |
const |
|
inline |
Get the total number of folds (repetitions * folds)
- Returns
- size_t Number of evaluations
Definition at line 163 of file folds.h.
◆ numFolds()
| size_t slope::Folds::numFolds |
( |
| ) |
const |
|
inline |
Get the number of folds.
- Returns
- size_t Number of folds
Definition at line 149 of file folds.h.
◆ numRepetitions()
| size_t slope::Folds::numRepetitions |
( |
| ) |
const |
|
inline |
Get the number of repetitions.
- Returns
- size_t Number of repetitions
Definition at line 156 of file folds.h.
◆ split()
template<typename T >
| auto slope::Folds::split |
( |
Eigen::EigenBase< T > & |
x, |
|
|
const Eigen::MatrixXd & |
y, |
|
|
size_t |
fold_idx, |
|
|
size_t |
rep_idx = 0 |
|
) |
| const |
|
inline |
Split data into training and test sets for a specific fold and repetition.
- Template Parameters
-
| T | Type of design matrix (supports both dense and sparse matrices) |
- Parameters
-
| x | Input feature matrix |
| y | Response matrix |
| fold_idx | Index of the fold to use as test set |
| rep_idx | Index of the repetition (default: 0) |
- Returns
- std::tuple containing (x_train, y_train, x_test, y_test)
This method creates training and test datasets by subsetting the original data according to the specified fold indices. For dense matrices, it creates copies of the data. For sparse matrices, it creates efficiently constructed sparse matrix subsets.
Definition at line 127 of file folds.h.
◆ folds
| std::vector<std::vector<std::vector<int> > > slope::Folds::folds |
Indices for each fold in each repetition.
Definition at line 166 of file folds.h.
◆ n_folds
| std::size_t slope::Folds::n_folds |
Number of folds.
Definition at line 167 of file folds.h.
◆ n_repeats
| std::size_t slope::Folds::n_repeats |
Number of repetitions.
Definition at line 168 of file folds.h.
The documentation for this class was generated from the following file: