8 #include "L0NormProbe.hpp" 9 #include "columns/HyPerCol.hpp" 10 #include "layers/HyPerLayer.hpp" 14 L0NormProbe::L0NormProbe() : AbstractNormProbe() { initialize_base(); }
16 L0NormProbe::L0NormProbe(
const char *name, HyPerCol *hc) : AbstractNormProbe() {
21 L0NormProbe::~L0NormProbe() {}
23 int L0NormProbe::initialize(
const char *name, HyPerCol *hc) {
24 return AbstractNormProbe::initialize(name, hc);
34 parent->parameters()->ioParamValue(ioFlag, getName(),
"nnzThreshold", &nnzThreshold, (
float)0);
38 if (index < 0 || index >= parent->getNBatch()) {
41 PVLayerLoc const *loc = getTargetLayer()->getLayerLoc();
42 int const nx = loc->nx;
43 int const ny = loc->ny;
44 int const nf = loc->nf;
45 PVHalo const *halo = &loc->halo;
46 int const lt = halo->lt;
47 int const rt = halo->rt;
48 int const dn = halo->dn;
49 int const up = halo->up;
51 float const *aBuffer =
52 getTargetLayer()->
getLayerData() + index * getTargetLayer()->getNumExtended();
56 PVHalo const *maskHalo = &maskLoc->halo;
57 float const *maskLayerData =
62 int const maskLt = maskHalo->lt;
63 int const maskRt = maskHalo->rt;
64 int const maskDn = maskHalo->dn;
65 int const maskUp = maskHalo->up;
67 assert(getTargetLayer()->getNumNeurons() == nx * ny * nf);
69 #ifdef PV_USE_OPENMP_THREADS 70 #pragma omp parallel for reduction(+ : sum) 71 #endif // PV_USE_OPENMP_THREADS 72 for (
int kxy = 0; kxy < nxy; kxy++) {
73 int kexMask = kIndexExtended(kxy, nx, ny, 1, maskLt, maskRt, maskDn, maskUp);
74 if (maskLayerData[kexMask]) {
75 int featureBase = kxy * nf;
76 for (
int f = 0; f < nf; f++) {
77 int kex = kIndexExtended(featureBase++, nx, ny, nf, lt, rt, dn, up);
78 float val = fabsf(aBuffer[kex]);
79 sum += val > nnzThreshold;
85 #ifdef PV_USE_OPENMP_THREADS 86 #pragma omp parallel for reduction(+ : sum) 87 #endif // PV_USE_OPENMP_THREADS 88 for (
int k = 0; k < getTargetLayer()->getNumNeurons(); k++) {
89 int kex = kIndexExtended(k, nx, ny, nf, lt, rt, dn, up);
90 int kexMask = kIndexExtended(k, nx, ny, nf, maskLt, maskRt, maskDn, maskUp);
91 if (maskLayerData[kexMask]) {
92 float val = fabsf(aBuffer[kex]);
93 sum += val > nnzThreshold;
99 if (getTargetLayer()->getSparseFlag()) {
101 long int numActive = cube.numActive[index];
102 int numItems = cube.numItems / cube.loc.nbatch;
105 #ifdef PV_USE_OPENMP_THREADS 106 #pragma omp parallel for reduction(+ : sum) 107 #endif // PV_USE_OPENMP_THREADS 108 for (
int k = 0; k < numActive; k++) {
109 int extIndex = activeList[k].index;
110 int inRestricted = !extendedIndexInBorderRegion(
111 extIndex, nx, ny, nf, halo->lt, halo->rt, halo->dn, halo->up);
112 float val = inRestricted * fabsf(aBuffer[extIndex]);
113 sum += val > nnzThreshold;
117 #ifdef PV_USE_OPENMP_THREADS 118 #pragma omp parallel for reduction(+ : sum) 119 #endif // PV_USE_OPENMP_THREADS 120 for (
int k = 0; k < getTargetLayer()->getNumNeurons(); k++) {
121 int kex = kIndexExtended(k, nx, ny, nf, lt, rt, dn, up);
122 float val = fabsf(aBuffer[kex]);
123 sum += val > nnzThreshold;
virtual int setNormDescription() override
PVLayerCube createCube(int delay=0)
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
HyPerLayer * getMaskLayer()
int setNormDescriptionToString(char const *s)
virtual void ioParam_nnzThreshold(enum ParamsIOFlag ioFlag)
nnzThreshold: The threshold for computing the L0-norm. getValue(t, index) returns the number of targe...
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
bool maskHasSingleFeature()
virtual double getValueInternal(double timevalue, int index) override
const float * getLayerData(int delay=0)