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. 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... | |
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. More... | |
size_t | obsDims () |
Returns the number of obs dims. More... | |
GSupervisedLearner * | observationFunc () |
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 GDomNode * | serialize (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... | |
GSupervisedLearner * | transitionFunc () |
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... | |
![]() | |
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 | |
GMatrix * | joshuaEstimateState (GMatrix *pActions, GMatrix *pObservations) |
GMatrix * | mosesEstimateState (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) |
![]() | |
GDomNode * | baseDomNode (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 |
GSupervisedLearner * | m_pObservationFunc |
size_t * | m_pParamRanges |
double * | m_pParams |
GRand * | m_pRand |
GSupervisedLearner * | m_pTransitionFunc |
std::vector< GMatrix * > * | m_pValidationData |
double | m_trainingSeconds |
bool | m_transitionDelta |
bool | m_useIsomap |
double | m_validationInterval |
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 |
|
static |
Blur the image vector.
|
virtual |
See the comment for GSystemLearner::calibrate.
Implements GClasses::GSystemLearner.
|
inline |
Returns a pointer to the context vector.
|
inline |
Returns the number of dimensions in the context (state) vector.
|
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.
|
protected |
|
protected |
|
inline |
Returns the number of obs dims.
|
inline |
Returns the observation function.
|
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.
|
inlinevirtual |
If validateDuringTraining was called, then this method is called whenever validation data is obtained.
|
inline |
Trains with the back-prop-through-time algorithm. Returns the final sequence length.
|
inline |
|
inline |
|
virtual |
See the comment for GSystemLearner::predict.
Implements GClasses::GSystemLearner.
void GClasses::GRecurrentModel::predictPixel | ( | const double * | pParams, |
double * | pObs | ||
) |
|
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.
|
inline |
Set the number of seconds to train.
|
inline |
Specify whether to use Isomap (instead of BreadthFirstUnfolding). (This only applies when trainMoses is called.)
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.
Trains with the MOSES algorithm. (Calls onFinishedComputingStateEstimate when the state estimate is computed.)
|
protected |
|
protected |
|
protected |
|
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.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |