Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RDatasetLoader.hxx
Go to the documentation of this file.
1// Author: Martin Føll, University of Oslo (UiO) & CERN 01/2026
2
3/*************************************************************************
4 * Copyright (C) 1995-2026, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#ifndef ROOT_INTERNAL_ML_RDATASETLOADER
12#define ROOT_INTERNAL_ML_RDATASETLOADER
13
14#include <algorithm>
15#include <memory>
16#include <numeric>
17#include <string>
18#include <type_traits>
19#include <vector>
20
23#include "ROOT/RDataFrame.hxx"
24#include "ROOT/RDF/Utils.hxx"
25
27
28/**
29\class ROOT::Experimental::Internal::ML::RDatasetLoader
30
31\brief Load the whole dataset into memory.
32
33In this class the whole dataset is loaded into memory. The dataset is further shuffled and spit into training and
34validation sets with the user-defined validation split fraction.
35*/
36
38private:
40
41 std::vector<std::size_t> fVecSizes;
42 std::size_t fSumVecSizes;
44 std::size_t fNumDatasetCols;
45
47
48 // rows of fDataset in the training and validation sets, one set per dataframe or a single one if concatenated
49 std::vector<std::vector<std::size_t>> fTrainingRows;
50 std::vector<std::vector<std::size_t>> fValidationRows;
51
54 std::unique_ptr<RFlat2DMatrixOperators> fTensorOperators;
55
56 std::vector<ROOT::RDF::RNode> f_rdfs;
57 std::vector<std::string> fCols;
58 std::size_t fNumCols;
59 std::size_t fSetSeed;
60
62
63public:
64 RDatasetLoader(const std::vector<ROOT::RDF::RNode> &rdfs, const float validationSplit,
65 const std::vector<std::string> &cols, const std::vector<std::size_t> &vecSizes = {},
66 const float vecPadding = 0.0, bool shuffle = true, const std::size_t setSeed = 0);
67
68 std::vector<std::size_t> CountEntries(std::vector<ROOT::RDF::RNode> &rdfs);
69
70 void LoadDataframe(ROOT::RDF::RNode &rdf, std::size_t NumEntries);
71
72 void
73 SplitRows(std::size_t firstRow, std::vector<std::size_t> &TrainingRows, std::vector<std::size_t> &ValidationRows);
74
75 void SplitDatasets(bool concatenate);
76
77 RFlat2DMatrix ReleaseDataset() { return std::move(fDataset); }
78
79 std::vector<std::vector<std::size_t>> ReleaseTrainingRows() { return std::move(fTrainingRows); }
80 std::vector<std::vector<std::size_t>> ReleaseValidationRows() { return std::move(fValidationRows); }
81
84};
85
86} // namespace ROOT::Experimental::Internal::ML
87#endif // ROOT_INTERNAL_ML_RDATASETLOADER
Load the whole dataset into memory.
std::vector< std::size_t > CountEntries(std::vector< ROOT::RDF::RNode > &rdfs)
Number of entries to reserve for each dataframe.
void SplitRows(std::size_t firstRow, std::vector< std::size_t > &TrainingRows, std::vector< std::size_t > &ValidationRows)
Split the rows of the dataset from firstRow on into training and validation rows.
std::unique_ptr< RFlat2DMatrixOperators > fTensorOperators
void SplitDatasets(bool concatenate)
Load the dataframes into a single dataset and split it in training and validation rows.
std::vector< std::vector< std::size_t > > fTrainingRows
void LoadDataframe(ROOT::RDF::RNode &rdf, std::size_t NumEntries)
Load all the entries of an individual dataframe at the end of the dataset.
std::vector< std::vector< std::size_t > > ReleaseTrainingRows()
RDatasetLoader(const std::vector< ROOT::RDF::RNode > &rdfs, const float validationSplit, const std::vector< std::string > &cols, const std::vector< std::size_t > &vecSizes={}, const float vecPadding=0.0, bool shuffle=true, const std::size_t setSeed=0)
std::vector< std::vector< std::size_t > > ReleaseValidationRows()
std::vector< std::vector< std::size_t > > fValidationRows
The public interface to the RDataFrame federation of classes.
Wrapper around ROOT::RVec<float> representing a 2D matrix.