Advertisement
pasholnahuy

layer.h

Jan 17th, 2024
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "Threshold_Func.h"
  4. #include <Eigen/Dense>
  5. #include <EigenRand/EigenRand>
  6. #include <utility>
  7.  
  8. namespace network {
  9.  
  10. class Layer {
  11. public:
  12. using MatrixXd = Eigen::MatrixXd;
  13. using VectorXd = Eigen::VectorXd;
  14. Layer(Threshold_Id id, int rows, int columns);
  15.  
  16. MatrixXd apply(const MatrixXd &x) const; // vector of values
  17. MatrixXd derive(const MatrixXd &vec)
  18. const; // vec is a matrix of y_i = (Ax + b)_i - result of apply
  19.  
  20. MatrixXd gradA(const VectorXd &x, const VectorXd &u,
  21. const VectorXd &vec) const; // u is a gradient vector
  22.  
  23. MatrixXd gradb(const VectorXd &u, const VectorXd &vec) const;
  24.  
  25. VectorXd gradx(const VectorXd &u, const VectorXd &vec) const;
  26.  
  27. void apply_gradA(const MatrixXd &grad, double step);
  28.  
  29. void apply_gradb(const VectorXd &grad, double step);
  30.  
  31. private:
  32. static MatrixXd getNormal(int rows, int columns);
  33. static inline Eigen::Rand::Vmt19937_64 urng = 1;
  34. Threshold_Func threshold_func_;
  35. MatrixXd A_;
  36. MatrixXd b_;
  37. };
  38. } // namespace network
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement