Advertisement
pasholnahuy

Untitled

Jan 17th, 2024
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. //
  2. // Created by Denis Ryapolov on 06.01.2024.
  3. //
  4.  
  5. #include "Threshold_Func.h"
  6.  
  7. namespace network {
  8. using VectorXd = Threshold_Func::VectorXd;
  9. using MatrixXd = Threshold_Func::MatrixXd;
  10.  
  11. Threshold_Func::Threshold_Func(FunctionType evaluate_0, FunctionType evaluate_1)
  12. : evaluate_0_(std::move(evaluate_0)), evaluate_1_(std::move(evaluate_1)) {}
  13.  
  14. Threshold_Func Threshold_Func::create(Threshold_Id threshold) {
  15. switch (threshold) {
  16. case Threshold_Id::Sigmoid:
  17. return Threshold_Func::create<Threshold_Id::Sigmoid>();
  18. case Threshold_Id::ReLu:
  19. return Threshold_Func::create<Threshold_Id::ReLu>();
  20. default:
  21. return Threshold_Func::create<Threshold_Id::Sigmoid>();
  22. }
  23. }
  24.  
  25. double Threshold_Func::evaluate_0(double x) const { return evaluate_0_(x); }
  26.  
  27. double Threshold_Func::evaluate_1(double x) const { return evaluate_1_(x); }
  28.  
  29. MatrixXd Threshold_Func::apply(const MatrixXd &mat) const {
  30. return mat.unaryExpr([this](double x) { return evaluate_0(x); });
  31. }
  32.  
  33. MatrixXd Threshold_Func::derive(const MatrixXd &mat) const {
  34. return mat.unaryExpr([this](double x) { return evaluate_1(x); });
  35. }
  36. } // namespace network
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement