GClasses
GClasses::GRecurrentModel Class Reference

This class can be used to implement recurrent neural networks, or recurrent forms of other supervised models. More...

#include <GSystemLearner.h>

Inheritance diagram for GClasses::GRecurrentModel:
GClasses::GSystemLearner GClasses::MyRecurrentModel

Public Member Functions

 GRecurrentModel (GSupervisedLearner *pTransition, GSupervisedLearner *pObservation, size_t actionDims, size_t contextDims, size_t obsDims, GRand *pRand, std::vector< size_t > *pParamDims=NULL)
 Takes ownership of pTransition and pObservation. More...
 
 GRecurrentModel (GDomNode *pNode, GRand *pRand)
 Load from a DOM. More...
 
virtual ~GRecurrentModel ()
 
virtual void calibrate (const double *pObs)
 See the comment for GSystemLearner::calibrate. More...
 
double * context ()
 Returns a pointer to the context vector. More...
 
size_t contextDims ()
 Returns the number of dimensions in the context (state) vector. More...
 
virtual void doAction (const double *pAction)
 See the comment for GSystemLearner::doAction. More...
 
GImageframes (GMatrix *pDataAction, GMatrix *pDataObs, bool calibrateContext, unsigned int frameWidth, int stepsPerImage, double scalePredictions)
 Generates a film-strip-like sequence of frames that compare the expected observations (left) with predicted observations (right). If the predictions are not in the form of images, or they are not parameterized with two variables, then this method will throw. More...
 
size_t obsDims ()
 Returns the number of obs dims. More...
 
GSupervisedLearnerobservationFunc ()
 Returns the observation function. More...
 
virtual void onFinishedComputingStateEstimate (GMatrix *pStateEstimate)
 This method is called when trainMoses finishes computing the state estimate. By default, it does nothing, but you can overload it if you wish to do something with it. More...
 
virtual void onObtainValidationScore (size_t timeSlice, double seconds, double squaredError)
 If validateDuringTraining was called, then this method is called whenever validation data is obtained. More...
 
size_t paramDims ()
 Trains with the back-prop-through-time algorithm. Returns the final sequence length. More...
 
size_t * paramRanges ()
 
double * params ()
 
virtual void predict (double *pObs)
 See the comment for GSystemLearner::predict. More...
 
void predictPixel (const double *pParams, double *pObs)
 
double quickValidate (GMatrix *pDataAction, GMatrix *pDataObs, size_t pixelSamples, double *paramArray, bool monotonic)
 Quickly compute an error estimate for use as an optimization heurisitic. More...
 
virtual GDomNodeserialize (GDom *pDoc) const
 See the comment for GSystemLearner::serialize. More...
 
void setTrainingSeconds (double d)
 Set the number of seconds to train. More...
 
void setUseIsomap (bool b)
 Specify whether to use Isomap (instead of BreadthFirstUnfolding). (This only applies when trainMoses is called.) More...
 
void trainEvolutionary (GMatrix *pActions, GMatrix *pObservations)
 Trains with an evolutionary optimizer. More...
 
void trainHillClimber (GMatrix *pActions, GMatrix *pObservations, double dev, double decay, double seconds, bool climb, bool anneal)
 Trains with a hill climber. More...
 
void trainMoses (GMatrix *pActions, GMatrix *pObservations)
 Trains with the MOSES algorithm. (Calls onFinishedComputingStateEstimate when the state estimate is computed.) More...
 
GSupervisedLearnertransitionFunc ()
 Returns the transition function. More...
 
double validate (std::vector< GMatrix * > &validationData, bool calibrateContext, bool monotonic, double multiplier)
 Computes the mean squared error with respect to some test sequence of actions and observations. More...
 
void validateDuringTraining (double timeInterval, std::vector< GMatrix * > *pValidationData)
 Perform validation at periodic intervals with the specified data during training. Results are passed to the onObtainValidationScore method. pValidationData should refer to some number of validation data pairs, where each validation data pair is an observation dataset followed by an action dataset. More...
 
- Public Member Functions inherited from GClasses::GSystemLearner
 GSystemLearner ()
 
 GSystemLearner (GDomNode *pNode)
 
virtual ~GSystemLearner ()
 

Static Public Member Functions

static void blurImageVector (const double *pIn, double *pOut, int wid, int hgt, int chan, double valueRange, int radius, int iters)
 Blur the image vector. More...
 

Protected Member Functions

