incremental_sgd.h

Go to the documentation of this file.
00001 #ifndef INCREMENTAL_SGD_H
00002 #define INCREMENTAL_SGD_H
00003 
00004 #include "model.h"
00005 #include "reservoir.h"
00006 #include <cmath>
00007 
00008 const int RESERVOIR_ITERATIONS = 3;
00009 
00014 // template parameter is the kind of updates that one takes.
00015 template<class T>
00016 class IncrementalSGD {
00017  protected:
00019   double lambda;
00020   
00022   struct model _m;
00028   void oneStep(double y, T ex); 
00029  public:
00035   IncrementalSGD(int dim, double l);
00036   
00037   void resetModel();
00038 
00039   /*
00040    * We want the model to be copied in, so it's not passed by reference.
00041    * \param[in] m model to be copied
00042    */
00043   void setModel(model m) { _m = m; }
00048   struct model& getModel() { return _m; }
00049   
00058   bool virtual addExample(int y, T ex) = 0;
00059   
00063   virtual ~IncrementalSGD() { } 
00064   
00070   bool classifyExample(T f);
00071   
00078   static double classifyExample(struct model &m, T x) {
00079     return dot(m.w,x) * m.wscale + m.bias;
00080   }
00081 };
00082 
00086 template<class T>
00087 class TrueSGD : public IncrementalSGD<T> {
00088  public:
00094  TrueSGD(int dim,double lambda) : IncrementalSGD<T>(dim,lambda) { } 
00101   bool addExample(int y, T ex);
00102 };
00103 
00109 template<class T> 
00110 class ReservoirSGD : public IncrementalSGD<T> {
00111   Reservoir<T> _r;
00112  public:
00119  ReservoirSGD(int dim, double lambda, int _rsize) : IncrementalSGD<T>(dim, lambda),_r(_rsize)  { } 
00124   bool isFull() { return _r.isFull(); } // useful as a fast path
00131   bool addExample(int y, T ex);
00132 };
00133 
00134 #include "incremental_sgd.hxx"
00135 
00136 #endif

Generated on Wed Dec 15 10:46:15 2010 for Hazy_System by  doxygen 1.4.7