8 #include "FirmThresholdCostFnProbe.hpp" 9 #include "columns/HyPerCol.hpp" 10 #include "layers/ANNLayer.hpp" 14 FirmThresholdCostFnProbe::FirmThresholdCostFnProbe() : AbstractNormProbe() { initialize_base(); }
16 FirmThresholdCostFnProbe::FirmThresholdCostFnProbe(
const char *name, HyPerCol *hc)
17 : AbstractNormProbe() {
22 int FirmThresholdCostFnProbe::initialize_base() {
28 FirmThresholdCostFnProbe::~FirmThresholdCostFnProbe() {}
30 int FirmThresholdCostFnProbe::initialize(
const char *name, HyPerCol *hc) {
31 return AbstractNormProbe::initialize(name, hc);
42 parent->parameters()->ioParamValue(
43 ioFlag, name,
"VThresh", &VThresh, VThresh ,
false );
47 parent->parameters()->ioParamValue(
48 ioFlag, name,
"VWidth", &VWidth, VWidth ,
false );
56 std::shared_ptr<CommunicateInitInfoMessage const> message) {
62 if (targetANNLayer !=
nullptr) {
63 if (!parent->parameters()->
present(getName(),
"VThresh")) {
64 VThresh = targetANNLayer->getVThresh();
66 if (!parent->parameters()->
present(getName(),
"VWidth")) {
67 VWidth = targetANNLayer->getVWidth();
73 parent->parameters()->ioParamValue(
74 PARAMS_IO_READ, name,
"VThresh", &VThresh, VThresh ,
true );
75 parent->parameters()->ioParamValue(
76 PARAMS_IO_READ, name,
"VThresh", &VThresh, VThresh ,
true );
78 return Response::SUCCESS;
82 if (index < 0 || index >= parent->getNBatch()) {
85 PVLayerLoc const *loc = getTargetLayer()->getLayerLoc();
86 int const nx = loc->nx;
87 int const ny = loc->ny;
88 int const nf = loc->nf;
89 PVHalo const *halo = &loc->halo;
90 int const lt = halo->lt;
91 int const rt = halo->rt;
92 int const dn = halo->dn;
93 int const up = halo->up;
95 double VThreshPlusVWidth = VThresh + VWidth;
96 double amax = 0.5 * VThreshPlusVWidth;
97 double a2 = 0.5 / VThreshPlusVWidth;
98 float const *aBuffer =
99 getTargetLayer()->
getLayerData() + index * getTargetLayer()->getNumExtended();
103 PVHalo const *maskHalo = &maskLoc->halo;
104 float const *maskLayerData =
109 int const maskLt = maskHalo->lt;
110 int const maskRt = maskHalo->rt;
111 int const maskDn = maskHalo->dn;
112 int const maskUp = maskHalo->up;
114 assert(getTargetLayer()->getNumNeurons() == nx * ny * nf);
116 #ifdef PV_USE_OPENMP_THREADS 117 #pragma omp parallel for reduction(+ : sum) 118 #endif // PV_USE_OPENMP_THREADS 119 for (
int kxy = 0; kxy < nxy; kxy++) {
120 int kexMask = kIndexExtended(kxy, nx, ny, 1, maskLt, maskRt, maskDn, maskUp);
121 if (maskLayerData[kexMask] == 0) {
124 int featureBase = kxy * nf;
125 for (
int f = 0; f < nf; f++) {
126 int kex = kIndexExtended(featureBase++, nx, ny, nf, lt, rt, dn, up);
127 double a = (double)fabs(aBuffer[kex]);
128 if (a >= VThreshPlusVWidth) {
132 sum += a * (1.0 - a2 * a);
138 #ifdef PV_USE_OPENMP_THREADS 139 #pragma omp parallel for reduction(+ : sum) 140 #endif // PV_USE_OPENMP_THREADS 141 for (
int k = 0; k < getTargetLayer()->getNumNeurons(); k++) {
142 int kex = kIndexExtended(k, nx, ny, nf, lt, rt, dn, up);
143 double a = (double)fabs(aBuffer[kex]);
147 int kexMask = kIndexExtended(k, nx, ny, nf, maskLt, maskRt, maskDn, maskUp);
148 if (maskLayerData[kexMask] == 0) {
151 if (a >= VThreshPlusVWidth) {
155 sum += a * (1.0 - a2 * a);
161 if (getTargetLayer()->getSparseFlag()) {
163 long int numActive = cube.numActive[index];
164 int numItems = cube.numItems / cube.loc.nbatch;
167 #ifdef PV_USE_OPENMP_THREADS 168 #pragma omp parallel for reduction(+ : sum) 169 #endif // PV_USE_OPENMP_THREADS 170 for (
int k = 0; k < numActive; k++) {
171 int extIndex = activeList[k].index;
172 int inRestricted = !extendedIndexInBorderRegion(
173 extIndex, nx, ny, nf, halo->lt, halo->rt, halo->dn, halo->up);
174 double a = inRestricted * (double)fabs(aBuffer[extIndex]);
175 if (a >= VThreshPlusVWidth) {
179 sum += a * (1.0 - a2 * a);
184 #ifdef PV_USE_OPENMP_THREADS 185 #pragma omp parallel for reduction(+ : sum) 186 #endif // PV_USE_OPENMP_THREADS 187 for (
int k = 0; k < getTargetLayer()->getNumNeurons(); k++) {
188 int kex = kIndexExtended(k, nx, ny, nf, lt, rt, dn, up);
189 double a = (double)fabs(aBuffer[kex]);
193 if (a >= VThreshPlusVWidth) {
197 sum += a * (1.0 - a2 * a);
virtual int setNormDescription() override
virtual void ioParam_VThresh(enum ParamsIOFlag ioFlag)
VThresh: The threshold where the transfer function returns 0 if |V|<VThresh. If the target layer is a...
virtual Response::Status communicateInitInfo(std::shared_ptr< CommunicateInitInfoMessage const > message) override
virtual void ioParam_VWidth(enum ParamsIOFlag ioFlag)
VWidth: The width of the interval over which the transfer function changes from hard to soft threshol...
int present(const char *groupName, const char *paramName)
PVLayerCube createCube(int delay=0)
virtual double getValueInternal(double timevalue, int index) override
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
HyPerLayer * getMaskLayer()
static bool completed(Status &a)
int setNormDescriptionToString(char const *s)
virtual Response::Status communicateInitInfo(std::shared_ptr< CommunicateInitInfoMessage const > message) override
bool maskHasSingleFeature()
const float * getLayerData(int delay=0)