NeuralDecoder.H
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef MODELNEURON_NEURALDECODER_H_DEFINED
00040 #define MODELNEURON_NEURALDECODER_H_DEFINED
00041
00042 #include "Util/SimTime.H"
00043 #include "GenericUtils/GenericFactory.H"
00044 #include "GenericUtils/CreateFunctor.H"
00045
00046
00047
00048
00049
00050 class NeuralDecoder
00051 {
00052 public:
00053
00054 typedef CreateFunctor<NeuralDecoder, ParamList<SimTime> > Creator;
00055 typedef GenericFactory<NeuralDecoder, std::string, Creator> Factory;
00056
00057
00058 NeuralDecoder(const SimTime& timeStep = SimTime::MSECS(1.0),
00059 const SimTime& windowSize = SimTime::MSECS(100.0)) :
00060 itsWindowSize(windowSize),
00061 itsSamples( (uint)(itsWindowSize.secs()*timeStep.hertz()) ) { };
00062
00063
00064 virtual ~NeuralDecoder() { };
00065
00066
00067 virtual void push(const double& in) = 0;
00068
00069
00070 virtual const double getOutput() const = 0;
00071
00072
00073 virtual NeuralDecoder* clone() const = 0;
00074
00075
00076 virtual void reset() { };
00077
00078 protected:
00079
00080 NeuralDecoder(const NeuralDecoder& rhs);
00081 NeuralDecoder& operator=(const NeuralDecoder& rhs);
00082
00083 SimTime itsWindowSize;
00084 uint itsSamples;
00085 };
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 template <class Derived>
00105 class NeuralDecoderDerived : public NeuralDecoder
00106 {
00107 public:
00108 NeuralDecoder* clone() const
00109 { return new Derived(dynamic_cast<const Derived&>(*this)); };
00110
00111 protected:
00112 NeuralDecoderDerived(const SimTime& timeStep = SimTime::MSECS(1.0),
00113 const SimTime& windowSize = SimTime::MSECS(100.0)) :
00114 NeuralDecoder(timeStep, windowSize) { };
00115
00116 ~NeuralDecoderDerived() { };
00117 };
00118
00119
00120
00121
00122 class HoldDecoder: public NeuralDecoderDerived<HoldDecoder>
00123 {
00124 public:
00125
00126 HoldDecoder(const SimTime& timeStep = SimTime::MSECS(1.0),
00127 const SimTime& windowSize = SimTime::ZERO()) :
00128 NeuralDecoderDerived<HoldDecoder>(timeStep, windowSize), itsLastSpike(0.0),
00129 itsSignal(itsSamples, 0.0) { };
00130
00131
00132 ~HoldDecoder() { };
00133
00134
00135 void push(const double& in);
00136
00137
00138 const double getOutput() const;
00139
00140
00141 void reset();
00142
00143 private:
00144 double itsLastSpike;
00145 std::deque<double> itsSignal;
00146 };
00147
00148
00149
00150
00151 class HistDecoder: public NeuralDecoderDerived<HistDecoder>
00152 {
00153 public:
00154
00155 HistDecoder(const SimTime& timeStep = SimTime::MSECS(1.0),
00156 const SimTime& windowSize = SimTime::MSECS(100.0)) :
00157 NeuralDecoderDerived<HistDecoder>(timeStep,windowSize), itsSpikeCount(0),
00158 itsLastCount(0.0), itsSampleCount(0) { };
00159
00160
00161 ~HistDecoder() { };
00162
00163
00164 void push(const double& in);
00165
00166
00167 const double getOutput() const;
00168
00169
00170 void reset();
00171
00172 private:
00173 double itsSpikeCount, itsLastCount;
00174 uint itsSampleCount;
00175 };
00176
00177
00178
00179
00180 class RectDecoder: public NeuralDecoderDerived<RectDecoder>
00181 {
00182 public:
00183
00184 RectDecoder(const SimTime& timeStep = SimTime::MSECS(1.0),
00185 const SimTime& windowSize = SimTime::MSECS(100.0)) :
00186 NeuralDecoderDerived<RectDecoder>(timeStep, windowSize),
00187 itsSpikeRate(0.0), itsSignal(itsSamples, 0.0) { };
00188
00189
00190 ~RectDecoder() { };
00191
00192
00193 void push(const double& in);
00194
00195
00196 const double getOutput() const;
00197
00198
00199 void reset();
00200
00201 private:
00202 double itsSpikeRate;
00203 std::deque<double> itsSignal;
00204 };
00205
00206
00207
00208
00209 class ExpDecoder: public NeuralDecoderDerived<ExpDecoder>
00210 {
00211 public:
00212
00213 ExpDecoder(const SimTime& timeStep = SimTime::MSECS(1.0),
00214 const SimTime& windowSize = SimTime::MSECS(100.0),
00215 const double& alpha = 0.99) :
00216 NeuralDecoderDerived<ExpDecoder>(timeStep,windowSize), itsSpikeRate(0.0),
00217 itsAlpha(alpha) { };
00218
00219
00220 ~ExpDecoder() { };
00221
00222
00223 void push(const double& in);
00224
00225
00226 const double getOutput() const;
00227
00228
00229 void reset();
00230
00231 private:
00232 double itsSpikeRate;
00233 double itsAlpha;
00234 };
00235
00236
00237
00238
00239 class AlphaDecoder: public NeuralDecoderDerived<AlphaDecoder>
00240 {
00241 public:
00242
00243
00244
00245 AlphaDecoder(const SimTime& timeStep = SimTime::MSECS(1.0),
00246 const SimTime& windowSize = SimTime::MSECS(15.0));
00247
00248 ~AlphaDecoder() { };
00249
00250
00251 void push(const double& in);
00252
00253
00254 const double getOutput() const;
00255
00256
00257 void reset();
00258
00259 private:
00260 std::deque<double> itsSignal;
00261 std::vector<double> itsKernel;
00262 };
00263
00264
00265
00266
00267 namespace
00268 {
00269 typedef NeuralDecoder::Factory NDFactory;
00270 typedef NeuralDecoder::Creator NDCreator;
00271
00272 struct RegisterNeuralDecoder
00273 {
00274 RegisterNeuralDecoder()
00275 {
00276 const SimTime time = SimTime::MSECS(1.0);
00277 NDFactory::instance().add("HoldDecoder", NDCreator::make<HoldDecoder>(time));
00278 NDFactory::instance().add("HistDecoder", NDCreator::make<HistDecoder>(time));
00279 NDFactory::instance().add("RectDecoder", NDCreator::make<RectDecoder>(time));
00280 NDFactory::instance().add("ExpDecoder", NDCreator::make<ExpDecoder>(time));
00281 NDFactory::instance().add("AlphaDecoder", NDCreator::make<AlphaDecoder>(time));
00282 }
00283 };
00284 static RegisterNeuralDecoder registerneuraldecoder;
00285 }
00286
00287 #endif
00288
00289
00290
00291
00292
00293
00294
00295
00296