00001
00020 #ifndef AURESERVOIR_SIMULATE_H__
00021 #define AURESERVOIR_SIMULATE_H__
00022
00023 #include "utilities.h"
00024 #include "filter.h"
00025 #include "delaysum.h"
00026 #include <vector>
00027
00028 namespace aureservoir
00029 {
00030
00037 enum SimAlgorithm
00038 {
00039 SIM_STD,
00040 SIM_SQUARE,
00041 SIM_LI,
00042 SIM_BP,
00043 SIM_FILTER,
00044 SIM_FILTER2,
00045 SIM_FILTER_DS
00046 };
00047
00048 template <typename T> class ESN;
00049
00066 template <typename T>
00067 class SimBase
00068 {
00069 public:
00070
00072 SimBase(ESN<T> *esn);
00073
00075 virtual ~SimBase() {}
00076
00079 virtual SimBase<T> *clone(ESN<T> *esn) const = 0;
00080
00087 virtual void simulate(const typename ESN<T>::DEMatrix &in,
00088 typename ESN<T>::DEMatrix &out) = 0;
00089
00091 virtual void reallocate();
00092
00094
00095 virtual void setBPCutoffConst(T f1, T f2) throw(AUExcept);
00096 virtual void setBPCutoff(const typename ESN<T>::DEVector &f1,
00097 const typename ESN<T>::DEVector &f2)
00098 throw(AUExcept);
00099 virtual void setIIRCoeff(const typename DEMatrix<T>::Type &B,
00100 const typename DEMatrix<T>::Type &A,
00101 int series = 1) throw(AUExcept);
00102 virtual void initDelayLine(int index, const typename DEVector<T>::Type &initbuf)
00103 throw(AUExcept);
00104 virtual typename DEMatrix<T>::Type getDelays() throw(AUExcept);
00105 virtual typename DEVector<T>::Type &getDelayBuffer(int output, int nr)
00106 throw(AUExcept);
00108
00110 typename ESN<T>::DEMatrix last_out_;
00111
00113 typename ESN<T>::DEVector t_;
00114
00115 protected:
00116
00118 ESN<T> *esn_;
00119 };
00120
00134 template <typename T>
00135 class SimStd : public SimBase<T>
00136 {
00137 using SimBase<T>::esn_;
00138 using SimBase<T>::last_out_;
00139 using SimBase<T>::t_;
00140
00141 public:
00142 SimStd(ESN<T> *esn) : SimBase<T>(esn) {}
00143 virtual ~SimStd() {}
00144
00146 virtual SimStd<T> *clone(ESN<T> *esn) const
00147 {
00148 SimStd<T> *new_obj = new SimStd<T>(esn);
00149 new_obj->t_ = t_; new_obj->last_out_ = last_out_;
00150 return new_obj;
00151 }
00152
00155 virtual void simulate(const typename ESN<T>::DEMatrix &in,
00156 typename ESN<T>::DEMatrix &out);
00157 };
00158
00175 template <typename T>
00176 class SimLI : public SimBase<T>
00177 {
00178 using SimBase<T>::esn_;
00179 using SimBase<T>::last_out_;
00180 using SimBase<T>::t_;
00181
00182 public:
00183 SimLI(ESN<T> *esn) : SimBase<T>(esn) {}
00184 virtual ~SimLI() {}
00185
00187 virtual SimLI<T> *clone(ESN<T> *esn) const
00188 {
00189 SimLI<T> *new_obj = new SimLI<T>(esn);
00190 new_obj->t_ = t_; new_obj->last_out_ = last_out_;
00191 return new_obj;
00192 }
00193
00196 virtual void simulate(const typename ESN<T>::DEMatrix &in,
00197 typename ESN<T>::DEMatrix &out);
00198 };
00199
00232 template <typename T>
00233 class SimBP : public SimBase<T>
00234 {
00235 using SimBase<T>::esn_;
00236 using SimBase<T>::last_out_;
00237 using SimBase<T>::t_;
00238
00239 public:
00240 SimBP(ESN<T> *esn) : SimBase<T>(esn) {}
00241 virtual ~SimBP() {}
00242
00244 virtual SimBP<T> *clone(ESN<T> *esn) const
00245 {
00246 SimBP<T> *new_obj = new SimBP<T>(esn);
00247 new_obj->t_ = t_; new_obj->last_out_ = last_out_;
00248 new_obj->filter_ = filter_;
00249 return new_obj;
00250 }
00251
00253 virtual void setBPCutoffConst(T f1, T f2) throw(AUExcept);
00254
00256 virtual void setBPCutoff(const typename ESN<T>::DEVector &f1,
00257 const typename ESN<T>::DEVector &f2)
00258 throw(AUExcept);
00259
00262 virtual void simulate(const typename ESN<T>::DEMatrix &in,
00263 typename ESN<T>::DEMatrix &out);
00264
00266 BPFilter<T> filter_;
00267 };
00268
00298 template <typename T>
00299 class SimFilter : public SimBase<T>
00300 {
00301 using SimBase<T>::esn_;
00302 using SimBase<T>::last_out_;
00303 using SimBase<T>::t_;
00304
00305 public:
00306 SimFilter(ESN<T> *esn) : SimBase<T>(esn) {}
00307 virtual ~SimFilter() {}
00308
00310 virtual SimFilter<T> *clone(ESN<T> *esn) const
00311 {
00312 SimFilter<T> *new_obj = new SimFilter<T>(esn);
00313 new_obj->t_ = t_; new_obj->last_out_ = last_out_;
00314 new_obj->filter_ = filter_;
00315 return new_obj;
00316 }
00317
00330 virtual void setIIRCoeff(const typename DEMatrix<T>::Type &B,
00331 const typename DEMatrix<T>::Type &A,
00332 int series=1) throw(AUExcept);
00333
00336 virtual void simulate(const typename ESN<T>::DEMatrix &in,
00337 typename ESN<T>::DEMatrix &out);
00338
00340 SerialIIRFilter<T> filter_;
00341 };
00342
00354 template <typename T>
00355 class SimFilter2 : public SimFilter<T>
00356 {
00357 using SimBase<T>::esn_;
00358 using SimBase<T>::last_out_;
00359 using SimBase<T>::t_;
00360 using SimFilter<T>::filter_;
00361
00362 public:
00363 SimFilter2(ESN<T> *esn) : SimFilter<T>(esn) {}
00364 virtual ~SimFilter2() {}
00365
00367 virtual SimFilter2<T> *clone(ESN<T> *esn) const
00368 {
00369 SimFilter2<T> *new_obj = new SimFilter2<T>(esn);
00370 new_obj->t_ = t_; new_obj->last_out_ = last_out_;
00371 new_obj->filter_ = filter_;
00372 return new_obj;
00373 }
00374
00377 virtual void simulate(const typename ESN<T>::DEMatrix &in,
00378 typename ESN<T>::DEMatrix &out);
00379 };
00380
00401 template <typename T>
00402 class SimFilterDS : public SimFilter<T>
00403 {
00404 using SimBase<T>::esn_;
00405 using SimBase<T>::last_out_;
00406 using SimBase<T>::t_;
00407 using SimFilter<T>::filter_;
00408
00409 public:
00410 SimFilterDS(ESN<T> *esn) : SimFilter<T>(esn) {}
00411 virtual ~SimFilterDS() {}
00412
00414 virtual SimFilterDS<T> *clone(ESN<T> *esn) const
00415 {
00416 SimFilterDS<T> *new_obj = new SimFilterDS<T>(esn);
00417 new_obj->t_ = t_; new_obj->last_out_ = last_out_;
00418 new_obj->filter_ = filter_; new_obj->dellines_ = dellines_;
00419 new_obj->intmp_ = intmp_;
00420 return new_obj;
00421 }
00422
00424 virtual void reallocate();
00425
00433 virtual void initDelayLine(int index,
00434 const typename DEVector<T>::Type &initbuf)
00435 throw(AUExcept);
00436
00442 virtual typename DEMatrix<T>::Type getDelays() throw(AUExcept);
00443
00449 virtual typename DEVector<T>::Type &getDelayBuffer(int output, int nr)
00450 throw(AUExcept);
00451
00454 virtual void simulate(const typename ESN<T>::DEMatrix &in,
00455 typename ESN<T>::DEMatrix &out);
00456
00457 protected:
00458
00460 std::vector< DelayLine<T> > dellines_;
00461
00463 typename ESN<T>::DEMatrix intmp_;
00464 };
00465
00482 template <typename T>
00483 class SimSquare : public SimFilterDS<T>
00484 {
00485 using SimBase<T>::esn_;
00486 using SimBase<T>::last_out_;
00487 using SimBase<T>::t_;
00488 using SimFilter<T>::filter_;
00489 using SimFilterDS<T>::dellines_;
00490 using SimFilterDS<T>::intmp_;
00491
00492 public:
00493 SimSquare(ESN<T> *esn) : SimFilterDS<T>(esn) {}
00494 virtual ~SimSquare() {}
00495
00497 virtual SimSquare<T> *clone(ESN<T> *esn) const
00498 {
00499 SimSquare<T> *new_obj = new SimSquare<T>(esn);
00500 new_obj->t_ = t_; new_obj->last_out_ = last_out_;
00501 new_obj->filter_ = filter_; new_obj->dellines_ = dellines_;
00502 new_obj->intmp_ = intmp_; new_obj->t2_ = t2_;
00503 new_obj->insq_ = insq_;
00504 return new_obj;
00505 }
00506
00508 virtual void reallocate();
00509
00512 virtual void simulate(const typename ESN<T>::DEMatrix &in,
00513 typename ESN<T>::DEMatrix &out);
00514 protected:
00516 typename ESN<T>::DEVector t2_;
00517 typename ESN<T>::DEVector insq_;
00518 };
00519
00520 }
00521
00522 #endif // AURESERVOIR_SIMULATE_H__