GMatrixjoshuaEstimateState (GMatrix *pActions, GMatrix *pObservations)
 
GMatrixmosesEstimateState (GMatrix *pActions, GMatrix *pObservations)
 
void prepareForOptimization (GMatrix *pActions, GMatrix *pObservations)
 
void trainObservationFunction (GMatrix *pEstState, GMatrix *pObservations)
 
void trainObservationFunctionIteratively (double dStart, GMatrix *pEstState, GMatrix *pObservations)
 
void trainTransitionFunction (GMatrix *pActions, GMatrix *pEstState)
 
- Protected Member Functions inherited from GClasses::GSystemLearner
GDomNodebaseDomNode (GDom *pDoc, const char *szClassName) const
 Child classes should use this in their implementation of serialize. More...
 

Protected Attributes

size_t m_actionDims
 
size_t m_channels
 
size_t m_contextDims
 
double m_multiplier
 
size_t m_obsDims
 
size_t m_paramDims
 
double * m_pBuf
 
double * m_pContext
 
size_t m_pixels
 
GSupervisedLearnerm_pObservationFunc
 
size_t * m_pParamRanges
 
double * m_pParams
 
GRandm_pRand
 
GSupervisedLearnerm_pTransitionFunc
 
std::vector< GMatrix * > * m_pValidationData
 
double m_trainingSeconds
 
bool m_transitionDelta
 
bool m_useIsomap
 
double m_validationInterval
 

Detailed Description

This class can be used to implement recurrent neural networks, or recurrent forms of other supervised models.

Constructor & Destructor Documentation

GClasses::GRecurrentModel::GRecurrentModel ( GSupervisedLearner pTransition,
GSupervisedLearner pObservation,
size_t  actionDims,
size_t  contextDims,
size_t  obsDims,
GRand pRand,
std::vector< size_t > *  pParamDims = NULL 
)

Takes ownership of pTransition and pObservation.

GClasses::GRecurrentModel::GRecurrentModel ( GDomNode pNode,
GRand pRand 
)

Load from a DOM.

virtual GClasses::GRecurrentModel::~GRecurrentModel ( )
virtual

Member Function Documentation

static void GClasses::GRecurrentModel::blurImageVector ( const double *  pIn,
double *  pOut,
int  wid,
int  hgt,
int  chan,
double  valueRange,
int  radius,
int  iters 
)
static

Blur the image vector.

virtual void GClasses::GRecurrentModel::calibrate ( const double *  pObs)
virtual

See the comment for GSystemLearner::calibrate.

Implements GClasses::GSystemLearner.

double* GClasses::GRecurrentModel::context ( )
inline

Returns a pointer to the context vector.

size_t GClasses::GRecurrentModel::contextDims ( )
inline

Returns the number of dimensions in the context (state) vector.

virtual void GClasses::GRecurrentModel::doAction ( const double *  pAction)
virtual

See the comment for GSystemLearner::doAction.

Implements GClasses::GSystemLearner.

GImage* GClasses::GRecurrentModel::frames ( GMatrix pDataAction,
GMatrix pDataObs,
bool  calibrateContext,
unsigned int  frameWidth,
int  stepsPerImage,
double  scalePredictions 
)

Generates a film-strip-like sequence of frames that compare the expected observations (left) with predicted observations (right). If the predictions are not in the form of images, or they are not parameterized with two variables, then this method will throw.

GMatrix* GClasses::GRecurrentModel::joshuaEstimateState ( GMatrix pActions,
GMatrix pObservations 
)
protected
GMatrix* GClasses::GRecurrentModel::mosesEstimateState ( GMatrix pActions,
GMatrix pObservations 
)
protected
size_t GClasses::GRecurrentModel::obsDims ( )
inline

Returns the number of obs dims.

GSupervisedLearner* GClasses::GRecurrentModel::observationFunc ( )
inline

Returns the observation function.

virtual void GClasses::GRecurrentModel::onFinishedComputingStateEstimate ( GMatrix pStateEstimate)
inlinevirtual

This method is called when trainMoses finishes computing the state estimate. By default, it does nothing, but you can overload it if you wish to do something with it.

Reimplemented in GClasses::MyRecurrentModel.

virtual void GClasses::GRecurrentModel::onObtainValidationScore ( size_t  timeSlice,
double  seconds,
double  squaredError 
)
inlinevirtual

If validateDuringTraining was called, then this method is called whenever validation data is obtained.

size_t GClasses::GRecurrentModel::paramDims ( )
inline

