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

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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ NeuralNetwork() [1/3]

FlexNN::NeuralNetwork::NeuralNetwork ( const std::vector< Layers::Layer > &  layers)
inline

Construct from new modular layers (preferred).

Parameters
layersHeterogeneous stack — each element is a Layers::Layer wrapping a concrete Dense/Conv1D/... Example: NeuralNetwork({Layers::Dense(784,64, Activations::ReLU)})

◆ NeuralNetwork() [2/3]

FlexNN::NeuralNetwork::NeuralNetwork ( std::vector< Layers::Layer > &&  layers)
inline

◆ NeuralNetwork() [3/3]

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.

Member Function Documentation

◆ accuracy()

double FlexNN::NeuralNetwork::accuracy ( const Eigen::MatrixXd &  X,
const Eigen::VectorXd &  Y 
)

Accuracy on (X, Y) — argmax per column.

◆ layers() [1/2]

const std::vector< Layers::Layer > & FlexNN::NeuralNetwork::layers ( ) const
inlinenoexcept

Direct access to layers (for tests / ModelIO).

◆ layers() [2/2]

std::vector< Layers::Layer > & FlexNN::NeuralNetwork::layers ( )
inlinenoexcept

◆ predict()

Eigen::MatrixXd FlexNN::NeuralNetwork::predict ( const Eigen::MatrixXd &  input)
inline

Predict — forward pass, returns activation of last layer.

◆ train()

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.


The documentation for this class was generated from the following files: