1 /**
2     Contains an implementation of dropout.
3 
4     Authors: Henry Gouk
5 */
6 module dopt.nnet.layers.dropout;
7 
8 import dopt.core;
9 import dopt.nnet;
10 import dopt.nnet.layers.util;
11 import dopt.online;
12 
13 ///
14 Layer dropout(Layer input, float dropProb)
15 {
16     import std.array : array;
17     import std.range : repeat;
18 
19     auto x = input.output;
20     auto xTr = input.trainOutput;
21     
22     auto dropMask = float32(xTr.shape, repeat(dropProb, xTr.volume).array());
23     auto yTr = uniformSample(xTr.shape).gt(dropMask) * xTr;
24 
25     auto scale = float32(x.shape, repeat((1.0f - dropProb), x.volume).array());
26     auto y = x * scale;
27 
28     return new Layer([input], y, yTr, null);
29 }