|
FlexNN 1
Fully connected neural network built from scratch with flexible n-layer design and multiple activations.
|
Namespace for the FlexNN neural network library. More...
Namespaces | |
| namespace | Activations |
| namespace | Layers |
Classes | |
| struct | ExportOptions |
| Options for export (currently version). More... | |
| class | Layer |
| Represents a single layer in a neural network. More... | |
| struct | LayerHeader |
| struct | MainHeader |
| class | NeuralNetwork |
| Linear stack of heterogeneous layers (vector<Layers::Layer>). More... | |
| struct | Status |
| Result of export/import. More... | |
Functions | |
| Status | exportModel (const NeuralNetwork &net, const std::string &path, ExportOptions opts={}) |
Export a trained NeuralNetwork to flat binary model.bin. | |
| Status | importModel (NeuralNetwork &net, const std::string &path) |
Import a flat binary model.bin into a NeuralNetwork. | |
| Eigen::MatrixXd | oneHotEncode (const Eigen::VectorXd &Y, int num_classes) |
| One-hot encodes a vector of class labels. | |
| void | readCSV_XY (const std::string &filename, Eigen::MatrixXd &X, Eigen::VectorXd &Y) |
| Reads a CSV where first column is label, rest are features. | |
| void | setRandomSeed (uint32_t seed) |
Set the global RNG seed for splitXY (deterministic splits). | |
| uint32_t | getRandomSeed () noexcept |
| Get the current global RNG seed. | |
| std::vector< std::pair< Eigen::MatrixXd, Eigen::VectorXd > > | splitXY (const Eigen::MatrixXd &X, const Eigen::VectorXd &Y, const std::vector< double > &proportions) |
| Splits dataset into multiple sets by proportions (uses global seed). | |
| std::vector< std::pair< Eigen::MatrixXd, Eigen::VectorXd > > | splitXY (const Eigen::MatrixXd &X, const Eigen::VectorXd &Y, const std::vector< double > &proportions, uint32_t seed) |
| Splits dataset with explicit seed (deterministic, no global state). | |
Namespace for the FlexNN neural network library.
This namespace contains all the classes and functions related to the FlexNN library, including the NeuralNetwork class and Layer class. It provides a structured way to organize the library's components and avoid naming conflicts with other libraries.
| Status FlexNN::exportModel | ( | const NeuralNetwork & | net, |
| const std::string & | path, | ||
| ExportOptions | opts = {} |
||
| ) |
Export a trained NeuralNetwork to flat binary model.bin.
Validates each layer (e.g., Conv1D dilation==1, Softmax only on last layer, unknown DType, LeakyReLU alpha in (0,1)) and returns Status::Err on impossible export without writing. Otherwise writes main header (20B) + N*52B LayerHeaders + blobs (float32 LE, row-major) + file CRC32 and returns Ok. v2 writes ActivationParameters for LeakyReLU as aux.
| net | Network to export (weights are double, cast to float32) |
| path | Destination file (truncated if exists) |
| opts | Export options (formatVersion 1 or 2) |
|
noexcept |
Get the current global RNG seed.
random_device once) | Status FlexNN::importModel | ( | NeuralNetwork & | net, |
| const std::string & | path | ||
| ) |
Import a flat binary model.bin into a NeuralNetwork.
Validates magic, version, header_len, layer_count, header/file CRC32, offsets, and per-type counts. Reconstructs Layers::Dense / Conv1D with the same activation and float32 blobs cast back to double.
| net | Output network (overwritten on success, unchanged on failure) |
| path | Source file |
| Eigen::MatrixXd FlexNN::oneHotEncode | ( | const Eigen::VectorXd & | Y, |
| int | num_classes | ||
| ) |
One-hot encodes a vector of class labels.
| Y | Input vector of class labels (size = batch) |
| num_classes | Number of unique classes |
| void FlexNN::readCSV_XY | ( | const std::string & | filename, |
| Eigen::MatrixXd & | X, | ||
| Eigen::VectorXd & | Y | ||
| ) |
Reads a CSV where first column is label, rest are features.
| filename | Path to CSV |
| X | Output features [samples × features] |
| Y | Output labels [samples] |
| void FlexNN::setRandomSeed | ( | uint32_t | seed | ) |
Set the global RNG seed for splitXY (deterministic splits).
Thread-safe (atomic). The thread_local engine is reseeded on next splitXY call without explicit seed. For per-call determinism, use splitXY(X,Y,props,seed) instead.
| seed | New seed |
| std::vector< std::pair< Eigen::MatrixXd, Eigen::VectorXd > > FlexNN::splitXY | ( | const Eigen::MatrixXd & | X, |
| const Eigen::VectorXd & | Y, | ||
| const std::vector< double > & | proportions | ||
| ) |
Splits dataset into multiple sets by proportions (uses global seed).
Shuffles indices via a thread_local mt19937 seeded from the global getRandomSeed() (or random_device on first call). For reproducibility, call setRandomSeed(42) before splitXY, or use the overload with explicit seed.
| X | Features [samples × features] |
| Y | Labels [samples] |
| proportions | Split fractions (sum ≤1, last is remainder) |
| std::vector< std::pair< Eigen::MatrixXd, Eigen::VectorXd > > FlexNN::splitXY | ( | const Eigen::MatrixXd & | X, |
| const Eigen::VectorXd & | Y, | ||
| const std::vector< double > & | proportions, | ||
| uint32_t | seed | ||
| ) |
Splits dataset with explicit seed (deterministic, no global state).
Uses a local mt19937(seed) so the global seed is unchanged. Prefer this in tests for hermetic determinism.
| X | Features [samples × features] |
| Y | Labels [samples] |
| proportions | Split fractions |
| seed | Explicit seed |