-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathDropout.h
54 lines (43 loc) · 1.01 KB
/
Dropout.h
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef DROPOUT
#define DROPOUT
#include "tensor.h"
#include "MyLib.h"
using namespace std;
using namespace mshadow;
using namespace mshadow::expr;
using namespace mshadow::utils;
template<typename xpu>
inline void dropoutcol(Tensor<xpu, 2, dtype> w, dtype dropOut)
{
w = 1.0;
std::vector<int> indexes;
for (int i = 0; i < w.size(1); ++i)
indexes.push_back(i);
int dropNum = (int) (w.size(1) * dropOut);
for(int idx = 0; idx < w.size(0); idx++)
{
random_shuffle(indexes.begin(), indexes.end());
for(int idy = 0; idy < dropNum; idy++)
{
w[idx][indexes[idy]] = 0.0;
}
}
}
template<typename xpu>
inline void dropoutrow(Tensor<xpu, 2, dtype> w, dtype dropOut)
{
w = 1.0;
std::vector<int> indexes;
for (int i = 0; i < w.size(0); ++i)
indexes.push_back(i);
int dropNum = (int) (w.size(0) * dropOut);
for(int idx = 0; idx < w.size(1); idx++)
{
random_shuffle(indexes.begin(), indexes.end());
for(int idy = 0; idy < dropNum; idy++)
{
w[indexes[idy]][idx] = 0.0;
}
}
}
#endif