Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- auto forward(const T& inputs) const {
- auto out = (weights_ * inputs) + biases_;
- auto out_activated = activation_.f(out);
- using ResultType = typename Eigen::internal::remove_all<decltype(out)>::type;
- using Traits = typename Eigen::internal::traits<ResultType>;
- return FwdOutput<Eigen::Matrix<fp_t, Traits::RowsAtCompileTime, Traits::ColsAtCompileTime>> { out, out_activated };
- }
- template <typename Error, typename SelfOutUnactivated, typename LayerInputs>
- auto backProp(const Error& e, const SelfOutUnactivated& selfOut, const LayerInputs& inputs, fp_t learningRate) {
- auto delta = activation_.f_grad(selfOut).cwiseProduct(e);
- auto oldWeights = weights_;
- auto weightAdj = learningRate * delta * inputs.transpose();
- auto biasAdj = learningRate * delta;
- weights_ -= weightAdj;
- biases_ -= biasAdj;
- return std::make_tuple(delta, oldWeights.transpose());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement