-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlayer_dropconnect.cpp
More file actions
32 lines (28 loc) · 894 Bytes
/
layer_dropconnect.cpp
File metadata and controls
32 lines (28 loc) · 894 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
32
#include "layer_dropconnect.h"
void DropconnectLayer::feedforward(bool testing) {
if (!testing) {
m_dropconnect_mask = binomial(W.rows(), W.cols(), dropout_ratio);
m_dropped_weights = W.cwiseProduct(m_dropconnect_mask) * (1.0f/dropout_ratio);
Eigen::MatrixXf z1 = (X * m_dropped_weights).rowwise() + B.transpose();
Y = activation(z1);
} else {
Layer::feedforward(testing);
}
}
void DropconnectLayer::backpropagate() {
auto dy = dactivation(Y);
m_gradient = D.cwiseProduct(dy);
DW = X.transpose() * m_gradient;
DY = m_gradient * m_dropped_weights.transpose();
}
/*
Set current dropout rate
*/
void DropconnectLayer::preEpoch(const int epoch) {
Layer::preEpoch(epoch);
dropout_ratio = m_scenario.getKeepRate(epoch);
dropouts.push_back(dropout_ratio);
}
void DropconnectLayer::report() {
Layer::report();
}