MCPcopy Create free account
hub / github.com/davisking/dlib / test_sigmoid

Function test_sigmoid

dlib/test/dnn.cpp:82–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80 }
81
82 void test_sigmoid()
83 {
84 using namespace dlib::tt;
85 print_spinner();
86 resizable_tensor src, dest, gradient_input;
87 src = matrix_cast<float>(gaussian_randm(5,5, 0));
88 dest = matrix_cast<float>(gaussian_randm(5,5, 1));
89 gradient_input = matrix_cast<float>(gaussian_randm(5,5, 2));
90
91
92
93 auto grad_src = [&](long idx) {
94 auto f = [&](float eps) {
95 const float old = src.host()[idx];
96 src.host()[idx] += eps;
97 sigmoid(dest, src);
98 float result = dot(gradient_input, dest);
99 src.host()[idx] = old;
100 return result;
101 };
102 const float eps = 0.01;
103 return (f(+eps)-f(-eps))/(2*eps);
104 };
105
106 resizable_tensor src_grad;
107 src_grad.copy_size(src);
108 src_grad = 0;
109
110 sigmoid(dest, src);
111 sigmoid_gradient(src_grad, dest, gradient_input);
112
113 auto grad_error = compare_gradients(src_grad, grad_src);
114 dlog << LINFO << "src error: " << grad_error;
115 DLIB_TEST(grad_error < 0.001);
116 }
117
118 void test_softmax()
119 {

Callers 1

run_testsMethod · 0.85

Calls 9

print_spinnerFunction · 0.85
gaussian_randmFunction · 0.85
compare_gradientsFunction · 0.85
copy_sizeMethod · 0.80
fFunction · 0.70
sigmoidFunction · 0.50
dotFunction · 0.50
sigmoid_gradientFunction · 0.50
hostMethod · 0.45

Tested by

no test coverage detected