Aicraft
Skip to main content

Layers API

#include "aicraft/layers.h"

AcLayer

All layers share the AcLayer type:

typedef struct AcLayer {
AcTensor *weights;
AcTensor *bias;
AcTensor *(*forward)(struct AcLayer *, AcTensor *);
int type;
} AcLayer;

Dense (Fully Connected)

AcLayer *ac_dense(int in_features, int out_features, AcActivation act);
ParameterDescription
in_featuresInput dimension
out_featuresOutput dimension
actActivation: AC_RELU, AC_SIGMOID, AC_SOFTMAX, AC_NONE

Example

AcLayer *layer = ac_dense(784, 128, AC_RELU);
AcTensor *out = layer->forward(layer, input);

Sequential Forward

AcTensor *ac_forward_seq(AcLayer **layers, int n, AcTensor *input);

Pass input through a sequence of layers:

AcLayer *net[] = {
ac_dense(784, 128, AC_RELU),
ac_dense(128, 10, AC_SOFTMAX)
};
AcTensor *out = ac_forward_seq(net, 2, x);

Activation Functions

ActivationConstantFormula
ReLUAC_RELUmax(0, x)
SigmoidAC_SIGMOID1 / (1 + e⁻ˣ)
SoftmaxAC_SOFTMAXeˣⁱ / Σeˣʲ
NoneAC_NONEIdentity

Weight Initialisation

Weights are initialised using Kaiming (He) uniform initialisation by default. Biases are initialised to zero.