Advertisement
Trainlover08

Untitled

Mar 25th, 2024
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. auto forward(const T& inputs) const {
  2.         auto out = (weights_ * inputs) + biases_;
  3.         auto out_activated = activation_.f(out);
  4.  
  5.         using ResultType = typename Eigen::internal::remove_all<decltype(out)>::type;
  6.         using Traits = typename Eigen::internal::traits<ResultType>;
  7.  
  8.         return FwdOutput<Eigen::Matrix<fp_t, Traits::RowsAtCompileTime, Traits::ColsAtCompileTime>> { out, out_activated };
  9.     }
  10.  
  11.     template <typename Error, typename SelfOutUnactivated, typename LayerInputs>
  12.     auto backProp(const Error& e, const SelfOutUnactivated& selfOut, const LayerInputs& inputs, fp_t learningRate) {
  13.         auto delta = activation_.f_grad(selfOut).cwiseProduct(e);
  14.         auto oldWeights = weights_;
  15.         auto weightAdj = learningRate * delta * inputs.transpose();
  16.         auto biasAdj = learningRate * delta;
  17.         weights_ -= weightAdj;
  18.         biases_ -= biasAdj;
  19.  
  20.         return std::make_tuple(delta, oldWeights.transpose());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement