Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ This is a numerical algorithms library providing digital signal processing (DSP)

- **numerical/**: Core implementation of algorithms organized by domain:
- `analysis/`: Signal analysis (FFT, PSD, DCT)
- `controllers/`: Control algorithms (PID controllers)
- `dynamics/`: Dynamics and modeling (Euler-Lagrange)
- `estimators/`: Estimation algorithms (Linear Regression, Yule-Walker)
- `windowing/`: Window functions for spectral analysis
- `control_analysis/`: Control system analysis (Frequency Response, Root Locus)
- `controllers/`: Control algorithms (PID, LQR, MPC)
- `dynamics/`: Dynamics and modeling (Euler-Lagrange, Newton-Euler)
- `estimators/`: Estimation algorithms
- `offline/`: Batch estimators (Linear Regression, Yule-Walker)
- `online/`: Streaming estimators (Recursive Least Squares)
- `filters/`: Digital filters (FIR, IIR, Kalman)
- `kinematics/`: Forward/inverse kinematics
- `math/`: Mathematical foundations (QNumber, Matrix, Complex, Trigonometric functions)
- `neural_network/`: Neural network components (layers, activations, optimizers)
- `solvers/`: Numerical solvers (Levinson-Durbin)
- `windowing/`: Window functions for signal processing
- `neural_network/`: Neural network components (layers, activations, losses, model)
- `optimization/`: General-purpose optimizers (Gradient Descent)
- `regularization/`: Regularization techniques (L1, L2)
- `solvers/`: Numerical solvers (Levinson-Durbin, Gaussian Elimination, DARE)
- **doc/**: Comprehensive documentation for each algorithm with mathematical background
- **embedded-infra-lib/**: Submodule containing infrastructure foundations and utilities for embedded systems

Expand Down Expand Up @@ -61,7 +67,7 @@ Place code here when it is:
- Estimators and solvers
- Neural network components
- Hardware-agnostic and reusable across projects
- Organized by domain (analysis, controllers, dynamics, filters, estimators, math, neural_network, solvers, windowing)
- Organized by domain (analysis, control_analysis, controllers, dynamics, estimators, filters, kinematics, math, neural_network, optimization, regularization, solvers)

### Documentation (`doc/`)

Expand Down Expand Up @@ -285,15 +291,18 @@ class Algorithm
- **INTERFACES**: Define interfaces (pure virtual classes) for testability and flexibility
- **NAMESPACE**: Use appropriate namespaces by domain:
- `analysis::` - Signal analysis algorithms
- `control_analysis::` - Control system analysis (Frequency Response, Root Locus)
- `controllers::` - Control system algorithms
- `dynamics::` - Dynamics and modeling algorithms
- `estimators::` - Estimation algorithms
- `filters::passive::` - Passive filters (FIR, IIR)
- `filters::active::` - Active filters (Kalman)
- `math::` - Mathematical utilities and functions
- `neural_network::` - Neural network components
- `optimization::` - General-purpose optimizers
- `regularization::` - Regularization techniques
- `solvers::` - Numerical solvers
- `windowing::` - Window functions
- `windowing::` - Window functions (under `analysis/windowing/`)
- **SELF-DOCUMENTING CODE**: Write clear, self-explanatory code with descriptive names
- **UNITS**: Be explicit about units (radians, Hz, samples, normalized) in variable names or comments
- **NUMERICAL TYPES**: Support multiple numeric representations:
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ Refer to the documentation to quickly integrate and utilize the library's signal

| Category | Description |
|--------------------------------------------------------------------|----------------------------------------------------------------------|
| [Analysis](doc/analysis/README.md) | FFT, Power Spectral Density, DCT, Root Locus |
| [Controllers](doc/controllers/README.md) | PID, LQR |
| [Analysis](doc/analysis/README.md) | FFT, Power Spectral Density, DCT, Window Functions |
| [Control Analysis](doc/control_analysis/README.md) | Frequency Response, Root Locus |
| [Controllers](doc/controllers/README.md) | PID, LQR, MPC |
| [Dynamics](doc/dynamics/README.md) | Euler-Lagrange, Newton-Euler, Recursive Newton-Euler, ABA |
Comment thread
gabrielfrasantos marked this conversation as resolved.
Resolved
| [Estimators](doc/estimators/README.md) | Linear Regression, Yule-Walker |
| [Estimators](doc/estimators/README.md) | Linear Regression, Yule-Walker (offline), Recursive Least Squares (online) |
| [Filters](doc/filters/README.md) | Kalman, Extended Kalman, Unscented Kalman, FIR, IIR |
| [Kinematics](doc/kinematics/README.md) | Forward Kinematics |
| [Neural Network](doc/neural_network/README.md) | Layers, activations, losses, optimizers, regularization |
| [Neural Network](doc/neural_network/README.md) | Layers, activations, losses, model |
| [Optimization](doc/optimization/README.md) | Gradient Descent |
| [Regularization](doc/regularization/README.md) | L1 (Lasso), L2 (Ridge) |
| [Solvers](doc/solvers/README.md) | Gaussian Elimination, Levinson-Durbin, Durand-Kerner, Cholesky, DARE |
| [Windowing](doc/windowing/README.md) | Rectangular, Hamming, Hann, Blackman |
| [Performance Optimization](doc/performance-optimization/README.md) | Compiler optimizations, SIMD |
Comment thread
gabrielfrasantos marked this conversation as resolved.
Resolved

Each category page lists its algorithms with a brief description and links to the detailed documentation.
Expand Down
11 changes: 9 additions & 2 deletions doc/analysis/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Analysis

Signal analysis algorithms for frequency-domain decomposition, spectral estimation, and system characterization.
Signal analysis algorithms for frequency-domain decomposition and spectral estimation.

## Algorithms

Expand All @@ -9,4 +9,11 @@ Signal analysis algorithms for frequency-domain decomposition, spectral estimati
| [Fast Fourier Transform](FastFourierTransform.md) | Efficient computation of the Discrete Fourier Transform using the Cooley-Tukey radix-2 algorithm |
| [Power Spectral Density](PowerDensitySpectrum.md) | Estimation of signal power distribution across frequencies using Welch's method |
| [Discrete Cosine Transform](DiscreteCosineTransform.md) | Real-valued frequency decomposition via cosine basis functions, computed through FFT |
| [Root Locus](RootLocus.md) | Closed-loop pole trajectory analysis as a function of loop gain |

## Sub-domains

| Sub-domain | Description |
|-------------------------------------|----------------------------------------------------------------------------------|
| [Windowing](../windowing/README.md) | Window functions (Rectangular, Hamming, Hanning, Blackman) for FFT preprocessing |

> **Note:** For control system analysis tools (Frequency Response, Root Locus), see [Control Analysis](../control_analysis/README.md).
10 changes: 10 additions & 0 deletions doc/control_analysis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Control Analysis

Control system analysis tools for characterizing dynamic systems and feedback loop behavior.

## Algorithms

| Algorithm | Description |
|--------------------------------------------|-------------------------------------------------------------------------------|
| [Frequency Response](FrequencyResponse.md) | Magnitude and phase response of digital filters across the frequency spectrum |
| [Root Locus](RootLocus.md) | Closed-loop pole trajectory analysis as a function of loop gain |
File renamed without changes.
8 changes: 7 additions & 1 deletion doc/estimators/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

Statistical estimation algorithms for fitting models to observed data and making predictions.

## Algorithms
## Offline Estimators (Batch)

| Algorithm | Description |
|------------------------------------------|-------------------------------------------------------------------------|
| [Linear Regression](LinearRegression.md) | Ordinary least-squares regression using the normal equation |
| [Yule-Walker](YuleWalker.md) | Autoregressive model parameter estimation via the Yule-Walker equations |

## Online Estimators (Streaming)

| Algorithm | Description |
|-----------------------------------------------------|--------------------------------------------------------------------------|
| [Recursive Least Squares](RecursiveLeastSquares.md) | Sample-by-sample parameter estimation with exponential forgetting factor |
6 changes: 3 additions & 3 deletions doc/neural_network/NeuralNetwork.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ graph LR
- **Dead neurons.** ReLU neurons that receive only negative inputs output zero forever. LeakyReLU mitigates this.
- **Fixed-point saturation.** In Q15/Q31, activations and gradients must stay within $[-1, 1)$. Scale inputs and learning rates accordingly.
- **Learning rate sensitivity.** Too high → divergence; too low → no progress. Start with $\eta = 0.01$ and adjust.
- **Overfitting.** Small embedded datasets are easily memorized. Apply [regularization](regularization/Regularization.md) (L2 weight decay).
- **Overfitting.** Small embedded datasets are easily memorized. Apply [regularization](../regularization/Regularization.md) (L2 weight decay).

## Variants & Generalizations

Expand Down Expand Up @@ -151,8 +151,8 @@ graph TD
| [Dense Layer](layer/Layer.md) | The fundamental building block; computes affine transformations |
| [Activation Functions](activation/Activation.md) | Introduce non-linearity after each layer |
| [Loss Functions](losses/Loss.md) | Define the training objective |
| [Optimizer](optimizer/Optimizer.md) | Drives parameter updates via gradient descent |
| [Regularization](regularization/Regularization.md) | Penalizes complexity to prevent overfitting |
| [Optimizer](../optimization/Optimizer.md) | Drives parameter updates via gradient descent |
| [Regularization](../regularization/Regularization.md) | Penalizes complexity to prevent overfitting |
| [Model](model/Model.md) | Composes layers into a trainable pipeline |
| [Linear Regression](../estimators/LinearRegression.md) | Special case: single layer, identity activation, MSE loss |

Expand Down
4 changes: 2 additions & 2 deletions doc/neural_network/README.md
Comment thread
gabrielfrasantos marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ Components for building, training, and evaluating feed-forward neural networks e
| [Layers](layer/Layer.md) | Dense (fully connected) layer with forward and backward pass |
| [Activation Functions](activation/Activation.md) | Non-linear element-wise transforms: ReLU, LeakyReLU, Sigmoid, Tanh, Softmax |
| [Loss Functions](losses/Loss.md) | Objective functions: MSE, MAE, Binary Cross-Entropy, Categorical Cross-Entropy |
| [Optimizers](optimizer/Optimizer.md) | Parameter update strategies: Gradient Descent |
| [Regularization](regularization/Regularization.md) | Complexity penalties: L1 (Lasso) and L2 (Ridge) |
| [Model](model/Model.md) | Variadic-template model composing layers, optimizer, and loss into a trainable pipeline |

> **See also:** [Optimization](../optimization/README.md) for optimizers (Gradient Descent) and [Regularization](../regularization/README.md) for weight penalties (L1, L2) — these are general-purpose domains used by neural networks and other algorithms.
2 changes: 1 addition & 1 deletion doc/neural_network/layer/Layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ graph TD
|-----------------------------------------------------------|----------------------------------------------------------------------------------------|
| [Activation Functions](../activation/Activation.md) | Applied element-wise after the affine transformation |
| [Model](../model/Model.md) | Chains multiple dense layers into a network |
| [Optimizer](../optimizer/Optimizer.md) | Updates $W$ and $b$ using the computed gradients |
| [Optimizer](../../optimization/Optimizer.md) | Updates $W$ and $b$ using the computed gradients |
| [Linear Regression](../../estimators/LinearRegression.md) | A dense layer with identity activation and MSE loss is equivalent to linear regression |

## References & Further Reading
Expand Down
4 changes: 2 additions & 2 deletions doc/neural_network/losses/Loss.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ graph TD
| Component | Relationship |
|-----------------------------------------------------------|------------------------------------------------------------------------------------------------------|
| [Activation Functions](../activation/Activation.md) | Output activation must match: Sigmoid ↔ BCE, Softmax ↔ CCE, identity ↔ MSE |
| [Optimizer](../optimizer/Optimizer.md) | Uses $\nabla \mathcal{L}$ to update parameters |
| [Regularization](../regularization/Regularization.md) | Adds a penalty term to the loss: $\mathcal{L}_{\text{total}} = \mathcal{L} + \lambda \Omega(\theta)$ |
| [Optimizer](../../optimization/Optimizer.md) | Uses $\nabla \mathcal{L}$ to update parameters |
| [Regularization](../../regularization/Regularization.md) | Adds a penalty term to the loss: $\mathcal{L}_{\text{total}} = \mathcal{L} + \lambda \Omega(\theta)$ |
| [Linear Regression](../../estimators/LinearRegression.md) | Solved analytically when the loss is MSE and the model is linear |

## References & Further Reading
Expand Down
6 changes: 3 additions & 3 deletions doc/neural_network/model/Model.md
Comment thread
gabrielfrasantos marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A **Model** composes a sequence of [dense layers](../layer/Layer.md) into a sing

1. Chains layers so the output of each feeds into the next (**forward pass**).
2. Propagates gradients backward through the chain (**backward pass**).
3. Flattens all layer parameters into a single vector for the [optimizer](../optimizer/Optimizer.md).
3. Flattens all layer parameters into a single vector for the [optimizer](../../optimization/Optimizer.md).
4. Verifies dimensional compatibility **at compile time** using variadic templates.

In this library, the Model is fully statically typed — layer dimensions, parameter counts, and memory footprints are all known at compile time, enabling zero-overhead abstraction on embedded targets.
Expand Down Expand Up @@ -144,8 +144,8 @@ graph TD
|-------------------------------------------------------|--------------------------------------------------------------------------------------------|
| [Dense Layer](../layer/Layer.md) | The Model is a sequence of layers stored in a `std::tuple` |
| [Loss Functions](../losses/Loss.md) | Measures prediction error; the Model delegates loss computation to a Loss object |
| [Optimizer](../optimizer/Optimizer.md) | Receives the flat parameter/gradient vectors from the Model and returns updated parameters |
| [Regularization](../regularization/Regularization.md) | Added to the loss before optimization |
| [Optimizer](../../optimization/Optimizer.md) | Receives the flat parameter/gradient vectors from the Model and returns updated parameters |
| [Regularization](../../regularization/Regularization.md) | Added to the loss before optimization |

## References & Further Reading

Expand Down
9 changes: 9 additions & 0 deletions doc/optimization/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Optimization

General-purpose optimization algorithms for parameter fitting, training, and control.

## Algorithms

| Algorithm | Description |
|----------------------------------|----------------------------------------------------------------|
| [Gradient Descent](Optimizer.md) | Iterative batch optimization via gradient-based weight updates |
9 changes: 9 additions & 0 deletions doc/regularization/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Regularization

General-purpose regularization techniques for preventing overfitting in parameter estimation and training.

## Algorithms

| Algorithm | Description |
|-------------------------------------|--------------------------------------------------|
| [Regularization](Regularization.md) | L1 (Lasso) and L2 (Ridge) weight penalty methods |
6 changes: 3 additions & 3 deletions doc/solvers/DurandKerner.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ After ~15–20 iterations the roots converge to $z \approx \{1, 2, 3\}$ (imagina
- **Leading coefficient must be non-zero.** The polynomial degree is determined by the first coefficient.
- **Complex arithmetic required.** This algorithm operates entirely in $\mathbb{C}$, so it is limited to floating-point types (`float`, `double`). Fixed-point types are not supported.
- **No convergence guarantee for all polynomials.** Wilkinson's polynomial and other pathological cases may require higher precision or alternative methods.
- **Root ordering.** Results are sorted by real part (ascending), which may not correspond to meaningful branch ordering in applications like [Root Locus](../analysis/RootLocus.md).
- **Root ordering.** Results are sorted by real part (ascending), which may not correspond to meaningful branch ordering in applications like [Root Locus](../control_analysis/RootLocus.md).

## Variants & Generalizations

Expand All @@ -90,7 +90,7 @@ After ~15–20 iterations the roots converge to $z \approx \{1, 2, 3\}$ (imagina

## Applications

- **Root locus analysis** — The [Root Locus](../analysis/RootLocus.md) algorithm calls Durand-Kerner at each gain step to find the closed-loop poles.
- **Root locus analysis** — The [Root Locus](../control_analysis/RootLocus.md) algorithm calls Durand-Kerner at each gain step to find the closed-loop poles.
- **Stability analysis** — Determining whether all roots of a characteristic polynomial lie inside the unit circle (discrete) or left half-plane (continuous).
- **Filter design** — Finding pole and zero locations of transfer functions.
- **Control system design** — Evaluating characteristic equations to check stability margins.
Expand All @@ -108,7 +108,7 @@ graph LR

| Algorithm | Relationship |
|------------------------------------------------|-------------------------------------------------------------------------------------------------------|
| [Root Locus](../analysis/RootLocus.md) | Primary consumer — calls Durand-Kerner to find characteristic polynomial roots at each gain step |
| [Root Locus](../control_analysis/RootLocus.md) | Primary consumer — calls Durand-Kerner to find characteristic polynomial roots at each gain step |
| [Gaussian Elimination](GaussianElimination.md) | Alternative approach: form the companion matrix and compute eigenvalues (requires a different solver) |

## References & Further Reading
Expand Down
Loading
Loading