PetaVision  Alpha
InitWeights.hpp
1 /*
2  * InitWeights.hpp
3  *
4  * Created on: Aug 5, 2011
5  * Author: kpeterson
6  */
7 
8 #ifndef INITWEIGHTS_HPP_
9 #define INITWEIGHTS_HPP_
10 
11 #include "columns/BaseObject.hpp"
12 #include "components/WeightsPair.hpp"
13 #include "layers/HyPerLayer.hpp"
14 
15 namespace PV {
16 
17 class InitWeights : public BaseObject {
18  protected:
33  virtual void ioParam_weightInitType(enum ParamsIOFlag ioFlag);
34 
44  virtual void ioParam_initWeightsFile(enum ParamsIOFlag ioFlag);
45 
53  virtual void ioParam_frameNumber(enum ParamsIOFlag ioFlag);
54 
55  // useListOfArborFiles, combineWeightFiles, and numWeightFiles were marked obsolete July 13,
56  // 2017.
60  virtual void ioParam_useListOfArborFiles(enum ParamsIOFlag ioFlag);
61 
65  virtual void ioParam_combineWeightFiles(enum ParamsIOFlag ioFlag);
66 
70  virtual void ioParam_numWeightFiles(enum ParamsIOFlag ioFlag) {}
73  public:
74  InitWeights(char const *name, HyPerCol *hc);
75  virtual ~InitWeights();
76 
77  virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override;
78 
79  protected:
80  InitWeights();
81  int initialize(const char *name, HyPerCol *hc);
82  void handleObsoleteFlag(std::string const &flagName);
83 
84  virtual void setObjectType() override;
85 
86  virtual Response::Status
87  communicateInitInfo(std::shared_ptr<CommunicateInitInfoMessage const> message) override;
88 
89  /*
90  * initializeState checks initWeightsFile. If initWeightsFile is set, the weights are
91  * loaded from the file. If it is not set, it calls calcWeights with no arguments.
92  * Generally, derived classes should not override initializeState, but instead override
93  * one or both of the calcWeights methods, in order to preserve the initWeightsFile behavior.
94  */
95  virtual Response::Status initializeState() override;
96 
102  virtual void calcWeights();
103 
108  virtual void calcWeights(int dataPatchIndex, int arborId);
109 
110  virtual int readWeights(const char *filename, int frameNumber, double *timestampPtr = nullptr);
111 
112  virtual int initRNGs(bool isKernel) { return PV_SUCCESS; }
113 
114  int
115  dataIndexToUnitCellIndex(int dataIndex, int *kx = nullptr, int *ky = nullptr, int *kf = nullptr);
116  int kernelIndexCalculations(int patchIndex);
117  float calcYDelta(int jPost);
118  float calcXDelta(int iPost);
119  float calcDelta(int post, float dPost, float distHeadPreUnits);
120 
121  protected:
122  Weights *mWeights = nullptr; // initializeWeights sets this to the WeightsPair's PreWeights.
123 
124  char *mWeightInitTypeString = nullptr;
125 
126  char *mFilename = nullptr;
127  int mFrameNumber = 0;
128  float mDxPost;
129  float mDyPost;
130  float mXDistHeadPreUnits;
131  float mYDistHeadPreUnits;
132 
133 }; // class InitWeights
134 
135 } /* namespace PV */
136 #endif /* INITWEIGHTS_HPP_ */
virtual void ioParam_initWeightsFile(enum ParamsIOFlag ioFlag)
initWeightsFile: A path to a weight pvp file to use for initializing the weights, which overrides the...
Definition: InitWeights.cpp:55
virtual void ioParam_weightInitType(enum ParamsIOFlag ioFlag)
weightInitType: Specifies the type of weight initialization.
Definition: InitWeights.cpp:50
virtual void ioParam_numWeightFiles(enum ParamsIOFlag ioFlag)
numWeightFiles is obsolete.
Definition: InitWeights.hpp:70
virtual void ioParam_useListOfArborFiles(enum ParamsIOFlag ioFlag)
useListOfArborFiles is obsolete.
Definition: InitWeights.cpp:78
virtual void ioParam_frameNumber(enum ParamsIOFlag ioFlag)
frameNumber: If initWeightsFile is set, the frameNumber parameter selects which frame of the pvp file...
Definition: InitWeights.cpp:60
virtual void calcWeights()
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
Definition: InitWeights.cpp:39
virtual void ioParam_combineWeightFiles(enum ParamsIOFlag ioFlag)
combineWeightFiles is obsolete.
Definition: InitWeights.cpp:84