MachineIntelligenceCore:Algorithms
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mic::types::Batch< DataType, LabelType > Class Template Reference

Template class storing the sample batches. A batch is stored in fact as three vectors, containing data, labels and sample numbers respectively. More...

#include <Batch.hpp>

Inheritance diagram for mic::types::Batch< DataType, LabelType >:

Public Member Functions

 Batch (size_t batch_size_=1)
 
 Batch (const mic::types::Batch< DataType, LabelType > &batch_)
 
mic::types::Batch< DataType,
LabelType > & 
operator= (const mic::types::Batch< DataType, LabelType > &batch_)
 
virtual ~Batch ()
 
std::vector< std::shared_ptr
< DataType > > & 
data ()
 Returns sample data. More...
 
std::vector< std::shared_ptr
< LabelType > > & 
labels ()
 Returns sample labels. More...
 
std::vector< size_t > & indices ()
 Returns sample numbers (sample "positions" in original dataset). More...
 
std::shared_ptr< DataType > data (size_t index_)
 
std::shared_ptr< LabelType > labels (size_t index_)
 
std::vector< size_t > indices (size_t index_)
 
size_t size ()
 
void setBatchSize (size_t batch_size_)
 
size_t getBatchSize ()
 
mic::types::Batch< DataType,
LabelType > 
getRandomBatch ()
 
mic::types::Batch< DataType,
LabelType > 
getNextBatch ()
 
mic::types::Batch< DataType,
LabelType > 
getBatch (std::vector< size_t > indices_)
 
mic::types::Batch< DataType,
LabelType > 
getBatchDirect (std::vector< size_t > indices_)
 
bool isLastBatch ()
 
mic::types::Sample< DataType,
LabelType > 
getRandomSample ()
 
mic::types::Sample< DataType,
LabelType > 
getNextSample ()
 
mic::types::Sample< DataType,
LabelType > 
getSample (size_t index_)
 
mic::types::Sample< DataType,
LabelType > 
getSampleDirect (size_t index_)
 
void setNextSampleIndex (size_t index_=0)
 
bool isLastSample ()
 
virtual void add (mic::types::Sample< DataType, LabelType > sample_)
 
virtual void add (std::shared_ptr< DataType > data_, std::shared_ptr< LabelType > label_, size_t index_)
 
virtual void add (std::shared_ptr< DataType > data_, std::shared_ptr< LabelType > label_)
 
void countClasses ()
 
size_t classes ()
 

Protected Attributes

size_t next_sample_index
 
size_t batch_size
 
std::random_device rd
 
std::mt19937_64 rng_mt19937_64
 
std::vector< std::shared_ptr
< DataType > > 
sample_data
 Stores the data. More...
 
std::vector< std::shared_ptr
< LabelType > > 
sample_labels
 Stores labels. More...
 
std::vector< size_t > sample_indices
 Stores sample indices (sample "positions" in original dataset). More...
 
size_t number_of_classes
 

Detailed Description

template<typename DataType, typename LabelType>
class mic::types::Batch< DataType, LabelType >

Template class storing the sample batches. A batch is stored in fact as three vectors, containing data, labels and sample numbers respectively.

Template Parameters
DataTypeTemplate parameter defining the sample data type.
LabelTypeTemplate parameters defining the sample label label.
Author
tkornuta

Definition at line 44 of file Batch.hpp.

Constructor & Destructor Documentation

template<typename DataType, typename LabelType>
mic::types::Batch< DataType, LabelType >::Batch ( size_t  batch_size_ = 1)
inline

Empty constructor.

Definition at line 49 of file Batch.hpp.

template<typename DataType, typename LabelType>
mic::types::Batch< DataType, LabelType >::Batch ( const mic::types::Batch< DataType, LabelType > &  batch_)
inline

Copy constructor.

Parameters
batch_Batch to be copied.

Definition at line 61 of file Batch.hpp.

template<typename DataType, typename LabelType>
virtual mic::types::Batch< DataType, LabelType >::~Batch ( )
inlinevirtual

Destructor. Empty for now.

Definition at line 95 of file Batch.hpp.

Member Function Documentation

template<typename DataType, typename LabelType>
virtual void mic::types::Batch< DataType, LabelType >::add ( mic::types::Sample< DataType, LabelType >  sample_)
inlinevirtual

Adds sample to the batch.

Parameters
sample_Sample to be added.

Definition at line 377 of file Batch.hpp.

Referenced by mic::types::Batch< mic::types::MatrixXf, unsigned int >::getBatch(), and mic::types::Batch< mic::types::MatrixXf, unsigned int >::getBatchDirect().

template<typename DataType, typename LabelType>
virtual void mic::types::Batch< DataType, LabelType >::add ( std::shared_ptr< DataType >  data_,
std::shared_ptr< LabelType >  label_,
size_t  index_ 
)
inlinevirtual

Adds sample to the batch.

Parameters
data_Sample data.
label_Sample label.
number_Sample number.

