PLearn 0.1
ObservationWindow.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // ObservationWindow.h
00003 // 
00004 // Copyright (C) 2006 Christian Dorion
00005 // Copyright (C) 2006 ApStat Technologies Inc.
00006 // Copyright (C) 2007 Xavier Saint-Mleux, ApSTAT Technologies inc.
00007 // 
00008 // Redistribution and use in source and binary forms, with or without
00009 // modification, are permitted provided that the following conditions are met:
00010 // 
00011 //  1. Redistributions of source code must retain the above copyright
00012 //     notice, this list of conditions and the following disclaimer.
00013 // 
00014 //  2. Redistributions in binary form must reproduce the above copyright
00015 //     notice, this list of conditions and the following disclaimer in the
00016 //     documentation and/or other materials provided with the distribution.
00017 // 
00018 //  3. The name of the authors may not be used to endorse or promote
00019 //     products derived from this software without specific prior written
00020 //     permission.
00021 // 
00022 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
00023 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00024 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
00025 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00027 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00028 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00029 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00030 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00031 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032 // 
00033 // This file is part of the PLearn library. For more information on the PLearn
00034 // library, go to the PLearn Web site at www.plearn.org
00035 
00037 #ifndef ObservationWindow_INC
00038 #define ObservationWindow_INC
00039 
00040 // From PLearn
00041 #include <plearn/base/Object.h>
00042 #include <plearn/base/PP.h>
00043 #include <plearn/base/tuple.h>
00044 #include <plearn/math/TVec.h>
00045 
00046 // From C++ stdlib
00047 #include <map>
00048 
00049 namespace PLearn {
00050 using namespace std;
00051 
00058 class ObservationWindow: public Object
00059 {
00060     typedef Object inherited;
00061 
00062 public:    
00063     int m_window;
00064 
00065     int m_nobs;
00066     int m_cursor;
00067     Mat m_observations;
00068     Vec m_obs_weights;    
00069     bool unlimited_size;
00070 
00071     tuple<Vec, real> m_last_update_rvalue;
00072     
00073     ObservationWindow(int window=-1);// -2 means unlimited size
00074 
00076     int  length () const;
00077     bool isEmpty() const { return length() == 0; }
00078     bool isFull () const { return length() == m_window; }
00079     
00080     void forget();
00081     tuple<Vec, real> update(const Vec& obs, real weight=1.0);
00082 
00084     const Vec   getObs   (int t)          const;
00085           real  getObs   (int t, int col) const;
00086           real  getWeight(int t)          const;
00087     
00088     const Vec lastObs() const;
00089     real lastWeight() const;
00090 
00091     //TBA: // Get the min/max value in a column
00092     //TBA: void columnMin(int col, real& min, real& agemin) const;
00093     //TBA: void columnMax(int col, real& max, real& agemax) const;
00094 
00095     //#####  PLearn::Object Protocol  #########################################
00096 
00097     // Declares other standard object methods.
00098     // ### If your class is not instantiatable (it has pure virtual methods)
00099     // ### you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT
00100     PLEARN_DECLARE_OBJECT(ObservationWindow);
00101 
00102     // Simply calls inherited::build() then build_()
00103     virtual void build();
00104 
00106     // (PLEASE IMPLEMENT IN .cc)
00107     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00108 
00110     //ObservationWindow* deepCopy(CopiesMap& copies) const;
00111 
00112 protected:
00113     //#####  Protected Member Functions  ######################################
00114 
00116     // (PLEASE IMPLEMENT IN .cc)
00117     static void declareOptions(OptionList& ol);
00118 
00119 private:
00120     //#####  Private Member Functions  ########################################
00121 
00123     // (PLEASE IMPLEMENT IN .cc)
00124     void build_();
00125 
00126 
00127 };
00128 
00129 /*
00130 inline PStream& operator<<(PStream& out, const ObservationWindow& win)
00131 {
00132     out << "ObservationWindow(len=" << win.length() << ", window=" << win.m_window << ")";
00133     return out;
00134 }
00135 
00136 inline PStream& operator<<(PStream& out, const ObservationWindow* win)
00137 {
00138     out << *win;
00139     return out;
00140 }
00141 */
00142 
00143 DECLARE_OBJECT_PTR(ObservationWindow);
00144 
00145 } // end of namespace PLearn
00146 
00147 #endif
00148 
00149 
00150 /*
00151   Local Variables:
00152   mode:c++
00153   c-basic-offset:4
00154   c-file-style:"stroustrup"
00155   c-file-offsets:((innamespace . 0)(inline-open . 0))
00156   indent-tabs-mode:nil
00157   fill-column:79
00158   End:
00159 */
00160 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines