Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leaky ReLU #357

Merged
merged 6 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ Changelog
New
~~~

- Implement ``ReLU`` and its derivative in the expression
system (`#356 <https://github.com/bluescarni/heyoka/pull/356>`__).
- Implement (leaky) ``ReLU`` and its derivative in the expression
system (`#357 <https://github.com/bluescarni/heyoka/pull/357>`__,
`#356 <https://github.com/bluescarni/heyoka/pull/356>`__).
- Add feed-forward neural network model
(`#355 <https://github.com/bluescarni/heyoka/pull/355>`__).
- Implement the eccentric longitude :math:`F` in the expression
system (`#352 <https://github.com/bluescarni/heyoka/pull/352>`__).
- Implement the delta eccentric anomaly :math:`\Delta E` in the expression
Expand Down
41 changes: 37 additions & 4 deletions include/heyoka/math/relu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define HEYOKA_MATH_RELU_HPP

#include <cstdint>
#include <sstream>
#include <vector>

#include <heyoka/config.hpp>
Expand All @@ -26,16 +27,23 @@ namespace detail

class HEYOKA_DLL_PUBLIC relu_impl : public func_base
{
double m_slope;

friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive &ar, unsigned)
{
ar &boost::serialization::base_object<func_base>(*this);
ar & m_slope;
}

public:
relu_impl();
explicit relu_impl(expression);
explicit relu_impl(expression, double);

[[nodiscard]] double get_slope() const noexcept;

void to_stream(std::ostringstream &) const;

[[nodiscard]] expression normalise() const;

Expand All @@ -55,16 +63,23 @@ class HEYOKA_DLL_PUBLIC relu_impl : public func_base

class HEYOKA_DLL_PUBLIC relup_impl : public func_base
{
double m_slope;

friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive &ar, unsigned)
{
ar &boost::serialization::base_object<func_base>(*this);
ar & m_slope;
}

public:
relup_impl();
explicit relup_impl(expression);
explicit relup_impl(expression, double);

[[nodiscard]] double get_slope() const noexcept;

void to_stream(std::ostringstream &) const;

[[nodiscard]] expression normalise() const;

Expand All @@ -84,9 +99,27 @@ class HEYOKA_DLL_PUBLIC relup_impl : public func_base

} // namespace detail

HEYOKA_DLL_PUBLIC expression relu(expression);
HEYOKA_DLL_PUBLIC expression relu(expression, double = 0);

HEYOKA_DLL_PUBLIC expression relup(expression, double = 0);

class HEYOKA_DLL_PUBLIC leaky_relu
{
double m_slope;

public:
explicit leaky_relu(double);
expression operator()(expression) const;
};

HEYOKA_DLL_PUBLIC expression relup(expression);
class HEYOKA_DLL_PUBLIC leaky_relup
{
double m_slope;

public:
explicit leaky_relup(double);
expression operator()(expression) const;
};

HEYOKA_END_NAMESPACE

Expand Down
2 changes: 2 additions & 0 deletions src/func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,8 @@ std::pair<std::string, std::vector<llvm::Type *>> llvm_c_eval_func_name_args(llv
std::uint32_t batch_size,
const std::vector<expression> &args)
{
assert(std::find(name.begin(), name.end(), '.') == name.end());

// Fetch the vector floating-point type.
auto *val_t = make_vector_type(fp_t, batch_size);

Expand Down
1 change: 0 additions & 1 deletion src/llvm_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <type_traits>
#include <utility>
#include <variant>
#include <vector>

#include <boost/algorithm/string/predicate.hpp>
#include <boost/numeric/conversion/cast.hpp>
Expand Down
Loading