This guide shows how to run the current MLP, edit experiments, and contribute new modules.
g++ or clang++)nvcc)Build commands and all CLI flags are in Quick Start and Main Options in the README.
Expected behavior:
For OpenMP, CUDA, and BLAS build commands and notes, see Backend Options in the README.
To validate the BLAS acceptance target from issue #4, run:
cmake -S . -B build-blas -DMLP_ENABLE_BLAS=ON
cmake --build build-blas
./build-blas/mlp_dense_benchmark --min-speedup 2.0
The default example is in src/main.cpp:
Sequential and layersBinaryCrossEntropy) and optimizer (SGD)Core module map:
include/layer.hpp: base layer APIinclude/dense.hpp + src/dense.cpp: dense layerinclude/activations.hpp + src/activations.cpp: activation layersinclude/loss.hpp + src/loss.cpp: loss functionsinclude/mlp/metrics.hpp + src/metrics.cpp: binary classification metricsinclude/optimizer.hpp + src/optimizer.cpp: optimizer logicinclude/model.hpp + src/model.cpp: sequential containerinclude/matrix.hpp: CPU matrix operationsinclude/cuda_ops.hpp + src/cuda_ops.cu: CUDA backend operationstests/test_helpers.hpp: shared matrix/vector assertions for testsFor fast tests, use CLI:
./build/mlp --hidden 8
./build/mlp --hidden 16,16
./build/mlp --hidden 64,32,16
Typical changes:
8 -> 16/32/64)--hiddensrc/main.cpp if you want different activation policiesFrom CLI:
--epochs--lr--thresholdSuggested sweeps:
0.01, 0.05, 0.1, 0.51000, 5000, 10000Current data is generated programmatically with --samples and random --seed.
Split control:
--train-ratio--val-ratio1 - train - valTo use your own dataset, replace the generator in main.cpp and keep:
x.size() == y.size()Dense input size = number of featuresinclude/activations.hpp inheriting Layer.forward and backward in src/activations.cpp.tests/test_activations.cpp, and use tests/gradient_check.hpp when a finite-difference backward-pass check is appropriate.src/main.cpp.include/loss.hpp inheriting Loss.forward and backward in src/loss.cpp.tests/test_loss.cpp.BinaryCrossEntropy usage in src/main.cpp.include/optimizer.hpp.src/optimizer.cpp.src/optimizer.cpp instead of duplicating matrix/vector loops.tests/test_experiment.cpp when the optimizer should be available through run_xor_experiment.See Optimizers Included in the README for the full list and CLI strings.
Use LambdaOptimizer with custom matrix/vector update rules:
LambdaOptimizer optimizer(
[](Matrix ¶m, const Matrix &grad, std::size_t) {
const double lr = 0.1;
for (std::size_t i = 0; i < rows(param); ++i) {
for (std::size_t j = 0; j < cols(param); ++j) {
param[i][j] -= lr * grad[i][j];
}
}
},
[](Vector ¶m, const Vector &grad, std::size_t) {
const double lr = 0.1;
for (std::size_t i = 0; i < param.size(); ++i) {
param[i] -= lr * grad[i];
}
});
The code reports:
Use --threshold to control classification cutoff for binary metrics.
nan:
std::invalid_argument from matrix or layer code:
Matrix row has the same column count.std::logic_error from backward():
forward(...) on the same layer/loss instance before calling backward(...).MLPSEQv1.The full phased roadmap with links to GitHub issues is in ROADMAP.md at the repository root.
README.md and this tutorial.ctest --test-dir build --output-on-failure before opening a pull request.ROADMAP.md and link the GitHub issue.The project now exposes mlp_lib and a public API in include/mlp/library.hpp.
Core entry point:
mlp::run_xor_experiment(const mlp::ExperimentOptions&, std::ostream* log_stream = nullptr, std::size_t log_every = 500)This lets you reuse training/evaluation logic in other C++ apps without relying on CLI execution.
Example app:
examples/library_usage.cppcmake --build build --target mlp_library_example./build/mlp_library_exampleModel persistence API:
include/mlp/io.hppmlp::save_sequential(...) and mlp::load_sequential(...)Roundtrip example:
examples/io_roundtrip.cppcmake --build build --target mlp_io_example./build/mlp_io_exampleFor install commands and find_package usage, see Install and find_package in the README.
For test commands and CI configuration details, see Testing and CI in the README.
CI now also includes an Ubuntu Valgrind memcheck job that runs the test suite with full leak checks and fails on definite leaks.
That includes the BLAS benchmark gate whenever a BLAS backend is detected/enabled.
The local test suite also includes mlp_test_activations for ReLU, Sigmoid, and Tanh forward/backward checks, mlp_test_loss for BinaryCrossEntropy forward/backward, clamp, and shape-mismatch coverage, and mlp_test_gradient_check for reusable finite-difference checks on Dense and Tanh layers.
Shared matrix/vector assertions live in tests/test_helpers.hpp; use them when adding new tests.