PetaVision  Alpha
InitOneToOneWeightsWithDelays.cpp
1 /*
2  * InitOneToOneWeightsWithDelays.cpp
3  *
4  * Created on: Sep 20, 2013
5  * Author: wchavez
6  */
7 
8 #include "InitOneToOneWeightsWithDelays.hpp"
9 
10 namespace PV {
11 
12 InitOneToOneWeightsWithDelays::InitOneToOneWeightsWithDelays(char const *name, HyPerCol *hc) {
13  initialize(name, hc);
14 }
15 
16 InitOneToOneWeightsWithDelays::InitOneToOneWeightsWithDelays() {}
17 
18 InitOneToOneWeightsWithDelays::~InitOneToOneWeightsWithDelays() {}
19 
20 int InitOneToOneWeightsWithDelays::initialize(char const *name, HyPerCol *hc) {
21  int status = InitWeights::initialize(name, hc);
22  return status;
23 }
24 
25 void InitOneToOneWeightsWithDelays::calcWeights(int patchIndex, int arborId) {
26  float *dataStart = mWeights->getDataFromDataIndex(arborId, patchIndex);
27  createOneToOneConnectionWithDelays(dataStart, patchIndex, mWeightInit, arborId);
28 }
29 
30 void InitOneToOneWeightsWithDelays::createOneToOneConnectionWithDelays(
31  float *dataStart,
32  int dataPatchIndex,
33  float iWeight,
34  int arborId) {
35 
36  const int nArbors = mWeights->getNumArbors();
37  int unitCellIndex = dataIndexToUnitCellIndex(dataPatchIndex);
38 
39  int const nfp = mWeights->getPatchSizeF();
40  int const nyp = mWeights->getPatchSizeY();
41  int const nxp = mWeights->getPatchSizeX();
42 
43  int const sxp = mWeights->getGeometry()->getPatchStrideX();
44  int const syp = mWeights->getGeometry()->getPatchStrideY();
45  int const sfp = mWeights->getGeometry()->getPatchStrideF();
46 
47  // clear all weights in patch
48  memset(dataStart, 0, nxp * nyp * nfp);
49  // then set the center point of the patch for each feature
50  int x = (int)(nxp / 2);
51  int y = (int)(nyp / 2);
52  for (int f = 0; f < nfp; f++) {
53  dataStart[x * sxp + y * syp + f * sfp] = f == nArbors * unitCellIndex + arborId ? iWeight : 0;
54  }
55 }
56 
57 } /* namespace PV */
int getPatchSizeX() const
Definition: Weights.hpp:219
float * getDataFromDataIndex(int arbor, int dataIndex)
Definition: Weights.cpp:200
int getNumArbors() const
Definition: Weights.hpp:151
int getPatchSizeY() const
Definition: Weights.hpp:222
std::shared_ptr< PatchGeometry > getGeometry() const
Definition: Weights.hpp:148
virtual void calcWeights()
int getPatchSizeF() const
Definition: Weights.hpp:225