Home /Modules/artificial-intelligence/README.md

README.md

artificial-intelligence/neural-nets/README.md · 83 line(s) · markdown

Neural Networks

Portable native neural-network API for SLeeLa, with a C ABI and a C++17 facade.

Public files

FilePurpose
neural_nets.hStable C declarations, status codes, configuration, and opaque network handle
neural_nets.cDependency-light CPU implementation
neural_nets.hppC++17 RAII interface
neural_nets.cppC++ facade implementation
xor_example.cDeterministic XOR learning example and regression check

Current capabilities

C example

#include "neural_nets.h"

size_t layers[] = { 2, 8, 1 };
slnn_network_config config = {
    SLNN_ABI_VERSION, 2, layers,
    SLNN_ACTIVATION_RELU, SLNN_ACTIVATION_LINEAR, 42
};
slnn_network *network = NULL;

if (slnn_network_create(&config, &network) == SLNN_OK) {
    double input[] = { 0.25, 0.75 };
    double output[1];
    if (slnn_network_predict(network, input, 2, output, 1) == SLNN_OK) {
        /* Consume output[0]. */
    }
}
slnn_network_destroy(network);

Build

Compile the C implementation as C11 and link the platform math library where required:

cc -std=c11 -O2 -c neural_nets.c -o neural_nets.o
c++ -std=c++17 -O2 -c neural_nets.cpp -o neural_nets_cpp.o

Link the C++ facade with the C object and the platform math library (often -lm on Unix-like systems).

XOR learning example

xor_example.c trains a seeded 2–4–1 sigmoid network on the four XOR samples using the public single-sample SGD API. It runs 5,000 epochs and checks that both expected-zero outputs are at most 0.20 and both expected-one outputs are at least 0.80. It prints all four predictions and exits nonzero if training or classification fails.

From the repository root, run the integrated test with:

make -C tests ai-neural-nets-xor

The same target is included in the native portability workflow for Linux, macOS, and Windows/MinGW-w64.

Contract and limitations