Trains with the back-prop-through-time algorithm. Returns the final sequence length.

size_t* GClasses::GRecurrentModel::paramRanges ( )
inline
double* GClasses::GRecurrentModel::params ( )
inline
virtual void GClasses::GRecurrentModel::predict ( double *  pObs)
virtual

See the comment for GSystemLearner::predict.

Implements GClasses::GSystemLearner.

void GClasses::GRecurrentModel::predictPixel ( const double *  pParams,
double *  pObs 
)
void GClasses::GRecurrentModel::prepareForOptimization ( GMatrix pActions,
GMatrix pObservations 
)
protected
double GClasses::GRecurrentModel::quickValidate ( GMatrix pDataAction,
GMatrix pDataObs,
size_t  pixelSamples,
double *  paramArray,
bool  monotonic 
)

Quickly compute an error estimate for use as an optimization heurisitic.

virtual GDomNode* GClasses::GRecurrentModel::serialize ( GDom pDoc) const
virtual

See the comment for GSystemLearner::serialize.

void GClasses::GRecurrentModel::setTrainingSeconds ( double  d)
inline

Set the number of seconds to train.

void GClasses::GRecurrentModel::setUseIsomap ( bool  b)
inline

Specify whether to use Isomap (instead of BreadthFirstUnfolding). (This only applies when trainMoses is called.)

void GClasses::GRecurrentModel::trainEvolutionary ( GMatrix pActions,
GMatrix pObservations 
)

Trains with an evolutionary optimizer.

void GClasses::GRecurrentModel::trainHillClimber ( GMatrix pActions,
GMatrix pObservations,
double  dev,
double  decay,
double  seconds,
bool  climb,
bool  anneal 
)

Trains with a hill climber.

void GClasses::GRecurrentModel::trainMoses ( GMatrix pActions,
GMatrix pObservations 
)

Trains with the MOSES algorithm. (Calls onFinishedComputingStateEstimate when the state estimate is computed.)

void GClasses::GRecurrentModel::trainObservationFunction ( GMatrix pEstState,
GMatrix pObservations 
)
protected
void GClasses::GRecurrentModel::trainObservationFunctionIteratively ( double  dStart,
GMatrix pEstState,
GMatrix pObservations 
)
protected
void GClasses::GRecurrentModel::trainTransitionFunction ( GMatrix pActions,
GMatrix pEstState 
)
protected
GSupervisedLearner* GClasses::GRecurrentModel::transitionFunc ( )
inline

Returns the transition function.

double GClasses::GRecurrentModel::validate ( std::vector< GMatrix * > &  validationData,
bool  calibrateContext,
bool  monotonic,
double  multiplier 
)

Computes the mean squared error with respect to some test sequence of actions and observations.

void GClasses::GRecurrentModel::validateDuringTraining ( double  timeInterval,
std::vector< GMatrix * > *  pValidationData 
)

Perform validation at periodic intervals with the specified data during training. Results are passed to the onObtainValidationScore method. pValidationData should refer to some number of validation data pairs, where each validation data pair is an observation dataset followed by an action dataset.

Member Data Documentation

size_t GClasses::GRecurrentModel::m_actionDims
protected
size_t GClasses::GRecurrentModel::m_channels
protected
size_t GClasses::GRecurrentModel::m_contextDims
protected
double GClasses::GRecurrentModel::m_multiplier
protected
size_t GClasses::GRecurrentModel::m_obsDims
protected
size_t GClasses::GRecurrentModel::m_paramDims
protected
double* GClasses::GRecurrentModel::m_pBuf
protected
double* GClasses::GRecurrentModel::m_pContext
protected
size_t GClasses::GRecurrentModel::m_pixels
protected
GSupervisedLearner* GClasses::GRecurrentModel::m_pObservationFunc
protected
size_t* GClasses::GRecurrentModel::m_pParamRanges
protected
double* GClasses::GRecurrentModel::m_pParams
protected
GRand* GClasses::GRecurrentModel::m_pRand
protected
GSupervisedLearner* GClasses::GRecurrentModel::m_pTransitionFunc
protected
std::vector<GMatrix*>* GClasses::GRecurrentModel::m_pValidationData
protected
double GClasses::GRecurrentModel::m_trainingSeconds
protected
bool GClasses::GRecurrentModel::m_transitionDelta
protected
bool GClasses::GRecurrentModel::m_useIsomap
protected
double GClasses::GRecurrentModel::m_validationInterval
protected