feat(nn): migrate the relu layer
This commit is contained in:
@@ -160,6 +160,43 @@ private:
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class relu final : public layer_info {
|
||||||
|
template <typename Input, typename... Layers>
|
||||||
|
friend class network;
|
||||||
|
private:
|
||||||
|
template <class NN, std::size_t I>
|
||||||
|
struct inner final {
|
||||||
|
using input_type = typename input_type_s<NN, I>::type;
|
||||||
|
using output_type = input_type;
|
||||||
|
|
||||||
|
typename input_type::template with_storage<math::inline_storage_tag> retained;
|
||||||
|
|
||||||
|
struct gradient {
|
||||||
|
void reset() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
void dump(std::ostream& os) const {}
|
||||||
|
|
||||||
|
void load(std::istream& is) {}
|
||||||
|
|
||||||
|
template <typename Dist>
|
||||||
|
void fill_random(const Dist& dist) {}
|
||||||
|
|
||||||
|
template <typename Fwd>
|
||||||
|
auto feed(Fwd&& fwd) {
|
||||||
|
retained = std::forward<Fwd>(fwd);
|
||||||
|
return retained.apply([](auto in) { return in > 0.0 ? in : 0.0; });
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Error>
|
||||||
|
auto backward(gradient& grad, Error prevErr) const {
|
||||||
|
return prevErr.apply(retained, [](auto in, auto check) { return check > 0.0 ? in : 0.0; });
|
||||||
|
}
|
||||||
|
|
||||||
|
void apply_grad(gradient&, double, double) {}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace layers
|
} // namespace layers
|
||||||
} // namespace cenet
|
} // namespace cenet
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user