PetaVision  Alpha
Retina.hpp
1 /*
2  * Retina.h
3  *
4  * Created on: Jul 29, 2008
5  *
6  */
7 
8 #ifndef RETINA_HPP_
9 #define RETINA_HPP_
10 
11 #include "HyPerLayer.hpp"
12 //#include "../kernels/Retina_params.h"
13 #include "../include/pv_types.h"
14 #include "../io/fileio.hpp"
15 #include "columns/Random.hpp"
16 
17 #define NUM_RETINA_CHANNELS 2
18 #define NUM_RETINA_EVENTS 3
19 //#define EV_R_PHI_E 0
20 //#define EV_R_PHI_I 1
21 //#define EV_R_ACTIVITY 2
22 
23 struct Retina_params {
24  float probStim;
25  float probBase;
26  double beginStim;
27  double endStim;
28  float burstFreq; // frequency of bursts
29  float burstDuration; // duration of each burst, <=0 -> sinusoidal
30 
31  float refractory_period;
32  float abs_refractory_period;
33 };
34 
35 namespace PV {
36 
37 class Retina : public PV::HyPerLayer {
38  public:
39  friend int test_kernels(int argc, char *argv[]);
40 
41  Retina(const char *name, HyPerCol *hc);
42  virtual ~Retina();
43  virtual Response::Status
44  communicateInitInfo(std::shared_ptr<CommunicateInitInfoMessage const> message) override;
45  virtual Response::Status allocateDataStructures() override;
46 
47  int setRetinaParams(PVParams *p);
48 
49  virtual Response::Status updateState(double time, double dt) override;
50 
51  virtual bool activityIsSpiking() override { return spikingFlag; }
52 
53  protected:
54  Retina();
55  int initialize(const char *name, HyPerCol *hc);
56  virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override;
57  virtual void ioParam_InitVType(enum ParamsIOFlag ioFlag) override;
58  virtual void ioParam_spikingFlag(enum ParamsIOFlag ioFlag);
59  virtual void ioParam_foregroundRate(enum ParamsIOFlag ioFlag);
60  virtual void ioParam_backgroundRate(enum ParamsIOFlag ioFlag);
61  virtual void ioParam_beginStim(enum ParamsIOFlag ioFlag);
62  virtual void ioParam_endStim(enum ParamsIOFlag ioFlag);
63  virtual void ioParam_burstFreq(enum ParamsIOFlag ioFlag);
64  virtual void ioParam_burstDuration(enum ParamsIOFlag ioFlag);
65  virtual void ioParam_refractoryPeriod(enum ParamsIOFlag ioFlag);
66  virtual void ioParam_absRefractoryPeriod(enum ParamsIOFlag ioFlag);
67  virtual void allocateV() override;
68  virtual Response::Status registerData(Checkpointer *checkpointer) override;
69  virtual void initializeV() override;
70  virtual void initializeActivity() override;
71  virtual Response::Status readStateFromCheckpoint(Checkpointer *checkpointer) override;
72  virtual void readRandStateFromCheckpoint(Checkpointer *checkpointer);
73 
74  bool spikingFlag; // specifies that layer is spiking
75  Retina_params rParams; // used in update state
76  Random *randState;
77  float probStimParam;
78  float probBaseParam;
79 
80  private:
81  int initialize_base();
82 
83  // For input from a given source input layer, determine which
84  // cells in this layer will respond to the input activity.
85  // Return the feature vectors for both the input and the sensitive
86  // neurons, since most likely we will have to determine those.
87  int findPostSynaptic(
88  int dim,
89  int maxSize,
90  int col,
91  // input: which layer, which neuron
92  HyPerLayer *lSource,
93  float pos[],
94  // output: how many of our neurons are connected.
95  // an array with their indices.
96  // an array with their feature vectors.
97  int *nNeurons,
98  int nConnectedNeurons[],
99  float *vPos);
100 
101  int calculateWeights(HyPerLayer *lSource, float *pos, float *vPos, float *vfWeights);
102 
103 }; // class Retina
104 
105 } // namespace PV
106 
107 #endif /* RETINA_HPP_ */