1#ifndef TMVA_RBatchLoader
2#define TMVA_RBatchLoader
11#include <condition_variable>
18namespace Experimental {
42 RBatchLoader(
const std::size_t batchSize,
const std::size_t numColumns,
const std::size_t maxBatches)
59 fCurrentBatch = std::make_unique<TMVA::Experimental::RTensor<float>>(std::vector<std::size_t>({0}));
101 std::unique_lock<std::mutex> lock(
fBatchLock);
130 std::unique_ptr<TMVA::Experimental::RTensor<float>>
134 std::make_unique<TMVA::Experimental::RTensor<float>>(std::vector<std::size_t>({
fBatchSize,
fNumColumns}));
136 for (std::size_t i = 0; i <
fBatchSize; i++) {
151 std::vector<std::size_t> eventIndices,
const bool shuffle =
true)
156 std::unique_lock<std::mutex> lock(
fBatchLock);
163 std::shuffle(eventIndices.begin(), eventIndices.end(),
fRng);
165 std::vector<std::unique_ptr<TMVA::Experimental::RTensor<float>>> batches;
171 std::vector<std::size_t> idx;
172 for (std::size_t i = start; i < (start +
fBatchSize); i++) {
173 idx.push_back(eventIndices[i]);
177 batches.emplace_back(
CreateBatch(chunkTensor, idx));
181 std::unique_lock<std::mutex> lock(
fBatchLock);
182 for (std::size_t i = 0; i < batches.size(); i++) {
195 const std::vector<std::size_t> eventIndices)
200 std::vector<std::size_t> idx;
202 for (std::size_t i = start; i < (start +
fBatchSize); i++) {
203 idx.push_back(eventIndices[i]);
207 std::unique_lock<std::mutex> lock(
fBatchLock);
216 std::unique_lock<std::mutex> lock(
fBatchLock);
void Activate()
Activate the batchloader so it will accept chunks to batch.
void CreateValidationBatches(const TMVA::Experimental::RTensor< float > &chunkTensor, const std::vector< std::size_t > eventIndices)
Create validation batches from the given chunk based on the given event indices Batches are added to ...
RBatchLoader(const std::size_t batchSize, const std::size_t numColumns, const std::size_t maxBatches)
std::unique_ptr< TMVA::Experimental::RTensor< float > > CreateBatch(const TMVA::Experimental::RTensor< float > &chunkTensor, const std::vector< std::size_t > idx)
Create a batch filled with the events on the given idx.
TMVA::Experimental::RTensor< float > fEmptyTensor
void CreateTrainingBatches(const TMVA::Experimental::RTensor< float > &chunkTensor, std::vector< std::size_t > eventIndices, const bool shuffle=true)
Create training batches from the given chunk of data based on the given event indices Batches are add...
std::vector< std::unique_ptr< TMVA::Experimental::RTensor< float > > > fValidationBatches
bool HasTrainData()
Checks if there are more training batches available.
std::condition_variable fBatchCondition
const TMVA::Experimental::RTensor< float > & GetTrainBatch()
Return a batch of data as a unique pointer.
bool HasValidationData()
Checks if there are more training batches available.
std::unique_ptr< TMVA::Experimental::RTensor< float > > fCurrentBatch
TMVA::RandomGenerator< TRandom3 > fRng
void StartValidation()
Reset the validation process.
const TMVA::Experimental::RTensor< float > & GetValidationBatch()
Returns a batch of data for validation The owner of this batch has to be with the RBatchLoader.
std::size_t fValidationIdx
void DeActivate()
DeActivate the batchloader.
std::queue< std::unique_ptr< TMVA::Experimental::RTensor< float > > > fTrainingBatchQueue
RTensor is a container with contiguous memory and shape information.
create variable transformations