solidc
Robust collection of general-purpose cross-platform C libraries and data structures designed for rapid and safe development in C
Loading...
Searching...
No Matches
ml.h
Go to the documentation of this file.
1
13#ifndef ML_H
14#define ML_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20#include "matrix.h"
21#include "vec.h"
22
23// Max layers for the fixed-size network
24#define ML_MAX_LAYERS 8
25
30typedef struct ML_Layer {
31 Mat4 weights; // Weights matrix (4x4)
32 Vec4 bias; // Bias vector (4)
33
34 // Cache for backpropagation
35 Vec4 input; // Input to this layer
36 Vec4 z; // Pre-activation output (Wx + b)
37 Vec4 output; // Post-activation output (Sigmoid(z))
38
39 // Gradients
40 Mat4 d_weights;
41 Vec4 d_bias;
42} ML_Layer;
43
48typedef struct ML_Network {
49 ML_Layer layers[ML_MAX_LAYERS];
50 int layer_count;
51 float learning_rate;
53
60void ml_init(ML_Network* net, int num_layers, float learning_rate);
61
68Vec4 ml_forward(ML_Network* net, Vec4 input);
69
77float ml_train_step(ML_Network* net, Vec4 input, Vec4 target);
78
79#ifdef __cplusplus
80}
81#endif
82
83#endif // ML_H
Matrix operations and mathematical utilities.
Vec4 ml_forward(ML_Network *net, Vec4 input)
Perform forward propagation.
Definition ml.c:47
float ml_train_step(ML_Network *net, Vec4 input, Vec4 target)
Train the network on a single sample.
Definition ml.c:74
void ml_init(ML_Network *net, int num_layers, float learning_rate)
Initialize a new network.
Definition ml.c:36
Represents a single fully connected layer 4 inputs -> 4 outputs.
Definition ml.h:30
A neural network composed of multiple layers.
Definition ml.h:48
A 4x4 matrix for 3D transformations.
4D vector storage type (16 bytes, naturally aligned).
Definition vec.h:75