PetaVision  Alpha
ANNLayer.hpp
1 /*
2  * ANNLayer.hpp
3  *
4  * Created on: Dec 21, 2010
5  * Author: pschultz
6  */
7 
8 #ifndef ANNLAYER_HPP_
9 #define ANNLAYER_HPP_
10 
11 #include "HyPerLayer.hpp"
12 #include <limits>
13 
14 #define NUM_ANN_EVENTS 3
15 #define EV_ANN_ACTIVITY 2
16 
17 namespace PV {
18 
19 class ANNLayer : public HyPerLayer {
20  public:
21  ANNLayer(const char *name, HyPerCol *hc);
22  virtual ~ANNLayer();
23 
30  bool layerListsVerticesInParams() const { return verticesListInParams; }
31 
32  float getVThresh() const { return VThresh; }
33  float getAMax() const { return AMax; }
34  float getAMin() const { return AMin; }
35  float getAShift() const { return AShift; }
36  float getVWidth() const { return VWidth; }
37 
41  int getNumVertices() const { return numVertices; }
42 
47  float getVertexV(int n) const {
48  if (n >= 0 && n < numVertices) {
49  return verticesV[n];
50  }
51  else {
52  return nan("");
53  }
54  }
55 
60  float getVertexA(int n) const {
61  if (n >= 0 && n < numVertices) {
62  return verticesA[n];
63  }
64  else {
65  return nan("");
66  }
67  }
68  float getSlopeNegInf() const { return slopeNegInf; }
69  float getSlopePosInf() const { return slopePosInf; }
70 
71  virtual bool activityIsSpiking() override { return false; }
72 
73  protected:
74  ANNLayer();
75  int initialize(const char *name, HyPerCol *hc);
76  virtual Response::Status updateState(double time, double dt) override;
77  virtual int setActivity() override;
78 
79  virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override;
80 
96  virtual void ioParam_verticesV(enum ParamsIOFlag ioFlag);
97 
105  virtual void ioParam_verticesA(enum ParamsIOFlag ioFlag);
106 
114  virtual void ioParam_slopeNegInf(enum ParamsIOFlag ioFlag);
115 
123  virtual void ioParam_slopePosInf(enum ParamsIOFlag ioFlag);
124 
131  virtual void ioParam_VThresh(enum ParamsIOFlag ioFlag);
132 
138  virtual void ioParam_AMin(enum ParamsIOFlag ioFlag);
139 
145  virtual void ioParam_AMax(enum ParamsIOFlag ioFlag);
146 
152  virtual void ioParam_AShift(enum ParamsIOFlag ioFlag);
153 
161  virtual void ioParam_VWidth(enum ParamsIOFlag ioFlag);
162 
169  virtual int setVertices();
170 
179  virtual int checkVertices() const;
180 
185  void setSlopes();
186 
187  virtual int resetGSynBuffers(double timef, double dt) override;
188 
189  // Data members, initialized to default values.
190  bool verticesListInParams =
191  false; // True if verticesV/verticesA were specified in params explicitly; false otherwise
192  int numVertices = 0;
193  float *verticesV = nullptr;
194  float *verticesA = nullptr;
195  float *slopes = nullptr; // slopes[0]=slopeNegInf; slopes[numVertices]=slopePosInf;
196  // slopes[k]=slope from vertex k-1 to vertex k
197  float slopeNegInf = 1.0f;
198  float slopePosInf = 1.0f;
199 
200  float VThresh = -FLT_MAX; // threshold potential, values smaller than VThresh are set to AMin
201  float AMax = FLT_MAX; // maximum membrane potential, larger values are set to AMax
202  float AMin = -FLT_MAX; // minimum membrane potential, smaller values are set to AMin
203  float AShift =
204  (float)0; // shift potential, values above VThresh are shifted downward by this amount
205  // AShift == 0, hard threshold condition
206  // AShift == VThresh, soft threshold condition
207  float VWidth = (float)0; // The thresholding occurs linearly over the region
208  // [VThresh,VThresh+VWidth]. VWidth=0,AShift=0 is standard
209  // hard-thresholding
210 
211  private:
212  int initialize_base();
213 }; // end of class ANNLayer
214 
215 } // end namespace PV
216 
217 #endif /* ANNLAYER_HPP_ */
virtual void ioParam_verticesV(enum ParamsIOFlag ioFlag)
verticesV: An array of membrane potentials at points where the transfer function jumps or changes slo...
Definition: ANNLayer.cpp:111
bool layerListsVerticesInParams() const
Definition: ANNLayer.hpp:30
virtual void ioParam_AShift(enum ParamsIOFlag ioFlag)
AShift: Only read if verticesV is absent. When membrane potential V is above the threshold VThresh...
Definition: ANNLayer.cpp:204
virtual void ioParam_slopeNegInf(enum ParamsIOFlag ioFlag)
slopeNegInf: The slope of the transfer function when x is less than the first element of verticesV...
Definition: ANNLayer.cpp:171
virtual void ioParam_verticesA(enum ParamsIOFlag ioFlag)
verticesA: An array of activities of points where the transfer function jumps or changes slope...
Definition: ANNLayer.cpp:141
float getVertexV(int n) const
Definition: ANNLayer.hpp:47
virtual void ioParam_AMin(enum ParamsIOFlag ioFlag)
AMin: Only read if verticesV is absent. When membrane potential V is below the threshold VThresh...
Definition: ANNLayer.cpp:188
void setSlopes()
Definition: ANNLayer.cpp:359
int getNumVertices() const
Definition: ANNLayer.hpp:41
virtual void ioParam_AMax(enum ParamsIOFlag ioFlag)
AMax: Only read if verticesV is absent. Activity that would otherwise be greater than AMax is truncat...
Definition: ANNLayer.cpp:199
virtual void ioParam_slopePosInf(enum ParamsIOFlag ioFlag)
slopePosInf: The slope of the transfer function when x is greater than the last element of verticesV...
Definition: ANNLayer.cpp:177
virtual void ioParam_VWidth(enum ParamsIOFlag ioFlag)
VWidth: Only read if verticesV is absent. When the membrane potential is between VThresh and VThresh+...
Definition: ANNLayer.cpp:209
virtual void ioParam_VThresh(enum ParamsIOFlag ioFlag)
VThresh: Only read if verticesV is absent. The threshold value for the membrane potential. Below this value, the output activity will be AMin. Above, it will obey the transfer function as specified by AMax, VWidth, and AShift. Default is -infinity.
Definition: ANNLayer.cpp:183
virtual int setVertices()
Definition: ANNLayer.cpp:214
virtual int checkVertices() const
Definition: ANNLayer.cpp:386
float getVertexA(int n) const
Definition: ANNLayer.hpp:60
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
Definition: ANNLayer.cpp:89