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

Neural network layer construction, evaluation, and parameters. More...

Data Structures

struct  mg_layer
 Layer of neurons in a neural network. More...
 

Functions

bool mg_layer_init (mg_graph *g, mg_layer *l, size_t n_in, size_t n_out, bool non_linear)
 Initialize a layer.
 
bool mg_layer_call (mg_graph *g, mg_layer *l, mg_value **x, mg_value **out)
 Evaluate a layer with the given input values.
 
void mg_layer_free (mg_layer *l)
 Free memory owned by a layer.
 
size_t mg_layer_param_count (const mg_layer *l)
 Get the number of trainable parameters in a layer.
 
void mg_layer_params (const mg_layer *l, mg_value **out)
 Copy a layer's parameters into a flat array.
 

Detailed Description

Neural network layer construction, evaluation, and parameters.

Function Documentation

◆ mg_layer_call()

bool mg_layer_call ( mg_graph g,
mg_layer l,
mg_value **  x,
mg_value **  out 
)

Evaluate a layer with the given input values.

Parameters
gGraph that owns any intermediate and output values.
lLayer to evaluate.
xArray of l->n_in input values.
outOutput array with at least l->n_out entries.
Returns
true on success, false on invalid input or allocation failure.

◆ mg_layer_free()

void mg_layer_free ( mg_layer l)

Free memory owned by a layer.

Parameters
lLayer to free.

◆ mg_layer_init()

bool mg_layer_init ( mg_graph g,
mg_layer l,
size_t  n_in,
size_t  n_out,
bool  non_linear 
)

Initialize a layer.

Parameters
gGraph that owns the layer's values.
lLayer to initialize.
n_inNumber of input values consumed by each neuron.
n_outNumber of output values produced by the layer.
non_linearWhether each neuron should use a non-linear activation function.
Returns
true on success, false on allocation failure.

◆ mg_layer_param_count()

size_t mg_layer_param_count ( const mg_layer l)

Get the number of trainable parameters in a layer.

Parameters
lLayer to inspect.
Returns
Total number of parameters across all neurons.

◆ mg_layer_params()

void mg_layer_params ( const mg_layer l,
mg_value **  out 
)

Copy a layer's parameters into a flat array.

Parameters
lLayer to inspect.
outOutput array with at least mg_layer_param_count(l) entries.