lucid  0.0.1
Lifting-based Uncertain Control Invariant Dynamics
Loading...
Searching...
No Matches
lucid::KFold Class Referencefinal

Generic K-Fold cross-validation, where the dataset is divided into k folds. More...

#include <KFold.h>

Inheritance diagram for lucid::KFold:
lucid::CrossValidator

Public Member Functions

 KFold (Dimension num_folds=5, bool shuffle=true)
 Construct a new KFold cross-validator with the specified number of folds.
 
Dimension num_folds (ConstMatrixRef training_inputs) const override
 Get the number of folds used in cross-validation.
 
Dimension num_folds () const
 Get read-only access to the num_folds of the the cross-validation.
 
bool shuffle () const
 Check whether the to be shuffled before being split into folds is data.
 
std::string to_string () const override
 Obtain the string representation of this object.
 
- Public Member Functions inherited from lucid::CrossValidator
double fit (Estimator &estimator, ConstMatrixRef training_inputs, ConstMatrixRef training_outputs, const scorer::Scorer &scorer=nullptr) const
 Fit the estimator using cross-validation on the provided training_inputs and training_outputs.
 
double fit (Estimator &estimator, ConstMatrixRef training_inputs, ConstMatrixRef training_outputs, const Tuner &tuner, const scorer::Scorer &scorer=nullptr) const
 Fit the estimator using cross-validation on the provided training_inputs and training_outputs using the tuner tuner to optimize @hp.
 
std::vector< double > score (const Estimator &estimator, ConstMatrixRef inputs, ConstMatrixRef outputs, const scorer::Scorer &scorer=nullptr) const
 Evaluate the estimator using cross-validation on the provided inputs and outputs.
 

Private Member Functions

std::pair< SliceSelector, SliceSelectorcompute_folds (ConstMatrixRef training_inputs) const override
 Compute the training and validation folds for cross-validation.
 

Private Attributes

Dimension num_folds_
 Number of folds to use in cross-validation.
 
bool shuffle_
 Whether to shuffle the data before splitting into folds.
 

Additional Inherited Members

- Public Types inherited from lucid::CrossValidator
using SliceSelector = std::vector<std::vector<Index>>
 Type alias for slice selector.
 
- Protected Member Functions inherited from lucid::CrossValidator
double fit (Estimator &estimator, ConstMatrixRef training_inputs, ConstMatrixRef training_outputs, const Tuner *tuner, const scorer::Scorer &scorer) const
 Fit the estimator using cross-validation on the provided training_inputs and training_outputs using the tuner tuner to optimize @hp, if provided.
 

Detailed Description

Generic K-Fold cross-validation, where the dataset is divided into k folds.

The model is trained k times, each time using k-1 folds for training and the remaining fold for validation. The final model is the one that achieved the best validation score across all folds. This technique helps to mitigate overfitting and provides a more robust estimate of the model's performance.

---
title: "K fold [k = 4]"
config:
    packet:
        bitWidth: 64
        bitsPerRow: 12
        showBits: false
---
packet
+9: "Training"
+3: "Validation"
+6: "Training"
+3: "Validation"
+3: "Training"
+3: "Training"
+3: "Validation"
+6: "Training"
+3: "Validation"
+9: "Training"

Constructor & Destructor Documentation

◆ KFold()

lucid::KFold::KFold ( Dimension num_folds = 5,
bool shuffle = true )
explicit

Construct a new KFold cross-validator with the specified number of folds.

Precondition
num_folds must be at least 2
Parameters
num_foldsnumber of folds to use in cross-validation
shufflewhether to shuffle the data before splitting into folds

Member Function Documentation

◆ compute_folds()

std::pair< CrossValidator::SliceSelector, CrossValidator::SliceSelector > lucid::KFold::compute_folds ( ConstMatrixRef training_inputs) const
nodiscardoverrideprivatevirtual

Compute the training and validation folds for cross-validation.

Each fold is represented as a pair of index vectors, where the first vector contains the indices for the training set and the second vector contains the indices for the validation set.

Parameters
training_inputs\( \texttip{n}{Number of samples} \times \texttip{d_x}{Dimension of the input vector space} \) training input data
Returns
pair of slice selectors for training and validation folds

Implements lucid::CrossValidator.

◆ num_folds() [1/2]

Dimension lucid::KFold::num_folds ( ) const
inlinenodiscard

Get read-only access to the num_folds of the the cross-validation.

Returns
num_folds of the the cross-validation

◆ num_folds() [2/2]

Dimension lucid::KFold::num_folds ( ConstMatrixRef training_inputs) const
nodiscardoverridevirtual

Get the number of folds used in cross-validation.

In KFold cross-validation, the dataset is divided into the number of folds specified during construction.

Precondition
The number of samples in training_inputs must be at least equal to the number of folds
Parameters
training_inputs\( \texttip{n}{Number of samples} \times \texttip{d_x}{Dimension of the input vector space} \) training input data
Returns
number of folds

Implements lucid::CrossValidator.

◆ shuffle()

bool lucid::KFold::shuffle ( ) const
inlinenodiscard

Check whether the to be shuffled before being split into folds is data.

Returns
true if the to be shuffled before being split into folds is data
false if the to be shuffled before being split into folds is not data

◆ to_string()

std::string lucid::KFold::to_string ( ) const
nodiscardoverridevirtual

Obtain the string representation of this object.

Returns
string representation of this object

Reimplemented from lucid::CrossValidator.


The documentation for this class was generated from the following files: