wbc
ActivationFunction.hpp
Go to the documentation of this file.
1#ifndef ACTIVATION_FUNCTION_HPP
2#define ACTIVATION_FUNCTION_HPP
3
4#include <base/Eigen.hpp>
5#include <stdexcept>
6
7namespace wbc{
8
21
23 double threshold;
25 base::VectorXd activation;
26
27 const base::VectorXd &compute(const base::VectorXd& values){
28
30 throw std::invalid_argument("ActivationFunction::compute: Threshold must be within [0..1]");
31
32 activation.resize(values.size());
33 activation.setZero();
34
35 for(uint i = 0; i < values.size(); i++){
36 switch(type){
37 case NO_ACTIVATION:
38 activation(i) = 1;
39 break;
40 case STEP_ACTIVATION:
41 if(fabs(values(i)) > threshold)
42 activation(i) = 1;
43 else
44 activation(i) = 0;
45 break;
47 if(values(i) < threshold)
48 activation(i) = (1.0/threshold) * values(i);
49 else
50 activation(i) = 1;
51 break;
53 if(values(i) < threshold)
54 activation(i) = (1.0/(threshold*threshold)) * (values(i)*values(i));
55 else
56 activation(i) = 1;
57 break;
59 if(values(i) < threshold)
60 activation(i) = values(i);
61 else
62 activation(i) = 1;
63
64 break;
65 default:{
66 std::stringstream s;
67 s << "Invalid activation type: " << type;
68 throw std::invalid_argument(s.str());
69 }
70 }
71 }
72 return activation;
73 }
74};
75
76}
77
78#endif
Definition ContactsAccelerationConstraint.cpp:3
activationType
Definition ActivationFunction.hpp:9
@ QUADRATIC_ACTIVATION
Definition ActivationFunction.hpp:12
@ STEP_ACTIVATION
Definition ActivationFunction.hpp:10
@ NO_ACTIVATION
Definition ActivationFunction.hpp:9
@ PROPORTIONAL_ACTIVATION
Definition ActivationFunction.hpp:13
@ LINEAR_ACTIVATION
Definition ActivationFunction.hpp:11
Definition ActivationFunction.hpp:17
const base::VectorXd & compute(const base::VectorXd &values)
Definition ActivationFunction.hpp:27
ActivationFunction()
Definition ActivationFunction.hpp:18
activationType type
Definition ActivationFunction.hpp:24
double threshold
Definition ActivationFunction.hpp:23
base::VectorXd activation
Definition ActivationFunction.hpp:25