-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
79 lines (62 loc) · 1.51 KB
/
test.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <string>
#include <vector>
#include <Eigen/Dense>
using namespace std;
using namespace Eigen;
double DReLU(double x)
{
if (x > 0.0){
return 1;
}
else{
return 0;
}
}
MatrixXd ReLU(MatrixXd X)
{
MatrixXd X_DReLU = X.unaryExpr(&DReLU);
MatrixXd res = X.cwiseProduct(X_DReLU);
// MatrixXd res = X_DReLU.array() * X.array();
// res = res.array().abs();
return res.cwiseAbs();
}
MatrixXd Softmax(MatrixXd X)
{
MatrixXd res(X.rows(), X.cols());
MatrixXd X_e = X.array().exp();
cout << X_e << endl;
VectorXd X_sum= X_e.rowwise().sum();
cout << X_sum << endl;
for (int i = 0; i < X.rows(); i++)
{
res.row(i) = X_e.row(i)/X_sum(i,0);
}
return res;
}
int main()
{
cout << "Working " << endl;
MatrixXd X = MatrixXd::Random(3,3);
cout << X << endl;
MatrixXd Y = MatrixXd::Random(3,3);
cout << Y << endl;
MatrixXd Z = X- Y;
cout << Z << endl;
// VectorXi argmax(X.rows());
// cout << argmax.rows() << "," << argmax.cols() << endl;
// for (int i = 0; i < X.rows(); i++){
// // cout << i << endl;
// X.row(i).maxCoeff(&argmax[i]);
// }
// cout << argmax << endl;
// MatrixXd X_log = X.array().log();
// cout << X_log << endl;
// MatrixXd X_mult = X.cwiseProduct(X_log);
// cout << X_mult.sum() << endl;
// MatrixXd X_R = ReLU(X);
// cout << X_R << endl;
// MatrixXd X_S = Softmax(X);
// cout << X_S<< endl;
return 0;
}