-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlayer_drop.cpp
More file actions
31 lines (27 loc) · 783 Bytes
/
layer_drop.cpp
File metadata and controls
31 lines (27 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "layer_drop.h"
void DropoutLayer::feedforward(bool testing) {
Layer::feedforward(testing);
if (!testing) {
dropout_mask = binomial(Y.rows(), Y.cols(), dropout_ratio);
Y = Y.cwiseProduct(dropout_mask);
} else {
Y = Y * (1.0 - m_scenario.averageDropout());
}
}
void DropoutLayer::backpropagate() {
m_gradient = D.cwiseProduct(dactivation(Y));
m_gradient = m_gradient.cwiseProduct(dropout_mask);
DW = X.transpose() * m_gradient;
DY = m_gradient * W.transpose();
}
/*
Set current dropout rate
*/
void DropoutLayer::preEpoch(const int epoch) {
Layer::preEpoch(epoch);
dropout_ratio = m_scenario.getKeepRate(epoch);
dropouts.push_back(dropout_ratio);
}
void DropoutLayer::report() {
Layer::report();
}