PetaVision  Alpha
DropoutLayer.cpp
1 #include "DropoutLayer.hpp"
2 
3 namespace PV {
4 
5 DropoutLayer::DropoutLayer(const char *name, HyPerCol *hc) { initialize(name, hc); }
6 
7 DropoutLayer::~DropoutLayer() {}
8 
9 int DropoutLayer::ioParamsFillGroup(enum ParamsIOFlag ioFlag) {
10  ioParam_probability(ioFlag);
11  return ANNLayer::ioParamsFillGroup(ioFlag);
12 }
13 
14 void DropoutLayer::ioParam_probability(enum ParamsIOFlag ioFlag) {
15  parent->parameters()->ioParamValue(
16  ioFlag, name, "probability", &mProbability, mProbability, true);
17  if (mProbability > 99) {
18  WarnLog() << getName() << ": probability was set to >= 100%. Changing to 99%.\n";
19  mProbability = 99;
20  }
21 }
22 
23 Response::Status DropoutLayer::updateState(double timestamp, double dt) {
24  ANNLayer::updateState(timestamp, dt);
25  float *A = getCLayer()->activity->data;
26  int total = getNumExtendedAllBatches();
27 
28 #ifdef PV_USE_OPENMP_THREADS
29 #pragma omp parallel for
30 #endif
31  for (int i = 0; i < total; ++i) {
32  if (rand() % 100 < mProbability) {
33  A[i] = 0.0f;
34  }
35  }
36 
37  return Response::SUCCESS;
38 }
39 }
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
Definition: DropoutLayer.cpp:9
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
Definition: ANNLayer.cpp:89