UESMANN CPP  1.0
Reference implementation of UESMANN
Public Types | Public Member Functions | List of all members
ExampleSet Class Reference

A set of example data. Each datum consists of hormone (i.e. modulator value), inputs and outputs. The data is stored as a single double array, with each example made up of inputs, followed by outputs, followed by modulator value (h). More...

#include <data.hpp>

Inheritance diagram for ExampleSet:
Inheritance graph
[legend]

Public Types

enum  ShuffleMode { STRIDE, ALTERNATE, SINGLE, NONE }
 Shuffling mode for shuffle() More...
 

Public Member Functions

 ExampleSet (int n, int nin, int nout, int levels)
 Constructor - creates but doesn't fill in the data. More...
 
 ExampleSet (const ExampleSet &parent, int start, int length)
 Constructor for making a subset of another set. This uses the actual data in the parent, but creates a fresh set of offset structures which can be independently shuffled. More...
 
 ExampleSet (const MNIST &mnist)
 Special constructor for generating a data set from an MNIST database with a single labelling (i.e. for use in non-modulatory training). We copy the data from the MNIST object. The outputs will use a one-hot encoding. This example set will have no modulation. More...
 
 ~ExampleSet ()
 Destructor - deletes data and offset array. More...
 
void shuffle (drand48_data *rd, ShuffleMode mode, int nExamples=0)
 Shuffle the example using a PRNG and a Fisher-Yates shuffle. More...
 
ExampleSetsetHRange (double mn, double mx)
 
int getInputCount () const
 get the number of inputs in all examples More...
 
int getOutputCount () const
 get the number of outputs in all examples More...
 
int getCount () const
 get the number of examples More...
 
double * getInputs (int example)
 Get a pointer to the inputs for a given example, for reading or writing. More...
 
double * getOutputs (int example)
 Get a pointer to the outputs for a given example, for reading or writing. More...
 
double getH (int example) const
 Get the h (modulator) for a given example. More...
 
int getNumHLevels ()
 return the number of different H-levels More...
 
void setH (int example, double h)
 Set the h (modulator) for a given example. More...
 
void dump (int start=0, int end=-1)
 dump to stdout More...
 

Detailed Description

A set of example data. Each datum consists of hormone (i.e. modulator value), inputs and outputs. The data is stored as a single double array, with each example made up of inputs, followed by outputs, followed by modulator value (h).

Definition at line 57 of file data.hpp.

Member Enumeration Documentation

Shuffling mode for shuffle()

Enumerator
STRIDE 

Shuffle blocks of numHLevels examples, rather than single examples. This is intended for cases where examples with the same inputs are added contiguously at different modulator levels. For this to work correctly, the modulator levels must be distributed evenly across their range. For example, for four modulator levels from 2-3:

  • ensure that numHLevels is 4
  • ensure that the values for 2,2.25,2.5 and 3 are equally represented in the data.
  • ensure that the data is provided in equally sized groups cycling through the modulator (similar to the output of the ALTERNATE mode)

It is possible to run a shuffle(rd,ALTERNATE) on the data after input, followed by training with this mode.

ALTERNATE 

Shuffle single examples, but follow up by running a pass over the examples to ensure that they alternate by modulator level. This is useful where there are discrete modulator levels but the examples are mixed up (as happens in the robot experiments). This doesn't require equal distribution of modulator levels, but the levels should be evenly spaced across the range. If the distribution is unequal, a portion at the end of the set will not alternate correctly.

SINGLE 

Shuffle single examples, no matter the value of numHLevels.

NONE 

Don't shuffle examples at all.

Definition at line 212 of file data.hpp.

Constructor & Destructor Documentation

ExampleSet::ExampleSet ( int  n,
int  nin,
int  nout,
int  levels 
)
inline

Constructor - creates but doesn't fill in the data.

Parameters
nnumber of examples
ninnumber of inputs to each example
noutnumber of outputs from each example
levelsnumber of modulator levels (see numHLevels)

Definition at line 104 of file data.hpp.

ExampleSet::ExampleSet ( const ExampleSet parent,
int  start,
int  length 
)
inline

Constructor for making a subset of another set. This uses the actual data in the parent, but creates a fresh set of offset structures which can be independently shuffled.

Parameters
parentthe set which holds our data.
startthe start index of the data in the parent.
lengththe length of the subset.

Definition at line 143 of file data.hpp.

ExampleSet::ExampleSet ( const MNIST mnist)
inline

Special constructor for generating a data set from an MNIST database with a single labelling (i.e. for use in non-modulatory training). We copy the data from the MNIST object. The outputs will use a one-hot encoding. This example set will have no modulation.

Definition at line 170 of file data.hpp.

ExampleSet::~ExampleSet ( )
inline

Destructor - deletes data and offset array.

Definition at line 201 of file data.hpp.

Member Function Documentation

void ExampleSet::dump ( int  start = 0,
int  end = -1 
)
inline

dump to stdout

Parameters
startindex to start dump
endindex to end dump (exclusive)

Definition at line 388 of file data.hpp.

int ExampleSet::getCount ( ) const
inline

get the number of examples

Returns
number of examples

Definition at line 327 of file data.hpp.

double ExampleSet::getH ( int  example) const
inline

Get the h (modulator) for a given example.

Parameters
exampleindex of the example

Definition at line 359 of file data.hpp.

int ExampleSet::getInputCount ( ) const
inline

get the number of inputs in all examples

Returns
number of inputs into each example

Definition at line 311 of file data.hpp.

double* ExampleSet::getInputs ( int  example)
inline

Get a pointer to the inputs for a given example, for reading or writing.

Parameters
exampleindex of the example

Definition at line 338 of file data.hpp.

int ExampleSet::getNumHLevels ( )
inline

return the number of different H-levels

Definition at line 367 of file data.hpp.

int ExampleSet::getOutputCount ( ) const
inline

get the number of outputs in all examples

Returns
number of outputs from each example

Definition at line 319 of file data.hpp.

double* ExampleSet::getOutputs ( int  example)
inline

Get a pointer to the outputs for a given example, for reading or writing.

Parameters
exampleindex of the example

Definition at line 349 of file data.hpp.

void ExampleSet::setH ( int  example,
double  h 
)
inline

Set the h (modulator) for a given example.

Parameters
exampleindex of the example
hmodulator to use

Definition at line 378 of file data.hpp.

ExampleSet& ExampleSet::setHRange ( double  mn,
double  mx 
)
inline

Modify the min/max h range, which is 0<=h<=1 by default.

Parameters
mnminimum H value in set domain
mxmaximum H value in set domain

Definition at line 300 of file data.hpp.

void ExampleSet::shuffle ( drand48_data *  rd,
ShuffleMode  mode,
int  nExamples = 0 
)
inline

Shuffle the example using a PRNG and a Fisher-Yates shuffle.

Parameters
rdpointer to a PRNG data block
modeShuffleMode::STRIDE to keep blocks of size numHLevels together, ShuffleMode::ALTERNATE to shuffle all examples but ensure that h-levels alternate after shuffling, or ShuffleMode::NONE to just shuffle.
nExampleshow many examples to shuffle; if 0, do all of them

Definition at line 259 of file data.hpp.


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