10 #include "L1NormProbe.hpp" 11 #include "columns/HyPerCol.hpp" 12 #include "layers/HyPerLayer.hpp" 16 L1NormProbe::L1NormProbe() : AbstractNormProbe() { initialize_base(); }
18 L1NormProbe::L1NormProbe(
const char *name, HyPerCol *hc) : AbstractNormProbe() {
23 L1NormProbe::~L1NormProbe() {}
25 int L1NormProbe::initialize(
const char *name, HyPerCol *hc) {
26 return AbstractNormProbe::initialize(name, hc);
30 if (index < 0 || index >= parent->getNBatch()) {
33 PVLayerLoc const *loc = getTargetLayer()->getLayerLoc();
34 int const nx = loc->nx;
35 int const ny = loc->ny;
36 int const nf = loc->nf;
37 PVHalo const *halo = &loc->halo;
38 int const lt = halo->lt;
39 int const rt = halo->rt;
40 int const dn = halo->dn;
41 int const up = halo->up;
43 float const *aBuffer =
44 getTargetLayer()->
getLayerData() + index * getTargetLayer()->getNumExtended();
47 PVHalo const *maskHalo = &maskLoc->halo;
48 float const *maskLayerData =
53 int const maskLt = maskHalo->lt;
54 int const maskRt = maskHalo->rt;
55 int const maskDn = maskHalo->dn;
56 int const maskUp = maskHalo->up;
58 assert(getTargetLayer()->getNumNeurons() == nx * ny * nf);
60 #ifdef PV_USE_OPENMP_THREADS 61 #pragma omp parallel for reduction(+ : sum) 62 #endif // PV_USE_OPENMP_THREADS 63 for (
int kxy = 0; kxy < nxy; kxy++) {
64 int kexMask = kIndexExtended(kxy, nx, ny, 1, maskLt, maskRt, maskDn, maskUp);
65 if (maskLayerData[kexMask]) {
66 int featureBase = kxy * nf;
67 for (
int f = 0; f < nf; f++) {
68 int kex = kIndexExtended(featureBase++, nx, ny, nf, lt, rt, dn, up);
69 float val = aBuffer[kex];
70 sum += (double)std::fabs(val);
76 #ifdef PV_USE_OPENMP_THREADS 77 #pragma omp parallel for reduction(+ : sum) 78 #endif // PV_USE_OPENMP_THREADS 79 for (
int k = 0; k < getTargetLayer()->getNumNeurons(); k++) {
80 int kex = kIndexExtended(k, nx, ny, nf, lt, rt, dn, up);
81 int kexMask = kIndexExtended(k, nx, ny, nf, maskLt, maskRt, maskDn, maskUp);
82 if (maskLayerData[kexMask]) {
83 float val = aBuffer[kex];
84 sum += std::fabs((
double)val);
90 if (getTargetLayer()->getSparseFlag()) {
92 long int numActive = cube.numActive[index];
93 int numItems = cube.numItems / cube.loc.nbatch;
96 #ifdef PV_USE_OPENMP_THREADS 97 #pragma omp parallel for reduction(+ : sum) 98 #endif // PV_USE_OPENMP_THREADS 99 for (
int k = 0; k < numActive; k++) {
100 int extIndex = activeList[k].index;
101 int inRestricted = !extendedIndexInBorderRegion(
102 extIndex, nx, ny, nf, halo->lt, halo->rt, halo->dn, halo->up);
103 double val = inRestricted * (double)fabs(aBuffer[extIndex]);
108 #ifdef PV_USE_OPENMP_THREADS 109 #pragma omp parallel for reduction(+ : sum) 110 #endif // PV_USE_OPENMP_THREADS 111 for (
int k = 0; k < getTargetLayer()->getNumNeurons(); k++) {
112 int kex = kIndexExtended(k, nx, ny, nf, lt, rt, dn, up);
113 sum += (double)fabs(aBuffer[kex]);
PVLayerCube createCube(int delay=0)
HyPerLayer * getMaskLayer()
int setNormDescriptionToString(char const *s)
virtual double getValueInternal(double timevalue, int index) override
virtual int setNormDescription() override
bool maskHasSingleFeature()
const float * getLayerData(int delay=0)