Definition at line 390 of file Batch.hpp.

template<typename DataType, typename LabelType>
virtual void mic::types::Batch< DataType, LabelType >::add ( std::shared_ptr< DataType >  data_,
std::shared_ptr< LabelType >  label_ 
)
inlinevirtual

Adds sample to the batch and generates the index of the added sample (sets it to the previous size).

Parameters
data_Sample data.
label_Sample label.

Definition at line 402 of file Batch.hpp.

template<typename DataType, typename LabelType>
size_t mic::types::Batch< DataType, LabelType >::classes ( )
inline

Returns the number of distinctive classes.

Returns
Number of classes.

Definition at line 427 of file Batch.hpp.

Referenced by mic::types::Batch< mic::types::MatrixXf, unsigned int >::countClasses(), and main().

template<typename DataType, typename LabelType>
void mic::types::Batch< DataType, LabelType >::countClasses ( )
inline

Counts the distinctive classes. Quite slow method, but works.

Definition at line 413 of file Batch.hpp.

template<typename DataType, typename LabelType>
std::vector<std::shared_ptr<DataType> >& mic::types::Batch< DataType, LabelType >::data ( )
inline

Returns sample data.

Definition at line 98 of file Batch.hpp.

Referenced by main().

template<typename DataType, typename LabelType>
std::shared_ptr<DataType> mic::types::Batch< DataType, LabelType >::data ( size_t  index_)
inline

Returns data from selected sample.

Parameters
index_Index of the sample from the batch.
Returns
Data.

Definition at line 117 of file Batch.hpp.

template<typename DataType, typename LabelType>
mic::types::Batch<DataType, LabelType> mic::types::Batch< DataType, LabelType >::getBatch ( std::vector< size_t >  indices_)
inline

Returns batch of samples with given indices. If any of the indices is out of dataset range throws an "std::out_of_range" exception.

Parameters
indices_Vector of indices
Returns
Batch - a pair of vectors of <shared pointers="" to="" samples>=""> / vectors of <shared pointers="" to="" labels>="">, supplemented by third vector containing sample numbers.

Definition at line 219 of file Batch.hpp.

template<typename DataType, typename LabelType>
mic::types::Batch<DataType, LabelType> mic::types::Batch< DataType, LabelType >::getBatchDirect ( std::vector< size_t >  indices_)
inline

Returns batch of samples with given positions in the batch (thus they can have different indices i.e. positions in the original dataset!). If any of the indices is out of dataset range throws an "std::out_of_range" exception.

Parameters
indices_Vector of indices
Returns
Batch - a pair of vectors of <shared pointers="" to="" samples>=""> / vectors of <shared pointers="" to="" labels>="">, supplemented by third vector containing sample numbers.

Definition at line 242 of file Batch.hpp.

Referenced by mic::types::Batch< mic::types::MatrixXf, unsigned int >::getNextBatch(), and mic::types::Batch< mic::types::MatrixXf, unsigned int >::getRandomBatch().

template<typename DataType, typename LabelType>
size_t mic::types::Batch< DataType, LabelType >::getBatchSize ( )
inline

Returns the size of the batch.

Definition at line 159 of file Batch.hpp.

template<typename DataType, typename LabelType>
mic::types::Batch<DataType, LabelType> mic::types::Batch< DataType, LabelType >::getNextBatch ( )
inline

Iterates through samples and returns them batch by batch. After returning the last possible batch from the dataset the procedure starts from the beginning. This behaviour can be avoided by manually calling the isLastBatch() method.

Returns
Batch - a pair of vectors of <shared pointers="" to="" samples>=""> / vectors of <shared pointers="" to="" labels>="">, supplemented by third vector containing sample numbers.

Definition at line 191 of file Batch.hpp.

Referenced by main().

template<typename DataType, typename LabelType>
mic::types::Sample<DataType, LabelType> mic::types::Batch< DataType, LabelType >::getNextSample ( )
inline

Iterates through samples and returns them one by one. After returning the last element from the dataset the procedure starts from the beginning. This behaviour can be avoided by manualy calling the isLastSample() method.

Returns
Sample containing shared pointer to sample data, its label and sample number.

Definition at line 290 of file Batch.hpp.

template<typename DataType, typename LabelType>
mic::types::Batch<DataType, LabelType> mic::types::Batch< DataType, LabelType >::getRandomBatch ( )
inline

Returns a batch of random samples.

Returns
Batch - a pair of vectors of <shared pointers="" to="" samples>=""> / vectors of <shared pointers="" to="" labels>="">, supplemented by third vector containing sample numbers.

Definition at line 168 of file Batch.hpp.

template<typename DataType, typename LabelType>
mic::types::Sample<DataType, LabelType> mic::types::Batch< DataType, LabelType >::getRandomSample ( )
inline

Picks a random sample from the dataset (the same sample can be selected many times - n-tuples).

Returns
Sample containing shared pointer to sample data, its label and sample number.

