00001
00002 #ifndef DDF_UPD_LIN_PRED_HPP
00003 #define DDF_UPD_LIN_PRED_HPP
00004
00005 #include <BayesFilter/bayesFlt.hpp>
00006 #include <BayesFilter/infFlt.hpp>
00007
00008
00009 #include "debugging.hpp"
00010 #include "predictenginebase.hpp"
00011 #include "infocontainer.hpp"
00012 #include "tools.hpp"
00013 #include "ctime.hpp"
00014
00015 namespace jafar
00016 {
00017 namespace ddf
00018 {
00020 typedef enum {NEED_UPD_F, NEED_UPD_G, NEED_UPD_Q, NEED_UPD_END} NEED_UPD_TYPE;
00021
00033 template<typename PARAMS>
00034 class Upd_lin_pred_model : public Bayesian_filter::Linear_invertable_predict_model, virtual public PredictionEngineGeneric<PARAMS>
00035 {
00036 std::vector<bool> m_need_update;
00037 Bayesian_filter::Information_scheme m_info_engine;
00038 InfoContainer m_yY;
00039 SpeedUpInfoStruct m_sp;
00040 Bayesian_filter::Information_scheme::Linear_predict_byproducts m_products;
00041
00042 protected:
00043
00044 using PredictionEngineGeneric<PARAMS>::m_fs_storage;
00045 using PredictionEngineGeneric<PARAMS>::m_horizon;
00046 using PredictionEngineGeneric<PARAMS>::m_info_mutex;
00047 using PredictionEngineGeneric<PARAMS>::m_current_time;
00048 using PredictionEngineGeneric<PARAMS>::m_params;
00049 using PredictionEngineGeneric<PARAMS>::m_model_need_update;
00050 using PredictionEngineGeneric<PARAMS>::m_predict_available;
00051 using PredictionEngineGeneric<PARAMS>::m_store_fstate;
00052
00053
00054 virtual void UpdateF(PARAMS & param)=0;
00055 virtual void UpdateG(PARAMS & param)=0;
00056 virtual void Updateq(PARAMS & param)=0;
00057
00058
00059 public:
00060
00061 Upd_lin_pred_model(unsigned short sv_size, unsigned short q_size) :
00062 PredictionEngineGeneric<PARAMS>(),
00063 Linear_invertable_predict_model(sv_size, q_size),
00064 m_need_update(NEED_UPD_END),
00065 m_info_engine(sv_size),
00066 m_yY(sv_size),
00067 m_sp(sv_size,1,q_size),
00068 m_products(sv_size, q_size)
00069 {
00070
00071 m_products.A.clear(); m_products.B.clear();
00072 m_products.tempG.clear(); m_products.y.clear();
00073
00074 m_need_update.clear(); Constructor();
00075 }
00076
00077
00078 virtual ~Upd_lin_pred_model() {}
00079
00080
00081 unsigned short GetSvSize() { return m_info_engine.y.size(); }
00082 unsigned short GetqSize() { return q.size(); }
00083
00084 void SetNeedUpdate(NEED_UPD_TYPE what, bool needUpd) { JFR_PRECOND(what < NEED_UPD_END, "invalid field"); m_need_update[what] = needUpd; }
00085 void SetNoUpdate() { for(short w = 0; w < NEED_UPD_END; w++) m_need_update[w] = false; }
00086 std::vector<bool> const& GetNeedUpdate() const { return m_need_update; }
00087 bool IsUpdated(NEED_UPD_TYPE what) { JFR_PRECOND(what < NEED_UPD_END, "invalid field"); return m_need_update[what]; }
00088
00089
00090 bool IsPSD(bool use_mutex);
00091 void PrintModel();
00092 void Predict(time const& horizon);
00093 void Init(InfoContainer const& inityY);
00094 void InitState(VEC const& x, MSYM const& X);
00095 void InitInformation(VEC const& y, MSYM const& Y);
00096 InfoContainer const& GetPrediction();
00097 InfoContainer const& GetInversePrediction();
00098 void UpdatePredictionWith(InfoContainer const& info);
00099 void UpdateModel();
00100
00101 void PrintHistory();
00102 FSStorageBase<PARAMS> const& RecallStoredState(unsigned int idx) const {
00103 JFR_PRECOND(idx < m_fs_storage.size(), "index");
00104 return m_fs_storage[idx];
00105 }
00106
00107 void ClearHistory() { m_fs_storage.clear(); }
00108 unsigned short GetHistorySize() const { return m_fs_storage.size(); }
00109 bool InsertDelayedMeasure(InfoContainer const& ICont, time const& avail_time);
00110
00111 private:
00112 void Init();
00113 void StoreState(FS_STORE_TYPE fs_type);
00114 void StoreState(MSYM const& I, VEC const& i);
00115 void Constructor() { m_yY.ClearAll(); m_info_engine.y.clear(); m_info_engine.Y.clear(); m_info_engine.x.clear(); m_info_engine.X.clear(); }
00116 };
00117
00118 }
00119 }
00120
00121 #include "upd_lin_pred.tpp"
00122
00123 #endif