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

Namespaces

namespace  detail
 

Classes

struct  ActivationParameters
 Hyperparameters for activations. More...
 

Enumerations

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

Functions

const char * to_string (Activation a) noexcept
 Convert Activation to canonical lower-case string.
 
bool try_parse (std::string_view s, Activation &out) noexcept
 Parse a string into an Activation.
 

Variables

constexpr double kDefaultLeakyAlpha = 0.01
 Default slope for LeakyReLU negative side (matches LLD_FLEXNN §4, v0.1).
 

Enumeration Type Documentation

◆ Activation

enum class FlexNN::Activations::Activation : uint8_t
strong

Activation function identifier.

Values are stable on-wire (model.bin) — do not reorder. 0 is linear (pre-BatchNorm or debugging). LeakyReLU alpha is configurable per-layer via ActivationParameters (default 0.01, see ActivationParameters.hpp); model.bin v2 stores it as 1 float32 in aux when act==LeakyReLU.

Enumerator
None 

Linear, no activation.

ReLU 

max(0, z)

LeakyReLU 

z>0 ? z : alpha*z (alpha from ActivationParameters)

Sigmoid 

1/(1+exp(-z)), clamped

Tanh 

std::tanh(z)

Softmax 

Stable col-wise softmax — only on last layer in v0.1.

Function Documentation

◆ to_string()

const char * FlexNN::Activations::to_string ( Activation  a)
noexcept

Convert Activation to canonical lower-case string.

Parameters
aActivation value
Returns
Non-owning C-string (e.g., "relu", "leaky_relu"). Returns "none" for unknown values (should be unreachable — all 6 values are covered).

◆ try_parse()

bool FlexNN::Activations::try_parse ( std::string_view  s,
Activation &  out 
)
noexcept

Parse a string into an Activation.

Case-insensitive, trims ASCII whitespace. Accepts canonical names ("relu", "leaky_relu", "leakyrelu", "sigmoid", "tanh", "softmax", "none") and common aliases ("leaky-relu", "lrelu", "linear" for None). Returns false on unknown input without throwing — caller decides whether to treat as None or error.

Note
noexcept: heap allocation for lowercasing may throw bad_alloc and terminate via std::terminate (acceptable for host training; tests use small strings).
Parameters
sInput view (not null-terminated required)
outOutput activation on success
Returns
true if parsed, false otherwise (out unchanged on false)

Variable Documentation

◆ kDefaultLeakyAlpha

constexpr double FlexNN::Activations::kDefaultLeakyAlpha = 0.01
inlineconstexpr

Default slope for LeakyReLU negative side (matches LLD_FLEXNN §4, v0.1).