SingleStepDuration.h

Go to the documentation of this file.
00001 
00024 #ifndef _SINGLESTEPDURATION_H
00025 #define _SINGLESTEPDURATION_H
00026 
00027 #include "../Predictor.h"
00028 
00032 typedef struct {
00034 
00035         unsigned long duration; // the time until the transition to context will occur
00036         double probability;
00038 } next_context_description;
00039 
00041 typedef map<unsigned long, next_context_description> membershiplist_duration;
00042 
00046 class SingleStepDurationPredictor : public PredictorAlgorithm
00047 {
00048         private:
00050 
00051                 typedef vector<unsigned long> durationfrequencies;
00052                 typedef map<unsigned long, durationfrequencies> nextcontexts;
00053                 // for smoothening (which is equal to a convolution with a mask), we need to use floating point...
00054                 typedef map<unsigned long, vector<double> > nextcontexts_smoothened;
00055                 
00056                 static const unsigned startfrequencieslength = 20;
00057                 static const unsigned incrementfrequencieslength = 10;
00059 
00063                 struct contextinfo {
00065 
00066                         nextcontexts transitions;
00067                         // the number of times that this state was entered at all
00068                         unsigned long entries;
00069                         contextinfo() : entries(0) {}
00071                 };
00072 
00074 
00075                 map<unsigned long, contextinfo> frequencies;
00076                 unsigned long curContext;
00077                 unsigned long curDuration;
00078                 bool firstEntry;
00079 
00080                 // these are configurable
00081                 unsigned int smoothingWindowWidth;
00082                 double smoothingFactor;
00083                 double peakDifference;
00085 
00086         public:
00088                 SingleStepDurationPredictor(predictorparams &params);
00089 
00091                 unsigned long getCurrentContextDuration() const;
00093                 membershiplist_duration getNextContextsWithDuration(unsigned int offset=0) const;
00094                 // this method is more flexible, the previous one is just a wrapper around it
00095                 // this one can be used to specify the context and duration to start at (which is used in conjunction with the ALZ predictor, which supplies the new context -- see main-prediction.cpp)
00096                 membershiplist_duration getNextContextsWithDuration(unsigned long startContext, unsigned long startDuration, unsigned int offset=0) const;
00097 
00098                 virtual void addContexts(const membershiplist* contexts, time_t time);
00099                 virtual void addContext(unsigned long contextId, time_t time);
00100 
00101                 virtual unsigned long getNextContext() const;
00102                 virtual membershiplist getNextContexts() const;
00103 
00104                 virtual contexttrajectory getContextTrajectory(unsigned int start, unsigned int end) const;
00105 
00106                 virtual unsigned long getContextAt(time_t time) const;
00107                 virtual membershiplist getContextsAt(time_t time) const;
00108 
00109                 virtual string serialize() const;
00110                 virtual void unserialize(string data);
00111 
00112 #if _DEBUG_PREDICTORS
00113                 virtual string toString() const;
00114 #endif
00115 };
00116 
00117 #endif

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