|
FlexNN 1
Fully connected neural network built from scratch with flexible n-layer design and multiple activations.
|
Linear stack of heterogeneous layers (vector<Layers::Layer>). More...
#include <FlexNN.h>
Public Member Functions | |
| NeuralNetwork (const std::vector< Layers::Layer > &layers) | |
| Construct from new modular layers (preferred). | |
| NeuralNetwork (std::vector< Layers::Layer > &&layers) | |
| NeuralNetwork (const std::vector< Layer > &oldLayers) | |
Deprecated: construct from legacy FlexNN::Layer (Dense-only). | |
| void | train (const Eigen::MatrixXd &input, const Eigen::VectorXd &target, double learningRate, int epochs) |
| Train the network on (X, Y) with SGD. | |
| double | accuracy (const Eigen::MatrixXd &X, const Eigen::VectorXd &Y) |
| Accuracy on (X, Y) — argmax per column. | |
| Eigen::MatrixXd | predict (const Eigen::MatrixXd &input) |
| Predict — forward pass, returns activation of last layer. | |
| const std::vector< Layers::Layer > & | layers () const noexcept |
| Direct access to layers (for tests / ModelIO). | |
| std::vector< Layers::Layer > & | layers () noexcept |
Linear stack of heterogeneous layers (vector<Layers::Layer>).
Currently holds only Layers::Dense (PR-04). Later PRs expand the variant to Conv1D, BatchNorm1D, MaxPool1D, AvgPool1D without changing this header — only include/layers/Layer.hpp's variant list grows.
Old code NeuralNetwork({Layer(784,64,"relu"), Layer(64,10,"softmax")}) still compiles via the deprecated converting constructor that maps each legacy Layer to Layers::Dense via Activations::try_parse.
|
inline |
Construct from new modular layers (preferred).
| layers | Heterogeneous stack — each element is a Layers::Layer wrapping a concrete Dense/Conv1D/... Example: NeuralNetwork({Layers::Dense(784,64, Activations::ReLU)}) |
|
inline |
| FlexNN::NeuralNetwork::NeuralNetwork | ( | const std::vector< Layer > & | oldLayers | ) |
Deprecated: construct from legacy FlexNN::Layer (Dense-only).
Converts each legacy Layer (which stores std::string activationFunction and MatrixXd W/VectorXd b) to Layers::Dense via Activations::try_parse. On unknown activation string, uses Activation::None.
Kept so src/main.cpp (which still uses Layer(..., "relu")) builds until PR-09 migrates it to Layers::Dense. New code should not use this.
| double FlexNN::NeuralNetwork::accuracy | ( | const Eigen::MatrixXd & | X, |
| const Eigen::VectorXd & | Y | ||
| ) |
Accuracy on (X, Y) — argmax per column.
|
inlinenoexcept |
Direct access to layers (for tests / ModelIO).
|
inlinenoexcept |
|
inline |
Predict — forward pass, returns activation of last layer.
| void FlexNN::NeuralNetwork::train | ( | const Eigen::MatrixXd & | input, |
| const Eigen::VectorXd & | target, | ||
| double | learningRate, | ||
| int | epochs | ||
| ) |
Train the network on (X, Y) with SGD.
X is [features × batch] (see Utility.h), Y is label vector (converted to one-hot inside). Uses the interleaved forward layout [input, Z0,A0, Z1,A1, ...] and backward that fuses Softmax+CE as dZ_last = (A - Y)/m.