PLearn 0.1
|
Used by StatsCollector to keep a finite-size window of observations. More...
#include <ObservationWindow.h>
Public Member Functions | |
ObservationWindow (int window=-1) | |
int | length () const |
Returns the current length (not m_window!). | |
bool | isEmpty () const |
bool | isFull () const |
void | forget () |
tuple< Vec, real > | update (const Vec &obs, real weight=1.0) |
const Vec | getObs (int t) const |
Intelligent accessors. | |
real | getObs (int t, int col) const |
real | getWeight (int t) const |
const Vec | lastObs () const |
real | lastWeight () const |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual ObservationWindow * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Post-constructor. | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
Static Public Member Functions | |
static string | _classname_ () |
static OptionList & | _getOptionList_ () |
static RemoteMethodMap & | _getRemoteMethodMap_ () |
static Object * | _new_instance_for_typemap_ () |
static bool | _isa_ (const Object *o) |
static void | _static_initialize_ () |
static const PPath & | declaringFile () |
Public Attributes | |
int | m_window |
int | m_nobs |
int | m_cursor |
Mat | m_observations |
Vec | m_obs_weights |
bool | unlimited_size |
tuple< Vec, real > | m_last_update_rvalue |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Deep copying. | |
Private Types | |
typedef Object | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Used by StatsCollector to keep a finite-size window of observations.
This allows StatsCollector to compute finite-horizon moving averages, for instance.
Definition at line 58 of file ObservationWindow.h.
typedef Object PLearn::ObservationWindow::inherited [private] |
Reimplemented from PLearn::Object.
Definition at line 60 of file ObservationWindow.h.
PLearn::ObservationWindow::ObservationWindow | ( | int | window = -1 | ) |
Definition at line 50 of file ObservationWindow.cc.
References forget().
: m_window(window), unlimited_size(window == -2) { forget(); }
string PLearn::ObservationWindow::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 47 of file ObservationWindow.cc.
OptionList & PLearn::ObservationWindow::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 47 of file ObservationWindow.cc.
RemoteMethodMap & PLearn::ObservationWindow::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 47 of file ObservationWindow.cc.
Reimplemented from PLearn::Object.
Definition at line 47 of file ObservationWindow.cc.
Object * PLearn::ObservationWindow::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 47 of file ObservationWindow.cc.
StaticInitializer ObservationWindow::_static_initializer_ & PLearn::ObservationWindow::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 47 of file ObservationWindow.cc.
void PLearn::ObservationWindow::build | ( | ) | [virtual] |
Post-constructor.
The normal implementation should call simply inherited::build(), then this class's build_(). This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.
Reimplemented from PLearn::Object.
Definition at line 58 of file ObservationWindow.cc.
References PLearn::Object::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::ObservationWindow::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::Object.
Definition at line 127 of file ObservationWindow.cc.
Referenced by build().
{ // ### This method should do the real building of the object, // ### according to set 'options', in *any* situation. // ### Typical situations include: // ### - Initial building of an object from a few user-specified options // ### - Building of a "reloaded" object: i.e. from the complete set of // ### all serialised options. // ### - Updating or "re-building" of an object after a few "tuning" // ### options have been modified. // ### You should assume that the parent class' build_() has already been // ### called. }
string PLearn::ObservationWindow::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 47 of file ObservationWindow.cc.
void PLearn::ObservationWindow::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Deep copying.
Declares the class options.
Reimplemented from PLearn::Object.
Definition at line 83 of file ObservationWindow.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::Object::declareOptions(), PLearn::OptionBase::learntoption, m_cursor, m_last_update_rvalue, m_nobs, m_obs_weights, m_observations, m_window, PLearn::OptionBase::nosave, and PLearn::OptionBase::remotetransmit.
{ // ### Declare all of this object's options here. // ### For the "flags" of each option, you should typically specify // ### one of OptionBase::buildoption, OptionBase::learntoption or // ### OptionBase::tuningoption. If you don't provide one of these three, // ### this option will be ignored when loading values from a script. // ### You can also combine flags, for example with OptionBase::nosave: // ### (OptionBase::buildoption | OptionBase::nosave) // ### ex: // declareOption(ol, "myoption", &ObservationWindow::myoption, // OptionBase::buildoption, // "Help text describing this option"); // ... declareOption(ol, "window", &ObservationWindow::m_window, OptionBase::buildoption, "Window length"); declareOption(ol, "nobs", &ObservationWindow::m_nobs, OptionBase::learntoption, "nb. observations"); declareOption(ol, "cursor", &ObservationWindow::m_cursor, OptionBase::learntoption | OptionBase::nosave | OptionBase::remotetransmit, "cursor pos."); declareOption(ol, "observations", &ObservationWindow::m_observations, OptionBase::learntoption | OptionBase::nosave | OptionBase::remotetransmit, "the observations themselves"); declareOption(ol, "obs_weights", &ObservationWindow::m_obs_weights, OptionBase::learntoption | OptionBase::nosave | OptionBase::remotetransmit, "observation weights"); declareOption(ol, "last_update_rvalue", &ObservationWindow::m_last_update_rvalue, OptionBase::learntoption | OptionBase::nosave | OptionBase::remotetransmit, "last_update_rvalue"); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::ObservationWindow::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::Object.
Definition at line 100 of file ObservationWindow.h.
:
//##### Protected Member Functions ######################################
ObservationWindow * PLearn::ObservationWindow::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 47 of file ObservationWindow.cc.
void PLearn::ObservationWindow::forget | ( | ) |
Definition at line 148 of file ObservationWindow.cc.
References m_cursor, m_nobs, m_observations, m_window, PLearn::TMat< T >::resize(), and unlimited_size.
Referenced by ObservationWindow().
{ m_nobs = 0; m_cursor = 0; if(unlimited_size) m_window= 0; else if(m_window >= 0) m_observations.resize(m_window, 0); m_observations.resize(0, 0); }
Intelligent accessors.
Definition at line 188 of file ObservationWindow.cc.
References length(), m_cursor, m_observations, m_window, and PLASSERT.
{ PLASSERT( t < m_window ); if ( length() < m_window ) return m_observations(t); int obs_index = (m_cursor+t) % m_window; return m_observations(obs_index); }
Definition at line 198 of file ObservationWindow.cc.
References length(), m_cursor, m_observations, m_window, and PLASSERT.
{ PLASSERT( t < m_window ); if ( length() < m_window ) return m_observations(t, col); int obs_index = (m_cursor+t) % m_window; return m_observations(obs_index, col); }
OptionList & PLearn::ObservationWindow::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 47 of file ObservationWindow.cc.
OptionMap & PLearn::ObservationWindow::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 47 of file ObservationWindow.cc.
RemoteMethodMap & PLearn::ObservationWindow::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 47 of file ObservationWindow.cc.
Definition at line 208 of file ObservationWindow.cc.
References length(), m_cursor, m_obs_weights, m_window, and PLASSERT.
{ PLASSERT( t < m_window ); if ( length() < m_window ) return m_obs_weights[t]; int obs_index = (m_cursor+t) % m_window; return m_obs_weights[obs_index]; }
bool PLearn::ObservationWindow::isEmpty | ( | ) | const [inline] |
Definition at line 77 of file ObservationWindow.h.
{ return length() == 0; }
bool PLearn::ObservationWindow::isFull | ( | ) | const [inline] |
Definition at line 78 of file ObservationWindow.h.
const Vec PLearn::ObservationWindow::lastObs | ( | ) | const |
Definition at line 218 of file ObservationWindow.cc.
References m_cursor, m_observations, and m_window.
{ int last_obs = (m_cursor-1) % m_window; return m_observations(last_obs); }
real PLearn::ObservationWindow::lastWeight | ( | ) | const |
Definition at line 224 of file ObservationWindow.cc.
References m_cursor, m_obs_weights, and m_window.
{ int last_obs = (m_cursor-1) % m_window; return m_obs_weights[last_obs]; }
int PLearn::ObservationWindow::length | ( | ) | const |
Returns the current length (not m_window!).
Definition at line 143 of file ObservationWindow.cc.
References PLearn::TMat< T >::length(), and m_observations.
Referenced by getObs(), and getWeight().
{ return m_observations.length(); }
void PLearn::ObservationWindow::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::Object.
Definition at line 64 of file ObservationWindow.cc.
References PLearn::deepCopyField(), m_last_update_rvalue, m_obs_weights, m_observations, and PLearn::Object::makeDeepCopyFromShallowCopy().
{ inherited::makeDeepCopyFromShallowCopy(copies); // ### Call deepCopyField on all "pointer-like" fields // ### that you wish to be deepCopied rather than // ### shallow-copied. // ### ex: // deepCopyField(trainvec, copies); // ### Remove this line when you have fully implemented this method. //PLERROR("ObservationWindow::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); deepCopyField(m_observations, copies); deepCopyField(m_obs_weights, copies); deepCopyField(m_last_update_rvalue, copies); }
Definition at line 160 of file ObservationWindow.cc.
References m_cursor, m_last_update_rvalue, m_nobs, m_obs_weights, m_observations, m_window, MIN, PLASSERT, PLearn::TVec< T >::resize(), PLearn::TMat< T >::resize(), PLearn::TVec< T >::size(), and unlimited_size.
{ Vec outdated; real outdated_weight = 0.0; ++m_nobs; if(unlimited_size) m_window= m_nobs; int new_size= MIN(m_nobs,m_window); int extra= unlimited_size? new_size : 0;//extra rows to alloc. when resizing m_observations.resize(new_size, obs.size(), extra*obs.size()); m_obs_weights.resize(new_size, extra); if (m_nobs > m_window) { outdated.resize(obs.size()); outdated << m_observations(m_cursor % m_window); outdated_weight = m_obs_weights[m_cursor % m_window]; m_nobs--; } m_observations(m_cursor % m_window) << obs; m_obs_weights[m_cursor % m_window] = weight; m_cursor++; PLASSERT( m_nobs <= m_window ); m_last_update_rvalue = tuple<Vec, real>(outdated, outdated_weight); return m_last_update_rvalue; }
Reimplemented from PLearn::Object.
Definition at line 100 of file ObservationWindow.h.
Definition at line 66 of file ObservationWindow.h.
Referenced by declareOptions(), forget(), getObs(), getWeight(), lastObs(), lastWeight(), and update().
Definition at line 71 of file ObservationWindow.h.
Referenced by declareOptions(), makeDeepCopyFromShallowCopy(), and update().
Definition at line 65 of file ObservationWindow.h.
Referenced by declareOptions(), forget(), and update().
Definition at line 68 of file ObservationWindow.h.
Referenced by declareOptions(), getWeight(), lastWeight(), makeDeepCopyFromShallowCopy(), and update().
Definition at line 67 of file ObservationWindow.h.
Referenced by declareOptions(), forget(), getObs(), lastObs(), length(), makeDeepCopyFromShallowCopy(), and update().
Definition at line 63 of file ObservationWindow.h.
Referenced by declareOptions(), forget(), getObs(), getWeight(), lastObs(), lastWeight(), and update().
Definition at line 69 of file ObservationWindow.h.