Skip to content

Commit

Permalink
Add mish and softplus nonlinear functions
Browse files Browse the repository at this point in the history
  • Loading branch information
josephjaspers committed Nov 22, 2019
1 parent ac9f986 commit 87fa2f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions include/neural_networks/layers/Nonlinear.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ auto funcName(SystemTag system, BC::size_t inputs) {\
BC_NONLINEAR_DEF(Tanh, tanh)
BC_NONLINEAR_DEF(Logistic, logistic)
BC_NONLINEAR_DEF(Relu, relu)
BC_NONLINEAR_DEF(SoftPlus, softplus)
BC_NONLINEAR_DEF(Mish, mish)

#undef BC_NONLINEAR_DEF
}
Expand Down
10 changes: 7 additions & 3 deletions include/operations/CMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,13 @@ BLACKCAT_FUNCTOR_DEF(Logistic, logistic, (1 / (1 + std::exp(-x))),

BLACKCAT_FUNCTOR_DEF(Relu, relu, BC::traits::max(0, x), DERIVATIVE_DEF(x > 0 ? 1 : 0));
BLACKCAT_FUNCTOR_DEF(Logical, logical, x != 0 ? 1 : 0);



BLACKCAT_FUNCTOR_DEF(SoftPlus, softplus, std::log(1 + std::exp(x)), DERIVATIVE_DEF(Logistic::apply(x)))
BLACKCAT_FUNCTOR_DEF(Mish, mish,
x * std::tanh(SoftPlus::apply(x)),
DERIVATIVE_DEF(
std::exp(x)*
(4*(x+1) + 4*(std::exp(2*x)) + std::exp(3*x) + std::exp(x)*(4*x+6)) /
std::pow((2*std::exp(x) + std::exp(2*x) + 2),2)))

#undef BLACKCAT_FUNCTOR_DEF
#undef BLACKCAT_MATH_DEF
Expand Down

0 comments on commit 87fa2f4

Please sign in to comment.