Predictor.h

Go to the documentation of this file.
00001 
00024 #ifndef _PREDICTOR_H
00025 #define _PREDICTOR_H
00026 
00027 #ifdef _PREDICTOR_EXPORT
00028 # define _FEATURE_EXPORT
00029 #endif
00030 #ifdef _PREDICTOR_EXPORT_CLASS
00031 # define _FEATURE_EXPORT_CLASS
00032 #endif
00033 
00034 #include "../Features/Feature.h"
00035 
00037 
00038 #define PREDICTOR_EXPORT FEATURE_EXPORT
00039 #define PREDICTOR_EXPORT_CLASS FEATURE_EXPORT_CLASS
00040 
00041 
00052 #define EXPORT_PREDICTOR(predictor) \
00053  \
00054         static predictor *pred; \
00055         void INIT_EXPORT library_initialize() { pred = NULL; } \
00056         void FINI_EXPORT library_finalize() { if (pred != NULL) delete pred; } \
00057  \
00063         extern "C" PREDICTOR_EXPORT PredictorAlgorithm* getPredictor(predictorparams &params) { if (pred == NULL) pred = new predictor(params); return pred; }
00064 
00077 typedef parametermap predictorparams;
00078 
00080 typedef vector<unsigned long> contexttrajectory;
00081 
00087 class PredictorAlgorithm {
00088         public:
00089                 virtual ~PredictorAlgorithm() {}
00090 
00091                 // add a single step to the model
00093                 virtual void addContexts(const membershiplist* contexts, time_t time) = 0;
00095                 virtual void addContext(unsigned long contextId, time_t time) = 0;
00096 
00097                 // this is single-step prediction
00099                 virtual unsigned long getNextContext() const = 0;
00101                 virtual membershiplist getNextContexts() const = 0;
00102 
00103                 // this is multi-step prediction
00104                 // the parameters ars start and end (in number of time steps) of the trajectory that should be predicted
00105                 // if no offset is necessary (the trajectory should be predicted from the current context), give 0 as start
00106                 // the returned vector will have a length of (end - start)
00108                 virtual contexttrajectory getContextTrajectory(unsigned int start, unsigned int end) const = 0;
00109 
00110                 // this is a prediction for specific points in time
00111                 // this will just return 0 if no prediction can be made (because no context is known until now)
00113                 virtual unsigned long getContextAt(time_t time) const = 0;
00114                 // this will return an empty list if no prediction can be made at all
00116                 virtual membershiplist getContextsAt(time_t time) const = 0;
00117 
00123                 virtual string serialize() const = 0;
00124 
00130                 virtual void unserialize(string data) = 0;
00131 
00132 #if _DEBUG_PREDICTORS
00133 
00134                 virtual string toString() const = 0;
00135 #endif
00136 };
00137 
00145 class Predictor : PredictorAlgorithm {
00146         private:
00148                 PredictorAlgorithm *pa;
00149 
00150 #if defined(_WIN32_WCE) || defined (_WINDOWS)
00151                 HMODULE dll;
00152 #else
00153 
00154                 void* dlHandle;
00155 #endif
00156 
00157         public:
00164                 Predictor(const string &name, const predictorparams &params);
00168                 virtual ~Predictor();
00169 
00170                 virtual void addContexts(const membershiplist* contexts, time_t time) { pa->addContexts(contexts, time); }
00171                 virtual void addContext(unsigned long contextId, time_t time) { pa->addContext(contextId, time); }
00172                 virtual unsigned long getNextContext() const { return pa->getNextContext(); }
00173                 virtual membershiplist getNextContexts() const { return pa->getNextContexts(); }
00174                 virtual unsigned long getContextAt(time_t time) const { return pa->getContextAt(time); }
00175                 virtual membershiplist getContextsAt(time_t time) const { return pa->getContextsAt(time); }
00176                 virtual string serialize() const { return pa->serialize(); }
00177                 virtual void unserialize(string data) { pa->unserialize(data); }
00178 };
00179 
00186 typedef PredictorAlgorithm* (*getPredictor_t) (const predictorparams &params);
00187 
00188 #endif

Generated on Mon Jun 5 10:20:42 2006 for Intelligence.kdevelop by  doxygen 1.4.6