PetaVision  Alpha
HyPerConn.hpp
1 /*
2  * HyPerConn.hpp
3  *
4  *
5  * Created on: Oct 21, 2008
6  * Author: Craig Rasmussen
7  */
8 
9 #ifndef HYPERCONN_HPP_
10 #define HYPERCONN_HPP_
11 
12 #include "components/ArborList.hpp"
13 #include "components/ConnectionData.hpp"
14 #include "components/SharedWeights.hpp"
15 #include "components/WeightsPair.hpp"
16 #include "connections/BaseConnection.hpp"
17 #include "normalizers/NormalizeBase.hpp"
18 #include "weightinit/InitWeights.hpp"
19 #include "weightupdaters/BaseWeightUpdater.hpp"
20 
21 namespace PV {
22 
23 class HyPerCol;
24 
25 class HyPerConn : public BaseConnection {
26  public:
27  HyPerConn(char const *name, HyPerCol *hc);
28 
29  virtual ~HyPerConn();
30 
31  virtual Response::Status respond(std::shared_ptr<BaseMessage const> message) override;
32 
33  // get-methods for params
34  int getPatchSizeX() const { return mPatchSize->getPatchSizeX(); }
35  int getPatchSizeY() const { return mPatchSize->getPatchSizeY(); }
36  int getPatchSizeF() const { return mPatchSize->getPatchSizeF(); }
37  int getSharedWeights() const { return mSharedWeights->getSharedWeights(); }
38 
39  int getNumAxonalArbors() const { return mArborList->getNumAxonalArbors(); }
40  int getDelay(int arbor) const { return mArborList->getDelay(arbor); }
41 
42  int getStrength() const { return mWeightNormalizer->getStrength(); }
43 
44  // other get-methods
45  int getNumDataPatches() const { return mWeightsPair->getPreWeights()->getNumDataPatches(); }
46  int getNumGeometryPatches() const {
47  return mWeightsPair->getPreWeights()->getGeometry()->getNumPatches();
48  }
49  Patch const *getPatch(int kPre) { return &mWeightsPair->getPreWeights()->getPatch(kPre); }
50  float *getWeightsDataStart(int arbor) const {
51  return mWeightsPair->getPreWeights()->getData(arbor);
52  }
53  float *getWeightsDataHead(int arbor, int dataIndex) const {
54  return mWeightsPair->getPreWeights()->getDataFromDataIndex(arbor, dataIndex);
55  }
56  float *getWeightsData(int arbor, int patchIndex) {
57  auto *preWeights = mWeightsPair->getPreWeights();
58  return preWeights->getDataFromPatchIndex(arbor, patchIndex)
59  + preWeights->getPatch(patchIndex).offset;
60  }
61  float const *getDeltaWeightsDataStart(int arbor) const;
62  float const *getDeltaWeightsDataHead(int arbor, int dataIndex) const;
63  int getPatchStrideX() const { return mWeightsPair->getPreWeights()->getPatchStrideX(); }
64  int getPatchStrideY() const { return mWeightsPair->getPreWeights()->getPatchStrideY(); }
65  int getPatchStrideF() const { return mWeightsPair->getPreWeights()->getPatchStrideF(); }
66 
67  double getLastUpdateTime() const { return mWeightsPair->getPreWeights()->getTimestamp(); }
68 
69  int calcDataIndexFromPatchIndex(int patchIndex) {
70  return mWeightsPair->getPreWeights()->calcDataIndexFromPatchIndex(patchIndex);
71  }
72 
73  protected:
74  HyPerConn();
75 
76  int initialize(char const *name, HyPerCol *hc);
77 
78  virtual void defineComponents() override;
79 
80  virtual BaseDelivery *createDeliveryObject() override;
81  virtual ArborList *createArborList();
82  virtual PatchSize *createPatchSize();
83  virtual SharedWeights *createSharedWeights();
84  virtual WeightsPairInterface *createWeightsPair();
85  virtual InitWeights *createWeightInitializer();
86  virtual NormalizeBase *createWeightNormalizer();
87  virtual BaseWeightUpdater *createWeightUpdater();
88 
89  Response::Status respondConnectionUpdate(std::shared_ptr<ConnectionUpdateMessage const> message);
90 
91  Response::Status
92  respondConnectionNormalize(std::shared_ptr<ConnectionNormalizeMessage const> message);
93 
94  virtual Response::Status registerData(Checkpointer *checkpointer) override;
95 
96  virtual Response::Status initializeState() override;
97 
98  protected:
99  ArborList *mArborList = nullptr;
100  PatchSize *mPatchSize = nullptr;
101  SharedWeights *mSharedWeights = nullptr;
102  WeightsPairInterface *mWeightsPair = nullptr;
103  InitWeights *mWeightInitializer = nullptr;
104  NormalizeBase *mWeightNormalizer = nullptr;
105  BaseWeightUpdater *mWeightUpdater = nullptr;
106 
107  Timer *mUpdateTimer = nullptr;
108 
109 }; // class HyPerConn
110 
111 } // namespace PV
112 
113 #endif // HYPERCONN_HPP_
float * getData(int arbor)
Definition: Weights.cpp:196
int getPatchStrideF() const
Definition: Weights.hpp:236
int getNumDataPatches() const
Definition: Weights.hpp:174
Patch const & getPatch(int patchIndex) const
Definition: Weights.cpp:194
float * getDataFromDataIndex(int arbor, int dataIndex)
Definition: Weights.cpp:200
std::shared_ptr< PatchGeometry > getGeometry() const
Definition: Weights.hpp:148
int getPatchStrideY() const
Definition: Weights.hpp:248
int getNumAxonalArbors() const
Definition: ArborList.hpp:52
float * getDataFromPatchIndex(int arbor, int patchIndex)
Definition: Weights.cpp:205
double getTimestamp() const
Definition: Weights.hpp:216
int getPatchStrideX() const
Definition: Weights.hpp:242