GClasses
|
This class can be used to implement recurrent neural networks, or recurrent forms of other supervised models. More...
#include <GSystemLearner.h>
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. | |
GRecurrentModel (GDomNode *pNode, GRand *pRand) | |
Load from a DOM. | |
virtual | ~GRecurrentModel () |
virtual GDomNode * | serialize (GDom *pDoc) |
See the comment for GSystemLearner::serialize. | |
GSupervisedLearner * | transitionFunc () |
Returns the transition function. | |
GSupervisedLearner * | observationFunc () |
Returns the observation function. | |
size_t | contextDims () |
Returns the number of dimensions in the context (state) vector. | |
double * | context () |
Returns a pointer to the context vector. | |
double * | params () |
size_t | obsDims () |
Returns the number of obs dims. | |
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. | |
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. | |
virtual void | onObtainValidationScore (size_t timeSlice, double seconds, double squaredError) |
If validateDuringTraining was called, then this method is called whenever validation data is obtained. | |
void | trainMoses (GMatrix *pActions, GMatrix *pObservations) |
Trains with the MOSES algorithm. (Calls onFinishedComputingStateEstimate when the state estimate is computed.) | |
void | trainAaron (GMatrix *pActions, GMatrix *pObservations) |
An experimental training technique. | |
void | trainJoshua (GMatrix *pActions, GMatrix *pObservations) |
An experimental training technique. | |
void | trainEvolutionary (GMatrix *pActions, GMatrix *pObservations) |
Trains with an evolutionary optimizer. | |
void | trainHillClimber (GMatrix *pActions, GMatrix *pObservations, double dev, double decay, double seconds, bool climb, bool anneal) |
Trains with a hill climber. | |
size_t | trainBackPropThroughTime (GMatrix *pActions, GMatrix *pObservations, size_t depth, size_t itersPerSeqLen) |
Trains with the back-prop-through-time algorithm. Returns the final sequence length. | |
size_t | paramDims () |
size_t * | paramRanges () |
virtual void | doAction (const double *pAction) |
See the comment for GSystemLearner::doAction. | |
virtual void | predict (double *pObs) |
See the comment for GSystemLearner::predict. | |
void | predictPixel (const double *pParams, double *pObs) |
virtual void | calibrate (const double *pObs) |
See the comment for GSystemLearner::calibrate. | |
GImage * | 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. | |
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. | |
double | quickValidate (GMatrix *pDataAction, GMatrix *pDataObs, size_t pixelSamples, double *paramArray, bool monotonic) |
Quickly compute an error estimate for use as an optimization heurisitic. | |
void | setUseIsomap (bool b) |
Specify whether to use Isomap (instead of BreadthFirstUnfolding). (This only applies when trainMoses is called.) | |
void | setTrainingSeconds (double d) |
Set the number of seconds to train. | |
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. | |
Protected Member Functions | |
GMatrix * | mosesEstimateState (GMatrix *pActions, GMatrix *pObservations) |
GMatrix * | joshuaEstimateState (GMatrix *pActions, GMatrix *pObservations) |
void | trainTransitionFunction (GMatrix *pActions, GMatrix *pEstState) |
void | trainObservationFunction (GMatrix *pEstState, GMatrix *pObservations) |
void | trainObservationFunctionIteratively (double dStart, GMatrix *pEstState, GMatrix *pObservations) |
void | prepareForOptimization (GMatrix *pActions, GMatrix *pObservations) |
Protected Attributes | |
size_t | m_actionDims |
size_t | m_contextDims |
size_t | m_obsDims |
size_t | m_pixels |
size_t | m_channels |
GSupervisedLearner * | m_pTransitionFunc |
GSupervisedLearner * | m_pObservationFunc |
size_t | m_paramDims |
size_t * | m_pParamRanges |
double * | m_pParams |
double * | m_pContext |
double * | m_pBuf |
bool | m_transitionDelta |
bool | m_useIsomap |
GRand * | m_pRand |
double | m_trainingSeconds |
double | m_validationInterval |
double | m_multiplier |
std::vector< GMatrix * > * | m_pValidationData |
This class can be used to implement recurrent neural networks, or recurrent forms of other supervised models.
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.
virtual GClasses::GRecurrentModel::~GRecurrentModel | ( | ) | [virtual] |
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 | ) | [inline, virtual] |
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.
virtual void GClasses::GRecurrentModel::onObtainValidationScore | ( | size_t | timeSlice, |
double | seconds, | ||
double | squaredError | ||
) | [inline, virtual] |
If validateDuringTraining was called, then this method is called whenever validation data is obtained.
size_t GClasses::GRecurrentModel::paramDims | ( | ) | [inline] |
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.
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.)
An experimental training technique.
size_t GClasses::GRecurrentModel::trainBackPropThroughTime | ( | GMatrix * | pActions, |
GMatrix * | pObservations, | ||
size_t | depth, | ||
size_t | itersPerSeqLen | ||
) |
Trains with the back-prop-through-time algorithm. Returns the final sequence length.
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.
An experimental training technique.
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.
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] |
size_t* GClasses::GRecurrentModel::m_pParamRanges [protected] |
double* GClasses::GRecurrentModel::m_pParams [protected] |
GRand* GClasses::GRecurrentModel::m_pRand [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] |