FlexNN 1
Fully connected neural network built from scratch with flexible n-layer design and multiple activations.
Loading...
Searching...
No Matches
Activation.hpp File Reference

Public activation enum and helpers for FlexNN. More...

#include <cstdint>
#include <string_view>
#include <type_traits>
#include <Eigen/Dense>
#include "ActivationParameters.hpp"
Include dependency graph for Activation.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  FlexNN
 Namespace for the FlexNN neural network library.
 
namespace  FlexNN::Activations
 
namespace  FlexNN::Activations::detail
 

Enumerations

enum class  FlexNN::Activations::Activation : uint8_t {
  FlexNN::Activations::None = 0 , FlexNN::Activations::ReLU = 1 , FlexNN::Activations::LeakyReLU = 2 , FlexNN::Activations::Sigmoid = 3 ,
  FlexNN::Activations::Tanh = 4 , FlexNN::Activations::Softmax = 5
}
 Activation function identifier. More...
 

Functions

const char * FlexNN::Activations::to_string (Activation a) noexcept
 Convert Activation to canonical lower-case string.
 
bool FlexNN::Activations::try_parse (std::string_view s, Activation &out) noexcept
 Parse a string into an Activation.
 
Eigen::MatrixXd FlexNN::Activations::detail::forward (Activation act, const Eigen::MatrixXd &Z, const ActivationParameters &params=ActivationParameters{})
 Elementwise forward for a single activation.
 
Eigen::MatrixXd FlexNN::Activations::detail::backward (Activation act, const Eigen::MatrixXd &dA, const Eigen::MatrixXd &Z, const Eigen::MatrixXd &A, const ActivationParameters &params=ActivationParameters{}) noexcept
 Elementwise backward for a single activation (hidden layers).
 
Eigen::MatrixXd FlexNN::Activations::detail::softmax_forward (const Eigen::MatrixXd &Z)
 Stable column-wise softmax forward.
 
Eigen::MatrixXd FlexNN::Activations::detail::softmax_backward_hidden (const Eigen::MatrixXd &s, const Eigen::MatrixXd &upstream) noexcept
 Softmax hidden backward: dZ = J * upstream per column.
 

Detailed Description

Public activation enum and helpers for FlexNN.

Defines the type-safe FlexNN::Activations::Activation enum that replaces the old stringly-typed std::string activationFunction. The enum is 1 byte (uint8_t) so it maps directly to the model.bin flat binary (see LLD_FLEXNN §7 / Appendix A). Per-activation elementwise ops live in include/activations (e.g., ReLU.hpp) and are re-exported via FlexNN::Activations::detail for use by lib/layers.

Why this file exists:

  • Gives -Wswitch-enum exhaustiveness: adding a new Activation forces updates to every switch without a default branch.
  • No heap, no linear string compare in hot forward path.
  • Keeps the public enum separate from the per-activation math so tests can include a single header (Activation.hpp) without pulling all per-activation headers unless needed.