micrograd 0.1.0
Small C implementation of micrograd
Loading...
Searching...
No Matches
MLP API

Multi-layer perceptron construction, evaluation, and parameters. More...

Data Structures

struct  mg_mlp
 Multi-layer perceptron model. More...
 

Functions

bool mg_mlp_init (mg_graph *g, mg_mlp *m, size_t n_in, const size_t *sizes, size_t n_sizes)
 Initialize an MLP model.
 
bool mg_mlp_call (mg_graph *g, mg_mlp *m, mg_value **x, mg_value **out)
 Evaluate an MLP model.
 
void mg_mlp_free (mg_mlp *m)
 Free memory owned by an MLP model.
 
size_t mg_mlp_param_count (const mg_mlp *m)
 Get the number of trainable parameters in an MLP model.
 
void mg_mlp_params (const mg_mlp *m, mg_value **out)
 Copy an MLP model's parameters into a flat array.
 

Detailed Description

Multi-layer perceptron construction, evaluation, and parameters.

Function Documentation

◆ mg_mlp_call()

bool mg_mlp_call ( mg_graph g,
mg_mlp m,
mg_value **  x,
mg_value **  out 
)

Evaluate an MLP model.

Calls each layer in the model sequentially.

Parameters
gGraph that owns any intermediate and output values.
mModel to evaluate.
xArray of input values.
outOutput array with enough entries for the final layer.
Returns
true on success, false on invalid input or allocation failure.

◆ mg_mlp_free()

void mg_mlp_free ( mg_mlp m)

Free memory owned by an MLP model.

Parameters
mModel to free.

◆ mg_mlp_init()

bool mg_mlp_init ( mg_graph g,
mg_mlp m,
size_t  n_in,
const size_t *  sizes,
size_t  n_sizes 
)

Initialize an MLP model.

Parameters
gGraph that owns the model's values.
mModel to initialize.
n_inNumber of input features.
sizesArray containing each layer's output size.
n_sizesNumber of entries in sizes.
Returns
true on success, false on allocation failure.

◆ mg_mlp_param_count()

size_t mg_mlp_param_count ( const mg_mlp m)

Get the number of trainable parameters in an MLP model.

Parameters
mModel to inspect.
Returns
Total number of parameters across all layers.

◆ mg_mlp_params()

void mg_mlp_params ( const mg_mlp m,
mg_value **  out 
)

Copy an MLP model's parameters into a flat array.

Parameters
mModel to inspect.
outOutput array with at least mg_mlp_param_count(m) entries.