PetaVision  Alpha
L2ConnProbe.cpp
1 /*
2  * L2ConnProbe.cpp
3  *
4  * Created on: July 24th, 2015
5  * Author: Kendall Stewart
6  */
7 
8 #include "L2ConnProbe.hpp"
9 
10 namespace PV {
11 
12 L2ConnProbe::L2ConnProbe() {}
13 
14 L2ConnProbe::L2ConnProbe(const char *probename, HyPerCol *hc) : KernelProbe(probename, hc) {}
15 
16 L2ConnProbe::~L2ConnProbe() {}
17 
18 Response::Status L2ConnProbe::outputState(double timed) {
19  if (mOutputStreams.empty()) {
20  return Response::NO_ACTION;
21  }
22  Communicator *icComm = parent->getCommunicator();
23  const int rank = icComm->commRank();
24  assert(getTargetConn() != NULL);
25  int nxp = getTargetHyPerConn()->getPatchSizeX();
26  int nyp = getTargetHyPerConn()->getPatchSizeY();
27  int nfp = getTargetHyPerConn()->getPatchSizeF();
28  int patchSize = nxp * nyp * nfp;
29 
30  int arborID = getArbor();
31  int numKern = getTargetHyPerConn()->getNumDataPatches();
32 
33  if (numKern != getTargetHyPerConn()->getPre()->getLayerLoc()->nf) {
34  Fatal().printf(
35  "L2ConnProbe %s: L2ConnProbe only works for 1-to-many or "
36  "1-to-1 weights.\n",
37  name);
38  }
39 
40 #ifdef PV_USE_OPENMP_THREADS
41 #pragma omp parallel for schedule(guided)
42 #endif
43  for (int kernelIndex = 0; kernelIndex < numKern; ++kernelIndex) {
44  const float *wdata =
45  getTargetHyPerConn()->getWeightsDataStart(arborID) + patchSize * kernelIndex;
46 
47  float sumsq = 0;
48 
49  for (int f = 0; f < nfp; f++) {
50 
51  for (int y = 0; y < nyp; y++) {
52 
53  for (int x = 0; x < nxp; x++) {
54 
55  int k = kIndex(x, y, f, nxp, nyp, nfp);
56  float w = (float)wdata[k];
57  sumsq += w * w;
58  }
59  }
60  }
61  output(0) << "t=" << timed << ", f=" << kernelIndex << ", squaredL2=" << sumsq << "\n";
62  }
63 
64  return Response::SUCCESS;
65 }
66 
67 } // end namespace PV
PrintStream & output(int b)
Definition: BaseProbe.hpp:291
virtual Response::Status outputState(double timef) override
Definition: L2ConnProbe.cpp:18