PetaVision  Alpha
InitUniformWeights.cpp
1 /*
2  * InitUniformWeights.cpp
3  *
4  * Created on: Aug 23, 2011
5  * Author: kpeterson
6  */
7 
8 #include "InitUniformWeights.hpp"
9 
10 namespace PV {
11 
12 InitUniformWeights::InitUniformWeights(char const *name, HyPerCol *hc) { initialize(name, hc); }
13 
14 InitUniformWeights::InitUniformWeights() {}
15 
16 InitUniformWeights::~InitUniformWeights() {}
17 
18 int InitUniformWeights::initialize(char const *name, HyPerCol *hc) {
19  int status = InitWeights::initialize(name, hc);
20  return status;
21 }
22 
23 int InitUniformWeights::ioParamsFillGroup(enum ParamsIOFlag ioFlag) {
24  int status = InitWeights::ioParamsFillGroup(ioFlag);
25  ioParam_weightInit(ioFlag);
27  return status;
28 }
29 
30 void InitUniformWeights::ioParam_weightInit(enum ParamsIOFlag ioFlag) {
31  parent->parameters()->ioParamValue(ioFlag, name, "weightInit", &mWeightInit, mWeightInit);
32 }
33 
35  parent->parameters()->ioParamValue(
36  ioFlag,
37  name,
38  "connectOnlySameFeatures",
39  &mConnectOnlySameFeatures,
40  mConnectOnlySameFeatures);
41 }
42 
43 void InitUniformWeights::calcWeights(int patchIndex, int arborId) {
44  float *dataStart = mWeights->getDataFromDataIndex(arborId, patchIndex);
45  const int nfp = mWeights->getPatchSizeF();
46  const int kf = patchIndex % nfp;
47 
48  uniformWeights(dataStart, mWeightInit, kf, mConnectOnlySameFeatures);
49 }
50 
51 void InitUniformWeights::uniformWeights(
52  float *dataStart,
53  float weightInit,
54  int kf,
55  bool connectOnlySameFeatures) {
56  const int nxp = mWeights->getPatchSizeX();
57  const int nyp = mWeights->getPatchSizeY();
58  const int nfp = mWeights->getPatchSizeF();
59 
60  const int sxp = mWeights->getGeometry()->getPatchStrideX();
61  const int syp = mWeights->getGeometry()->getPatchStrideY();
62  const int sfp = mWeights->getGeometry()->getPatchStrideF();
63 
64  // loop over all post-synaptic cells in patch
65  for (int y = 0; y < nyp; y++) {
66  for (int x = 0; x < nxp; x++) {
67  for (int f = 0; f < nfp; f++) {
68  if ((connectOnlySameFeatures) and (kf != f)) {
69  dataStart[x * sxp + y * syp + f * sfp] = 0;
70  }
71  else {
72  dataStart[x * sxp + y * syp + f * sfp] = weightInit;
73  }
74  }
75  }
76  }
77 }
78 
79 } /* end namespace PV */
virtual void ioParam_weightInit(enum ParamsIOFlag ioFlag)
weightInit: The value of each weight.
int getPatchSizeX() const
Definition: Weights.hpp:219
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
virtual void ioParam_connectOnlySameFeatures(enum ParamsIOFlag ioFlag)
connectOnlySameFeatures: If this flag is set to false, all weights are set to the weightInit value...
float * getDataFromDataIndex(int arbor, int dataIndex)
Definition: Weights.cpp:200
int getPatchSizeY() const
Definition: Weights.hpp:222
std::shared_ptr< PatchGeometry > getGeometry() const
Definition: Weights.hpp:148
virtual void calcWeights()
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
Definition: InitWeights.cpp:39
int getPatchSizeF() const
Definition: Weights.hpp:225