Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RSampler.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_RSAMPLER
12#define ROOT_INTERNAL_ML_RSAMPLER
13
14#include <memory>
15#include <string>
16#include <vector>
17
19
20// Forward decls
22class RFlat2DMatrixOperators;
23}
24
26/**
27\class ROOT::Experimental::Internal::ML::RSampler
28
29\brief Implementation of different sampling strategies.
30*/
31
32class RSampler {
33private:
34 std::vector<RFlat2DMatrix> &fDatasets;
35 std::string fSampleType;
39 std::size_t fSetSeed;
40 std::size_t fNumEntries;
41
42 std::size_t fMajor;
43 std::size_t fMinor;
44 std::size_t fNumMajor;
45 std::size_t fNumMinor;
46 std::size_t fNumResampledMajor;
47 std::size_t fNumResampledMinor;
48
49 std::vector<std::size_t> fSamples;
50
51 std::unique_ptr<RFlat2DMatrixOperators> fTensorOperators;
52
53public:
54 RSampler(std::vector<RFlat2DMatrix> &datasets, const std::string &sampleType, float sampleRatio,
55 bool replacement = false, bool shuffle = true, std::size_t setSeed = 0);
56
58
59 void SetupSampler();
60
62
64
66
68
70
71 void SampleWithReplacement(std::size_t n_samples, std::size_t max);
72
73 void SampleWithoutReplacement(std::size_t n_samples, std::size_t max);
74
75 std::size_t GetNumEntries() { return fNumEntries; }
76};
77
78} // namespace ROOT::Experimental::Internal::ML
79#endif // ROOT_INTERNAL_ML_RSAMPLER
Implementation of different sampling strategies.
Definition RSampler.hxx:32
void SampleWithoutReplacement(std::size_t n_samples, std::size_t max)
Add indices without replacement to fSamples.
Definition RSampler.cxx:183
void SetupRandomUndersampler()
Calculate fNumEntries and major/minor variables for the random undersampler.
Definition RSampler.cxx:54
void RandomOversampler(RFlat2DMatrix &ShuffledTensor)
Oversample entries randomly from the minority dataset.
Definition RSampler.cxx:128
void SampleWithReplacement(std::size_t n_samples, std::size_t max)
Add indices with replacement to fSamples.
Definition RSampler.cxx:152
void SetupRandomOversampler()
Calculate fNumEntries and major/minor variables for the random oversampler.
Definition RSampler.cxx:80
void SetupSampler()
Calculate fNumEntries and major/minor variables.
Definition RSampler.cxx:31
std::vector< std::size_t > fSamples
Definition RSampler.hxx:49
std::unique_ptr< RFlat2DMatrixOperators > fTensorOperators
Definition RSampler.hxx:51
RSampler(std::vector< RFlat2DMatrix > &datasets, const std::string &sampleType, float sampleRatio, bool replacement=false, bool shuffle=true, std::size_t setSeed=0)
Definition RSampler.cxx:14
void RandomUndersampler(RFlat2DMatrix &ShuffledTensor)
Undersample entries randomly from the majority dataset.
Definition RSampler.cxx:99
std::vector< RFlat2DMatrix > & fDatasets
Definition RSampler.hxx:34
void Sampler(RFlat2DMatrix &SampledTensor)
Collection of sampling types.
Definition RSampler.cxx:43
Wrapper around ROOT::RVec<float> representing a 2D matrix.