Definition at line 270 of file Batch.hpp.

Referenced by main().

template<typename DataType, typename LabelType>
mic::types::Sample<DataType, LabelType> mic::types::Batch< DataType, LabelType >::getSample ( size_t  index_)
inline

Returns sample with given index. If index is out of batch range throws an "std::out_of_range" exception.

Parameters
index_Sample index.
Returns
Sample containing shared pointer to sample data, its label and sample number.

Definition at line 309 of file Batch.hpp.

Referenced by mic::types::Batch< mic::types::MatrixXf, unsigned int >::getBatch().

template<typename DataType, typename LabelType>
mic::types::Sample<DataType, LabelType> mic::types::Batch< DataType, LabelType >::getSampleDirect ( size_t  index_)
inline

Returns sample being in a given position in the batch (thus it can have different index i.e. position in the original dataset!). If index is out of batch range throws an "std::out_of_range" exception.

Parameters
index_Sample index.
Returns
Sample containing shared pointer to sample data, its label and sample number.

Definition at line 338 of file Batch.hpp.

Referenced by mic::types::Batch< mic::types::MatrixXf, unsigned int >::getBatchDirect(), mic::types::Batch< mic::types::MatrixXf, unsigned int >::getNextSample(), and mic::types::Batch< mic::types::MatrixXf, unsigned int >::getRandomSample().

template<typename DataType, typename LabelType>
std::vector<size_t>& mic::types::Batch< DataType, LabelType >::indices ( )
inline

Returns sample numbers (sample "positions" in original dataset).

Definition at line 108 of file Batch.hpp.

Referenced by mic::types::Batch< mic::types::MatrixXf, unsigned int >::getNextBatch().

template<typename DataType, typename LabelType>
std::vector<size_t> mic::types::Batch< DataType, LabelType >::indices ( size_t  index_)
inline

Returns sample number (sample "position" in original dataset).

Parameters
index_Index of the sample from the batch.
Returns
Sample number.

Definition at line 135 of file Batch.hpp.

template<typename DataType, typename LabelType>
bool mic::types::Batch< DataType, LabelType >::isLastBatch ( )
inline

Checks if the returned batch was the last possible one.

Returns
True if the batch was the last one.

Definition at line 261 of file Batch.hpp.

Referenced by main().

template<typename DataType, typename LabelType>
bool mic::types::Batch< DataType, LabelType >::isLastSample ( )
inline

Checks if the returned sample was the last one.

Returns
True if the sample was the last one.

Definition at line 368 of file Batch.hpp.

template<typename DataType, typename LabelType>
std::vector<std::shared_ptr<LabelType> >& mic::types::Batch< DataType, LabelType >::labels ( )
inline

Returns sample labels.

Definition at line 103 of file Batch.hpp.

template<typename DataType, typename LabelType>
std::shared_ptr<LabelType> mic::types::Batch< DataType, LabelType >::labels ( size_t  index_)
inline

Returns label of the selected sample.

Parameters
index_Index of the sample from the batch.
Returns
Sample label

Definition at line 126 of file Batch.hpp.

template<typename DataType, typename LabelType>
mic::types::Batch<DataType, LabelType>& mic::types::Batch< DataType, LabelType >::operator= ( const mic::types::Batch< DataType, LabelType > &  batch_)
inline

Assignment operator.

Parameters
batch_Batch to be copied.
Returns
An exact copy of the input batch.

Definition at line 81 of file Batch.hpp.

template<typename DataType, typename LabelType>
void mic::types::Batch< DataType, LabelType >::setBatchSize ( size_t  batch_size_)
inline

Sets the batch size.

Parameters
batch_size_Batch size.

Definition at line 151 of file Batch.hpp.

Referenced by main().

template<typename DataType, typename LabelType>
void mic::types::Batch< DataType, LabelType >::setNextSampleIndex ( size_t  index_ = 0)
inline

Sets the index of the next returned sample.

Parameters
index_Sample index.

Definition at line 360 of file Batch.hpp.

template<typename DataType, typename LabelType>
size_t mic::types::Batch< DataType, LabelType >::size ( )
inline

Returns the size of the batch.

Returns
Batch size.

Definition at line 143 of file Batch.hpp.

Referenced by main().

Member Data Documentation

template<typename DataType, typename LabelType>
std::random_device mic::types::Batch< DataType, LabelType >::rd
protected

Random device used for generation of random numbers.

Definition at line 445 of file Batch.hpp.

template<typename DataType, typename LabelType>
std::mt19937_64 mic::types::Batch< DataType, LabelType >::rng_mt19937_64
protected

Mersenne Twister pseudo-random generator of 32-bit numbers with a state size of 19937 bits.

Definition at line 450 of file Batch.hpp.

Referenced by mic::types::Batch< mic::types::MatrixXf, unsigned int >::getRandomBatch(), and mic::types::Batch< mic::types::MatrixXf, unsigned int >::getRandomSample().


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