-
Notifications
You must be signed in to change notification settings - Fork 1
/
custom_activation.cpp
42 lines (41 loc) · 1.26 KB
/
custom_activation.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
// *************************************************************
// Author: Abhirup Das
// Github: https://github.com/codebuddha
// LinkedIn: https://www.linkedin.com/in/abhirup-das-5a174212a/
// *************************************************************
#include <arrayfire.h>
#include <af/util.h>
#include <iostream>
#include "Layer.hpp"
af::array ReLU (const af::array &x)
{
af::array y = x;
y(af::where(y<0)) = 0;
return y;
}
af::array deriv_ReLU(const af::array &x)
{
af::array y = x;
y(af::where(y<0)) = 0;
y(af::where(y==0)) = 0.5;
y(af::where(y>0)) = 1.0;
return y;
}
int main()
{
auto &activs = Layer::activ_map;
float a[] = {-1, -0.5, 0, 0.5, 0, 1};
af::array input(5, a);
std::cout << "List of already included Activation functions:\n";
for(auto &i: activs)
{
std::cout << "Name: " << i.first <<"\n";
af_print(i.second.first(input));
}
std::cout << "Including custom ReLU activation in Layer::activ_map.\n";
Layer::setNewActivation(&ReLU, &deriv_ReLU, std::string("custom_ReLU"));
std::cout << "Updated Activations list.\n";
for(auto &i: activs)
std::cout << i.first << "\n";
std::cout << "Now it can be used like other included activation functions in 'Layer.hpp'\n";
}