|
CMP++: Uncertainty Quantification & Bayesian Calibration
|
K-Fold cross-validation partition generator. More...
#include <statistics.h>
Classes | |
| class | KFoldIterator |
| Iterator class to traverse folds for K-Fold cross-validation. More... | |
Public Member Functions | |
| KFold (Eigen::Index n_splits, Eigen::Index n_obs, bool shuffle=false, unsigned int random_state=42) | |
| Constructor for the KFold partitioner. | |
| KFoldIterator | begin () const |
| Gets the iterator pointing to the first fold. | |
| KFoldIterator | end () const |
| Gets the iterator pointing to the end of the folds. | |
| std::pair< Eigen::VectorXs, Eigen::VectorXs > | operator() (Eigen::Index split) const |
| Directly accesses the train/test indices for a specific split without iterating. | |
| size_t | nFolds () const |
| Gets the total number of splits/folds \( K \). | |
Private Attributes | |
| Eigen::Index | nSplits_ |
| Number of folds/splits \( K \). | |
| Eigen::Index | nObs_ |
| Total number of observations \( N \) in the dataset. | |
| bool | shuffle_ |
| Flag indicating if the dataset indices should be shuffled before splitting. | |
| unsigned int | rngState_ |
| Seed for the random number generator. | |
| std::default_random_engine | rng_ |
| Random number engine used for shuffling. | |
| Eigen::VectorXs | indices_ |
| Internal array storing the (potentially shuffled) sequence of indices. | |
K-Fold cross-validation partition generator.
Partitions a dataset \(\mathcal{D}\) of size \(N\) into \(K\) mutually exclusive, approximately equal-sized subsets \(\{F_1, \dots, F_K\}\) such that:
\[ \bigcup_{k=1}^K F_k = \mathcal{D}, \quad F_i \cap F_j = \emptyset \quad \forall i \neq j \]
During the \(k\)-th fold iteration, the model is trained on \(\mathcal{D} \setminus F_k\) and validated on \(F_k\).
|
inline |
Constructor for the KFold partitioner.
| n_splits | Number of folds \( K \). Must be at least 2 and at most n_obs. |
| n_obs | Total number of observations \( N \) in the dataset. Must be at least 2. |
| shuffle | Whether to shuffle the data before splitting into folds. |
| random_state | Seed for the random number generator (used if shuffle is true). |
| std::invalid_argument | if the input parameters violate minimum constraints. |
|
inline |
Gets the iterator pointing to the first fold.
|
inline |
Gets the iterator pointing to the end of the folds.
|
inline |
Gets the total number of splits/folds \( K \).
|
inline |
Directly accesses the train/test indices for a specific split without iterating.
| split | The specific split index \( k \) to extract. |
| std::out_of_range | if the requested split is invalid. |
|
private |
Internal array storing the (potentially shuffled) sequence of indices.
|
private |
Total number of observations \( N \) in the dataset.
|
private |
Number of folds/splits \( K \).
|
private |
Random number engine used for shuffling.
|
private |
Seed for the random number generator.
|
private |
Flag indicating if the dataset indices should be shuffled before splitting.